From d4a833edcc337c39bf987fdb909e86391231b640 Mon Sep 17 00:00:00 2001 From: Agatha Rose Date: Wed, 22 Apr 2020 21:56:01 +0300 Subject: [PATCH] Add colored to dependencies Disable waffle command Proper error handling 2: electric boogaloo Add more uwu pictures Add arg handling for info command --- Cargo.lock | 23 +++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 64 +++++++++++++++++++++++++++++++++++------------------ 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fe4bb8..330bee1 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,16 @@ name = "antidote" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "autocfg" version = "1.0.0" @@ -132,6 +142,16 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "command_attr" version = "0.1.7" @@ -1032,6 +1052,7 @@ dependencies = [ name = "rustcord" version = "0.3.4" dependencies = [ + "colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "owoify 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1746,6 +1767,7 @@ dependencies = [ "checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" "checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5" +"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" @@ -1763,6 +1785,7 @@ dependencies = [ "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum colored 1.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" "checksum command_attr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b61098146d3e0ad56c4918ae30ab9f32a7222cc859fc65fbc2a8475c1e48b336" "checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" diff --git a/Cargo.toml b/Cargo.toml index 5a172c2..a6ad8ea 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ sys-info = "0.6.0" urbandict = "0.2.0" owoify = "0.1.5" lazy_static = "1.4.0" +colored = "1.9.3" [patch.crates-io] openssl = { git = "https://github.com/ishitatsuyuki/rust-openssl", branch = "0.9.x" } diff --git a/src/main.rs b/src/main.rs index f58550e..fd6d36e 100755 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,14 @@ #[macro_use] extern crate lazy_static; +use colored::*; use rand::Rng; use serenity::{ client::Client, framework::standard::{ macros::{check, command, group}, - Args, CheckResult, CommandOptions, CommandResult, DispatchError, Reason, StandardFramework, + Args, CheckResult, CommandError, CommandOptions, CommandResult, DispatchError, Reason, + StandardFramework, }, model::{channel::Message, gateway::Ready, id::UserId, user::OnlineStatus}, prelude::*, @@ -38,8 +40,8 @@ impl EventHandler for Handler { #[group] #[commands( - init, ping, halt, list_srv, host, ship, bottom_rng, headpat, uwu, gayculator, waffle, sausage, - help, embed, define, owo, info + init, ping, halt, list_srv, host, ship, bottom_rng, headpat, uwu, gayculator, sausage, help, + embed, define, owo, info )] struct General; @@ -78,6 +80,14 @@ fn main() { .say(&ctx.http, &format!("Try again in {} seconds.", seconds)); } }) + .after(|_ctx, _msg, cmd_name, error| { + if let Err(why) = error { + eprintln!( + "{}", + format!("Error in {}: {}", cmd_name.purple(), why.0.red().bold()) + ); + } + }) .group(&GENERAL_GROUP), ); @@ -191,19 +201,7 @@ fn embed(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { let input_embed: EmbedProperties = match toml::from_str(args.rest().trim()) { Ok(v) => v, Err(e) => { - eprintln!("Deserialization error: {:?}", e); - - EmbedProperties { - author: None, - colour: None, - description: None, - fields: None, - footer: None, - image: None, - timestamp: None, - title: None, - url: None, - } + return Err(CommandError(format!("Deserialization error: {:?}", e))); } }; @@ -365,8 +363,14 @@ fn ship(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { #[command] #[aliases("pat")] fn headpat(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { + let args = args.rest().trim(); + + if args.is_empty() { + return Err(CommandError("Please specify a username!".to_string())); + } + let name = match message.mentions.len() { - 0 => args.rest().trim(), + 0 => args, _ => message.mentions[0].name.as_str(), }; @@ -391,12 +395,23 @@ fn uwu(ctx: &mut Context, message: &Message) -> CommandResult { "https://i.redditmedia.com/qDD9W7NJqTAk31y061TuRW9R8qOcCuEmmCWyOsUEavE.png?fit=crop&crop=faces%2Centropy&arh=2&w=640&s=ebdd3f1970b4fe70ccd24a1958e7fc32", "https://www.shitpostbot.com/img/sourceimages/smash-that-mfuckn-uwu-button-57b5aa1de9fe4.jpeg", "https://www.shitpostbot.com/img/sourceimages/fallout-nv-owo-57e586ae15322.jpeg", - "https://i.redditmedia.com/-JaK9YW7mPz2S2xBJmXvW4fZ58uGMa4l6GIgYt3dqZg.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=640&s=ebab29a577346b4d18ec914538b69bb4" + "https://i.redditmedia.com/-JaK9YW7mPz2S2xBJmXvW4fZ58uGMa4l6GIgYt3dqZg.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=640&s=ebab29a577346b4d18ec914538b69bb4", + "https://preview.redd.it/ie48xuwurzt41.jpg?width=640&crop=smart&auto=webp&s=c4a27d5ed086430cd29530a3d3c8e846cad867d5", + "https://i.redd.it/9aw0yzprztq41.jpg", + "https://i.redd.it/gxjx9jb01ef41.jpg", + "https://i.redd.it/n0liugufmks41.jpg", + "https://preview.redd.it/fcfrmarhj9s41.jpg?width=640&crop=smart&auto=webp&s=5a4ff9a471dca7cad61b8e56bc65876ef083304a", + "https://i.redd.it/ifwsmbme48q41.jpg" ]; let num = rand::thread_rng().gen_range(0, images.len()); let _ = message .channel_id - .send_message(&ctx.http, |m| m.embed(|e| e.image(images[num]))); + .send_message(&ctx.http, |m| m.embed(|e| { + e.image(images[num]); + e.footer(|f| f.text(format!("Source: {}", images[num]))); + + e + })); Ok(()) } @@ -420,12 +435,14 @@ fn gayculator(ctx: &mut Context, message: &Message, mut args: Args) -> CommandRe Ok(()) } +/* #[command] fn waffle(ctx: &mut Context, message: &Message) -> CommandResult { let _ = message.channel_id.say(&ctx.http, "h"); Ok(()) } +*/ #[command] fn sausage(ctx: &mut Context, message: &Message) -> CommandResult { @@ -464,7 +481,7 @@ fn help(ctx: &mut Context, message: &Message) -> CommandResult { .fields(vec![ ("owo init", "Introduce me", false), ("owo ping", "Pong", false), - ("owo waffle", "stroopwafel owo", false), + /*("owo waffle", "stroopwafel owo", false),*/ ("owo sausage", "sosig", false), ("owo help", "Help the fellow humanz!", false), ("owo info", "Show information about me!", false), @@ -499,12 +516,15 @@ fn help(ctx: &mut Context, message: &Message) -> CommandResult { } #[command] -fn info(ctx: &mut Context, message: &Message) -> CommandResult { +fn info(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { + if !args.is_empty() { + return Err(CommandError("Error: Called with args!".to_string())); + } + let num = ctx.cache.read().guilds.len(); let _ = message.channel_id.send_message(&ctx.http, |m| m .embed(|e| e .title("Discordinator9000's info:") - .description("h") .field("Author:", "Ahtågä lrig etüc#9000 / Agatha", false) .field("Server count:", num , false) .field("Invite:", "[Invite link](https://discordapp.com/api/oauth2/authorize?client_id=470350233419907129&permissions=2048&scope=bot)", false )