use crate::core::model::ApiClient; use crate::core::colours; use crate::core::consts::*; use serenity::framework::standard::{ Args, Command, CommandError, CommandOptions }; use serenity::model::channel::Message; use serenity::prelude::Context; use std::sync::Arc; pub struct Furry; impl Command for Furry { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("I see your a individual of culture...".to_string()), usage: Some("[tags]".to_string()), example: Some("minecraft".to_string()), aliases: vec!["furry"].iter().map(|e| e.to_string()).collect(), owner_privileges: false, ..default }; Arc::new(options) } fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { let data = ctx.data.lock(); message.channel_id.broadcast_typing()?; if let Some(api) = data.get::() { let res = api.furry(args.full(), 1)?; let post = &res[0]; message.channel_id.send_message(|m| m .embed(|e| e .image(&post.file_url) .description(format!("**Tags:** {}\n**Post:** [{}]({})\n**Artist:** {}\n**Score::** {}", &post.tags.replace("_", "\\_"), &post.id, format!("https://e621.net/post/show/{}", &post.id), &post.artist[0], &post.score ) ) ))?; } else { failed!(API_FAIL); } Ok(()) } } pub struct UrbanDictionary; // Urban impl Command for UrbanDictionary { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Hmm, be responsible.".to_string()), usage: Some(r#"<"term"> [count]"#.to_string()), example: Some(r#""boku no pico" 5"#.to_string()), aliases: vec!["urban", "ud", "urbandict"].iter().map(|e| e.to_string()).collect(), owner_privileges: false, ..default }; Arc::new(options) } fn execute(&self, ctx: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { let api = { let data = ctx.data.lock(); data.get::().cloned() }; if let Some(api) = api { let term = args.single_quoted::().unwrap_or(String::new()); let res = api.urban(term.as_str())?; if !res.definitions.is_empty() { let count = args.single::().unwrap_or(1); let mut tags: Vec = Vec::new(); if let Some(res_tags) = &res.tags { tags = res_tags.clone(); tags.sort(); tags.dedup(); } if count == 1 { let item = &res.definitions[0]; let tags_list = { let list = tags.iter().map(|t| "#".to_string()+t).collect::>().join(", "); if !list.is_empty() { list } else { "None".to_string() } }; let definition = { let mut i = item.definition.clone(); if i.len() > 1000 { i.truncate(997); i += "..."; } i }; message.channel_id.send_message(|m| m .embed(|e| e .colour(*colours::MAIN) .field(format!(r#"Definition of "{}" by {}"#, item.word, item.author), &item.permalink, false) .field("Thumbs Up", &item.thumbs_up, true) .field("Thumbs Down", &item.thumbs_down, true) .field("Definition", definition, false) .field("Example", &item.example, false) .field("Tags", tags_list, false) ))?; } else { let mut list = res.definitions; list.truncate(count as usize); let list = list.iter() .map(|c| format!(r#""{}" by {}: {}"#, c.word, c.author, c.permalink)) .collect::>() .join("\n"); message.channel_id.send_message(|m| m .embed(|e| e .title(format!("Top {} results for {}", count, term)) .description(list) .colour(*colours::MAIN) ))?; } } } else { failed!(API_FAIL); } Ok(()) } }