mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-04-30 06:24:27 +02:00
feat: decancer user names
This commit is contained in:
parent
ba7b82a6de
commit
28a19c4120
@ -1,6 +1,8 @@
|
|||||||
use crate::{utils::load_configuration, Context, Error};
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
use crate::utils::load_configuration;
|
||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn reload(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn reload(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
// Update the configuration
|
// Update the configuration
|
||||||
|
5
src/events/guild_member_addition.rs
Normal file
5
src/events/guild_member_addition.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub async fn guild_member_addition(ctx: &serenity::Context, new_member: &serenity::Member) {
|
||||||
|
crate::utils::cure(ctx, new_member).await;
|
||||||
|
}
|
9
src/events/guild_member_update.rs
Normal file
9
src/events/guild_member_update.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub async fn guild_member_update(
|
||||||
|
ctx: &serenity::Context,
|
||||||
|
_old_if_available: &Option<serenity::Member>,
|
||||||
|
new: &serenity::Member,
|
||||||
|
) {
|
||||||
|
crate::utils::cure(ctx, new).await;
|
||||||
|
}
|
@ -1,8 +1,12 @@
|
|||||||
use poise::serenity_prelude::{self as serenity, Mutex, RwLock, ShardManager, UserId};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{model::application::Configuration, Error};
|
use poise::serenity_prelude::{self as serenity, Mutex, RwLock, ShardManager, UserId};
|
||||||
|
|
||||||
|
use crate::model::application::Configuration;
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
mod guild_member_addition;
|
||||||
|
mod guild_member_update;
|
||||||
mod message_create;
|
mod message_create;
|
||||||
mod thread_create;
|
mod thread_create;
|
||||||
|
|
||||||
@ -43,7 +47,7 @@ impl<T: Send + Sync> Handler<T> {
|
|||||||
bot_id: self.bot_id.read().await.unwrap(),
|
bot_id: self.bot_id.read().await.unwrap(),
|
||||||
options: &self.options,
|
options: &self.options,
|
||||||
user_data: &self.data,
|
user_data: &self.data,
|
||||||
shard_manager: &(*self.shard_manager.read().await).clone().unwrap(), // Shard manager can be read between all poise events without locks
|
shard_manager: &(*self.shard_manager.read().await).clone().unwrap(), /* Shard manager can be read between all poise events without locks */
|
||||||
};
|
};
|
||||||
poise::dispatch_event(framework_data, ctx, event).await;
|
poise::dispatch_event(framework_data, ctx, event).await;
|
||||||
}
|
}
|
||||||
@ -59,12 +63,16 @@ impl serenity::EventHandler for Handler<Arc<RwLock<Configuration>>> {
|
|||||||
async fn message(&self, ctx: serenity::Context, new_message: serenity::Message) {
|
async fn message(&self, ctx: serenity::Context, new_message: serenity::Message) {
|
||||||
message_create::message_create(&ctx, &new_message).await;
|
message_create::message_create(&ctx, &new_message).await;
|
||||||
|
|
||||||
self.dispatch_poise_event(&ctx, &poise::Event::Message { new_message })
|
self.dispatch_poise_event(&ctx, &poise::Event::Message {
|
||||||
|
new_message,
|
||||||
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn interaction_create(&self, ctx: serenity::Context, interaction: serenity::Interaction) {
|
async fn interaction_create(&self, ctx: serenity::Context, interaction: serenity::Interaction) {
|
||||||
self.dispatch_poise_event(&ctx, &poise::Event::InteractionCreate { interaction })
|
self.dispatch_poise_event(&ctx, &poise::Event::InteractionCreate {
|
||||||
|
interaction,
|
||||||
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,20 +83,28 @@ impl serenity::EventHandler for Handler<Arc<RwLock<Configuration>>> {
|
|||||||
new: Option<serenity::Message>,
|
new: Option<serenity::Message>,
|
||||||
event: serenity::MessageUpdateEvent,
|
event: serenity::MessageUpdateEvent,
|
||||||
) {
|
) {
|
||||||
self.dispatch_poise_event(
|
self.dispatch_poise_event(&ctx, &poise::Event::MessageUpdate {
|
||||||
&ctx,
|
|
||||||
&poise::Event::MessageUpdate {
|
|
||||||
old_if_available,
|
old_if_available,
|
||||||
new,
|
new,
|
||||||
event,
|
event,
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn thread_create(&self, ctx: serenity::Context, thread: serenity::GuildChannel) {
|
async fn thread_create(&self, ctx: serenity::Context, thread: serenity::GuildChannel) {
|
||||||
thread_create::thread_create(&ctx, &thread).await;
|
thread_create::thread_create(&ctx, &thread).await;
|
||||||
self.dispatch_poise_event(&ctx, &poise::Event::ThreadCreate { thread })
|
}
|
||||||
.await;
|
|
||||||
|
async fn guild_member_addition(&self, ctx: serenity::Context, new_member: serenity::Member) {
|
||||||
|
guild_member_addition::guild_member_addition(&ctx, &new_member).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn guild_member_update(
|
||||||
|
&self,
|
||||||
|
ctx: serenity::Context,
|
||||||
|
old_if_available: Option<serenity::Member>,
|
||||||
|
new: serenity::Member,
|
||||||
|
) {
|
||||||
|
guild_member_update::guild_member_update(&ctx, &old_if_available, &new).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -1,11 +1,13 @@
|
|||||||
use crate::model::application::Configuration;
|
use std::env;
|
||||||
use std::{env, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use commands::configuration;
|
use commands::configuration;
|
||||||
use events::Handler;
|
use events::Handler;
|
||||||
use poise::serenity_prelude::{self as serenity, RwLock};
|
use poise::serenity_prelude::{self as serenity, RwLock};
|
||||||
use utils::load_configuration;
|
use utils::load_configuration;
|
||||||
|
|
||||||
|
use crate::model::application::Configuration;
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod events;
|
mod events;
|
||||||
mod logger;
|
mod logger;
|
||||||
@ -87,7 +89,9 @@ async fn main() {
|
|||||||
let mut client = serenity::Client::builder(
|
let mut client = serenity::Client::builder(
|
||||||
env::var("DISCORD_AUTHORIZATION_TOKEN")
|
env::var("DISCORD_AUTHORIZATION_TOKEN")
|
||||||
.expect("Could not load Discord authorization token"),
|
.expect("Could not load Discord authorization token"),
|
||||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
|
serenity::GatewayIntents::non_privileged()
|
||||||
|
| serenity::GatewayIntents::MESSAGE_CONTENT
|
||||||
|
| serenity::GatewayIntents::GUILD_MEMBERS,
|
||||||
)
|
)
|
||||||
.event_handler_arc(handler.clone())
|
.event_handler_arc(handler.clone())
|
||||||
.await
|
.await
|
||||||
|
27
src/utils.rs
27
src/utils.rs
@ -1,7 +1,11 @@
|
|||||||
use poise::serenity_prelude::CreateEmbed;
|
use decancer::Decancer;
|
||||||
|
use poise::serenity_prelude::{self as serenity, CreateEmbed, RwLock};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use crate::model::application::Configuration;
|
use crate::model::application::Configuration;
|
||||||
|
|
||||||
|
const DECANCER: Decancer = Decancer::new();
|
||||||
|
|
||||||
pub(crate) fn load_configuration() -> Configuration {
|
pub(crate) fn load_configuration() -> Configuration {
|
||||||
Configuration::load().expect("Failed to load configuration")
|
Configuration::load().expect("Failed to load configuration")
|
||||||
}
|
}
|
||||||
@ -30,3 +34,24 @@ impl PoiseEmbed for crate::model::application::Embed {
|
|||||||
.author(|a| a.name(self.author.name).icon_url(self.author.icon_url))
|
.author(|a| a.name(self.author.name).icon_url(self.author.icon_url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn cure(ctx: &serenity::Context, member: &serenity::Member) {
|
||||||
|
let display_name = member.display_name();
|
||||||
|
let name = display_name.to_string();
|
||||||
|
|
||||||
|
let cured_user_name = DECANCER.cure(&name);
|
||||||
|
|
||||||
|
if name == cured_user_name {
|
||||||
|
return; // username is already cured
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Cured user {}", name);
|
||||||
|
|
||||||
|
member
|
||||||
|
.guild_id
|
||||||
|
.edit_member(&ctx.http, member.user.id, |edit_member| {
|
||||||
|
edit_member.nickname(cured_user_name)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user