spectate command; remove spectate from ST; currently_playing improvements
This commit is contained in:
92
src/main.rs
92
src/main.rs
@@ -1,12 +1,16 @@
|
|||||||
use std::{future::Future, io, path::Path};
|
use std::{future::Future, io, path::Path};
|
||||||
|
|
||||||
use ::serenity::all::{ChannelId, GuildId, UserId};
|
use ::serenity::all::{ChannelId, GuildId, Mentionable, UserId};
|
||||||
use eyre::{Context as _, Error, OptionExt, Result};
|
use eyre::{Context as _, Error, OptionExt, Result};
|
||||||
use futures::{FutureExt, StreamExt, TryStreamExt};
|
use futures::{FutureExt, StreamExt, TryStreamExt};
|
||||||
use poise::serenity_prelude as serenity;
|
use poise::serenity_prelude as serenity;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use rusqlite::OptionalExtension;
|
use rusqlite::OptionalExtension;
|
||||||
use tracing_subscriber::{fmt::{self, format::FmtSpan}, layer::SubscriberExt, EnvFilter};
|
use tracing_subscriber::{
|
||||||
|
fmt::{self, format::FmtSpan},
|
||||||
|
layer::SubscriberExt,
|
||||||
|
EnvFilter,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
struct GuildData {
|
struct GuildData {
|
||||||
@@ -175,7 +179,12 @@ async fn collect(
|
|||||||
.flatten()
|
.flatten()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
move_users(ctx, guild, users.iter().map(|user| (to, user.user.id)).collect()).await?;
|
move_users(
|
||||||
|
ctx,
|
||||||
|
guild,
|
||||||
|
users.iter().map(|user| (to, user.user.id)).collect(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
futures::future::try_join_all(users.iter().map(|user| guild.move_member(&ctx, user, to)))
|
futures::future::try_join_all(users.iter().map(|user| guild.move_member(&ctx, user, to)))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -253,31 +262,54 @@ async fn join(
|
|||||||
|
|
||||||
#[poise::command(slash_command, ephemeral)]
|
#[poise::command(slash_command, ephemeral)]
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<()> {
|
async fn st(ctx: Context<'_>) -> Result<()> {
|
||||||
let guild = ctx
|
let guild = ctx
|
||||||
.guild_id()
|
.guild_id()
|
||||||
.ok_or_eyre("This bot only works in servers")?;
|
.ok_or_eyre("This bot only works in servers")?;
|
||||||
let GuildData { st, .. } = ctx.data().get(guild).await?;
|
let GuildData { st, .. } = ctx.data().get(guild).await?;
|
||||||
spectators.push(ctx.author().id);
|
let sender = ctx.author().id;
|
||||||
|
|
||||||
futures::future::try_join_all(guild.members(&ctx, None, None).await?.into_iter().map(
|
futures::future::try_join_all(guild.members(&ctx, None, None).await?.into_iter().map(
|
||||||
|member| {
|
|member| async move {
|
||||||
let spectators = &spectators;
|
match (sender == member.user.id, member.roles.contains(&st)) {
|
||||||
async move {
|
|
||||||
match (
|
|
||||||
spectators.contains(&member.user.id),
|
|
||||||
member.roles.contains(&st),
|
|
||||||
) {
|
|
||||||
(true, true) | (false, false) => Ok(()),
|
(true, true) | (false, false) => Ok(()),
|
||||||
(true, false) => member.add_role(&ctx, st).await,
|
(true, false) => member.add_role(&ctx, st).await,
|
||||||
(false, true) => member.remove_role(&ctx, st).await,
|
(false, true) => member.remove_role(&ctx, st).await,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
ctx.reply(format!("{} members given ST", spectators.len()))
|
ctx.reply("You are now the ST").await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[poise::command(slash_command, ephemeral)]
|
||||||
|
#[tracing::instrument]
|
||||||
|
async fn spectate(ctx: Context<'_>, player: Option<serenity::UserId>) -> Result<()> {
|
||||||
|
let guild = ctx
|
||||||
|
.guild_id()
|
||||||
|
.ok_or_eyre("This bot only works in servers")?;
|
||||||
|
let GuildData { st, .. } = ctx.data().get(guild).await?;
|
||||||
|
|
||||||
|
let member = guild
|
||||||
|
.member(&ctx, player.unwrap_or(ctx.author().id))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let msg = if member.roles.contains(&st) {
|
||||||
|
member.remove_role(&ctx, st).await?;
|
||||||
|
"no longer a spectator"
|
||||||
|
} else {
|
||||||
|
member.add_role(&ctx, st).await?;
|
||||||
|
"now a spectator"
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.reply(if player.is_some() {
|
||||||
|
format!("{} is {}", member.mention(), msg)
|
||||||
|
} else {
|
||||||
|
format!("You are {}", msg)
|
||||||
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -285,22 +317,31 @@ async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<(
|
|||||||
|
|
||||||
#[poise::command(slash_command, ephemeral)]
|
#[poise::command(slash_command, ephemeral)]
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn currently_playing(ctx: Context<'_>, players: Vec<serenity::UserId>) -> Result<()> {
|
async fn currently_playing(ctx: Context<'_>, player: Option<serenity::UserId>) -> Result<()> {
|
||||||
let guild = ctx
|
let guild = ctx
|
||||||
.guild_id()
|
.guild_id()
|
||||||
.ok_or_eyre("This bot only works in servers")?;
|
.ok_or_eyre("This bot only works in servers")?;
|
||||||
let GuildData {
|
let GuildData { currently_playing, .. } = ctx.data().get(guild).await?;
|
||||||
currently_playing, ..
|
|
||||||
} = ctx.data().get(guild).await?;
|
let member = guild
|
||||||
for player in &players {
|
.member(&ctx, player.unwrap_or(ctx.author().id))
|
||||||
guild
|
|
||||||
.member(&ctx, player)
|
|
||||||
.await?
|
|
||||||
.add_role(&ctx, currently_playing)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
|
||||||
ctx.reply(format!("Given {} members currently playing", players.len()))
|
let msg = if member.roles.contains(¤tly_playing) {
|
||||||
|
member.remove_role(&ctx, currently_playing).await?;
|
||||||
|
"no longer"
|
||||||
|
} else {
|
||||||
|
member.add_role(&ctx, currently_playing).await?;
|
||||||
|
"now"
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.reply(if player.is_some() {
|
||||||
|
format!("{} is {} {}", member.mention(), msg, currently_playing.mention())
|
||||||
|
} else {
|
||||||
|
format!("You are {} {}", msg, currently_playing.mention())
|
||||||
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,6 +423,7 @@ async fn main() -> Result<()> {
|
|||||||
dusk(),
|
dusk(),
|
||||||
dawn(),
|
dawn(),
|
||||||
st(),
|
st(),
|
||||||
|
spectate(),
|
||||||
currently_playing(),
|
currently_playing(),
|
||||||
join(),
|
join(),
|
||||||
configure(),
|
configure(),
|
||||||
|
|||||||
Reference in New Issue
Block a user