fix: check parent channels when thread_option is present

This commit is contained in:
oSumAtrIX 2023-06-22 01:19:35 +02:00
parent b470563aab
commit 88902ace64
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 51 additions and 42 deletions

View File

@ -1,34 +1,34 @@
{ {
"$schema": "./configuration.schema.json",
"general": { "general": {
"embed_color": 0, "embed_color": 0,
"mute": { "mute": {
"role": 0, "role": 0,
"take": [0] "take": [
0
]
}, },
"media_channels": [0],
"logging_channel": 0 "logging_channel": 0
}, },
"administrators": { "administrators": {
"roles": [0], "roles": [
"users": [0] 0
],
"users": [
0
]
}, },
"thread_introductions": [
{
"channels": [0],
"response": {
"message": ""
}
}
],
"message_responses": [ "message_responses": [
{ {
"includes": { "includes": {
"channels": [0], "channels": [
0
],
"match": [] "match": []
}, },
"excludes": { "excludes": {
"roles": [0], "roles": [
0
],
"match": [] "match": []
}, },
"condition": { "condition": {
@ -38,6 +38,10 @@
}, },
"response": { "response": {
"message": "" "message": ""
},
"thread_options": {
"lock_on_response": false,
"close_on_response": false,
} }
} }
] ]

View File

@ -14,13 +14,10 @@
}, },
"administrators": { "administrators": {
"roles": [ "roles": [
955220417969262612 955220417969262612,
], 973886585294704640
"users": [
737323631117598811
] ]
}, },
"thread_introductions": [],
"message_responses": [ "message_responses": [
{ {
"includes": { "includes": {
@ -40,8 +37,7 @@
955220417969262612, 955220417969262612,
952987191401926697, 952987191401926697,
1027874293192863765 1027874293192863765
], ]
"match": []
}, },
"condition": { "condition": {
"user": { "user": {
@ -94,8 +90,7 @@
955220417969262612, 955220417969262612,
952987191401926697, 952987191401926697,
1027874293192863765 1027874293192863765
], ]
"match": []
}, },
"response": { "response": {
"embed": { "embed": {
@ -311,17 +306,24 @@
} }
} }
}, },
{ {
"includes": { "includes": {
"channels": [952946952348270626, 954147049832603748], "channels": [
"match": ["(?i)(((video|buffer|play|stuck|work|time|freeze|infinite|1:09|endless|\\sload).*){2,})"] 952946952348270626,
1019635439272992868,
954147049832603748
],
"match": [
"(?i)(((video|buffer|play|stuck|work|time|freeze|infinite|1:09|endless|\\sload).*){2,})"
]
}, },
"excludes": { "excludes": {
"roles": [ "roles": [
965267139902705744, 955220417969262612, 952987191401926697, 965267139902705744,
955220417969262612,
952987191401926697,
1027874293192863765 1027874293192863765
], ]
"match": []
}, },
"response": { "response": {
"embed": { "embed": {
@ -351,7 +353,10 @@
"url": "" "url": ""
} }
} }
},
"thread_options": {
"lock_on_response": true,
"close_on_response": true
} }
} }
] ]

View File

@ -152,8 +152,6 @@ pub struct Includes {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct Excludes { pub struct Excludes {
pub roles: Option<Vec<u64>>, pub roles: Option<Vec<u64>>,
#[serde(rename = "match", with = "serde_regex")]
pub match_field: Vec<Regex>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]

View File

@ -19,11 +19,18 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere
let message = &new_message.content; let message = &new_message.content;
for response in responses { for response in responses {
// check if the channel is whitelisted
if let Some(includes) = &response.includes { if let Some(includes) = &response.includes {
if let Some(channels) = &includes.channels { 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) { 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; continue;
} }
} }
// check if the message is not blacklisted
if contains_match(&excludes.match_field, message) {
continue;
}
} }
if let Some(condition) = &response.condition { if let Some(condition) = &response.condition {