mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-05-05 08:44:25 +02:00
feat: make configurations optional
This commit is contained in:
parent
2f983ecfe9
commit
580235beb8
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1172,9 +1172,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poise"
|
name = "poise"
|
||||||
version = "0.5.2"
|
version = "0.5.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2ca787e4e516076de1995a83ee05fbdfed71d072ea0da3df018318db42a87803"
|
checksum = "6d591af1c934c29adda172665f69b837e642d4fee85598baffb95dd98110467d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"derivative",
|
"derivative",
|
||||||
@ -1191,9 +1191,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poise_macros"
|
name = "poise_macros"
|
||||||
version = "0.5.2"
|
version = "0.5.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b80c1f4e04114527f9d41ed6bb31707a095276f51bb0aef3ca11f062b25a67c4"
|
checksum = "40270099e1527efae99fdc0609d397e76310b529d4980ad38ab14d81803ca0fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling 0.14.4",
|
"darling 0.14.4",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@ -1358,7 +1358,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revanced-discord-bot"
|
name = "revanced-discord-bot"
|
||||||
version = "2.3.1"
|
version = "2.4.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.0",
|
"base64 0.21.0",
|
||||||
"bson",
|
"bson",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["oSumAtrIX"]
|
authors = ["ReVanced"]
|
||||||
description = "The official Discord bot assisting the ReVanced Discord server."
|
description = "The official Discord bot assisting the ReVanced Discord server."
|
||||||
homepage = "https://revanced.app"
|
homepage = "https://revanced.app"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
name = "revanced-discord-bot"
|
name = "revanced-discord-bot"
|
||||||
repository = "https://github.com/revanced/revanced-discord-bot"
|
repository = "https://github.com/revanced/revanced-discord-bot"
|
||||||
version = "2.3.1"
|
version = "2.4.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
@ -89,9 +89,9 @@ pub struct Introduction {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct MessageResponse {
|
pub struct MessageResponse {
|
||||||
pub includes: Includes,
|
pub includes: Option<Includes>,
|
||||||
pub excludes: Excludes,
|
pub excludes: Option<Excludes>,
|
||||||
pub condition: Condition,
|
pub condition: Option<Condition>,
|
||||||
pub response: Response,
|
pub response: Response,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,14 +145,14 @@ pub struct Author {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Includes {
|
pub struct Includes {
|
||||||
pub channels: Vec<u64>,
|
pub channels: Option<Vec<u64>>,
|
||||||
#[serde(rename = "match", with = "serde_regex")]
|
#[serde(rename = "match", with = "serde_regex")]
|
||||||
pub match_field: Vec<Regex>,
|
pub match_field: Vec<Regex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Excludes {
|
pub struct Excludes {
|
||||||
pub roles: Vec<u64>,
|
pub roles: Option<Vec<u64>>,
|
||||||
#[serde(rename = "match", with = "serde_regex")]
|
#[serde(rename = "match", with = "serde_regex")]
|
||||||
pub match_field: Vec<Regex>,
|
pub match_field: Vec<Regex>,
|
||||||
}
|
}
|
||||||
|
@ -19,38 +19,43 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
|
|||||||
let message = &new_message.content;
|
let message = &new_message.content;
|
||||||
|
|
||||||
for response in responses {
|
for response in responses {
|
||||||
// check if the message was sent in a channel that is included in the responder
|
tracing::log::trace!("d");
|
||||||
if !response
|
// check if the channel is whitelisted
|
||||||
.includes
|
if let Some(includes) = &response.includes {
|
||||||
.channels
|
if let Some(channels) = &includes.channels {
|
||||||
.iter()
|
if !channels.contains(&new_message.channel_id.0) {
|
||||||
.any(|&channel_id| channel_id == new_message.channel_id.0)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if the message was sent by a user that is not excluded from the responder
|
// check if message matches regex
|
||||||
let excludes = &response.excludes;
|
if !contains_match(&includes.match_field, message) {
|
||||||
|
tracing::log::trace!("Message does not match regex");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(excludes) = &response.excludes {
|
||||||
|
// check if the role is blacklisted
|
||||||
|
if let Some(roles) = &excludes.roles {
|
||||||
let member_roles = &new_message.member.as_ref().unwrap().roles;
|
let member_roles = &new_message.member.as_ref().unwrap().roles;
|
||||||
if excludes.roles.iter().any(|&role_id| {
|
if roles.iter().any(|&role_id| {
|
||||||
member_roles
|
member_roles
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&member_role| role_id == member_role.0)
|
.any(|&member_role| role_id == member_role.0)
|
||||||
}) {
|
}) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if the message does not match any of the excludes
|
// check if the message is not blacklisted
|
||||||
if contains_match(&excludes.match_field, message) {
|
if contains_match(&excludes.match_field, message) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the message does match any of the includes
|
|
||||||
if !(contains_match(&response.includes.match_field, message)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let min_age = response.condition.user.server_age;
|
if let Some(condition) = &response.condition {
|
||||||
|
let min_age = condition.user.server_age;
|
||||||
|
|
||||||
if min_age != 0 {
|
if min_age != 0 {
|
||||||
let joined_at = ctx
|
let joined_at = ctx
|
||||||
@ -69,7 +74,9 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
|
|||||||
let but_joined_at = Utc::now() - Duration::days(min_age);
|
let but_joined_at = Utc::now() - Duration::days(min_age);
|
||||||
|
|
||||||
if must_joined_at <= but_joined_at {
|
if must_joined_at <= but_joined_at {
|
||||||
return;
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = new_message
|
if let Err(err) = new_message
|
||||||
@ -90,9 +97,7 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
|
|||||||
})
|
})
|
||||||
.thumbnail(&embed.thumbnail.url)
|
.thumbnail(&embed.thumbnail.url)
|
||||||
.image(&embed.image.url)
|
.image(&embed.image.url)
|
||||||
.author(|a| {
|
.author(|a| a.name(&embed.author.name).icon_url(&embed.author.icon_url))
|
||||||
a.name(&embed.author.name).icon_url(&embed.author.icon_url)
|
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
None => m.content(response.response.message.as_ref().unwrap()),
|
None => m.content(response.response.message.as_ref().unwrap()),
|
||||||
}
|
}
|
||||||
@ -107,4 +112,3 @@ pub async fn auto_respond(ctx: &serenity::Context, new_message: &serenity::Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user