Add balance system

This commit is contained in:
Hri7566 2023-12-02 16:54:39 -05:00
parent bc7600cf8e
commit 59edf1601c
7 changed files with 43 additions and 5 deletions

3
config/balance.yml Normal file
View File

@ -0,0 +1,3 @@
symbol: " star bits"
after: true
cutoff: 0

View File

@ -3,6 +3,7 @@ NONE:
permissions:
- cosmic.commandGroup.general
- cosmic.command.inventory
- cosmic.command.balance
- cosmic.command.magic8ball
- cosmic.command.color
- cosmic.command.id

View File

@ -25,6 +25,7 @@ model Inventory {
userId String @unique
user User @relation(fields: [userId], references: [id])
items Json
balance Float @default(0)
}
enum Role {

View File

@ -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)}`;
}
);

View File

@ -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");

17
src/economy/Balance.ts Normal file
View File

@ -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)}`;
}

View File

@ -8,6 +8,7 @@ export const defaultConfig = {
"cosmic.commandGroup.general",
"cosmic.command.inventory",
"cosmic.command.balance",
"cosmic.command.magic8ball",