Add automated warning and banning

This commit is contained in:
2025-08-14 23:18:43 -03:00
parent 8e0c591b21
commit 6dde25aa72
10 changed files with 587 additions and 36 deletions
+185
View File
@@ -0,0 +1,185 @@
use std::sync::Arc;
use twilight_model::{
channel::{Message, message::Embed},
oauth::Application,
};
use twilight_util::builder::embed::{
EmbedAuthorBuilder, EmbedBuilder, EmbedFieldBuilder, EmbedFooterBuilder, ImageSource,
};
use crate::{
constants::{COLOR_RED, COLOR_YELLOW}, discord::images, groups::calls::moderation::Rule, utils::ellipse,
};
pub fn first_warning_embed(
app: &Application,
message: &Message,
rules_broken: Vec<Arc<dyn Rule>>,
) -> Embed {
EmbedBuilder::new()
.author(
EmbedAuthorBuilder::new(app.name.clone())
.icon_url(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
)
).unwrap()
)
)
.title("Warning")
.description("You broke [Payphone's code of conduct](https://payphone.lat/code-of-conduct) during a call. Since it's your first offense, we assumed you didn't read the rules and made this a warning instead. Read the code of conduct to prevent getting banned.")
.field(EmbedFieldBuilder::new("What message broke the rules?", ellipse(message.content.clone(), 500)))
.field(EmbedFieldBuilder::new(
"What rules did you break?",
rules_broken
.iter()
.map(|rule| format!("- {}", rule.name()))
.collect::<Vec<_>>()
.join("\n"),
))
.color(COLOR_YELLOW)
.thumbnail(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
))
.unwrap()
)
.footer(EmbedFooterBuilder::new("This is a warning because it's your first offense. Breaking the rules again will result in a ban."))
.build()
}
pub fn repeat_warning_embed(
app: &Application,
message: &Message,
rules_broken: Vec<Arc<dyn Rule>>,
) -> Embed {
EmbedBuilder::new()
.author(
EmbedAuthorBuilder::new(app.name.clone())
.icon_url(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
)
).unwrap()
)
)
.title("Long Time no See!")
.description("You broke [Payphone's code of conduct](https://payphone.lat/code-of-conduct) during a call. It's not your first offense, yet you've gone for a long time with a good record so we're making this a warning instead. In case you've forgotten the rules, consider this a reminder to re-read them.")
.field(EmbedFieldBuilder::new("What message broke the rules?", ellipse(message.content.clone(), 500)))
.field(EmbedFieldBuilder::new(
"What rules did you break?",
rules_broken
.iter()
.map(|rule| format!("- {}", rule.name()))
.collect::<Vec<_>>()
.join("\n"),
))
.color(COLOR_YELLOW)
.thumbnail(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
))
.unwrap()
)
.footer(EmbedFooterBuilder::new("Breaking the rules again will result in a ban."))
.build()
}
pub fn first_ban_embed(
app: &Application,
message: &Message,
rules_broken: Vec<Arc<dyn Rule>>,
) -> Embed {
EmbedBuilder::new()
.author(
EmbedAuthorBuilder::new(app.name.clone())
.icon_url(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
)
).unwrap()
)
)
.title("Banned")
.description("You broke [Payphone's code of conduct](https://payphone.lat/code-of-conduct) during a call. This is your first offense, and as such, you are being issued a ban. This ban will last for 24 hours, next one will be permanent.")
.field(EmbedFieldBuilder::new("What message broke the rules?", ellipse(message.content.clone(), 500)))
.field(EmbedFieldBuilder::new(
"What rules did you break?",
rules_broken
.iter()
.map(|rule| format!("- {}", rule.name()))
.collect::<Vec<_>>()
.join("\n"),
))
.color(COLOR_RED)
.thumbnail(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
))
.unwrap()
)
.footer(EmbedFooterBuilder::new("Breaking the rules again will result in being permanently banned."))
.build()
}
pub fn final_ban_embed(
app: &Application,
message: &Message,
rules_broken: Vec<Arc<dyn Rule>>
) -> Embed {
EmbedBuilder::new()
.author(
EmbedAuthorBuilder::new(app.name.clone())
.icon_url(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
)
).unwrap()
)
)
.title("Permanently Banned")
.description("You broke [Payphone's code of conduct](https://payphone.lat/code-of-conduct) during a call. This is your final offense, and as such, you are being issued a permanent ban.")
.field(EmbedFieldBuilder::new("What message broke the rules?", ellipse(message.content.clone(), 500)))
.field(EmbedFieldBuilder::new(
"What rules did you break?",
rules_broken
.iter()
.map(|rule| format!("- {}", rule.name()))
.collect::<Vec<_>>()
.join("\n"),
))
.color(COLOR_RED)
.thumbnail(
ImageSource::url(
images::get_avatar_url(
app.icon,
app.bot.as_ref().unwrap().id.get(),
app.bot.as_ref().unwrap().discriminator as u64,
)
).unwrap()
)
.footer(EmbedFooterBuilder::new("You broke the rules 3 times."))
.build()
}