1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
use crate::core::model::ApiClient;
use crate::core::consts::*;
use serenity::framework::standard::{
Args,
Command,
CommandError,
CommandOptions
};
use serenity::model::channel::Message;
use serenity::prelude::Context;
use std::sync::Arc;
pub struct Furry;
impl Command for Furry {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("I see your a individual of culture...".to_string()),
usage: Some("[tags]".to_string()),
example: Some("minecraft".to_string()),
aliases: vec!["furry"].iter().map(|e| e.to_string()).collect(),
owner_privileges: false,
..default
};
Arc::new(options)
}
fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> {
let data = ctx.data.lock();
message.channel_id.broadcast_typing()?;
if let Some(api) = data.get::<ApiClient>() {
let res = api.furry(args.full(), 1)?;
let post = &res[0];
message.channel_id.send_message(|m| m
.embed(|e| e
.image(&post.file_url)
.description(format!("**Tags:** {}\n**Post:** [{}]({})\n**Artist:** {}\n**Score::** {}",
&post.tags.replace("_", "\\_"),
&post.id,
format!("https://e621.net/post/show/{}", &post.id),
&post.artist[0],
&post.score
)
)
))?;
} else { failed!(API_FAIL); }
Ok(())
}
}
|