user registration, bal, change_bal, transfer

This commit is contained in:
stjet
2024-07-25 05:25:40 +00:00
parent f8780249ce
commit 9226debee2
14 changed files with 328 additions and 19 deletions

35
commands/bal.ts Normal file
View File

@@ -0,0 +1,35 @@
import type { ChatInputCommandInteraction } from "discord.js";
import { EmbedBuilder } from "discord.js";
import type { CommandData } from "./index";
import type { User } from "../db";
import config from "../config.json";
import { get_user } from "../db";
import { BotError } from "./error";
async function run(interaction: ChatInputCommandInteraction, user: User) {
const options = interaction.options;
const target = (await options.get("target"))?.user;
let embeds = [];
let bal_embed = new EmbedBuilder();
let bal_target = target ?? interaction.user;
let bal_user = target ? await get_user(target.id) : user;
if (!bal_user) throw new BotError("Target is not registered"); //must be target
bal_embed.setTitle(`${bal_target.tag}'s Balance`);
bal_embed.setDescription(`${bal_user.balance} ${ bal_user.balance === 1 ? config.currency : config.currency_plural }`);
embeds.push(bal_embed);
return await interaction.editReply({ embeds });
}
const data: CommandData = {
name: "bal",
description: "Show you or someone else's balance",
registered_only: true,
ephemeral: false,
admin_only: false,
run,
};
export default data;