Add balance system
This commit is contained in:
parent
bc7600cf8e
commit
59edf1601c
|
@ -0,0 +1,3 @@
|
|||
symbol: " star bits"
|
||||
after: true
|
||||
cutoff: 0
|
|
@ -3,6 +3,7 @@ NONE:
|
|||
permissions:
|
||||
- cosmic.commandGroup.general
|
||||
- cosmic.command.inventory
|
||||
- cosmic.command.balance
|
||||
- cosmic.command.magic8ball
|
||||
- cosmic.command.color
|
||||
- cosmic.command.id
|
||||
|
|
|
@ -25,6 +25,7 @@ model Inventory {
|
|||
userId String @unique
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
items Json
|
||||
balance Float @default(0)
|
||||
}
|
||||
|
||||
enum Role {
|
||||
|
|
|
@ -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)}`;
|
||||
}
|
||||
);
|
|
@ -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");
|
||||
|
|
|
@ -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)}`;
|
||||
}
|
|
@ -8,6 +8,7 @@ export const defaultConfig = {
|
|||
"cosmic.commandGroup.general",
|
||||
|
||||
"cosmic.command.inventory",
|
||||
"cosmic.command.balance",
|
||||
|
||||
"cosmic.command.magic8ball",
|
||||
|
||||
|
|
Loading…
Reference in New Issue