feat: implement lootdrop management endpoints and fix class api types

This commit is contained in:
syntaxbullet
2026-02-08 16:56:34 +01:00
parent 4232674494
commit 073348fa55
3 changed files with 154 additions and 4 deletions

View File

@@ -93,11 +93,11 @@ class LootdropService {
}
}
private async spawnLootdrop(channel: TextChannel) {
public async spawnLootdrop(channel: TextChannel, overrideReward?: number, overrideCurrency?: string) {
const min = config.lootdrop.reward.min;
const max = config.lootdrop.reward.max;
const reward = Math.floor(Math.random() * (max - min + 1)) + min;
const currency = config.lootdrop.reward.currency;
const reward = overrideReward ?? (Math.floor(Math.random() * (max - min + 1)) + min);
const currency = overrideCurrency ?? config.lootdrop.reward.currency;
const { content, files, components } = await getLootdropMessage(reward, currency);
@@ -205,6 +205,36 @@ class LootdropService {
this.channelCooldowns.clear();
console.log("[LootdropService] Caches cleared via administrative action.");
}
public async deleteLootdrop(messageId: string): Promise<boolean> {
try {
// First fetch it to get channel info so we can delete the message
const drop = await DrizzleClient.query.lootdrops.findFirst({
where: eq(lootdrops.messageId, messageId)
});
if (!drop) return false;
// Delete from DB
await DrizzleClient.delete(lootdrops).where(eq(lootdrops.messageId, messageId));
// Try to delete from Discord
try {
const { AuroraClient } = await import("../../../bot/lib/BotClient");
const channel = await AuroraClient.channels.fetch(drop.channelId) as TextChannel;
if (channel) {
const message = await channel.messages.fetch(messageId);
if (message) await message.delete();
}
} catch (e) {
console.warn("Could not delete lootdrop message from Discord:", e);
}
return true;
} catch (error) {
console.error("Error deleting lootdrop:", error);
return false;
}
}
}
export const lootdropService = new LootdropService();