Add empty args handling for urbandict lookup, bump version
This commit is contained in:
parent
f9bde2fcb5
commit
cc25f78970
|
@ -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)",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rustcord"
|
||||
version = "0.3.2"
|
||||
version = "0.3.4"
|
||||
authors = ["Agatha <@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue