aboutsummaryrefslogtreecommitdiff
path: root/src/macros.rs
blob: 9e050a7c65ab8fd145d6b8a504b1c0d4c9d49def (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![macro_use]
#![allow(unused_macros)]

#[macro_export]
macro_rules! check_error {
    ($e:expr) => {
        if let Err(err) = $e {
            warn!("ERROR [{}:{}] {:?}", line!(), column!(), err);
        }
    };
}

macro_rules! failed {
    ($e:expr) => { warn!("[{}:{}] {}", line!(), column!(), $e); };
    ($e:expr, $w:expr) => { warn!("[{}:{}] {} | {}", line!(), column!(), $e, $w); };
}

macro_rules! now {
    () => { Utc::now().format("%FT%T").to_string() };
}

macro_rules! check_opt {
    ($expr:expr) => {
        match $expr {
            Some(v) => v,
            None => return
        }
    }
}

macro_rules! check_res {
    ($expr:expr) => {
        match $expr {
            Ok(v) => v,
            Err(e) => {
                warn_discord!("Error: {}", e);
                return
            }
        };
    }
}

macro_rules! check_res_msg {
    ($expr:expr) => {
        match $expr {
            Ok(v) => v,
            Err(e) => {
                warn_discord!("Error: {}", e);
                return Err(CommandError::from(get_msg!("error/unknown_error")))
            }
        };
    }
}

// macro_rules! warn_discord {
//     ($expr:expr $(, $replace:expr)*) => {
//         {
//             use utils::info::bot_update_info;
//             use utils::time::now_utc;

//             let now = now_utc().format("%Y-%m-%d %H:%M:%S UTC");

//             #[allow(unused_mut)]
//             let mut s = $expr.to_owned();

//             $(s = s.replacen("{}", &format!("{}", &$replace), 1);)*

//             warn!("[{}] {}", &now, &s);
//             bot_update_info(&format!("`[{}] WARN: {}`", &now, &s));
//         }
//     }
// }

// #[macro_export]
// macro_rules! info_discord {
//     ($expr:expr $(, $replace:expr)*) => {
//         {
//             use utils::info::bot_update_info;
//             use utils::time::now_utc;

//             let now = now_utc().format("%Y-%m-%d %H:%M:%S UTC");

//             #[allow(unused_mut)]
//             let mut s = $expr.to_owned();

//             $(s = s.replacen("{}", &format!("{}", &$replace), 1);)*

//             info!("[{}] {}", &now, &s);
//             bot_update_info(&format!("`[{}] INFO: {}`", &now, &s));
//         }
//     }
// }