Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
2
Indexable
Never
struct BotCommands {
    commands: Vec<BotAction>,
}

impl BotCommands {
    fn new() -> BotCommands {
        BotCommands {
            commands: Vec::new(),
        }
    }
    fn add_command(&mut self, command: BotAction) {
        self.commands.push(command);
    }
    fn runn_all(&self, message: &Message) {
        for command in &self.commands {
            if message.context.message.contains(command.activation_pattern) {
                (command.action)();
            }
        }
    }
}

struct BotAction {
    activation_pattern: &'static str,

    tts: bool,
    replay_message: Option<String>,
    action: fn(),
}

impl BotAction {
    fn new(
        activation_pattern: &'static str,
        tts: bool,
        replay_message: Option<String>,
        action: fn()
    ) -> BotAction {
        BotAction {
            activation_pattern,
            tts,
            replay_message,
            action,
        }
    }
}

fn test() {
    let mut commands = BotCommands::new();

    commands.add_command(
        BotAction::new("!test", true, Some("Test".to_string()), || {
            println!("Test");
        })
    );

    commands.runn_all(message);
}
Leave a Comment