From d8d2526782bc5e8f71aec79a20619169b8fba58d Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 14 Apr 2026 00:15:12 -0400 Subject: [PATCH] feat: set the bot nickname and status --- src/main.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index aafe77b..295ab8b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,10 @@ use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan}; use twilight_gateway::{Event, EventTypeFlags, Intents, Shard, StreamExt}; use twilight_model::{ application::interaction::InteractionData, - gateway::payload::incoming::InteractionCreate, + gateway::{ + payload::{incoming::InteractionCreate, outgoing::UpdatePresence}, + presence::{ActivityType, MinimalActivity, Status}, + }, id::{Id, marker::UserMarker}, }; @@ -20,7 +23,13 @@ struct AppArgs { discord_token: SecretString, #[arg(long, env)] - bot_owner: Id, + discord_bot_owner_user_id: Id, + + #[arg(long, env)] + discord_nickname: Option>, + + #[arg(long, env)] + discord_status: Option>, #[arg(long, env)] bot_data: Storage, @@ -77,7 +86,9 @@ async fn main() -> Result<(), MainError> { let AppArgs { discord_token, - bot_owner, + discord_bot_owner_user_id, + discord_nickname, + discord_status, bot_data, user_data, recording_data, @@ -91,6 +102,24 @@ async fn main() -> Result<(), MainError> { let discord_client = twilight_http::Client::new(discord_token.expose_secret().to_owned()); + let guilds = discord_client + .current_user_guilds() + .limit(200) + .await + .expect("TODO") + .model() + .await + .expect("TODO"); + + JoinSet::from_iter(guilds.into_iter().map(|guild| { + discord_client + .update_current_member(guild.id) + .nick(discord_nickname.as_deref()) + .into_future() + })) + .join_all() + .await; + let discord_user = discord_client .current_user() .await @@ -170,7 +199,7 @@ async fn main() -> Result<(), MainError> { bot_data, cancellation_token: cancellation_token.clone(), discord_application_id, - discord_bot_owner_user_id: bot_owner, + discord_bot_owner_user_id, discord_client, discord_user_id, recording_data, @@ -179,6 +208,27 @@ async fn main() -> Result<(), MainError> { vcs, }; + if let Some(discord_status) = discord_status { + shards.iter().for_each(|shard| { + shard.command( + &UpdatePresence::new( + vec![ + MinimalActivity { + kind: ActivityType::Listening, + name: (*discord_status).to_owned(), + url: None, + } + .into(), + ], + false, + None, + Status::Idle, + ) + .expect("TODO"), + ) + }); + } + let run_shards = JoinSet::from_iter( shards .into_iter() @@ -210,7 +260,7 @@ async fn main() -> Result<(), MainError> { } } -#[tracing::instrument(skip(command_router, state))] +#[tracing::instrument(skip(command_router, shard, state))] async fn handle_events(command_router: Arc, state: State, mut shard: Shard) { let event_types = EventTypeFlags::GUILD_VOICE_STATES | EventTypeFlags::INTERACTION_CREATE