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
use crate::{Instructions, MessageArgs};
use regex::Regex;
pub fn help() -> String {
    String::from("randfact\n Returns a random fact from http://randomfunfacts.com/")
}

pub fn main(message_args: MessageArgs) -> Vec<Instructions> {
    let message_info = message_args.message_info;
    let mut instructions: Vec<Instructions> = Vec::new();
    let data = ureq::get("http://randomfunfacts.com/").call().unwrap().into_string().unwrap();
    let matcher = Regex::new(r#"<strong><i>(.*)</i></strong>"#).unwrap();
    instructions.push(Instructions::SendMessage(message_info.room_id, format!("{}: {}", message_info.sender, matcher.captures(data.as_str()).unwrap()[1].to_string())));
    instructions
}