feat: when someone joins, if their account name is in the list then they are automatically added
This commit is contained in:
parent
f382784141
commit
58def2e01e
1 changed files with 27 additions and 11 deletions
38
src/main.rs
38
src/main.rs
|
@ -3,8 +3,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::gateway::{GatewayIntents, Ready};
|
||||||
use serenity::model::gateway::{GatewayIntents, Presence, Ready};
|
use serenity::model::guild::Member;
|
||||||
use serenity::model::id::GuildId;
|
use serenity::model::id::GuildId;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use serenity::model::prelude::RoleId;
|
use serenity::model::prelude::RoleId;
|
||||||
|
@ -15,17 +15,33 @@ struct Handler {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
// This event will be dispatched for guilds, but not for direct messages.
|
async fn guild_member_addition(&self, ctx: Context, mut new_member: Member) {
|
||||||
async fn message(&self, _ctx: Context, msg: Message) {
|
let config = Config {
|
||||||
println!("Received message: {}", msg.content);
|
server: GuildId(957961810147938334),
|
||||||
|
member_role_current: RoleId::from(1144760670995370094),
|
||||||
|
member_role_past: RoleId::from(1144760548072886353),
|
||||||
|
};
|
||||||
|
|
||||||
|
let members_lock = {
|
||||||
}
|
let data_read = ctx.data.read().await;
|
||||||
|
data_read.get::<Members>().expect("Expected Members in TypeMap.").clone()
|
||||||
|
};
|
||||||
|
|
||||||
// As the intents set in this example, this event shall never be dispatched.
|
let members = members_lock.read().await;
|
||||||
// Try it by changing your status.
|
if members.contains(&new_member.user.name) {
|
||||||
async fn presence_update(&self, _ctx: Context, _new_data: Presence) {
|
let mut roles = vec![];
|
||||||
println!("Presence Update");
|
|
||||||
|
if !new_member.roles.contains(&config.member_role_past){
|
||||||
|
roles.push(config.member_role_past);
|
||||||
|
}
|
||||||
|
if !new_member.roles.contains(&config.member_role_current){
|
||||||
|
roles.push(config.member_role_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = new_member.add_roles(&ctx, &roles).await {
|
||||||
|
println!("{:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||||
|
|
Loading…
Reference in a new issue