Skip to content

Commit 94d5089

Browse files
committed
Move emoji to context
1 parent 5987874 commit 94d5089

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/commands/springerWarning.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,7 @@ export default class SpringerWarningCommand implements SpecialCommand {
333333
return;
334334
}
335335

336-
const alarm = context.guild.emojis.resolve("677503944007876608");
337-
if (!alarm) {
338-
throw new Error("Alarm emoji not found");
339-
}
340-
336+
const alarm = context.emoji.alarm;
341337
await message.suppressEmbeds(true);
342338
await message.reply(`${alarm} Achtung, Link geht zu ${warning} ${alarm}`);
343339
}

src/context.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
VoiceChannel,
1111
APIInteractionGuildMember,
1212
Message,
13+
GuildEmoji,
1314
} from "discord.js";
1415
import { ChannelType } from "discord.js";
1516
import { SpotifyApi } from "@spotify/web-api-ts-sdk";
@@ -149,6 +150,10 @@ export interface BotContext {
149150
channelGuard: {
150151
isInBotSpam: (message: Message) => boolean;
151152
};
153+
154+
emoji: {
155+
alarm: GuildEmoji;
156+
};
152157
}
153158

154159
export interface QuoteConfig {
@@ -196,6 +201,14 @@ function ensureVoiceChannel(guild: Guild, channelId: Snowflake): VoiceChannel {
196201
return channel;
197202
}
198203

204+
function ensureEmoji(guild: Guild, emojiId: Snowflake): GuildEmoji {
205+
const emoji = guild.emojis.resolve(emojiId);
206+
if (!emoji) {
207+
throw new Error(`Emoji with ID "${emojiId}" not found in guild "${guild.id}"`);
208+
}
209+
return emoji;
210+
}
211+
199212
// #endregion
200213

201214
export async function createBotContext(client: Client<true>): Promise<BotContext> {
@@ -351,6 +364,10 @@ export async function createBotContext(client: Client<true>): Promise<BotContext
351364
channelGuard: {
352365
isInBotSpam: message => message.channelId === config.textChannel.botSpamChannelId,
353366
},
367+
368+
emoji: {
369+
alarm: ensureEmoji(guild, "677503944007876608"),
370+
},
354371
};
355372
}
356373

0 commit comments

Comments
 (0)