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:
|
permissions:
|
||||||
- cosmic.commandGroup.general
|
- cosmic.commandGroup.general
|
||||||
- cosmic.command.inventory
|
- cosmic.command.inventory
|
||||||
|
- cosmic.command.balance
|
||||||
- cosmic.command.magic8ball
|
- cosmic.command.magic8ball
|
||||||
- cosmic.command.color
|
- cosmic.command.color
|
||||||
- cosmic.command.id
|
- cosmic.command.id
|
||||||
|
|
|
@ -21,10 +21,11 @@ model User {
|
||||||
}
|
}
|
||||||
|
|
||||||
model Inventory {
|
model Inventory {
|
||||||
id Int @id @unique @default(autoincrement())
|
id Int @id @unique @default(autoincrement())
|
||||||
userId String @unique
|
userId String @unique
|
||||||
user User @relation(fields: [userId], references: [id])
|
user User @relation(fields: [userId], references: [id])
|
||||||
items Json
|
items Json
|
||||||
|
balance Float @default(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Role {
|
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 { role } from "./commands/utility/role";
|
||||||
import { ic } from "./commands/utility/ic";
|
import { ic } from "./commands/utility/ic";
|
||||||
import { uptime } from "./commands/utility/uptime";
|
import { uptime } from "./commands/utility/uptime";
|
||||||
|
import { balance } from "./commands/economy/balance";
|
||||||
|
|
||||||
export function loadCommands() {
|
export function loadCommands() {
|
||||||
// cringe
|
// cringe
|
||||||
|
@ -21,7 +22,7 @@ export function loadCommands() {
|
||||||
CommandHandler.addCommandGroup(general);
|
CommandHandler.addCommandGroup(general);
|
||||||
|
|
||||||
const economy = new CommandGroup("economy", "💸 Economy");
|
const economy = new CommandGroup("economy", "💸 Economy");
|
||||||
economy.addCommands([inventory]);
|
economy.addCommands([inventory, balance]);
|
||||||
CommandHandler.addCommandGroup(economy);
|
CommandHandler.addCommandGroup(economy);
|
||||||
|
|
||||||
const fun = new CommandGroup("fun", "✨ Fun");
|
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.commandGroup.general",
|
||||||
|
|
||||||
"cosmic.command.inventory",
|
"cosmic.command.inventory",
|
||||||
|
"cosmic.command.balance",
|
||||||
|
|
||||||
"cosmic.command.magic8ball",
|
"cosmic.command.magic8ball",
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue