feat: fmt and clippy

This commit is contained in:
silver 2023-08-27 17:38:30 +01:00
parent 9b42187b22
commit 802f3fce59
2 changed files with 245 additions and 224 deletions

9
.rustfmt.toml Normal file
View file

@ -0,0 +1,9 @@
max_width = 150
single_line_if_else_max_width = 100
chain_width = 100
fn_params_layout = "Compressed"
#control_brace_style = "ClosingNextLine"
#brace_style = "PreferSameLine"
struct_lit_width = 0
tab_spaces = 2
use_small_heuristics = "Max"

View file

@ -1,14 +1,25 @@
use std::env;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use dotenvy::dotenv;
use serenity::async_trait;
use serenity::model::gateway::{GatewayIntents, Ready};
use serenity::model::guild::Member;
use serenity::model::id::GuildId;
use serenity::prelude::*;
use serenity::model::prelude::RoleId;
use serenity::{
async_trait,
client::{Context, EventHandler},
model::{
gateway::{GatewayIntents, Ready},
guild::Member,
id::GuildId,
prelude::RoleId,
},
prelude::TypeMapKey,
Client,
};
use std::{
env,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
};
use tokio::sync::RwLock;
struct Handler {
is_loop_running: AtomicBool,
@ -32,10 +43,10 @@ impl EventHandler for Handler {
if members.contains(&new_member.user.name) {
let mut roles = vec![];
if !new_member.roles.contains(&config.member_role_past){
if !new_member.roles.contains(&config.member_role_past) {
roles.push(config.member_role_past);
}
if !new_member.roles.contains(&config.member_role_current){
if !new_member.roles.contains(&config.member_role_current) {
roles.push(config.member_role_current);
}
@ -99,7 +110,7 @@ struct Members;
impl TypeMapKey for Members {
type Value = Arc<RwLock<Vec<String>>>;
}
async fn bulk_check(ctx: Arc<Context>){
async fn bulk_check(ctx: Arc<Context>) {
let config_lock = {
let data_read = ctx.data.read().await;
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
@ -112,7 +123,7 @@ async fn bulk_check(ctx: Arc<Context>){
};
let members = members_lock.read().await;
let mut roles_set = [0,0,0];
let mut roles_set = [0, 0, 0];
let mut res = MembersCount {
members: 0,
members_current: 0,
@ -122,11 +133,11 @@ async fn bulk_check(ctx: Arc<Context>){
if members.contains(&member.user.name) {
let mut roles = vec![];
if !member.roles.contains(&config.member_role_past){
if !member.roles.contains(&config.member_role_past) {
roles_set[0] += 1;
roles.push(config.member_role_past);
}
if !member.roles.contains(&config.member_role_current){
if !member.roles.contains(&config.member_role_current) {
roles_set[1] += 1;
roles.push(config.member_role_current);
}
@ -142,10 +153,10 @@ async fn bulk_check(ctx: Arc<Context>){
}
}
if member.roles.contains(&config.member_role_past){
if member.roles.contains(&config.member_role_past) {
res.members += 1;
}
if member.roles.contains(&config.member_role_current){
if member.roles.contains(&config.member_role_current) {
res.members_current += 1;
}
}
@ -166,7 +177,7 @@ async fn bulk_check(ctx: Arc<Context>){
};
}
async fn fetch_accounts(ctx: Arc<Context>){
async fn fetch_accounts(ctx: Arc<Context>) {
let config_lock = {
let data_read = ctx.data.read().await;
data_read.get::<Config>().expect("Expected Config in TypeMap.").clone()
@ -193,7 +204,9 @@ async fn main() {
let intents = GatewayIntents::GUILDS | GatewayIntents::GUILD_MESSAGES | GatewayIntents::MESSAGE_CONTENT | GatewayIntents::GUILD_MEMBERS;
// Build our client.
let mut client = Client::builder(&config.discord_token, intents)
.event_handler(Handler { is_loop_running: AtomicBool::new(false)})
.event_handler(Handler {
is_loop_running: AtomicBool::new(false),
})
.await
.expect("Error creating client");
@ -206,10 +219,10 @@ async fn main() {
// a list of all current members
data.insert::<Members>(Arc::new(RwLock::new(vec![])));
// make config available top all, strangely its easier to keep it in a shared lock state.
data.insert::<Config>(Arc::new(RwLock::new(config)));
}
// Finally, start a single shard, and start listening to events.
//
// Shards will automatically attempt to reconnect, and will perform
@ -219,7 +232,6 @@ async fn main() {
}
}
struct Config {
server: GuildId,
member_role_current: RoleId,