Add refresh_non_members command

Add field to `Data` to store `RoleId`
Command streams all members and checks for no roles, giving users `non-member` role
This commit is contained in:
Aadi Desai 2023-10-15 15:20:20 +01:00
parent a9ac1e5368
commit 63c453d370
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 31 additions and 0 deletions

View file

@ -88,6 +88,29 @@ pub(crate) async fn edit_member_fresher(
Ok(())
}
/// Set all members with no roles to non-member
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)]
pub(crate) async fn refresh_non_members(ctx: ACtx<'_>) -> Result<(), Error> {
use serenity::futures::StreamExt;
tracing::info!("{}", ctx.author().name);
let mut members = ctx.data().server.members_iter(ctx.http()).boxed();
let mut cnt = 0;
while let Some(Ok(mut m)) = members.next().await {
if m.roles.is_empty() {
m.add_role(ctx.http(), ctx.data().non_member).await?;
cnt += 1;
}
}
tracing::info!("{cnt} users given non-member role");
ctx.say(format!(
"{cnt} users given <@&{}> role",
ctx.data().non_member
))
.await?;
Ok(())
}
/// Set all members to non-freshers
#[tracing::instrument(skip_all)]
#[poise::command(slash_command)]

View file

@ -18,6 +18,7 @@ struct Data {
fresher: serenity::RoleId,
gn_ch_id: serenity::ChannelId,
member: serenity::RoleId,
non_member: serenity::RoleId,
old_member: serenity::RoleId,
server: serenity::GuildId,
}
@ -95,6 +96,11 @@ async fn poise(
.expect("MEMBER_ID not found")
.parse()
.expect("MEMBER_ID not valid u64");
let non_member = secret_store
.get("NON_MEMBER_ID")
.expect("NON_MEMBER_ID not found")
.parse()
.expect("NON_MEMBER_ID not valid u64");
let old_member = secret_store
.get("OLD_MEMBER_ID")
.expect("OLD_MEMBER_ID not found")
@ -141,6 +147,7 @@ async fn poise(
fresher,
gn_ch_id,
member,
non_member,
old_member,
server,
})
@ -248,6 +255,7 @@ fn all_commands() -> Vec<poise::Command<Data, Error>> {
cmds::insert_member_from_pending(),
cmds::insert_member_from_manual(),
cmds::edit_member(),
cmds::refresh_non_members(),
cmds::set_members_non_fresher(),
cmds::count_pending(),
cmds::delete_pending(),