Skip to content

Commit

Permalink
Fix casing of fightHistory + fightInventory
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Jan 23, 2025
1 parent 78e6277 commit 8eafebe
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/commands/fight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
type FightScene,
} from "@/service/fightData.js";
import { setTimeout } from "node:timers/promises";
import { getFightInventoryEnriched, removeItemsAfterFight } from "@/storage/fightinventory.js";
import { getLastFight, insertResult } from "@/storage/fighthistory.js";
import { getFightInventoryEnriched, removeItemsAfterFight } from "@/storage/fightInventory.js";
import { getLastFight, insertResult } from "@/storage/fightHistory.js";

async function getFighter(user: User): Promise<BaseEntity> {
const userInventory = await getFightInventoryEnriched(user.id);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/gegenstand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as lootDataService from "@/service/lootData.js";
import { LootAttributeClassId, LootAttributeKindId, LootKindId } from "@/service/lootData.js";

import log from "@log";
import { equipItembyLoot, getFightInventoryUnsorted } from "@/storage/fightinventory.js";
import { equipItembyLoot, getFightInventoryUnsorted } from "@/storage/fightInventory.js";

export default class GegenstandCommand implements ApplicationCommand {
name = "gegenstand";
Expand Down
14 changes: 7 additions & 7 deletions src/commands/inventar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as lootDataService from "@/service/lootData.js";
import { LootAttributeKindId } from "@/service/lootData.js";

import log from "@log";
import { getFightInventoryEnriched } from "@/storage/fightinventory.js";
import { getFightInventoryEnriched } from "@/storage/fightInventory.js";

export default class InventarCommand implements ApplicationCommand {
name = "inventar";
Expand All @@ -39,7 +39,7 @@ export default class InventarCommand implements ApplicationCommand {
.setDescription("Anzeige")
.setRequired(false)
.addChoices(
{ name: "Kampfausrüstung", value: "fightinventory" },
{ name: "Kampfausrüstung", value: "fightInventory" },
{ name: "Komplett", value: "all" },
),
);
Expand All @@ -59,7 +59,7 @@ export default class InventarCommand implements ApplicationCommand {
}

switch (type) {
case "fightinventory":
case "fightInventory":
return await this.#createFightEmbed(context, interaction, user);
case "all":
return await this.#createLongEmbed(context, interaction, user);
Expand Down Expand Up @@ -172,17 +172,17 @@ export default class InventarCommand implements ApplicationCommand {
}

async #createFightEmbed(context: BotContext, interaction: CommandInteraction, user: User) {
const fightinventory = await getFightInventoryEnriched(user.id);
const fightInventory = await getFightInventoryEnriched(user.id);
const avatarURL = user.avatarURL();
const display = {
title: `Kampfausrüstung von ${user.displayName}`,
description:
"Du kannst maximal eine Rüstung, eine Waffe und drei Items tragen. Wenn du kämpfst, setzt du die Items ein und verlierst diese, egal ob du gewinnst oder verlierst.",
thumbnail: avatarURL ? { url: avatarURL } : undefined,
fields: [
{ name: "Waffe", value: fightinventory.weapon?.itemInfo?.displayName ?? "Nix" },
{ name: "Rüstung", value: fightinventory.armor?.itemInfo?.displayName ?? "Nackt" },
...fightinventory.items.map(item => {
{ name: "Waffe", value: fightInventory.weapon?.itemInfo?.displayName ?? "Nix" },
{ name: "Rüstung", value: fightInventory.armor?.itemInfo?.displayName ?? "Nackt" },
...fightInventory.items.map(item => {
return {
name: item.itemInfo?.displayName ?? "",
value: "Hier sollten die buffs stehen",
Expand Down
4 changes: 2 additions & 2 deletions src/storage/db/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export interface Database {
lootAttribute: LootAttributeTable;
emote: EmoteTable;
emoteUse: EmoteUseTable;
fighthistory: FightHistoryTable;
fightinventory: FightInventoryTable;
fightHistory: FightHistoryTable;
fightInventory: FightInventoryTable;
}

export type OneBasedMonth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
Expand Down
6 changes: 3 additions & 3 deletions src/storage/fighthistory.ts → src/storage/fightHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FightScene } from "@/service/fightData.js";
export async function insertResult(userId: User["id"], boss: string, win: boolean, ctx = db()) {
const lastWins = await getWinsForBoss(userId, boss);
return await ctx
.insertInto("fighthistory")
.insertInto("fightHistory")
.values({
userid: userId,
result: win,
Expand All @@ -17,7 +17,7 @@ export async function insertResult(userId: User["id"], boss: string, win: boolea

export async function getWinsForBoss(userId: User["id"], boss: string, ctx = db()) {
return await ctx
.selectFrom("fighthistory")
.selectFrom("fightHistory")
.where("userid", "=", userId)
.where("bossName", "=", boss)
.where("result", "=", true)
Expand All @@ -27,7 +27,7 @@ export async function getWinsForBoss(userId: User["id"], boss: string, ctx = db(

export async function getLastFight(userId: User["id"], ctx = db()) {
return await ctx
.selectFrom("fighthistory")
.selectFrom("fightHistory")
.where("userid", "=", userId)
.orderBy("createdAt desc")
.selectAll()
Expand Down
10 changes: 5 additions & 5 deletions src/storage/fightinventory.ts → src/storage/fightInventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deleteLoot } from "@/storage/loot.js";

export async function getFightInventoryUnsorted(userId: User["id"], ctx = db()) {
return await ctx
.selectFrom("fightinventory")
.selectFrom("fightInventory")
.where("userid", "=", userId)
.selectAll()
.execute();
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function getGameTemplate(

export async function getItemsByType(userId: User["id"], fightItemType: string, ctx = db()) {
return await ctx
.selectFrom("fightinventory")
.selectFrom("fightInventory")
.where("userid", "=", userId)
.where("equippedSlot", "=", fightItemType)
.selectAll()
Expand All @@ -54,7 +54,7 @@ export async function removeItemsAfterFight(userId: User["id"], ctx = db()) {
await deleteLoot(item.lootId, ctx);
}
await ctx
.deleteFrom("fightinventory")
.deleteFrom("fightInventory")
.where("userid", "=", userId)
.where("equippedSlot", "=", "item")
.execute();
Expand Down Expand Up @@ -83,11 +83,11 @@ export async function equipItembyLoot(
ctx,
);
unequippeditems.push(unequipitem?.displayName ?? String(equippedStuff[i].lootId));
await ctx.deleteFrom("fightinventory").where("id", "=", equippedStuff[i].id).execute();
await ctx.deleteFrom("fightInventory").where("id", "=", equippedStuff[i].id).execute();
}

await ctx
.insertInto("fightinventory")
.insertInto("fightInventory")
.values({
userid: userId,
lootId: loot.id,
Expand Down
8 changes: 5 additions & 3 deletions src/storage/migrations/11-fightsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { createUpdatedAtTrigger } from "@/storage/migrations/10-loot-attributes.

export async function up(db: Kysely<any>) {
await db.schema
.createTable("fightinventory")
.createTable("fightInventory")
.ifNotExists()
.addColumn("id", "integer", c => c.primaryKey().autoIncrement())
.addColumn("userid", "text")
.addColumn("lootId", "integer", c => c.references("loot.id"))
.addColumn("equippedSlot", "text")
.execute();

await db.schema
.createTable("fighthistory")
.createTable("fightHistory")
.ifNotExists()
.addColumn("id", "integer", c => c.primaryKey().autoIncrement())
.addColumn("userid", "text", c => c.notNull())
Expand All @@ -21,7 +22,8 @@ export async function up(db: Kysely<any>) {
.addColumn("createdAt", "timestamp", c => c.notNull().defaultTo(sql`current_timestamp`))
.addColumn("updatedAt", "timestamp", c => c.notNull().defaultTo(sql`current_timestamp`))
.execute();
await createUpdatedAtTrigger(db, "fighthistory");

await createUpdatedAtTrigger(db, "fightHistory");
}

export async function down(_db: Kysely<any>) {
Expand Down

0 comments on commit 8eafebe

Please sign in to comment.