aboutsummaryrefslogtreecommitdiff
path: root/src/modules/commands/admins/tests.rs
blob: c1468886f0831f11f6b24b930efe32095e8889b3 (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
use crate::core::consts::*;
use crate::core::consts::DB as db;
use crate::core::utils::*;
use serenity::framework::standard::{
    Args,
    Command,
    CommandError,
    CommandOptions
};
use serenity::model::channel::Message;
use serenity::model::id::ChannelId;
use serenity::model::Permissions;
use serenity::prelude::Context;
use std::sync::Arc;

pub struct TestWelcome;
impl Command for TestWelcome {
    fn options(&self) -> Arc<CommandOptions> {
        let default = CommandOptions::default();
        let options = CommandOptions {
            desc: Some("Feeling superstitious? I'll check if your welcome configuration is correct.".to_string()),
            max_args: Some(0),
            required_permissions: Permissions::MANAGE_GUILD,
            ..default
        };
        Arc::new(options)
    }

    fn execute(&self, _: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
        if let Some(guild_id) = message.guild_id {
            if let Some(member) = message.member() {
                let guild_data = db.get_guild(guild_id.0 as i64)?;
                if guild_data.welcome {
                    let channel = ChannelId(guild_data.welcome_channel as u64);
                    if guild_data.welcome_type.as_str() == "embed" {
                        send_welcome_embed(guild_data.welcome_message, &member, channel)?;
                    } else {
                        channel.say(parse_welcome_items(guild_data.welcome_message, &member))?;
                    }
                }
            } else { failed!(MEMBER_FAIL); }
        } else { failed!(GUILDID_FAIL); }
        Ok(())
    }
}

pub struct TestIntro;
impl Command for TestIntro {
    fn options(&self) -> Arc<CommandOptions> {
        let default = CommandOptions::default();
        let options = CommandOptions {
            desc: Some("Generates an introduction message to test your current setup.".to_string()),
            aliases: vec!["introduction"].iter().map(|e| e.to_string()).collect(),
            max_args: Some(0),
            required_permissions: Permissions::MANAGE_GUILD,
            ..default
        };
        Arc::new(options)
    }

    fn execute(&self, _: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
        if let Some(guild_id) = message.guild_id {
            if let Some(member) = message.member() {
                let guild_data = db.get_guild(guild_id.0 as i64)?;
                if guild_data.welcome {
                    let channel = ChannelId(guild_data.introduction_channel as u64);
                    if guild_data.introduction_type.as_str() == "embed" {
                        send_welcome_embed(guild_data.introduction_message, &member, channel)?;
                    } else {
                        channel.say(parse_welcome_items(guild_data.introduction_message, &member))?;
                    }
                }
            } else { failed!(MEMBER_FAIL); }
        } else { failed!(GUILDID_FAIL); }
        Ok(())
    }
}