diff options
| author | Fuwn <[email protected]> | 2020-10-26 19:03:53 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-10-26 19:03:53 -0700 |
| commit | 9742614a1dc4699c1f2c69d923d402237672335d (patch) | |
| tree | a49f7d834372f37cef06b30a28ff1b40bdfaa079 /src/modules/commands/general/misc.rs | |
| parent | Create README.md (diff) | |
| download | dep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.tar.xz dep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.zip | |
repo: push main from local to remote
Diffstat (limited to 'src/modules/commands/general/misc.rs')
| -rw-r--r-- | src/modules/commands/general/misc.rs | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/src/modules/commands/general/misc.rs b/src/modules/commands/general/misc.rs new file mode 100644 index 0000000..f342cd0 --- /dev/null +++ b/src/modules/commands/general/misc.rs @@ -0,0 +1,320 @@ +// use chrono::Utc; +use crate::core::colours; +use crate::core::consts::*; +// use crate::core::consts::DB as db; +use crate::core::model::*; +// use crate::core::utils::*; +// use forecast::Icon::*; +// use forecast::Units; +// use rand::prelude::*; +// use serenity::CACHE; +// use serenity::client::bridge::gateway::ShardId; +use serenity::framework::standard::{ + Args, + Command, + CommandError, + CommandOptions +}; +use serenity::model::{ + channel::Message, + // guild::Role, +}; +use serenity::prelude::{ + Context, + // Mentionable +}; +// use std::f64::NAN; +use std::sync::Arc; +// use sys_info; +// use sysinfo::{ +// ProcessExt, +// SystemExt, +// System, +// get_current_pid +// }; + +pub struct Anime; +impl Command for Anime { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + desc: Some("Want to share an anime ? Results provided by kitsu.io.".to_string()), + usage: Some("<anime title>".to_string()), + example: Some("darling in the franxx".to_string()), + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { + use kitsu::model::Status::*; + let data = ctx.data.lock(); + message.channel_id.broadcast_typing()?; + if let Some(api) = data.get::<ApiClient>() { + let res = api.anime(args.full())?; + if let Some(anime) = res.data.first() { + let status = match anime.attributes.status { + Some(stat) => { match stat { + Current => "Current", + Finished => "Complete", + TBA => "To Be Announced", + Unreleased => "Unreleased", + Upcoming => "Upcoming", + }}, + None => "Status Not Found", + }; + let cover_url = match anime.attributes.cover_image.clone() { + Some(cover) => { match cover.original { + Some(url) => url, + None => String::new(), + }}, + None => String::new(), + }; + message.channel_id.send_message(|m| m + .embed(|e| e + .title(anime.attributes.canonical_title.clone()) + .url(anime.url()) + .description(format!("{}\n\n{}\n**Score:** {}\n**Status:** {}", + anime.attributes.synopsis, + if let Some(count) = anime.attributes.episode_count { + let mut out = format!("**Episodes:** {}", count); + if let Some(length) = anime.attributes.episode_length { + out.push_str(format!(" ({} min/ep)", length).as_str()); + } + out + } else { String::from("Episode Information Not Found") }, + anime.attributes.average_rating.clone().unwrap_or(String::from("Not Found")), + status + )) + .thumbnail(cover_url) + .colour(*colours::MAIN) + ))?; + } + } else { failed!(API_FAIL); } + Ok(()) + } +} + +pub struct DadJoke; +impl Command for DadJoke { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + desc: Some("Who would voluntarily want a dad joke...".to_string()), + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> { + let data = ctx.data.lock(); + if let Some(api) = data.get::<ApiClient>() { + let res = api.joke()?; + message.channel_id.say(res)?; + } else { failed!(API_FAIL); } + Ok(()) + } +} + +pub struct Douse; +impl Command for Douse { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + ..default + }; + Arc::new(options) + } + + fn execute(&self, _ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> { + message.channel_id.send_message(|m| m + .embed(|e| e + .colour(*colours::MAIN) + .image("https://i.pinimg.com/originals/6a/c8/26/6ac826e3d0cbd64eb4f42c12a73fcdb8.gif") + ))?; + + Ok(()) + } +} + +pub struct Manga; +impl Command for Manga { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + desc: Some("Need info about a manga ? Results provided by kitsu.io".to_string()), + usage: Some("<anime title>".to_string()), + example: Some("deathnote".to_string()), + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { + use kitsu::model::Status::*; + let data = ctx.data.lock(); + message.channel_id.broadcast_typing()?; + if let Some(api) = data.get::<ApiClient>() { + let res = api.manga(args.full())?; + if let Some(manga) = res.data.first() { + let status = match manga.attributes.status { + Some(stat) => { match stat { + Current => "Current", + Finished => "Complete", + TBA => "To Be Announced", + Unreleased => "Unreleased", + Upcoming => "Upcoming", + }}, + None => "Status Not Found", + }; + let cover_url = match manga.attributes.cover_image.clone() { + Some(cover) => { match cover.original { + Some(url) => url, + None => String::new(), + }}, + None => String::new(), + }; + message.channel_id.send_message(|m| m + .embed(|e| e + .title(manga.attributes.canonical_title.clone()) + .url(manga.url()) + .description(format!("{}\n\n**Volumes:** {}\n**Chapters:** {}\n**Score:** {}\n**Status:** {}", + manga.attributes.synopsis, + manga.attributes.volume_count.map_or(String::from("Not Found"), |count| count.to_string()), + manga.attributes.chapter_count.map_or(String::from("Not Found"), |count| count.to_string()), + manga.attributes.average_rating.clone().unwrap_or(String::from("Not Found")), + status + )) + .thumbnail(cover_url) + .colour(*colours::MAIN) + ))?; + } + } else { failed!(API_FAIL); } + Ok(()) + } +} + +pub struct UrbanDictionary; // Urban +impl Command for UrbanDictionary { + fn options(&self) -> Arc<CommandOptions> { + 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(), + ..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::<ApiClient>().cloned() + }; + if let Some(api) = api { + let term = args.single_quoted::<String>().unwrap_or(String::new()); + let res = api.urban(term.as_str())?; + if !res.definitions.is_empty() { + let count = args.single::<u32>().unwrap_or(1); + let mut tags: Vec<String> = 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::<Vec<String>>().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::<Vec<String>>() + .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(()) + } +} + +// pub struct Waifu; +// impl Command for Waifu { +// fn options(&self) -> Arc<CommandOptions> { +// let default = CommandOptions::default(); +// let options = CommandOptions { +// desc: Some("I'll give you random waifu and backstory generated by a neural network, so don't get too attached.".to_string()), +// ..default +// }; +// Arc::new(options) +// } + +// fn execute(&self, ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> { +// let data = ctx.data.lock(); +// if let Some(api) = data.get::<ApiClient>() { +// let res = api.waifu_backstory()?; +// message.channel_id.send_message(|m| m +// .embed(|e| e +// // .image(res.image) +// .description(res) +// ))?; +// } else { failed!(API_FAIL); } + +// Ok(()) +// } +// } + +// pub struct DateFact; +// impl Command for DateFact { +// fn options(&self) -> Arc<CommandOptions> { +// let default = CommandOptions::default(); +// let options = CommandOptions { +// desc: Some("A fun fact about a fun date.".to_string()), +// ..default +// }; +// Arc::new(options) +// } + +// fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { +// let to_say = args; + +// message.channel_id.say(uwufied)?; + +// Ok(()) +// } +// } |