Skip to content

Commit

Permalink
Post item card
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Sep 9, 2024
1 parent 6179c47 commit 94b42c8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
30 changes: 29 additions & 1 deletion src/commands/gegenstand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type AutocompleteInteraction,
type CommandInteraction,
InteractionType,
SlashCommandBuilder,
SlashCommandStringOption,
SlashCommandSubcommandBuilder,
Expand Down Expand Up @@ -115,7 +116,34 @@ export default class GegenstandCommand implements ApplicationCommand {
});
}

async #showItemInfo(interaction: CommandInteraction, context: BotContext) {}
async #showItemInfo(interaction: CommandInteraction, _context: BotContext) {
if (!interaction.isChatInputCommand()) {
throw new Error("Interaction is not a chat input command");
}

const itemId = Number(interaction.options.getString("item"));
if (!Number.isSafeInteger(itemId)) {
throw new Error("Invalid item ID");
}

const item = await lootService.getUserLootById(interaction.user.id, itemId);
if (!item) {
await interaction.reply({
content: "Diesen Gegensand hast du nicht.",
});
return;
}

await interaction.reply({
embeds: [
{
title: item.displayName,
description: item.description,
color: 0x00ff00,
},
],
});
}

async autocomplete(interaction: AutocompleteInteraction) {
const subCommand = interaction.options.getSubcommand(true);
Expand Down
12 changes: 8 additions & 4 deletions src/service/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,19 @@ export function resolveLootTemplate(lootKindId: number) {
}

export async function getUserLootsByTypeId(userId: Snowflake, lootTypeId: number) {
return await loot.getUserLootsById(userId, lootTypeId);
return await loot.getUserLootsByTypeId(userId, lootTypeId);
}

export async function getUserLootById(userId: Snowflake, id: LootId) {
return await loot.getUserLootById(userId, id);
}

export async function getUserLootCountById(userId: Snowflake, lootTypeId: number): Promise<number> {
return (await loot.getUserLootsById(userId, lootTypeId)).length;
return (await loot.getUserLootsByTypeId(userId, lootTypeId)).length;
}

export async function getLootsByKindId(lootTykeId: LootTypeId) {
return await loot.getLootsByKindId(lootTykeId);
export async function getLootsByKindId(lootTypeId: LootTypeId) {
return await loot.getLootsByKindId(lootTypeId);
}

export function transferLootToUser(lootId: LootId, user: User, trackPredecessor: boolean) {
Expand Down
12 changes: 11 additions & 1 deletion src/storage/loot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function findOfMessage(message: Message<true>, ctx = db()) {
.executeTakeFirst();
}

export async function getUserLootsById(userId: User["id"], lootKindId: number, ctx = db()) {
export async function getUserLootsByTypeId(userId: User["id"], lootKindId: number, ctx = db()) {
return await ctx
.selectFrom("loot")
.where("winnerId", "=", userId)
Expand All @@ -80,6 +80,16 @@ export async function getUserLootsById(userId: User["id"], lootKindId: number, c
.execute();
}

export async function getUserLootById(userId: User["id"], lootId: LootId, ctx = db()) {
return await ctx
.selectFrom("loot")
.where("winnerId", "=", userId)
.where("id", "=", lootId)
.where(notDeleted)
.selectAll()
.executeTakeFirst();
}

export async function getLootsByKindId(lootKindId: number, ctx = db()) {
return await ctx
.selectFrom("loot")
Expand Down

0 comments on commit 94b42c8

Please sign in to comment.