From 3ce413322b475db2bac1c2c68393bbe7e1479493 Mon Sep 17 00:00:00 2001 From: Techbot121 Date: Sat, 4 Jan 2025 18:16:02 +0100 Subject: [PATCH] more icon refactoring --- app/services/discord/index.ts | 5 +++-- app/services/discord/modules/discord-events.ts | 1 - app/services/discord/modules/discord-guild-icon.ts | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/services/discord/index.ts b/app/services/discord/index.ts index 88b5f58..88c8259 100644 --- a/app/services/discord/index.ts +++ b/app/services/discord/index.ts @@ -118,12 +118,13 @@ export class DiscordBot extends Service { // sets both the bot's avatar and the guild's icon async setIcon( - path = this.data?.lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png" + path = this.data?.lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png", + reason?: string ): Promise { if (!this.ready || !this.discord.user) return false; try { await this.discord.user.setAvatar(path); - await this.getGuild()?.setIcon(path); + await this.getGuild()?.setIcon(path, reason); if (this.data) { this.data.lastDiscordGuildIcon = path; await this.data.save(); diff --git a/app/services/discord/modules/discord-events.ts b/app/services/discord/modules/discord-events.ts index 5dc86c4..b2c918e 100644 --- a/app/services/discord/modules/discord-events.ts +++ b/app/services/discord/modules/discord-events.ts @@ -67,7 +67,6 @@ export default async (bot: DiscordBot): Promise => { if (match) { const path = join(iconsPath, `${icon}.png`); await bot.setIcon(path); - await bot.discord.user?.setAvatar(path); await bot.setNickname( nicks[(Math.random() * nicks.length) | 0], event.name diff --git a/app/services/discord/modules/discord-guild-icon.ts b/app/services/discord/modules/discord-guild-icon.ts index e89b2b9..3c4338b 100644 --- a/app/services/discord/modules/discord-guild-icon.ts +++ b/app/services/discord/modules/discord-guild-icon.ts @@ -45,10 +45,10 @@ const fileExists = async (filePath: PathLike) => .catch(() => false); export default async (bot: DiscordBot): Promise => { - const data = await bot.container.getService("Data"); bot.discord.on("ready", async () => { const guild = bot.getGuild(); if (!guild) return; + const data = await bot.container.getService("Data"); const changeIcon = async (filePath: string, eventName: string) => { const eventChange = data.lastDiscordGuildEvent !== eventName; @@ -57,21 +57,19 @@ export default async (bot: DiscordBot): Promise => { if (eventChange && !guildEvents.find(ev => ev.isActive())) { try { - await guild.setIcon( + await bot.setIcon( filePath, eventName !== "None" ? `It's ${eventName}!` : "Back to regularly scheduled activities." ); - await bot.discord.user?.setAvatar(filePath); - data.lastDiscordGuildIcon = filePath; + data.lastDiscordGuildEvent = eventName; + await data.save(); } catch (err) { console.error(err); return; } - data.lastDiscordGuildEvent = eventName; } - await data.save(); }; const checkDate = async () => {