Untitled

 avatar
unknown
plain_text
a year ago
1.4 kB
4
Indexable
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("!test01", false, None, test01));
    commands.add_command(BotAction::new("!test02", false, None, test02));
    commands.add_command(BotAction::new("!test03", false, None, test03));

    commands.runn_all(message);
}

fn test01() {
    println!("Hello, world! form test01");
}

fn test02() {
    println!("Hello, world! form test02");
}

fn test03() {
    println!("Hello, world! form test03");
}
Editor is loading...
Leave a Comment