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]] [[package]]
name = "rustcord" name = "rustcord"
version = "0.2.5" version = "0.2.6"
dependencies = [ dependencies = [
"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)",
"rand 0.7.3 (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] [package]
name = "rustcord" name = "rustcord"
version = "0.2.5" version = "0.2.6"
authors = ["Agatha <@protonmail.com>"] authors = ["Agatha <@protonmail.com>"]
edition = "2018" 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!"); .say(&ctx.http, "The Discordinator9000 is gonna hug ny'all!");
} }
1 => { 1 => {
let _ = message.channel_id.say( let _ = message.channel_id.say(&ctx.http, "Nyaa~!");
&ctx.http,
"Nyaa~!",
);
} }
_ => { _ => {
let _ = message.channel_id.say(&ctx.http, "Oopsie woopsie! UwU"); let _ = message.channel_id.say(&ctx.http, "Oopsie woopsie! UwU");
@ -305,12 +302,12 @@ fn sausage(ctx: &mut Context, message: &Message) -> CommandResult {
#[checks(Server)] #[checks(Server)]
fn ad(ctx: &mut Context, message: &Message) -> CommandResult { fn ad(ctx: &mut Context, message: &Message) -> CommandResult {
let _ = message.channel_id.send_message(&ctx.http, |m| m let _ = message.channel_id.send_message(&ctx.http, |m| m
.embed(|e| e .embed(|e| e
.title(":b:ottom text") .title(":b:ottom text")
***REMOVED*** ***REMOVED***
.thumbnail("https://i.imgur.com/8MU0gqD.png") .thumbnail("https://i.imgur.com/8MU0gqD.png")
.color(0x00f3ff)) .color(0x00f3ff))
); );
Ok(()) Ok(())
} }
@ -402,17 +399,30 @@ fn compare_bot(ctx: &mut Context, message: &Message, mut args: Args) -> CommandR
#[aliases("what's this")] #[aliases("what's this")]
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.to_string())?; let defs = &urbandict::get_definitions(&text.to_string());
let def = &defs[0]; match defs {
let _ = message.channel_id.send_message(&ctx.http, |m| { Err(_e) => {
m.embed(|e| { let _ = message
e.title(format!("Author: {}", def.author)).field( .channel_id
"Definition: ", .say(&ctx.http, format!("Invalid query >w<"));
def.definition.replace(|c| c == '[' || c == ']', ""), }
false, 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(
"Definition: ",
def.definition.replace(|c| c == '[' || c == ']', ""),
false,
)
})
});
} else {
println!("No resuwults");
}
}
}
Ok(()) Ok(())
} }