diff --git a/config/balance.yml b/config/balance.yml new file mode 100644 index 0000000..d3a54cb --- /dev/null +++ b/config/balance.yml @@ -0,0 +1,3 @@ +symbol: " star bits" +after: true +cutoff: 0 diff --git a/config/roles.yml b/config/roles.yml index 5edc852..69e5de1 100644 --- a/config/roles.yml +++ b/config/roles.yml @@ -3,6 +3,7 @@ NONE: permissions: - cosmic.commandGroup.general - cosmic.command.inventory + - cosmic.command.balance - cosmic.command.magic8ball - cosmic.command.color - cosmic.command.id diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ce5adac..802804f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -21,10 +21,11 @@ model User { } model Inventory { - id Int @id @unique @default(autoincrement()) - userId String @unique - user User @relation(fields: [userId], references: [id]) - items Json + id Int @id @unique @default(autoincrement()) + userId String @unique + user User @relation(fields: [userId], references: [id]) + items Json + balance Float @default(0) } enum Role { diff --git a/src/commands/commands/economy/balance.ts b/src/commands/commands/economy/balance.ts new file mode 100644 index 0000000..e9eff2e --- /dev/null +++ b/src/commands/commands/economy/balance.ts @@ -0,0 +1,14 @@ +import { formatBalance } from "../../../economy/Balance"; +import { Item, StackableItem } from "../../../economy/Item"; +import { Command } from "../../Command"; + +export const balance = new Command( + "balance", + ["balance", "bal", "money"], + "get bozo's balance", + "balance", + (msg, agent) => { + const bal = msg.inventory.balance; + return `Balance: ${formatBalance(bal)}`; + } +); diff --git a/src/commands/index.ts b/src/commands/index.ts index 79c4fd8..d943b33 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -13,6 +13,7 @@ import { color } from "./commands/utility/color"; import { role } from "./commands/utility/role"; import { ic } from "./commands/utility/ic"; import { uptime } from "./commands/utility/uptime"; +import { balance } from "./commands/economy/balance"; export function loadCommands() { // cringe @@ -21,7 +22,7 @@ export function loadCommands() { CommandHandler.addCommandGroup(general); const economy = new CommandGroup("economy", "💸 Economy"); - economy.addCommands([inventory]); + economy.addCommands([inventory, balance]); CommandHandler.addCommandGroup(economy); const fun = new CommandGroup("fun", "✨ Fun"); diff --git a/src/economy/Balance.ts b/src/economy/Balance.ts new file mode 100644 index 0000000..2588dd9 --- /dev/null +++ b/src/economy/Balance.ts @@ -0,0 +1,17 @@ +import { loadConfig } from "../util/config"; + +const config = loadConfig("config/balance.yml", { + symbol: " star bits", + after: true, + cutoff: 0 +}); + +export function formatBalance( + balance: number, + symbol: string = config.symbol, + after: boolean = config.after, + cutoff: number = config.cutoff +) { + if (after) return `${balance.toFixed(cutoff)}${symbol}`; + else return `${symbol}${balance.toFixed(cutoff)}`; +} diff --git a/src/permissions/default.ts b/src/permissions/default.ts index 4570c14..a2c748d 100644 --- a/src/permissions/default.ts +++ b/src/permissions/default.ts @@ -8,6 +8,7 @@ export const defaultConfig = { "cosmic.commandGroup.general", "cosmic.command.inventory", + "cosmic.command.balance", "cosmic.command.magic8ball",