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
|
use crate::core::colours;
use crate::core::consts::DB as db;
use serenity::framework::standard::{
Args,
Command,
CommandError,
CommandOptions
};
use serenity::model::channel::Message;
use serenity::model::id::UserId;
use serenity::model::Permissions;
use serenity::prelude::Context;
use std::sync::Arc;
pub struct HackbanAdd;
impl Command for HackbanAdd {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
// desc: Some("Adds a user to the hackban list. Users on this list will be banned on joining.".to_string()),
desc: Some("This? It'll add someone to the \"hackban\" list, basically, they'll be banned upon joining.".to_string()),
usage: Some("<user_id> [reason]".to_string()),
example: Some("217348698294714370 spamming images in general".to_string()),
required_permissions: Permissions::BAN_MEMBERS,
..default
};
Arc::new(options)
}
fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> {
let guild_id = message.guild_id.unwrap();
let hackbans = db.get_hackbans(guild_id.0 as i64)?;
let user_id = UserId(args.single::<u64>()?);
match hackbans.iter().find(|e| e.id as u64 == user_id.0) {
Some(_) => { message.channel_id.say("User is already hackbanned.")?; },
None => {
let reason = args.single::<String>().ok();
db.new_hackban(user_id.0 as i64, guild_id.0 as i64, reason.clone())?;
message.channel_id.say(format!(
"Added {} to the hackban list{}",
user_id.0,
match reason {
Some(r) => format!(" with reason `{}`", r),
None => String::new(),
}
))?;
}
}
Ok(())
}
}
pub struct HackbanRemove;
impl Command for HackbanRemove {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
desc: Some("Feeling forgiveful? Take someone off the \"hackban\" list!".to_string()),
usage: Some("<user_id>".to_string()),
example: Some("217348698294714370".to_string()),
required_permissions: Permissions::BAN_MEMBERS,
..default
};
Arc::new(options)
}
fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> {
let guild_id = message.guild_id.unwrap();
let hackbans = db.get_hackbans(guild_id.0 as i64)?;
let user_id = UserId(args.single::<u64>()?);
match hackbans.iter().find(|e| e.id as u64 == user_id.0) {
None => { message.channel_id.say("User isn't hackbanned.")?; },
Some(_) => {
db.del_hackban(user_id.0 as i64, guild_id.0 as i64)?;
message.channel_id.say(format!(
"Removed {} from the hackban list",
user_id.0
))?;
}
}
Ok(())
}
}
pub struct HackbanList;
impl Command for HackbanList {
fn options(&self) -> Arc<CommandOptions> {
let default = CommandOptions::default();
let options = CommandOptions {
// desc: Some("Lets users on the hackban list along with their reasons, if provided.".to_string()),
desc: Some("Checking up? See who's on the \"hackban\" list.".to_string()),
required_permissions: Permissions::BAN_MEMBERS,
..default
};
Arc::new(options)
}
fn execute(&self, _: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> {
let guild_id = message.guild_id.unwrap();
let hackbans = db.get_hackbans(guild_id.0 as i64)?;
message.channel_id.send_message(|m| m
.embed(|e| e
.title("Hackbans")
.description(
hackbans.iter().cloned().map(|e| format!(
"{}{}",
e.id,
format!(": `{}`", e.reason.unwrap_or(String::new()))
))
.collect::<Vec<String>>()
.join("\n")
)
.colour(*colours::MAIN)
))?;
Ok(())
}
}
|