Add configurable bot nickname

This commit is contained in:
Lucy Bladen 2021-11-17 15:12:21 +00:00
parent 62712c44d4
commit 819feef76b
2 changed files with 11 additions and 1 deletions

View File

@ -24,7 +24,7 @@ impl Handler {
#[async_trait] #[async_trait]
impl EventHandler for Handler { impl EventHandler for Handler {
async fn ready(&self, ctx: Context, _data_about_bot: Ready) { async fn ready(&self, ctx: Context, data_about_bot: Ready) {
let data = ctx.data.read().await; let data = ctx.data.read().await;
let config = match data.get::<ManifoldConfig>() { let config = match data.get::<ManifoldConfig>() {
Some(c) => c.lock().await, Some(c) => c.lock().await,
@ -41,7 +41,16 @@ impl EventHandler for Handler {
None => "Manifold bot connected to discord and ready to begin broadcast operations.".to_string(), None => "Manifold bot connected to discord and ready to begin broadcast operations.".to_string(),
}; };
let bot_nickname = config.get_value(&"BotNickname".to_string()).map(|n| n.as_str());
let channel: ChannelId = config.get_channel(&"Log".to_string()); let channel: ChannelId = config.get_channel(&"Log".to_string());
for guild in data_about_bot.guilds {
match guild.id().edit_nickname(&ctx, bot_nickname).await {
Ok(()) => (),
Err(e) => {
error!("Error setting bot nickname (lack permission?): {:?}", e);
}
}
}
channel.say(&ctx, greeting).await.expect("Couldn't message log channel!"); channel.say(&ctx, greeting).await.expect("Couldn't message log channel!");
} }

View File

@ -75,6 +75,7 @@ pub async fn prepare_client<T: 'static + EventHandler>(arguments: ArgMatches<'_>
Err(e) => {error!("Could not write new config! {}", e.details); Err(e)?} Err(e) => {error!("Could not write new config! {}", e.details); Err(e)?}
} }
} }
Err("MadeConfig")?
} }
info!("Reading configuration..."); info!("Reading configuration...");