forked from sorceress/rustcord
Clean up define command
This commit is contained in:
parent
6a615bea42
commit
82d017b00f
|
@ -1,5 +1,5 @@
|
||||||
use serenity::{
|
use serenity::{
|
||||||
framework::standard::{macros::command, Args, CommandResult},
|
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||||
model::channel::Message,
|
model::channel::Message,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
@ -8,16 +8,18 @@ use serenity::{
|
||||||
#[command]
|
#[command]
|
||||||
#[aliases("what's this")]
|
#[aliases("what's this")]
|
||||||
async fn define(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
async fn define(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||||
let text: String = args.rest().trim().to_string();
|
if args.is_empty() {
|
||||||
let defs = &urbandict::get_definitions(&text);
|
return Err("No arguments!".into());
|
||||||
if !args.is_empty() {
|
|
||||||
match defs {
|
|
||||||
Err(_e) => {
|
|
||||||
return Err("Invalid query >w<".into());
|
|
||||||
}
|
}
|
||||||
Ok(v) => {
|
|
||||||
if !v.is_empty() {
|
let text: String = args.rest().trim().to_string();
|
||||||
let def = &v[0];
|
let defs =
|
||||||
|
urbandict::get_definitions(&text).map_err(|_| CommandError::from("Invalid query >w<"))?;
|
||||||
|
|
||||||
|
let def = defs
|
||||||
|
.first()
|
||||||
|
.ok_or_else(|| CommandError::from("No results!"))?;
|
||||||
|
|
||||||
let _ = message
|
let _ = message
|
||||||
.channel_id
|
.channel_id
|
||||||
.send_message(&ctx.http, |m| {
|
.send_message(&ctx.http, |m| {
|
||||||
|
@ -32,12 +34,6 @@ async fn define(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
} else {
|
|
||||||
return Err("No results!".into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue