sonicbot-matrix 0.1.5

Matrix bot that you can write plugins for
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use rand::seq::SliceRandom;
use crate::{Instructions, MessageArgs};

pub fn help() -> String {
    String::from("choose <choices seperated by ' or ' without the quotes>\nChooses a random choice from <choices>")
}

pub fn main(message_args: MessageArgs) -> Vec<Instructions> {
    let message_info = message_args.message_info;
    let mut instructions: Vec<Instructions> = Vec::new();
    let msg = message_info.words[1..].join(" ");
    let choices: Vec<&str> = msg.split(" or ").collect();
    let choice = choices.choose(&mut rand::thread_rng()).unwrap().to_string();
    instructions.push(Instructions::SendMessage(message_info.room_id, format!("{}: {}", message_info.sender, choice)));
    instructions
}