sonicbot_matrix/plugins/on_message/
randfact.rs1use crate::{Instructions, MessageArgs};
2use regex::Regex;
3pub fn help() -> String {
4 String::from("randfact\n Returns a random fact from http://randomfunfacts.com/")
5}
6
7pub fn main(message_args: MessageArgs) -> Vec<Instructions> {
8 let message_info = message_args.message_info;
9 let mut instructions: Vec<Instructions> = Vec::new();
10 let data = ureq::get("http://randomfunfacts.com/").call().unwrap().into_string().unwrap();
11 let matcher = Regex::new(r#"<strong><i>(.*)</i></strong>"#).unwrap();
12 instructions.push(Instructions::SendMessage(message_info.room_id, format!("{}: {}", message_info.sender, matcher.captures(data.as_str()).unwrap()[1].to_string())));
13 instructions
14}