mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 06:05:50 +00:00
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:
parent
a9ac1e5368
commit
63c453d370
|
@ -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)]
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue