fmt: fmt and clippy

This commit is contained in:
silver 2024-09-30 00:09:29 +01:00
parent 5e7964ae26
commit 0d9ce2de7f
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
3 changed files with 84 additions and 109 deletions

View file

@ -71,11 +71,7 @@ pub mod edit {
let mut delete = false;
if let Some(x) = command
.data
.options
.get(3) {
if let Some(x) = command.data.options.get(3) {
let tmp = x.to_owned();
if let Some(y) = tmp.resolved {
match y {
@ -109,7 +105,6 @@ pub mod edit {
}
}
let mut role_a_name = String::new();
let mut role_b_name = String::new();
let mut role_c_name = String::new();
@ -126,7 +121,6 @@ pub mod edit {
}
}
if delete {
format!("Removed {} + {} = {}", role_a_name, role_b_name, role_c_name)
} else {
@ -152,13 +146,7 @@ pub mod edit {
.kind(CommandOptionType::Role)
.required(true)
})
.create_option(|option| {
option
.name("role_c")
.description("Sum of A and B")
.kind(CommandOptionType::Role)
.required(true)
})
.create_option(|option| option.name("role_c").description("Sum of A and B").kind(CommandOptionType::Role).required(true))
.create_option(|option| {
option
.name("delete")
@ -200,22 +188,18 @@ pub mod edit {
action
}
}
// TODO
pub mod list {}
pub mod tools {
use serenity::client::Context;
use serenity::model::guild::Member;
use sqlx::{Pool, Sqlite};
use skynet_discord_bot::RoleAdder;
use sqlx::{Pool, Sqlite};
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, mut new_data: Member) {
// check if the role changed is part of the oens for this server
if let Some(role_adders) = sqlx::query_as::<_, RoleAdder>(
r#"
@ -227,31 +211,26 @@ pub mod tools {
.bind(*new_data.guild_id.as_u64() as i64)
.fetch_all(db)
.await
.ok() {
.ok()
{
let mut roles_add = vec![];
let mut roles_remove = vec![];
for role_adder in role_adders {
// if the user has both A dnd B give them C
if new_data.roles.contains(&role_adder.role_a) &&
new_data.roles.contains(&role_adder.role_b) &&
!new_data.roles.contains(&role_adder.role_c) {
if new_data.roles.contains(&role_adder.role_a) && new_data.roles.contains(&role_adder.role_b) && !new_data.roles.contains(&role_adder.role_c)
{
roles_add.push(role_adder.role_c);
}
// If the suer has C but not A or B remove C
if new_data.roles.contains(&role_adder.role_c) &&
(
!new_data.roles.contains(&role_adder.role_a) || !new_data.roles.contains(&role_adder.role_b)
) {
if new_data.roles.contains(&role_adder.role_c)
&& (!new_data.roles.contains(&role_adder.role_a) || !new_data.roles.contains(&role_adder.role_b))
{
roles_remove.push(role_adder.role_c);
}
}
if !roles_add.is_empty() {
if let Err(e) = new_data.add_roles(&ctx, &roles_add).await {
println!("{:?}", e);
@ -265,6 +244,4 @@ pub mod tools {
}
}
}
}

View file

@ -324,7 +324,6 @@ fn get_role_from_row(row: &SqliteRow, col: &str)-> RoleId{
}
}
pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
let database = format!("{}/{}", &config.home, &config.database);

View file

@ -1,5 +1,7 @@
pub mod commands;
use crate::commands::role_adder::tools::on_role_change;
use serenity::model::guild::Member;
use serenity::{
async_trait,
client::{Context, EventHandler},
@ -11,11 +13,9 @@ use serenity::{
},
Client,
};
use std::sync::Arc;
use serenity::model::guild::Member;
use skynet_discord_bot::{db_init, get_config, get_server_config, get_server_member, Config, DataBase};
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::commands::role_adder::tools::on_role_change;
struct Handler;
@ -126,7 +126,6 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
// handles role updates
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Member) {
// get config/db
let db_lock = {
let data_read = ctx.data.read().await;