stop using string keys in objects everywhere ffs

This commit is contained in:
Jill 2023-11-15 14:01:51 +03:00
parent b0389f3e58
commit 68d7e28335
Signed by: oat
GPG Key ID: 33489AA58A955108
3 changed files with 38 additions and 37 deletions

View File

@ -90,7 +90,7 @@ export async function setCounterConfig(counter: Counter, option: string, value:
await db<Counter>('counters')
.where('id', counter.id)
.update({
'emoji': value
emoji: value
});
return;
}
@ -105,9 +105,9 @@ export async function setCounterConfig(counter: Counter, option: string, value:
if (updated === 0) {
await db<CounterConfiguration>('counterConfigurations')
.insert({
'id': counter.id,
'configName': option,
'value': value
id: counter.id,
configName: option,
value: value
});
}
}
@ -238,7 +238,7 @@ export async function updateCounter(bot: Client, counter: Counter, value: number
await db<Counter>('counters')
.where('id', counter.id)
.update({
'message': message.id
message: message.id
});
}
}

View File

@ -1,6 +1,6 @@
import { Behavior, CraftingStation, DefaultItem, Recipe, formatItems, getDefaultItem } from './items';
enum DefaultItems {
export enum DefaultItems {
COIN = 1,
WORKBENCH = 2,
PEBBLE = 3
@ -8,39 +8,39 @@ enum DefaultItems {
export const defaultItems: DefaultItem[] = [
{
'id': -1,
'name': 'Coin',
'emoji': '🪙',
'type': 'plain',
'maxStack': 9999,
'untradable': false
id: -1,
name: 'Coin',
emoji: '🪙',
type: 'plain',
maxStack: 9999,
untradable: false
},
{
'id': -2,
'name': 'Workbench',
'description': 'A place for you to work with tools, for simple things',
'emoji': '🛠️',
'type': 'plain',
'maxStack': 1,
'untradable': false
id: -2,
name: 'Workbench',
description: 'A place for you to work with tools, for simple things',
emoji: '🛠️',
type: 'plain',
maxStack: 1,
untradable: false
},
{
'id': -3,
'name': 'Pebble',
'description': 'If you get 5 of them you will instantly ! !!!',
'emoji': '🪨',
'type': 'plain',
'maxStack': 64,
'untradable': false
id: -3,
name: 'Pebble',
description: 'If you get 5 of them you will instantly ! !!!',
emoji: '🪨',
type: 'plain',
maxStack: 64,
untradable: false
}
];
export const behaviors: Behavior[] = [
{
'name': 'heal',
'description': 'Heals the user by `behaviorValue`',
'itemType': 'consumable',
'action': async (item, user) => {
name: 'heal',
description: 'Heals the user by `behaviorValue`',
itemType: 'consumable',
action: async (item, user) => {
// todo
return false;
}

View File

@ -1,5 +1,6 @@
import { AutocompleteInteraction, User } from 'discord.js';
import { CustomItem, ItemInventory, db } from '../db';
import { DefaultItems, defaultItems } from './data';
export type DefaultItem = Omit<CustomItem, 'guild'>; // uses negative IDs
export type Item = DefaultItem | CustomItem;
@ -68,9 +69,9 @@ export async function getItemQuantity(user: string, itemID: number) {
.where('user', user)
.first())
|| {
'user': user,
'item': itemID,
'quantity': 0
user: user,
item: itemID,
quantity: 0
};
}
@ -84,7 +85,7 @@ export async function giveItem(user: string, item: Item, quantity = 1) {
if (storedItem) {
inv = await db<ItemInventory>('itemInventories')
.update({
'quantity': db.raw('MIN(quantity + ?, ?)', [quantity, getMaxStack(item)])
quantity: db.raw('MIN(quantity + ?, ?)', [quantity, getMaxStack(item)])
})
.limit(1)
.where('user', user)
@ -93,9 +94,9 @@ export async function giveItem(user: string, item: Item, quantity = 1) {
} else {
inv = await db<ItemInventory>('itemInventories')
.insert({
'user': user,
'item': Math.min(item.id, getMaxStack(item)),
'quantity': quantity
user: user,
item: Math.min(item.id, getMaxStack(item)),
quantity: quantity
})
.returning('*');
}