Fix urbandict lookup None unwrap error

This commit is contained in:
EvilDeaaaadd 2020-01-16 22:27:49 +02:00
parent b35e2a7721
commit 7ade211de6
3 changed files with 33 additions and 23 deletions

2
Cargo.lock generated
View File

@ -1194,7 +1194,7 @@ dependencies = [
[[package]]
name = "rustcord"
version = "0.2.5"
version = "0.2.6"
dependencies = [
"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)",

View File

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

View File

@ -95,10 +95,7 @@ fn init(ctx: &mut Context, message: &Message) -> CommandResult {
.say(&ctx.http, "The Discordinator9000 is gonna hug ny'all!");
}
1 => {
let _ = message.channel_id.say(
&ctx.http,
"Nyaa~!",
);
let _ = message.channel_id.say(&ctx.http, "Nyaa~!");
}
_ => {
let _ = message.channel_id.say(&ctx.http, "Oopsie woopsie! UwU");
@ -402,8 +399,16 @@ fn compare_bot(ctx: &mut Context, message: &Message, mut args: Args) -> CommandR
#[aliases("what's this")]
fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
let text: String = args.rest().trim().to_string();
let defs = &urbandict::get_definitions(&text.to_string())?;
let def = &defs[0];
let defs = &urbandict::get_definitions(&text.to_string());
match defs {
Err(_e) => {
let _ = message
.channel_id
.say(&ctx.http, format!("Invalid query >w<"));
}
Ok(v) => {
if v.len() > 0 {
let def = &v[0];
let _ = message.channel_id.send_message(&ctx.http, |m| {
m.embed(|e| {
e.title(format!("Author: {}", def.author)).field(
@ -413,6 +418,11 @@ fn what(ctx: &mut Context, message: &Message, args: Args) -> CommandResult {
)
})
});
} else {
println!("No resuwults");
}
}
}
Ok(())
}