1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
use saigon_core::content::Content; use saigon_core::{Command, HelpText, Plugin, PluginResponse, PluginResult}; use serde::Deserialize; pub struct CatFact; #[derive(Deserialize)] struct CatFactJson { pub fact: String, pub length: i32, } impl Plugin for CatFact { fn name(&self) -> String { env!("CARGO_PKG_NAME").into() } fn version(&self) -> String { env!("CARGO_PKG_VERSION").into() } fn help(&self) -> Option<HelpText> { Some(HelpText { command: "cat fact".into(), text: "Returns a fun fact about cats".into(), }) } fn receive(&mut self, command: &Command) -> PluginResult { match command.value.as_ref() { "cat fact" => { let res: CatFactJson = reqwest::get("https://catfact.ninja/fact") .unwrap() .json() .unwrap(); Ok(PluginResponse::Success(Content::Text(res.fact))) } _ => Ok(PluginResponse::Ignore), } } }