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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
// use chrono::Utc;
use crate::core::colours;
use crate::core::consts::*;
// use crate::core::consts::DB as db;
use crate::core::model::*;
// use crate::core::utils::*;
// use forecast::Icon::*;
// use forecast::Units;
// use rand::prelude::*;
// use serenity::CACHE;
// use serenity::client::bridge::gateway::ShardId;
use serenity::framework::standard::{
Args,
Command,
CommandError,
CommandOptions
};
use serenity::model::{
channel::Message,
// guild::Role,
};
use serenity::prelude::{
Context,
// Mentionable
};
// use std::f64::NAN;
use std::sync::Arc;
// use sys_info;
// use sysinfo::{
// ProcessExt,
// SystemExt,
// System,
// get_current_pid
// };
pub struct Anime;
impl Command for Anime {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("Want to share an anime? Results provided by kitsu.io.".to_string()),
usage: Some("<anime title>".to_string()),
example: Some("darling in the franxx".to_string()),
..default
};
Arc::new(options)
}
fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> {
use kitsu::model::Status::*;
let data = ctx.data.lock();
message.channel_id.broadcast_typing()?;
if let Some(api) = data.get::<ApiClient>() {
let res = api.anime(args.full())?;
if let Some(anime) = res.data.first() {
let status = match anime.attributes.status {
Some(stat) => { match stat {
Current => "Current",
Finished => "Complete",
TBA => "To Be Announced",
Unreleased => "Unreleased",
Upcoming => "Upcoming",
}},
None => "Status Not Found",
};
let cover_url = match anime.attributes.cover_image.clone() {
Some(cover) => { match cover.original {
Some(url) => url,
None => String::new(),
}},
None => String::new(),
};
message.channel_id.send_message(|m| m
.embed(|e| e
.title(anime.attributes.canonical_title.clone())
.url(anime.url())
.description(format!("{}\n\n{}\n**Score:** {}\n**Status:** {}",
anime.attributes.synopsis,
if let Some(count) = anime.attributes.episode_count {
let mut out = format!("**Episodes:** {}", count);
if let Some(length) = anime.attributes.episode_length {
out.push_str(format!(" ({} min/ep)", length).as_str());
}
out
} else { String::from("Episode Information Not Found") },
anime.attributes.average_rating.clone().unwrap_or(String::from("Not Found")),
status
))
.thumbnail(cover_url)
.colour(*colours::MAIN)
))?;
}
} else { failed!(API_FAIL); }
Ok(())
}
}
pub struct DadJoke;
impl Command for DadJoke {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("Who would voluntarily want a dad joke...".to_string()),
..default
};
Arc::new(options)
}
fn execute(&self, ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
let data = ctx.data.lock();
if let Some(api) = data.get::<ApiClient>() {
let res = api.joke()?;
message.channel_id.say(res)?;
} else { failed!(API_FAIL); }
Ok(())
}
}
pub struct Douse;
impl Command for Douse {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
..default
};
Arc::new(options)
}
fn execute(&self, _ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
message.channel_id.send_message(|m| m
.embed(|e| e
.colour(*colours::MAIN)
.image("https://i.pinimg.com/originals/6a/c8/26/6ac826e3d0cbd64eb4f42c12a73fcdb8.gif")
))?;
Ok(())
}
}
pub struct Manga;
impl Command for Manga {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("Need info about a manga? Results provided by kitsu.io".to_string()),
usage: Some("<anime title>".to_string()),
example: Some("deathnote".to_string()),
..default
};
Arc::new(options)
}
fn execute(&self, ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> {
use kitsu::model::Status::*;
let data = ctx.data.lock();
message.channel_id.broadcast_typing()?;
if let Some(api) = data.get::<ApiClient>() {
let res = api.manga(args.full())?;
if let Some(manga) = res.data.first() {
let status = match manga.attributes.status {
Some(stat) => { match stat {
Current => "Current",
Finished => "Complete",
TBA => "To Be Announced",
Unreleased => "Unreleased",
Upcoming => "Upcoming",
}},
None => "Status Not Found",
};
let cover_url = match manga.attributes.cover_image.clone() {
Some(cover) => { match cover.original {
Some(url) => url,
None => String::new(),
}},
None => String::new(),
};
message.channel_id.send_message(|m| m
.embed(|e| e
.title(manga.attributes.canonical_title.clone())
.url(manga.url())
.description(format!("{}\n\n**Volumes:** {}\n**Chapters:** {}\n**Score:** {}\n**Status:** {}",
manga.attributes.synopsis,
manga.attributes.volume_count.map_or(String::from("Not Found"), |count| count.to_string()),
manga.attributes.chapter_count.map_or(String::from("Not Found"), |count| count.to_string()),
manga.attributes.average_rating.clone().unwrap_or(String::from("Not Found")),
status
))
.thumbnail(cover_url)
.colour(*colours::MAIN)
))?;
}
} else { failed!(API_FAIL); }
Ok(())
}
}
// pub struct Waifu;
// impl Command for Waifu {
// fn options(&self) -> Arc<CommandOptions> {
// let default = CommandOptions::default();
// let options = CommandOptions {
// desc: Some("I'll give you random waifu and backstory generated by a neural network, so don't get too attached.".to_string()),
// ..default
// };
// Arc::new(options)
// }
// fn execute(&self, ctx: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
// let data = ctx.data.lock();
// if let Some(api) = data.get::<ApiClient>() {
// let res = api.waifu_backstory()?;
// message.channel_id.send_message(|m| m
// .embed(|e| e
// // .image(res.image)
// .description(res)
// ))?;
// } else { failed!(API_FAIL); }
// Ok(())
// }
// }
// pub struct DateFact;
// impl Command for DateFact {
// fn options(&self) -> Arc<CommandOptions> {
// let default = CommandOptions::default();
// let options = CommandOptions {
// desc: Some("A fun fact about a fun date.".to_string()),
// ..default
// };
// Arc::new(options)
// }
// fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> {
// let to_say = args;
// message.channel_id.say(uwufied)?;
// Ok(())
// }
// }
|