From 904ff5a2130358cdfbc8ae5ad2489c8df4c1b752 Mon Sep 17 00:00:00 2001 From: jakubmanczak Date: Fri, 20 Jun 2025 17:59:06 +0200 Subject: [PATCH] events: also update bot's avatar The events service will now also update the bot's avatar to reflect the current event, alongside the server icon's update. --- src/discordbot/events/service.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/discordbot/events/service.rs b/src/discordbot/events/service.rs index 2dcd0f7..1e7fd2d 100644 --- a/src/discordbot/events/service.rs +++ b/src/discordbot/events/service.rs @@ -1,13 +1,13 @@ use chrono::{Datelike, Duration, TimeZone, Utc}; use chrono_tz::Europe::Warsaw; -use serenity::all::{Context, CreateAttachment, EditGuild, Guild, GuildId}; +use serenity::all::{Context, CreateAttachment, EditGuild, EditProfile, Guild, GuildId}; use tracing::{error, info, warn}; use super::Event; pub async fn run_event_service(ctx: Context, guild_id: GuildId) { loop { - update_guild(&ctx, guild_id).await.ok(); + update_event_constituents(&ctx, guild_id).await.ok(); // make sure temporal boundaries have been cleared tokio::time::sleep(std::time::Duration::from_secs(10)).await; @@ -15,7 +15,7 @@ pub async fn run_event_service(ctx: Context, guild_id: GuildId) { } } -async fn update_guild(ctx: &Context, guild_id: GuildId) -> Result<(), String> { +async fn update_event_constituents(ctx: &Context, guild_id: GuildId) -> Result<(), String> { let mut guild = match Guild::get(&ctx.http, guild_id).await { Ok(g) => g, Err(e) => { @@ -47,6 +47,18 @@ async fn update_guild(ctx: &Context, guild_id: GuildId) -> Result<(), String> { } }; + match ctx + .http + .edit_profile(&EditProfile::new().avatar(&icon)) + .await + { + Ok(_) => info!("Bot avatar updated."), + Err(e) => { + error!("Could not update bot avatar: {e}"); + return Err("Could not update bot avatar: {e}".to_string()); + } + }; + Ok(()) }