forked from sorceress/rustcord
Clean up define command
This commit is contained in:
parent
e5bc576c83
commit
6fd658c6d0
|
@ -1,5 +1,5 @@
|
|||
use serenity::{
|
||||
framework::standard::{macros::command, Args, CommandResult},
|
||||
framework::standard::{macros::command, Args, CommandError, CommandResult},
|
||||
model::channel::Message,
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -8,36 +8,32 @@ use serenity::{
|
|||
#[command]
|
||||
#[aliases("what's this")]
|
||||
async fn define(ctx: &Context, message: &Message, args: Args) -> CommandResult {
|
||||
let text: String = args.rest().trim().to_string();
|
||||
let defs = &urbandict::get_definitions(&text);
|
||||
if !args.is_empty() {
|
||||
match defs {
|
||||
Err(_e) => {
|
||||
return Err("Invalid query >w<".into());
|
||||
}
|
||||
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,
|
||||
)
|
||||
.color(0xffd1dc)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
} else {
|
||||
return Err("No results!".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
if args.is_empty() {
|
||||
return Err("No arguments!".into());
|
||||
}
|
||||
|
||||
let text: String = args.rest().trim().to_string();
|
||||
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
|
||||
.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,
|
||||
)
|
||||
.color(0xffd1dc)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue