Skip to content

Commit

Permalink
fix: check parent channels when thread_option is present
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 21, 2023
1 parent b470563 commit 88902ac
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
36 changes: 20 additions & 16 deletions configuration.example.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -38,7 +38,11 @@
},
"response": {
"message": ""
},
"thread_options": {
"lock_on_response": false,
"close_on_response": false,
}
}
]
}
}
39 changes: 22 additions & 17 deletions configuration.revanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
},
"administrators": {
"roles": [
955220417969262612
],
"users": [
737323631117598811
955220417969262612,
973886585294704640
]
},
"thread_introductions": [],
"message_responses": [
{
"includes": {
Expand All @@ -40,8 +37,7 @@
955220417969262612,
952987191401926697,
1027874293192863765
],
"match": []
]
},
"condition": {
"user": {
Expand Down Expand Up @@ -94,8 +90,7 @@
955220417969262612,
952987191401926697,
1027874293192863765
],
"match": []
]
},
"response": {
"embed": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -351,8 +353,11 @@
"url": ""
}
}

},
"thread_options": {
"lock_on_response": true,
"close_on_response": true
}
}
]
}
}
2 changes: 0 additions & 2 deletions src/model/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ pub struct Includes {
#[derive(Serialize, Deserialize)]
pub struct Excludes {
pub roles: Option<Vec<u64>>,
#[serde(rename = "match", with = "serde_regex")]
pub match_field: Vec<Regex>,
}

#[derive(Serialize, Deserialize)]
Expand Down
16 changes: 9 additions & 7 deletions src/utils/message_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit 88902ac

Please sign in to comment.