Speed up ST command at the cost of large servers
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -179,7 +179,11 @@ async fn dawn(ctx: Context<'_>) -> Result<()> {
|
||||
}
|
||||
|
||||
#[poise::command(slash_command, ephemeral)]
|
||||
async fn join(ctx: Context<'_>, to: serenity::UserId, user: Option<serenity::UserId>) -> Result<()> {
|
||||
async fn join(
|
||||
ctx: Context<'_>,
|
||||
to: serenity::UserId,
|
||||
user: Option<serenity::UserId>,
|
||||
) -> Result<()> {
|
||||
let guild = ctx
|
||||
.guild_id()
|
||||
.ok_or_eyre("This bot only works in servers")?;
|
||||
@@ -195,7 +199,9 @@ async fn join(ctx: Context<'_>, to: serenity::UserId, user: Option<serenity::Use
|
||||
|
||||
match channel {
|
||||
Some(channel) => {
|
||||
guild.move_member(ctx, user.unwrap_or(ctx.author().id), channel).await?;
|
||||
guild
|
||||
.move_member(ctx, user.unwrap_or(ctx.author().id), channel)
|
||||
.await?;
|
||||
ctx.reply("Joined player").await?;
|
||||
}
|
||||
None => {
|
||||
@@ -213,9 +219,8 @@ async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<(
|
||||
let GuildData { st, .. } = ctx.data().get(guild).await?;
|
||||
spectators.push(ctx.author().id);
|
||||
|
||||
guild
|
||||
.members_iter(&ctx)
|
||||
.try_for_each(|member| {
|
||||
futures::future::try_join_all(guild.members(&ctx, None, None).await?.into_iter().map(
|
||||
|member| {
|
||||
let spectators = &spectators;
|
||||
async move {
|
||||
if spectators.contains(&member.user.id) {
|
||||
@@ -224,7 +229,8 @@ async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<(
|
||||
member.remove_role(&ctx, st).await
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
|
||||
ctx.reply(format!("{} members given ST", spectators.len()))
|
||||
@@ -313,7 +319,14 @@ async fn main() -> Result<()> {
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![dusk(), dawn(), st(), currently_playing(), join(), configure()],
|
||||
commands: vec![
|
||||
dusk(),
|
||||
dawn(),
|
||||
st(),
|
||||
currently_playing(),
|
||||
join(),
|
||||
configure(),
|
||||
],
|
||||
event_handler: |ctx, ev, ctxf, data| on_event(ctx, ev, ctxf, data).boxed(),
|
||||
..Default::default()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user