Compare commits

..

2 Commits

Author SHA1 Message Date
bluepython508
99e5a44e40 Add tool to remove embeds for clocktower.live links 2025-12-28 23:12:30 +00:00
bluepython508
3ba25db279 Fix /st?
At this point, IDFK. I changed nothing and the permissions are correct now.
2025-11-01 19:33:05 +00:00
2 changed files with 42 additions and 20 deletions

4
.envrc
View File

@@ -1,4 +1,4 @@
use flake use flake
export DISCORD_TOKEN_FILE=./token export DISCORD_TOKEN_FILE=./token-prod
export DB_FILE=db.sqlite export DB_FILE=db-prod.sqlite

View File

@@ -1,6 +1,6 @@
use std::{future::Future, io, path::Path}; use std::{io, path::Path};
use ::serenity::all::{ChannelId, GuildId, Mentionable, UserId}; use ::serenity::all::{ChannelId, EditMessage, 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;
@@ -107,19 +107,21 @@ async fn channel_children(
} }
#[tracing::instrument] #[tracing::instrument]
fn move_users<'a>( async fn move_users<'a>(
ctx: Context<'a>, ctx: Context<'a>,
guild: GuildId, guild: GuildId,
users: Vec<(ChannelId, UserId)>, users: Vec<(ChannelId, UserId)>,
) -> impl Future<Output = Result<()>> + Send + 'a { ) -> Result<()> {
futures::stream::iter(users.into_iter().map(move |(channel, user)| async move { futures::stream::iter(users.into_iter())
tracing::info!(?channel, ?user, "Moving user"); .map(Ok::<_, eyre::Error>)
guild.move_member(ctx, user, channel).await?; .try_for_each_concurrent(10, move |(channel, user)| async move {
tracing::info!(?channel, ?user, "Moved user"); tracing::info!(?channel, ?user, "Moving user");
Ok(()) guild.move_member(ctx, user, channel).await?;
})) tracing::info!(?channel, ?user, "Moved user");
.buffer_unordered(10) Ok(())
.try_collect::<()>() })
.await?;
Ok(())
} }
#[tracing::instrument] #[tracing::instrument]
@@ -321,7 +323,9 @@ async fn currently_playing(ctx: Context<'_>, player: Option<serenity::UserId>) -
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 { currently_playing, .. } = ctx.data().get(guild).await?; let GuildData {
currently_playing, ..
} = ctx.data().get(guild).await?;
let member = guild let member = guild
.member(&ctx, player.unwrap_or(ctx.author().id)) .member(&ctx, player.unwrap_or(ctx.author().id))
@@ -336,7 +340,12 @@ async fn currently_playing(ctx: Context<'_>, player: Option<serenity::UserId>) -
}; };
ctx.reply(if player.is_some() { ctx.reply(if player.is_some() {
format!("{} is {} {}", member.mention(), msg, currently_playing.mention()) format!(
"{} is {} {}",
member.mention(),
msg,
currently_playing.mention()
)
} else { } else {
format!("You are {} {}", msg, currently_playing.mention()) format!("You are {} {}", msg, currently_playing.mention())
}) })
@@ -382,15 +391,28 @@ async fn register_commands(
Ok(()) Ok(())
} }
#[tracing::instrument(skip(ctx))]
async fn handle_message(ctx: impl AsRef<serenity::Http>, message: &serenity::Message) -> Result<()> {
for embed in &message.embeds {
if embed.url.as_ref().is_some_and(|url| url.contains("https://clocktower.live")) {
let mut message = message.clone();
message.edit(&ctx.as_ref(), EditMessage::new().suppress_embeds(true)).await?;
}
}
Ok(())
}
async fn on_event( async fn on_event(
ctx: &serenity::Context, ctx: &serenity::Context,
event: &serenity::FullEvent, event: &serenity::FullEvent,
framework: poise::FrameworkContext<'_, Data, Error>, framework: poise::FrameworkContext<'_, Data, Error>,
_: &Data, _: &Data,
) -> Result<()> { ) -> Result<()> {
if let serenity::FullEvent::GuildCreate { guild, is_new: _ } = event { match event {
register_commands(ctx, framework.options, guild.id).await?; serenity::FullEvent::GuildCreate { guild, is_new: _ } => register_commands(ctx, framework.options, guild.id).await?,
}; serenity::FullEvent::Message { new_message: msg } | serenity::FullEvent::MessageUpdate { new: Some(msg), .. } => handle_message(ctx, msg).await?,
_ => {}
}
Ok(()) Ok(())
} }
@@ -415,7 +437,7 @@ async fn main() -> Result<()> {
.wrap_err("A Discord token is required")?; .wrap_err("A Discord token is required")?;
let dbfile = std::env::var_os("DB_FILE").ok_or_eyre("A database file is required")?; let dbfile = std::env::var_os("DB_FILE").ok_or_eyre("A database file is required")?;
let intents = let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::GUILD_MEMBERS; serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::GUILD_MEMBERS | serenity::GatewayIntents::GUILD_MESSAGES;
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {