feat: set the bot nickname and status
This commit is contained in:
60
src/main.rs
60
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<UserMarker>,
|
||||
discord_bot_owner_user_id: Id<UserMarker>,
|
||||
|
||||
#[arg(long, env)]
|
||||
discord_nickname: Option<Arc<str>>,
|
||||
|
||||
#[arg(long, env)]
|
||||
discord_status: Option<Arc<str>>,
|
||||
|
||||
#[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<CommandRouter>, state: State, mut shard: Shard) {
|
||||
let event_types = EventTypeFlags::GUILD_VOICE_STATES
|
||||
| EventTypeFlags::INTERACTION_CREATE
|
||||
|
||||
Reference in New Issue
Block a user