Skip to content

Commit

Permalink
more icon refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Jan 4, 2025
1 parent 2a5d227 commit 3ce4133
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/services/discord/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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();
Expand Down
1 change: 0 additions & 1 deletion app/services/discord/modules/discord-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export default async (bot: DiscordBot): Promise<void> => {
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
Expand Down
10 changes: 4 additions & 6 deletions app/services/discord/modules/discord-guild-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const fileExists = async (filePath: PathLike) =>
.catch(() => false);

export default async (bot: DiscordBot): Promise<void> => {
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;
Expand All @@ -57,21 +57,19 @@ export default async (bot: DiscordBot): Promise<void> => {

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 () => {
Expand Down

0 comments on commit 3ce4133

Please sign in to comment.