feat: function to go through all the users and assign roles
This commit is contained in:
parent
9a158701a9
commit
89e81b575c
1 changed files with 55 additions and 7 deletions
62
src/main.rs
62
src/main.rs
|
@ -1,22 +1,22 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::model::gateway::{GatewayIntents, Presence, Ready};
|
use serenity::model::gateway::{GatewayIntents, Presence, Ready};
|
||||||
|
use serenity::model::id::GuildId;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
use serenity::model::prelude::RoleId;
|
||||||
|
|
||||||
struct Handler;
|
struct Handler;
|
||||||
// eoghanconlon73
|
// eoghanconlon73
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
// This event will be dispatched for guilds, but not for direct messages.
|
// This event will be dispatched for guilds, but not for direct messages.
|
||||||
async fn message(&self, ctx: Context, msg: Message) {
|
async fn message(&self, _ctx: Context, msg: Message) {
|
||||||
println!("Received message: {}", msg.content);
|
println!("Received message: {}", msg.content);
|
||||||
|
|
||||||
|
|
||||||
if let Some(user) = ctx.cache.user("eoghanconlon73") {
|
|
||||||
println!("User with Id eoghanconlon73 is currently named {}", user.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the intents set in this example, this event shall never be dispatched.
|
// As the intents set in this example, this event shall never be dispatched.
|
||||||
|
@ -25,11 +25,59 @@ impl EventHandler for Handler {
|
||||||
println!("Presence Update");
|
println!("Presence Update");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ready(&self, _: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
println!("{} is connected!", ready.user.name);
|
println!("{} is connected!", ready.user.name);
|
||||||
|
|
||||||
|
let config = Config {
|
||||||
|
members: vec![String::from("silver_golden"), String::from("eoghanconlon73")],
|
||||||
|
server: GuildId(957961810147938334),
|
||||||
|
member_role_current: RoleId::from(1144760670995370094),
|
||||||
|
member_role_past: RoleId::from(1144760548072886353),
|
||||||
|
};
|
||||||
|
|
||||||
|
bulk_check(&ctx, &config).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Config {
|
||||||
|
members: Vec<String>,
|
||||||
|
server: GuildId,
|
||||||
|
member_role_current: RoleId,
|
||||||
|
member_role_past: RoleId,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn bulk_check(ctx: &Context, config: &Config){
|
||||||
|
let mut roles_set = [0,0,0];
|
||||||
|
if let Ok(x) = config.server.members(ctx, None, None).await {
|
||||||
|
for mut member in x {
|
||||||
|
if config.members.contains(&member.user.name) {
|
||||||
|
let mut roles = vec![];
|
||||||
|
|
||||||
|
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){
|
||||||
|
roles_set[1] += 1;
|
||||||
|
roles.push(config.member_role_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = member.add_roles(&ctx, &roles).await {
|
||||||
|
println!("{:?}", e);
|
||||||
|
}
|
||||||
|
} else if member.roles.contains(&config.member_role_current) {
|
||||||
|
roles_set[2] += 1;
|
||||||
|
// if theya re not a current member and have the role then remove it
|
||||||
|
if let Err(e) = member.remove_role(&ctx, &config.member_role_current).await {
|
||||||
|
println!("{:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// small bit of logging to note changes over time
|
||||||
|
println!("Changes: New: +{}, Current: +{}/-{}", roles_set[0], roles_set[1], roles_set[2]);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Configure the client with your Discord bot token in the environment.
|
// Configure the client with your Discord bot token in the environment.
|
||||||
|
|
Loading…
Reference in a new issue