Add empty args handling for urbandict lookup, bump version

This commit is contained in:
Agatha 2020-04-09 21:40:00 +03:00
parent f9bde2fcb5
commit cc25f78970
3 changed files with 23 additions and 20 deletions

2
Cargo.lock generated
View File

@ -1030,7 +1030,7 @@ dependencies = [
[[package]] [[package]]
name = "rustcord" name = "rustcord"
version = "0.3.2" version = "0.3.4"
dependencies = [ dependencies = [
"lazy_static 1.4.0 (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)", "owoify 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rustcord" name = "rustcord"
version = "0.3.2" version = "0.3.4"
authors = ["Agatha <@protonmail.com>"] authors = ["Agatha <@protonmail.com>"]
edition = "2018" edition = "2018"

View File

@ -542,6 +542,7 @@ fn compare_bot(ctx: &mut Context, message: &Message, mut args: Args) -> CommandR
fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult { fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
let text: String = args.rest().trim().to_string(); let text: String = args.rest().trim().to_string();
let defs = &urbandict::get_definitions(&text); let defs = &urbandict::get_definitions(&text);
if !args.is_empty() {
match defs { match defs {
Err(_e) => { Err(_e) => {
let _ = message.channel_id.say(&ctx.http, "Invalid query >w<"); let _ = message.channel_id.say(&ctx.http, "Invalid query >w<");
@ -551,7 +552,8 @@ fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
let def = &v[0]; let def = &v[0];
let _ = message.channel_id.send_message(&ctx.http, |m| { let _ = message.channel_id.send_message(&ctx.http, |m| {
m.embed(|e| { m.embed(|e| {
e.title(format!("Author: {}", def.author)).field( e.title(format!("Query: {}, Author: {}", text, def.author))
.field(
"Definition: ", "Definition: ",
def.definition.replace(|c| c == '[' || c == ']', ""), def.definition.replace(|c| c == '[' || c == ']', ""),
false, false,
@ -559,7 +561,8 @@ fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
}) })
}); });
} else { } else {
println!("No resuwults"); let _ = message.channel_id.say(&ctx.http, "No results!");
}
} }
} }
} }