diff --git a/commands/index.ts b/commands/index.ts index 078df35..244d30f 100644 --- a/commands/index.ts +++ b/commands/index.ts @@ -64,7 +64,7 @@ async function run(interaction: ChatInputCommandInteraction, found: CommandData, } try { - //admin stuff should be ideally handled by register.ts, but this is a fallback + //admin stuff should be ideally handled by register.ts, but this is a fallback (seemingly not handled by register.ts for some reason rn) if (found.admin_only && !is_admin(interaction)) throw new BotError("Admin permission needed to run that command"); if (found.registered_only) { await interaction.deferReply(); diff --git a/commands/role_income.ts b/commands/role_income.ts index 39027b4..e50600c 100644 --- a/commands/role_income.ts +++ b/commands/role_income.ts @@ -4,7 +4,7 @@ import { EmbedBuilder } from "discord.js"; import type { CommandData } from "./index"; import { BotError } from "./common/error"; import type { RoleIncome } from "../db"; -import { create_role_income, delete_role_income, get_role_income, get_all_role_income, get_item } from "../db"; +import { create_role_income, delete_role_income, get_role_income, get_all_role_income, edit_role_income, get_item } from "../db"; import { gen_action_row, is_admin } from "../util"; import { items_string_to_items } from "./common/common"; import config from "../config.json"; @@ -74,6 +74,19 @@ async function run(interaction: ChatInputCommandInteraction) { if (already_exists) return await interaction.editReply("Role income for that role already exists, delete it first."); await create_role_income(role_id, hours, income, items); return await interaction.editReply("Created role income"); + } else if (subcommand === "edit") { + const role_income = await get_role_income(role_id); + const income: number = (await options.get("income")).value as number; + const items_string = (await options.get("items"))?.value as (string | undefined); + let items; + if (items_string) { + items = await items_string_to_items(items_string); + if (typeof items === "string") throw new BotError(items); + } + role_income.income = income; + role_income.items = items; + await edit_role_income(role_income); + return await interaction.editReply("Edited role income."); } else if (subcommand === "delete") { await delete_role_income(role_id); return await interaction.editReply("Deleted role income"); @@ -85,10 +98,10 @@ async function run(interaction: ChatInputCommandInteraction) { const data: CommandData = { name: "role_income", - description: "View, create, or delete role incomes", + description: "View, create, edit, or delete role incomes", registered_only: false, ephemeral: false, - admin_only: false, + admin_only: false, //create, edit, and delete are admin only but checked in this file run, }; diff --git a/db.ts b/db.ts index 912c84d..a954ab0 100644 --- a/db.ts +++ b/db.ts @@ -173,6 +173,10 @@ export async function create_role_income(role: string, hours: number, income: nu }); } +export async function edit_role_income(role_income: RoleIncome) { + return await store.replaceOne({ role: role_income.role }, role_income); +} + export async function update_role_income_last_claim(role: string) { return await role_income.updateOne({ role }, { $set: { diff --git a/register.ts b/register.ts index a1d7511..7e79424 100644 --- a/register.ts +++ b/register.ts @@ -343,6 +343,31 @@ const commands = [ }, ], }, + { + type: 1, + name: "edit", + description: "Edit a role income's income or item income (admin only)", + options: [ + { + type: 8, + name: "role", + description: "Role to give role income to", + required: true, + }, + { + type: 4, + name: "income", + description: "Amount to give per user per payout", + required: true, + }, + { + type: 3, + name: "items", + description: "Items to give along with role income. In format name,quantity|name,quantity", + required: false, + }, + ], + }, { type: 1, name: "delete",