fmt: formatting and clippy
This commit is contained in:
parent
b7161e2614
commit
344d6d3585
14 changed files with 130 additions and 138 deletions
|
@ -1,11 +1,11 @@
|
|||
pub mod normal {
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::{GuildId, RoleId, UserId};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use crate::common::database::{DataBase, ServerMembersWolves, Servers, Wolves};
|
||||
use crate::get_now_iso;
|
||||
use crate::common::database::{DataBase, ServerMembersWolves, Servers, Wolves};
|
||||
use crate::get_now_iso;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::id::{GuildId, RoleId, UserId};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) {
|
||||
pub async fn update_server(ctx: &Context, server: &Servers, remove_roles: &[Option<RoleId>], members_changed: &[UserId]) {
|
||||
let db_lock = {
|
||||
let data_read = ctx.data.read().await;
|
||||
data_read.get::<DataBase>().expect("Expected Database in TypeMap.").clone()
|
||||
|
@ -131,14 +131,14 @@ pub mod normal {
|
|||
|
||||
// for updating committee members
|
||||
pub mod committee {
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use crate::common::database::{DataBase, Wolves};
|
||||
use crate::common::wolves::committees::Committees;
|
||||
use serenity::client::Context;
|
||||
use serenity::model::guild::Member;
|
||||
use serenity::model::id::{GuildId, RoleId};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use crate::common::database::{DataBase, Wolves};
|
||||
use crate::common::wolves::committees::Committees;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub async fn check_committee(ctx: Arc<Context>) {
|
||||
let db_lock = {
|
||||
|
@ -154,7 +154,7 @@ pub mod committee {
|
|||
update_committees(&db, &ctx, &mut members).await;
|
||||
}
|
||||
|
||||
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, members: &mut Vec<Member>){
|
||||
pub async fn update_committees(db: &Pool<Sqlite>, ctx: &Context, members: &mut Vec<Member>) {
|
||||
let server = GuildId(1220150752656363520);
|
||||
let committee_member = RoleId(1226602779968274573);
|
||||
let committees = get_committees(db).await;
|
||||
|
@ -168,24 +168,21 @@ pub mod committee {
|
|||
roles_name.insert(role.name.to_owned(), role.to_owned());
|
||||
}
|
||||
|
||||
|
||||
// a map of users and the roles they are goign to be getting
|
||||
let mut users_roles = HashMap::new();
|
||||
|
||||
// a list of all the roles that can be removed from folks who should have them
|
||||
let mut committee_roles = vec![
|
||||
committee_member
|
||||
];
|
||||
let mut committee_roles = vec![committee_member];
|
||||
|
||||
for committee in &committees {
|
||||
// get the role for this committee/club/soc
|
||||
let role = match roles_name.get(&committee.name) {
|
||||
Some(x) => {Some(x.to_owned())}
|
||||
Some(x) => Some(x.to_owned()),
|
||||
None => {
|
||||
// create teh role if it does not exist
|
||||
match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name)).await{
|
||||
Ok(x) => { Some(x) }
|
||||
Err(_) => {None}
|
||||
match server.create_role(&ctx, |r| r.hoist(false).mentionable(true).name(&committee.name)).await {
|
||||
Ok(x) => Some(x),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -196,7 +193,7 @@ pub mod committee {
|
|||
|
||||
for id_wolves in &committee.committee {
|
||||
// ID in this is the wolves ID, so we need to get a matching discord ID (if one exists)
|
||||
if let Some(x) = get_server_member_discord(&db, id_wolves).await {
|
||||
if let Some(x) = get_server_member_discord(db, id_wolves).await {
|
||||
if let Some(member_tmp) = x.discord {
|
||||
let values = users_roles.entry(member_tmp).or_insert(vec![]);
|
||||
values.push(r.id);
|
||||
|
@ -245,9 +242,9 @@ pub mod committee {
|
|||
FROM committees
|
||||
"#,
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
async fn get_server_member_discord(db: &Pool<Sqlite>, user: &i64) -> Option<Wolves> {
|
||||
|
@ -258,9 +255,9 @@ pub mod committee {
|
|||
WHERE id_wolves = ?
|
||||
"#,
|
||||
)
|
||||
.bind(user)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
.bind(user)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue