fmt: fmt and clippy
This commit is contained in:
parent
5e7964ae26
commit
0d9ce2de7f
3 changed files with 84 additions and 109 deletions
|
@ -71,11 +71,7 @@ pub mod edit {
|
||||||
|
|
||||||
let mut delete = false;
|
let mut delete = false;
|
||||||
|
|
||||||
if let Some(x) = command
|
if let Some(x) = command.data.options.get(3) {
|
||||||
.data
|
|
||||||
.options
|
|
||||||
.get(3) {
|
|
||||||
|
|
||||||
let tmp = x.to_owned();
|
let tmp = x.to_owned();
|
||||||
if let Some(y) = tmp.resolved {
|
if let Some(y) = tmp.resolved {
|
||||||
match y {
|
match y {
|
||||||
|
@ -109,7 +105,6 @@ pub mod edit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let mut role_a_name = String::new();
|
let mut role_a_name = String::new();
|
||||||
let mut role_b_name = String::new();
|
let mut role_b_name = String::new();
|
||||||
let mut role_c_name = String::new();
|
let mut role_c_name = String::new();
|
||||||
|
@ -126,7 +121,6 @@ pub mod edit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if delete {
|
if delete {
|
||||||
format!("Removed {} + {} = {}", role_a_name, role_b_name, role_c_name)
|
format!("Removed {} + {} = {}", role_a_name, role_b_name, role_c_name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,13 +146,7 @@ pub mod edit {
|
||||||
.kind(CommandOptionType::Role)
|
.kind(CommandOptionType::Role)
|
||||||
.required(true)
|
.required(true)
|
||||||
})
|
})
|
||||||
.create_option(|option| {
|
.create_option(|option| option.name("role_c").description("Sum of A and B").kind(CommandOptionType::Role).required(true))
|
||||||
option
|
|
||||||
.name("role_c")
|
|
||||||
.description("Sum of A and B")
|
|
||||||
.kind(CommandOptionType::Role)
|
|
||||||
.required(true)
|
|
||||||
})
|
|
||||||
.create_option(|option| {
|
.create_option(|option| {
|
||||||
option
|
option
|
||||||
.name("delete")
|
.name("delete")
|
||||||
|
@ -200,22 +188,18 @@ pub mod edit {
|
||||||
|
|
||||||
action
|
action
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
pub mod list {}
|
pub mod list {}
|
||||||
|
|
||||||
|
|
||||||
pub mod tools {
|
pub mod tools {
|
||||||
use serenity::client::Context;
|
use serenity::client::Context;
|
||||||
use serenity::model::guild::Member;
|
use serenity::model::guild::Member;
|
||||||
use sqlx::{Pool, Sqlite};
|
|
||||||
use skynet_discord_bot::RoleAdder;
|
use skynet_discord_bot::RoleAdder;
|
||||||
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
pub async fn on_role_change(db: &Pool<Sqlite>, ctx: &Context, mut new_data: Member) {
|
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
|
// check if the role changed is part of the oens for this server
|
||||||
if let Some(role_adders) = sqlx::query_as::<_, RoleAdder>(
|
if let Some(role_adders) = sqlx::query_as::<_, RoleAdder>(
|
||||||
r#"
|
r#"
|
||||||
|
@ -227,31 +211,26 @@ pub mod tools {
|
||||||
.bind(*new_data.guild_id.as_u64() as i64)
|
.bind(*new_data.guild_id.as_u64() as i64)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.await
|
||||||
.ok() {
|
.ok()
|
||||||
|
{
|
||||||
|
|
||||||
let mut roles_add = vec![];
|
let mut roles_add = vec![];
|
||||||
let mut roles_remove = vec![];
|
let mut roles_remove = vec![];
|
||||||
|
|
||||||
for role_adder in role_adders {
|
for role_adder in role_adders {
|
||||||
// if the user has both A dnd B give them C
|
// if the user has both A dnd B give them C
|
||||||
if new_data.roles.contains(&role_adder.role_a) &&
|
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)
|
||||||
new_data.roles.contains(&role_adder.role_b) &&
|
{
|
||||||
!new_data.roles.contains(&role_adder.role_c) {
|
|
||||||
roles_add.push(role_adder.role_c);
|
roles_add.push(role_adder.role_c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the suer has C but not A or B remove C
|
// If the suer has C but not A or B remove C
|
||||||
if new_data.roles.contains(&role_adder.role_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))
|
||||||
!new_data.roles.contains(&role_adder.role_a) || !new_data.roles.contains(&role_adder.role_b)
|
{
|
||||||
) {
|
|
||||||
roles_remove.push(role_adder.role_c);
|
roles_remove.push(role_adder.role_c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if !roles_add.is_empty() {
|
if !roles_add.is_empty() {
|
||||||
if let Err(e) = new_data.add_roles(&ctx, &roles_add).await {
|
if let Err(e) = new_data.add_roles(&ctx, &roles_add).await {
|
||||||
println!("{:?}", e);
|
println!("{:?}", e);
|
||||||
|
@ -265,6 +244,4 @@ pub mod tools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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> {
|
pub async fn db_init(config: &Config) -> Result<Pool<Sqlite>, Error> {
|
||||||
let database = format!("{}/{}", &config.home, &config.database);
|
let database = format!("{}/{}", &config.home, &config.database);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
|
||||||
|
use crate::commands::role_adder::tools::on_role_change;
|
||||||
|
use serenity::model::guild::Member;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
async_trait,
|
async_trait,
|
||||||
client::{Context, EventHandler},
|
client::{Context, EventHandler},
|
||||||
|
@ -11,11 +13,9 @@ use serenity::{
|
||||||
},
|
},
|
||||||
Client,
|
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 skynet_discord_bot::{db_init, get_config, get_server_config, get_server_member, Config, DataBase};
|
||||||
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use crate::commands::role_adder::tools::on_role_change;
|
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
|
|
||||||
|
@ -126,7 +126,6 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
|
||||||
|
|
||||||
// handles role updates
|
// handles role updates
|
||||||
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Member) {
|
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Member) {
|
||||||
|
|
||||||
// get config/db
|
// get config/db
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
let data_read = ctx.data.read().await;
|
let data_read = ctx.data.read().await;
|
||||||
|
|
Loading…
Reference in a new issue