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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
use crate::core::model::ApiClient;
use crate::core::colours;
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(())
}
}
pub struct UrbanDictionary; // Urban
impl Command for UrbanDictionary {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("Hmm, be responsible.".to_string()),
usage: Some(r#"<"term"> [count]"#.to_string()),
example: Some(r#""boku no pico" 5"#.to_string()),
aliases: vec!["urban", "ud", "urbandict"].iter().map(|e| e.to_string()).collect(),
owner_privileges: false,
..default
};
Arc::new(options)
}
fn execute(&self, ctx: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> {
let api = {
let data = ctx.data.lock();
data.get::<ApiClient>().cloned()
};
if let Some(api) = api {
let term = args.single_quoted::<String>().unwrap_or(String::new());
let res = api.urban(term.as_str())?;
if !res.definitions.is_empty() {
let count = args.single::<u32>().unwrap_or(1);
let mut tags: Vec<String> = Vec::new();
if let Some(res_tags) = &res.tags {
tags = res_tags.clone();
tags.sort();
tags.dedup();
}
if count == 1 {
let item = &res.definitions[0];
let tags_list = {
let list = tags.iter().map(|t| "#".to_string()+t).collect::<Vec<String>>().join(", ");
if !list.is_empty() {
list
} else {
"None".to_string()
}
};
let definition = {
let mut i = item.definition.clone();
if i.len() > 1000 {
i.truncate(997);
i += "...";
}
i
};
message.channel_id.send_message(|m| m
.embed(|e| e
.colour(*colours::MAIN)
.field(format!(r#"Definition of "{}" by {}"#, item.word, item.author), &item.permalink, false)
.field("Thumbs Up", &item.thumbs_up, true)
.field("Thumbs Down", &item.thumbs_down, true)
.field("Definition", definition, false)
.field("Example", &item.example, false)
.field("Tags", tags_list, false)
))?;
} else {
let mut list = res.definitions;
list.truncate(count as usize);
let list = list.iter()
.map(|c| format!(r#""{}" by {}: {}"#, c.word, c.author, c.permalink))
.collect::<Vec<String>>()
.join("\n");
message.channel_id.send_message(|m| m
.embed(|e| e
.title(format!("Top {} results for {}", count, term))
.description(list)
.colour(*colours::MAIN)
))?;
}
}
} else { failed!(API_FAIL); }
Ok(())
}
}
|