1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;

pub use web_sys;

#[wasm_bindgen(module = "@discord/embedded-app-sdk")]
extern "C" {
    #[wasm_bindgen(extends=js_sys::Object)]
    pub type DiscordSDK;

    #[wasm_bindgen(constructor, catch)]
    pub fn new(clientId: &str) -> Result<DiscordSDK, JsValue>;

    #[wasm_bindgen(method, getter)]
    pub fn commands(this: &DiscordSDK) -> DiscordSDKCommands;

    #[wasm_bindgen(method, catch)]
    pub async fn ready(this: &DiscordSDK) -> Result<(), JsValue>;

    #[wasm_bindgen(method, catch)]
    pub async fn subscribe(this: &DiscordSDK, event: &str, f: &Closure<dyn FnMut(JsValue)>) -> Result<(), JsValue>;

    #[wasm_bindgen(method, catch)]
    pub async fn unsubscribe(this: &DiscordSDK, event: &str) -> Result<(), JsValue>;
}

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends=js_sys::Object)]
    pub type DiscordSDKCommands;

    #[wasm_bindgen(method, catch)]
    pub async fn authorize(this: &DiscordSDKCommands, args: JsValue) -> Result<JsValue, JsValue>;

    #[wasm_bindgen(method, catch)]
    pub async fn authenticate(this: &DiscordSDKCommands, args: JsValue) -> Result<JsValue, JsValue>;
}

#[macro_export]
macro_rules! console_debug {
    ($($t:tt)*) => {
        $crate::web_sys::console::debug_1(&format_args!($($t)*).to_string().into())
    }
}

#[macro_export]
macro_rules! console_log {
    ($($t:tt)*) => {
        $crate::web_sys::console::log_1(&format_args!($($t)*).to_string().into())
    }
}

#[macro_export]
macro_rules! console_warn {
    ($($t:tt)*) => {
        $crate::web_sys::console::warn_1(&format_args!($($t)*).to_string().into())
    }
}

#[macro_export]
macro_rules! console_error {
    ($($t:tt)*) => {
        $crate::web_sys::console::error_1(&format_args!($($t)*).to_string().into())
    }
}