mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 14:15:51 +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(())
|
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
|
/// Set all members to non-freshers
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command)]
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct Data {
|
||||||
fresher: serenity::RoleId,
|
fresher: serenity::RoleId,
|
||||||
gn_ch_id: serenity::ChannelId,
|
gn_ch_id: serenity::ChannelId,
|
||||||
member: serenity::RoleId,
|
member: serenity::RoleId,
|
||||||
|
non_member: serenity::RoleId,
|
||||||
old_member: serenity::RoleId,
|
old_member: serenity::RoleId,
|
||||||
server: serenity::GuildId,
|
server: serenity::GuildId,
|
||||||
}
|
}
|
||||||
|
@ -95,6 +96,11 @@ async fn poise(
|
||||||
.expect("MEMBER_ID not found")
|
.expect("MEMBER_ID not found")
|
||||||
.parse()
|
.parse()
|
||||||
.expect("MEMBER_ID not valid u64");
|
.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
|
let old_member = secret_store
|
||||||
.get("OLD_MEMBER_ID")
|
.get("OLD_MEMBER_ID")
|
||||||
.expect("OLD_MEMBER_ID not found")
|
.expect("OLD_MEMBER_ID not found")
|
||||||
|
@ -141,6 +147,7 @@ async fn poise(
|
||||||
fresher,
|
fresher,
|
||||||
gn_ch_id,
|
gn_ch_id,
|
||||||
member,
|
member,
|
||||||
|
non_member,
|
||||||
old_member,
|
old_member,
|
||||||
server,
|
server,
|
||||||
})
|
})
|
||||||
|
@ -248,6 +255,7 @@ fn all_commands() -> Vec<poise::Command<Data, Error>> {
|
||||||
cmds::insert_member_from_pending(),
|
cmds::insert_member_from_pending(),
|
||||||
cmds::insert_member_from_manual(),
|
cmds::insert_member_from_manual(),
|
||||||
cmds::edit_member(),
|
cmds::edit_member(),
|
||||||
|
cmds::refresh_non_members(),
|
||||||
cmds::set_members_non_fresher(),
|
cmds::set_members_non_fresher(),
|
||||||
cmds::count_pending(),
|
cmds::count_pending(),
|
||||||
cmds::delete_pending(),
|
cmds::delete_pending(),
|
||||||
|
|
Loading…
Reference in a new issue