add /role_income edit

This commit is contained in:
stjet
2026-01-13 01:56:40 +00:00
parent e9c64d494f
commit 9a9a728949
4 changed files with 46 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ async function run(interaction: ChatInputCommandInteraction, found: CommandData,
} }
try { 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.admin_only && !is_admin(interaction)) throw new BotError("Admin permission needed to run that command");
if (found.registered_only) { if (found.registered_only) {
await interaction.deferReply(); await interaction.deferReply();

View File

@@ -4,7 +4,7 @@ import { EmbedBuilder } from "discord.js";
import type { CommandData } from "./index"; import type { CommandData } from "./index";
import { BotError } from "./common/error"; import { BotError } from "./common/error";
import type { RoleIncome } from "../db"; 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 { gen_action_row, is_admin } from "../util";
import { items_string_to_items } from "./common/common"; import { items_string_to_items } from "./common/common";
import config from "../config.json"; 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."); 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); await create_role_income(role_id, hours, income, items);
return await interaction.editReply("Created role income"); 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") { } else if (subcommand === "delete") {
await delete_role_income(role_id); await delete_role_income(role_id);
return await interaction.editReply("Deleted role income"); return await interaction.editReply("Deleted role income");
@@ -85,10 +98,10 @@ async function run(interaction: ChatInputCommandInteraction) {
const data: CommandData = { const data: CommandData = {
name: "role_income", name: "role_income",
description: "View, create, or delete role incomes", description: "View, create, edit, or delete role incomes",
registered_only: false, registered_only: false,
ephemeral: false, ephemeral: false,
admin_only: false, admin_only: false, //create, edit, and delete are admin only but checked in this file
run, run,
}; };

4
db.ts
View File

@@ -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) { export async function update_role_income_last_claim(role: string) {
return await role_income.updateOne({ role }, { return await role_income.updateOne({ role }, {
$set: { $set: {

View File

@@ -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, type: 1,
name: "delete", name: "delete",