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]]
name = "rustcord"
version = "0.3.2"
version = "0.3.4"
dependencies = [
"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)",

View File

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

View File

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