mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-05-01 23:14:25 +02:00
chore(fmt): change to default rustfmt config (#12)
This commit is contained in:
parent
ecafabde54
commit
607638b99f
16
rustfmt.toml
16
rustfmt.toml
@ -1,16 +0,0 @@
|
|||||||
edition = "2018"
|
|
||||||
match_block_trailing_comma = true
|
|
||||||
newline_style = "Unix"
|
|
||||||
use_field_init_shorthand = true
|
|
||||||
use_small_heuristics = "Max"
|
|
||||||
use_try_shorthand = true
|
|
||||||
|
|
||||||
hard_tabs = true
|
|
||||||
format_code_in_doc_comments = true
|
|
||||||
group_imports = "StdExternalCrate"
|
|
||||||
imports_granularity = "Module"
|
|
||||||
imports_layout = "HorizontalVertical"
|
|
||||||
match_arm_blocks = true
|
|
||||||
normalize_comments = true
|
|
||||||
overflow_delimited_expr = true
|
|
||||||
struct_lit_single_line = false
|
|
55
src/main.rs
55
src/main.rs
@ -62,10 +62,12 @@ impl EventHandler for Handler {
|
|||||||
}
|
}
|
||||||
// check if the user has an administrating role
|
// check if the user has an administrating role
|
||||||
if !permission_granted
|
if !permission_granted
|
||||||
&& administrators
|
&& administrators.roles.iter().any(|role_id| {
|
||||||
|
member
|
||||||
.roles
|
.roles
|
||||||
.iter()
|
.iter()
|
||||||
.any(|role_id| member.roles.iter().any(|member_role| member_role == role_id))
|
.any(|member_role| member_role == role_id)
|
||||||
|
})
|
||||||
{
|
{
|
||||||
permission_granted = true
|
permission_granted = true
|
||||||
}
|
}
|
||||||
@ -82,12 +84,12 @@ impl EventHandler for Handler {
|
|||||||
configuration.thread_introductions = new_config.thread_introductions;
|
configuration.thread_introductions = new_config.thread_introductions;
|
||||||
|
|
||||||
"Successfully reloaded configuration.".to_string()
|
"Successfully reloaded configuration.".to_string()
|
||||||
},
|
}
|
||||||
"stop" => {
|
"stop" => {
|
||||||
debug!("{:?} stopped the bot.", command.user);
|
debug!("{:?} stopped the bot.", command.user);
|
||||||
stop_command = true;
|
stop_command = true;
|
||||||
"Stopped the bot.".to_string()
|
"Stopped the bot.".to_string()
|
||||||
},
|
}
|
||||||
_ => "Unknown command.".to_string(),
|
_ => "Unknown command.".to_string(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -120,9 +122,13 @@ impl EventHandler for Handler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(message_response) =
|
if let Some(message_response) = get_configuration_lock(&ctx)
|
||||||
get_configuration_lock(&ctx).await.read().await.message_responses.iter().find(
|
.await
|
||||||
|&response| {
|
.read()
|
||||||
|
.await
|
||||||
|
.message_responses
|
||||||
|
.iter()
|
||||||
|
.find(|&response| {
|
||||||
// check if the message was sent in a channel that is included in the responder
|
// check if the message was sent in a channel that is included in the responder
|
||||||
response.includes.channels.iter().any(|&channel_id| channel_id == msg.channel_id.0)
|
response.includes.channels.iter().any(|&channel_id| channel_id == msg.channel_id.0)
|
||||||
// check if the message was sent by a user that is not excluded from the responder
|
// check if the message was sent by a user that is not excluded from the responder
|
||||||
@ -131,8 +137,8 @@ impl EventHandler for Handler {
|
|||||||
&& !contains_match(&response.excludes.match_field, &msg.content)
|
&& !contains_match(&response.excludes.match_field, &msg.content)
|
||||||
// check if the message matches any of the includes
|
// check if the message matches any of the includes
|
||||||
&& contains_match(&response.includes.match_field, &msg.content)
|
&& contains_match(&response.includes.match_field, &msg.content)
|
||||||
},
|
})
|
||||||
) {
|
{
|
||||||
let min_age = message_response.condition.user.server_age;
|
let min_age = message_response.condition.user.server_age;
|
||||||
|
|
||||||
if min_age != 0 {
|
if min_age != 0 {
|
||||||
@ -194,11 +200,19 @@ impl EventHandler for Handler {
|
|||||||
let configuration_lock = get_configuration_lock(&ctx).await;
|
let configuration_lock = get_configuration_lock(&ctx).await;
|
||||||
let configuration = configuration_lock.read().await;
|
let configuration = configuration_lock.read().await;
|
||||||
|
|
||||||
if let Some(introducer) = &configuration.thread_introductions.iter().find(|introducer| {
|
if let Some(introducer) = &configuration
|
||||||
introducer.channels.iter().any(|channel_id| *channel_id == thread.parent_id.unwrap().0)
|
.thread_introductions
|
||||||
}) {
|
.iter()
|
||||||
if let Err(why) =
|
.find(|introducer| {
|
||||||
thread.say(&ctx.http, &introducer.response.message.as_ref().unwrap()).await
|
introducer
|
||||||
|
.channels
|
||||||
|
.iter()
|
||||||
|
.any(|channel_id| *channel_id == thread.parent_id.unwrap().0)
|
||||||
|
})
|
||||||
|
{
|
||||||
|
if let Err(why) = thread
|
||||||
|
.say(&ctx.http, &introducer.response.message.as_ref().unwrap())
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
error!("Error sending message: {:?}", why);
|
error!("Error sending message: {:?}", why);
|
||||||
}
|
}
|
||||||
@ -208,9 +222,10 @@ impl EventHandler for Handler {
|
|||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
info!("Connected as {}", ready.user.name);
|
info!("Connected as {}", ready.user.name);
|
||||||
|
|
||||||
for (cmd, description) in
|
for (cmd, description) in [
|
||||||
[("repload", "Reloads the configuration."), ("stop", "Stop the Discord bot.")]
|
("repload", "Reloads the configuration."),
|
||||||
{
|
("stop", "Stop the Discord bot."),
|
||||||
|
] {
|
||||||
Command::create_global_application_command(&ctx.http, |command| {
|
Command::create_global_application_command(&ctx.http, |command| {
|
||||||
command.name(cmd).description(description)
|
command.name(cmd).description(description)
|
||||||
})
|
})
|
||||||
@ -249,7 +264,11 @@ async fn main() {
|
|||||||
.expect("Failed to create client");
|
.expect("Failed to create client");
|
||||||
|
|
||||||
// Save the configuration.
|
// Save the configuration.
|
||||||
client.data.write().await.insert::<BotConfiguration>(Arc::new(RwLock::new(configuration)));
|
client
|
||||||
|
.data
|
||||||
|
.write()
|
||||||
|
.await
|
||||||
|
.insert::<BotConfiguration>(Arc::new(RwLock::new(configuration)));
|
||||||
|
|
||||||
// Start the Discord bot.
|
// Start the Discord bot.
|
||||||
client.start().await.expect("failed to start discord bot");
|
client.start().await.expect("failed to start discord bot");
|
||||||
|
@ -21,7 +21,10 @@ impl Configuration {
|
|||||||
fn save(&self) -> Result<()> {
|
fn save(&self) -> Result<()> {
|
||||||
let sys_config_dir = config_dir().expect("find config dir");
|
let sys_config_dir = config_dir().expect("find config dir");
|
||||||
|
|
||||||
fs::create_dir_all(format!("{}/revanced-discord-bot", sys_config_dir.to_string_lossy()))
|
fs::create_dir_all(format!(
|
||||||
|
"{}/revanced-discord-bot",
|
||||||
|
sys_config_dir.to_string_lossy()
|
||||||
|
))
|
||||||
.expect("create config dir");
|
.expect("create config dir");
|
||||||
|
|
||||||
let mut file = File::create(CONFIG_PATH)?;
|
let mut file = File::create(CONFIG_PATH)?;
|
||||||
@ -32,8 +35,10 @@ impl Configuration {
|
|||||||
|
|
||||||
pub fn load() -> Result<Configuration> {
|
pub fn load() -> Result<Configuration> {
|
||||||
let sys_config_dir = config_dir().expect("Can not find the configuration directory.");
|
let sys_config_dir = config_dir().expect("Can not find the configuration directory.");
|
||||||
let sys_config =
|
let sys_config = format!(
|
||||||
format!("{}/revanced-discord-bot/{CONFIG_PATH}", sys_config_dir.to_string_lossy());
|
"{}/revanced-discord-bot/{CONFIG_PATH}",
|
||||||
|
sys_config_dir.to_string_lossy()
|
||||||
|
);
|
||||||
|
|
||||||
// config file in current dir
|
// config file in current dir
|
||||||
let mut file = if Path::new(CONFIG_PATH).exists() {
|
let mut file = if Path::new(CONFIG_PATH).exists() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user