Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: Don't delete triggering message when replying to message
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 4, 2024
1 parent 6bd4890 commit b87c601
Show file tree
Hide file tree
Showing 12 changed files with 883 additions and 700 deletions.
984 changes: 631 additions & 353 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ homepage = "https://revanced.app"
license = "GPL-3.0"
name = "revanced-discord-bot"
repository = "https://github.com/revanced/revanced-discord-bot"
version = "2.7.0"
version = "2.8.0"
edition = "2021"

[profile.release]
strip = true
opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
Expand All @@ -20,14 +19,14 @@ bson = "2.4"
serde_with_macros = "3.4"
mongodb = "2.4"
poise = "0.6"
decancer = "1.5"
decancer = "3.2"
tokio = { version = "1.26", features = ["rt-multi-thread"] }
dotenv = "0.15"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1.7"
serde_regex = "1.1"
reqwest = { version = "0.11", features = [
reqwest = { version = "0.12", features = [
"rustls-tls",
"json",
], default-features = false }
Expand All @@ -39,5 +38,5 @@ tracing = { version = "0.1", features = [
] }
tracing-subscriber = "0.3"
hmac-sha256 = "1.1"
base64 = "0.21"
base64 = "0.22"
parse_duration = "2.1"
56 changes: 18 additions & 38 deletions configuration.example.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,28 @@
{
"general": {
"embed_color": 0,
"mute": {
"role": 0,
"take": [
0
]
},
"logging_channel": 0
"default_embed": {
"color": 0
},
"mute": {
"role": 0,
"take": [0]
},
"log_channel": 0,
"administrators": {
"roles": [
0
],
"users": [
0
]
"roles": [0],
"users": [0]
},
"message_responses": [
"responses": [
{
"includes": {
"channels": [
0
],
"match": []
},
"excludes": {
"roles": [
0
],
"match": []
},
"condition": {
"user": {
"server_age": 2
}
"whitelist": {
"channels": [0],
"regex": [""]
},
"response": {
"message": ""
"blacklist": {
"roles": [0],
"regex": [""]
},
"thread_options": {
"lock_on_response": false,
"close_on_response": false,
"only_on_first_message": false
"message": {
"content": ""
},
"respond_to_reference": false
}
Expand Down
42 changes: 14 additions & 28 deletions src/commands/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
use poise::serenity_prelude::CreateEmbed;
use poise::CreateReply;
use tracing::debug;

use crate::utils::bot::load_configuration;
use crate::utils::create_default_embed;
use crate::{Context, Error};

/// Reload the Discord bot.
#[poise::command(slash_command)]
pub async fn reload(ctx: Context<'_>) -> Result<(), Error> {
// Update the configuration
// Update the configuration.
let configuration = load_configuration();
// Use the embed color from the updated configuration
let embed_color = configuration.general.embed_color;
// Also save the new configuration to the user data
let embed = create_default_embed(&configuration);
ctx.data().write().await.configuration = configuration;

debug!("{} reloaded the configuration.", ctx.author().name);

ctx.send(
CreateReply {
embeds: vec![
CreateEmbed::new()
.description("Reloading configuration...")
.color(embed_color),
],
ephemeral: Some(true),
..Default::default()
}
)
ctx.send(CreateReply {
embeds: vec![embed.description("Reloading configuration...")],
ephemeral: Some(true),
..Default::default()
})
.await?;

Ok(())
Expand All @@ -38,19 +30,13 @@ pub async fn reload(ctx: Context<'_>) -> Result<(), Error> {
pub async fn stop(ctx: Context<'_>) -> Result<(), Error> {
debug!("{} stopped the bot.", ctx.author().name);

let color = ctx.data().read().await.configuration.general.embed_color;
let configuration = &ctx.data().read().await.configuration;

ctx.send(
CreateReply {
ephemeral: Some(true),
embeds: vec![
CreateEmbed::new()
.description("Stopping the bot...")
.color(color),
],
..Default::default()
}
)
ctx.send(CreateReply {
ephemeral: Some(true),
embeds: vec![create_default_embed(configuration).description("Stopping the bot...")],
..Default::default()
})
.await?;

ctx.framework().shard_manager().shutdown_all().await;
Expand Down
18 changes: 7 additions & 11 deletions src/commands/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bson::{doc, Document};
use chrono::Utc;
use mongodb::options::{UpdateModifications, UpdateOptions};
use poise::serenity_prelude::{
self as serenity, CreateEmbed, CreateEmbedFooter, EditMessage, GetMessages, Mentionable, UserId,
CreateEmbedFooter, EditMessage, GetMessages, Mentionable, UserId,
};
use poise::CreateReply;
use tracing::{debug, trace};
Expand All @@ -13,7 +13,7 @@ use crate::utils::macros::to_user;
use crate::utils::moderation::{
ban_moderation, queue_unmute_member, respond_moderation, BanKind, ModerationKind,
};
use crate::utils::parse_duration;
use crate::utils::{create_default_embed, parse_duration};
use crate::{Context, Error};

/// Unmute a member.
Expand Down Expand Up @@ -41,7 +41,7 @@ pub async fn unmute(
data.database.clone(),
ctx.guild_id().unwrap(),
id,
configuration.general.mute.role,
configuration.mute.role,
0,
)
.await
Expand Down Expand Up @@ -73,7 +73,7 @@ pub async fn mute(
let configuration = &data.configuration;
let author = ctx.author();

let mute = &configuration.general.mute;
let mute = &configuration.mute;
let guild_id = ctx.guild_id().unwrap();

let discord = ctx.serenity_context();
Expand Down Expand Up @@ -185,7 +185,6 @@ pub async fn purge(

let data = ctx.data().read().await;
let configuration = &data.configuration;
let embed_color = configuration.general.embed_color;
let channel = ctx.channel_id();
let too_old_timestamp = Utc::now().timestamp() - MAX_BULK_DELETE_AGO_SECS;

Expand All @@ -196,10 +195,9 @@ pub async fn purge(

let handle = ctx
.send(CreateReply {
embeds: vec![CreateEmbed::new()
embeds: vec![create_default_embed(configuration)
.title("Purging messages")
.description("Accumulating...")
.color(embed_color)
.thumbnail(&image)],
..Default::default()
})
Expand Down Expand Up @@ -271,14 +269,12 @@ pub async fn purge(
.edit(
&ctx.serenity_context(),
EditMessage::new().embed(
serenity::CreateEmbed::default()
create_default_embed(configuration)
.title("Purge successful")
.field("Deleted messages", deleted_amount.to_string(), false)
.field("Action by", author.mention().to_string(), false)
.color(embed_color)
.thumbnail(&image)
.footer(CreateEmbedFooter::new("ReVanced").icon_url(image))
.clone(),
.footer(CreateEmbedFooter::new("ReVanced").icon_url(image)),
),
)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion src/events/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils::moderation::queue_unmute_member;

pub async fn load_muted_members(ctx: &serenity::Context, data: &Arc<RwLock<Data>>) {
let data = &mut *data.write().await;
let mute_role_id = data.configuration.general.mute.role;
let mute_role_id = data.configuration.mute.role;

let mut cursor = data
.database
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use commands::{configuration, misc, moderation};
use db::database::Database;
use events::event_handler;
use poise::serenity_prelude::prelude::{RwLock, TypeMapKey};
use poise::serenity_prelude::{CreateEmbed, UserId};
use poise::serenity_prelude::{UserId};
use poise::CreateReply;
use tokio::task::JoinHandle;
use tracing::{error, trace};
use utils::bot::load_configuration;
use utils::create_default_embed;

use crate::model::application::Configuration;

Expand Down Expand Up @@ -125,12 +126,11 @@ async fn main() {
if let Err(e) = ctx
.send(CreateReply {
ephemeral: Some(true),
embeds: vec![CreateEmbed::new()
embeds: vec![create_default_embed(configuration)
.title("Permission error")
.description(
"You do not have permission to use this command.",
)
.color(configuration.general.embed_color)
.thumbnail(member.user.avatar_url().unwrap_or_else(
|| member.user.default_avatar_url(),
))],
Expand Down
Loading

0 comments on commit b87c601

Please sign in to comment.