From 1b53f82e8a8df31a34696d11d8e4c26b697cd3bb Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Thu, 4 Dec 2025 19:08:27 +0100 Subject: [PATCH] refactor(discord-bot): move types to their services --- apps/discord-bot/src/services/wov.ts | 16 +++++++++++++- apps/discord-bot/src/types/index.ts | 30 --------------------------- apps/discord-bot/src/utils/discord.ts | 22 ++++++++++++++------ apps/discord-bot/src/utils/quest.ts | 2 +- 4 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 apps/discord-bot/src/types/index.ts diff --git a/apps/discord-bot/src/services/wov.ts b/apps/discord-bot/src/services/wov.ts index 489a1d9..a3c16bb 100644 --- a/apps/discord-bot/src/services/wov.ts +++ b/apps/discord-bot/src/services/wov.ts @@ -1,6 +1,20 @@ import { env } from "~/env"; import { redis } from "@lbf-bot/database"; -import type { QuestResult } from "~/types"; + +export type QuestResult = { + quest: { + id: string; + promoImageUrl: string; + promoImagePrimaryColor: string; + }; + participants: Array; +}; + +export type QuestParticipant = { + playerId: string; + username: string; + xp: number; +}; export const getLatestQuest = async (): Promise => { const response = await fetch( diff --git a/apps/discord-bot/src/types/index.ts b/apps/discord-bot/src/types/index.ts deleted file mode 100644 index 4db9887..0000000 --- a/apps/discord-bot/src/types/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -export type QuestResult = { - quest: { - id: string; - promoImageUrl: string; - promoImagePrimaryColor: string; - }; - participants: Array; -}; - -export type QuestParticipant = { - playerId: string; - username: string; - xp: number; -}; - -export type DiscordMessage = { - content: string; - embeds: Array; -}; - -export type DiscordEmbed = { - title?: string; - description: string; - image?: { - url: string; - }; - color: number; -}; - -export type TrackedPlayers = Record; diff --git a/apps/discord-bot/src/utils/discord.ts b/apps/discord-bot/src/utils/discord.ts index 0502af7..4c4ab99 100644 --- a/apps/discord-bot/src/utils/discord.ts +++ b/apps/discord-bot/src/utils/discord.ts @@ -1,16 +1,17 @@ import { getAccountBalance, setAccountBalance } from "~/services/account"; import { env } from "~/env"; -import type { QuestResult, DiscordMessage, DiscordEmbed } from "~/types"; +import type { QuestResult } from "~/services/wov"; +import type { MessageCreateOptions, APIEmbed } from "discord.js"; export const makeResultEmbed = async ( result: QuestResult, exclude: Array, -): Promise => { +): Promise => { const imageUrl = result.quest.promoImageUrl; const color = parseInt(result.quest.promoImagePrimaryColor.substring(1), 16); const participants = result.participants.toSorted((a, b) => b.xp - a.xp); - let rewardsEmbed: DiscordEmbed | undefined; + let rewardsEmbed: APIEmbed | undefined; if (env.QUEST_REWARDS) { const rewardedParticipants = participants .map((x) => ({ id: x.playerId, username: x.username })) @@ -69,7 +70,10 @@ export const makeResultEmbed = async ( }; }; -export const createErrorEmbed = (message: string, color = 15335424) => ({ +export const createErrorEmbed = ( + message: string, + color = 15335424, +): MessageCreateOptions => ({ embeds: [ { description: `### ❌ Erreur\n\n\n${message}`, @@ -78,7 +82,10 @@ export const createErrorEmbed = (message: string, color = 15335424) => ({ ], }); -export const createSuccessEmbed = (message: string, color = 65280) => ({ +export const createSuccessEmbed = ( + message: string, + color = 65280, +): MessageCreateOptions => ({ embeds: [ { description: `### ✅ ${message}`, @@ -87,7 +94,10 @@ export const createSuccessEmbed = (message: string, color = 65280) => ({ ], }); -export const createInfoEmbed = (message: string, color = 0x89cff0) => ({ +export const createInfoEmbed = ( + message: string, + color = 0x89cff0, +): MessageCreateOptions => ({ embeds: [ { description: message, diff --git a/apps/discord-bot/src/utils/quest.ts b/apps/discord-bot/src/utils/quest.ts index 70a404b..7645db0 100644 --- a/apps/discord-bot/src/utils/quest.ts +++ b/apps/discord-bot/src/utils/quest.ts @@ -1,7 +1,7 @@ import { ChannelType, type Client, type Message } from "discord.js"; import { env } from "~/env"; import { makeResultEmbed } from "~/utils/discord"; -import type { QuestResult } from "~/types"; +import type { QuestResult } from "~/services/wov"; export const askForGrinders = async (quest: QuestResult, client: Client) => { const adminChannel = await client.channels.fetch(env.DISCORD_ADMIN_CHANNEL);