From 88902ace64f888950a3606f0c5433db83deccc04 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 22 Jun 2023 01:19:35 +0200 Subject: [PATCH] fix: check parent channels when `thread_option` is present --- configuration.example.json | 36 ++++++++++++++++++-------------- configuration.revanced.json | 39 ++++++++++++++++++++--------------- src/model/application.rs | 2 -- src/utils/message_response.rs | 16 +++++++------- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/configuration.example.json b/configuration.example.json index 5f50d4d..be74183 100644 --- a/configuration.example.json +++ b/configuration.example.json @@ -1,34 +1,34 @@ { - "$schema": "./configuration.schema.json", "general": { "embed_color": 0, "mute": { "role": 0, - "take": [0] + "take": [ + 0 + ] }, - "media_channels": [0], "logging_channel": 0 }, "administrators": { - "roles": [0], - "users": [0] + "roles": [ + 0 + ], + "users": [ + 0 + ] }, - "thread_introductions": [ - { - "channels": [0], - "response": { - "message": "" - } - } - ], "message_responses": [ { "includes": { - "channels": [0], + "channels": [ + 0 + ], "match": [] }, "excludes": { - "roles": [0], + "roles": [ + 0 + ], "match": [] }, "condition": { @@ -38,7 +38,11 @@ }, "response": { "message": "" + }, + "thread_options": { + "lock_on_response": false, + "close_on_response": false, } } ] -} +} \ No newline at end of file diff --git a/configuration.revanced.json b/configuration.revanced.json index ecbd27a..5188de5 100644 --- a/configuration.revanced.json +++ b/configuration.revanced.json @@ -14,13 +14,10 @@ }, "administrators": { "roles": [ - 955220417969262612 - ], - "users": [ - 737323631117598811 + 955220417969262612, + 973886585294704640 ] }, - "thread_introductions": [], "message_responses": [ { "includes": { @@ -40,8 +37,7 @@ 955220417969262612, 952987191401926697, 1027874293192863765 - ], - "match": [] + ] }, "condition": { "user": { @@ -94,8 +90,7 @@ 955220417969262612, 952987191401926697, 1027874293192863765 - ], - "match": [] + ] }, "response": { "embed": { @@ -311,17 +306,24 @@ } } }, - { + { "includes": { - "channels": [952946952348270626, 954147049832603748], - "match": ["(?i)(((video|buffer|play|stuck|work|time|freeze|infinite|1:09|endless|\\sload).*){2,})"] + "channels": [ + 952946952348270626, + 1019635439272992868, + 954147049832603748 + ], + "match": [ + "(?i)(((video|buffer|play|stuck|work|time|freeze|infinite|1:09|endless|\\sload).*){2,})" + ] }, "excludes": { "roles": [ - 965267139902705744, 955220417969262612, 952987191401926697, + 965267139902705744, + 955220417969262612, + 952987191401926697, 1027874293192863765 - ], - "match": [] + ] }, "response": { "embed": { @@ -351,8 +353,11 @@ "url": "" } } - + }, + "thread_options": { + "lock_on_response": true, + "close_on_response": true } } ] -} +} \ No newline at end of file diff --git a/src/model/application.rs b/src/model/application.rs index b4127f7..440022a 100644 --- a/src/model/application.rs +++ b/src/model/application.rs @@ -152,8 +152,6 @@ pub struct Includes { #[derive(Serialize, Deserialize)] pub struct Excludes { pub roles: Option>, - #[serde(rename = "match", with = "serde_regex")] - pub match_field: Vec, } #[derive(Serialize, Deserialize)] diff --git a/src/utils/message_response.rs b/src/utils/message_response.rs index d966859..06882f8 100644 --- a/src/utils/message_response.rs +++ b/src/utils/message_response.rs @@ -19,11 +19,18 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere let message = &new_message.content; for response in responses { - // check if the channel is whitelisted if let Some(includes) = &response.includes { if let Some(channels) = &includes.channels { + // check if the channel is whitelisted, if not, check if the channel is a thread, if it is check if the parent id is whitelisted if !channels.contains(&new_message.channel_id.0) { - continue; + if response.thread_options.is_some() { + let Some(parent_id) = new_message.channel(&ctx.http).await.unwrap().guild().unwrap().parent_id else { continue; }; + if !channels.contains(&parent_id.0) { + continue; + } + } else { + continue; + } } } @@ -46,11 +53,6 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere continue; } } - - // check if the message is not blacklisted - if contains_match(&excludes.match_field, message) { - continue; - } } if let Some(condition) = &response.condition {