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
|
||||
if !permission_granted
|
||||
&& administrators
|
||||
&& administrators.roles.iter().any(|role_id| {
|
||||
member
|
||||
.roles
|
||||
.iter()
|
||||
.any(|role_id| member.roles.iter().any(|member_role| member_role == role_id))
|
||||
.any(|member_role| member_role == role_id)
|
||||
})
|
||||
{
|
||||
permission_granted = true
|
||||
}
|
||||
@ -82,12 +84,12 @@ impl EventHandler for Handler {
|
||||
configuration.thread_introductions = new_config.thread_introductions;
|
||||
|
||||
"Successfully reloaded configuration.".to_string()
|
||||
},
|
||||
}
|
||||
"stop" => {
|
||||
debug!("{:?} stopped the bot.", command.user);
|
||||
stop_command = true;
|
||||
"Stopped the bot.".to_string()
|
||||
},
|
||||
}
|
||||
_ => "Unknown command.".to_string(),
|
||||
}
|
||||
} else {
|
||||
@ -120,9 +122,13 @@ impl EventHandler for Handler {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(message_response) =
|
||||
get_configuration_lock(&ctx).await.read().await.message_responses.iter().find(
|
||||
|&response| {
|
||||
if let Some(message_response) = get_configuration_lock(&ctx)
|
||||
.await
|
||||
.read()
|
||||
.await
|
||||
.message_responses
|
||||
.iter()
|
||||
.find(|&response| {
|
||||
// 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)
|
||||
// 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)
|
||||
// check if the message matches any of the includes
|
||||
&& contains_match(&response.includes.match_field, &msg.content)
|
||||
},
|
||||
) {
|
||||
})
|
||||
{
|
||||
let min_age = message_response.condition.user.server_age;
|
||||
|
||||
if min_age != 0 {
|
||||
@ -194,11 +200,19 @@ impl EventHandler for Handler {
|
||||
let configuration_lock = get_configuration_lock(&ctx).await;
|
||||
let configuration = configuration_lock.read().await;
|
||||
|
||||
if let Some(introducer) = &configuration.thread_introductions.iter().find(|introducer| {
|
||||
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
|
||||
if let Some(introducer) = &configuration
|
||||
.thread_introductions
|
||||
.iter()
|
||||
.find(|introducer| {
|
||||
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);
|
||||
}
|
||||
@ -208,9 +222,10 @@ impl EventHandler for Handler {
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
info!("Connected as {}", ready.user.name);
|
||||
|
||||
for (cmd, description) in
|
||||
[("repload", "Reloads the configuration."), ("stop", "Stop the Discord bot.")]
|
||||
{
|
||||
for (cmd, description) in [
|
||||
("repload", "Reloads the configuration."),
|
||||
("stop", "Stop the Discord bot."),
|
||||
] {
|
||||
Command::create_global_application_command(&ctx.http, |command| {
|
||||
command.name(cmd).description(description)
|
||||
})
|
||||
@ -249,7 +264,11 @@ async fn main() {
|
||||
.expect("Failed to create client");
|
||||
|
||||
// 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.
|
||||
client.start().await.expect("failed to start discord bot");
|
||||
|
@ -21,7 +21,10 @@ impl Configuration {
|
||||
fn save(&self) -> Result<()> {
|
||||
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");
|
||||
|
||||
let mut file = File::create(CONFIG_PATH)?;
|
||||
@ -32,8 +35,10 @@ impl Configuration {
|
||||
|
||||
pub fn load() -> Result<Configuration> {
|
||||
let sys_config_dir = config_dir().expect("Can not find the configuration directory.");
|
||||
let sys_config =
|
||||
format!("{}/revanced-discord-bot/{CONFIG_PATH}", sys_config_dir.to_string_lossy());
|
||||
let sys_config = format!(
|
||||
"{}/revanced-discord-bot/{CONFIG_PATH}",
|
||||
sys_config_dir.to_string_lossy()
|
||||
);
|
||||
|
||||
// config file in current dir
|
||||
let mut file = if Path::new(CONFIG_PATH).exists() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user