mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
feat: add '!role_buttons reset' command
This commit is contained in:
parent
4a9ece8e3b
commit
b6ab2c7d4a
3 changed files with 46 additions and 0 deletions
|
@ -10,6 +10,7 @@ import { onButtonInteraction } from "./events/buttonInteraction";
|
|||
import { pluginInfo } from "./info";
|
||||
import { createButtonComponents } from "./functions/createButtonComponents";
|
||||
import { TooManyComponentsError } from "./functions/TooManyComponentsError";
|
||||
import { resetButtonsCmd } from "./commands/resetButtons";
|
||||
|
||||
export const RoleButtonsPlugin = zeppelinGuildPlugin<RoleButtonsPluginType>()({
|
||||
name: "role_buttons",
|
||||
|
@ -17,6 +18,21 @@ export const RoleButtonsPlugin = zeppelinGuildPlugin<RoleButtonsPluginType>()({
|
|||
info: pluginInfo,
|
||||
showInDocs: true,
|
||||
|
||||
defaultOptions: {
|
||||
config: {
|
||||
buttons: {},
|
||||
can_reset: false,
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
level: ">=100",
|
||||
config: {
|
||||
can_reset: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
configPreprocessor(options) {
|
||||
// Auto-fill "name" property for buttons based on the object key
|
||||
const buttonsArray = Array.isArray(options.config?.buttons) ? options.config.buttons : [];
|
||||
|
@ -58,6 +74,8 @@ export const RoleButtonsPlugin = zeppelinGuildPlugin<RoleButtonsPluginType>()({
|
|||
|
||||
events: [onButtonInteraction],
|
||||
|
||||
commands: [resetButtonsCmd],
|
||||
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.roleButtons = GuildRoleButtons.getGuildInstance(pluginData.guild.id);
|
||||
},
|
||||
|
|
27
backend/src/plugins/RoleButtons/commands/resetButtons.ts
Normal file
27
backend/src/plugins/RoleButtons/commands/resetButtons.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { typedGuildCommand } from "knub";
|
||||
import { RoleButtonsPluginType } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { applyAllRoleButtons } from "../functions/applyAllRoleButtons";
|
||||
|
||||
export const resetButtonsCmd = typedGuildCommand<RoleButtonsPluginType>()({
|
||||
trigger: "role_buttons reset",
|
||||
description:
|
||||
"In case of issues, you can run this command to have Zeppelin 'forget' about specific role buttons and re-apply them. This will also repost the message, if not targeting an existing message.",
|
||||
usage: "!role_buttons reset my_roles",
|
||||
permission: "can_reset",
|
||||
signature: {
|
||||
name: ct.string(),
|
||||
},
|
||||
async run({ pluginData, args, message }) {
|
||||
const config = pluginData.config.get();
|
||||
if (!config.buttons[args.name]) {
|
||||
sendErrorMessage(pluginData, message.channel, `Can't find role buttons with the name "${args.name}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
await pluginData.state.roleButtons.deleteRoleButtonItem(args.name);
|
||||
await applyAllRoleButtons(pluginData);
|
||||
sendSuccessMessage(pluginData, message.channel, "Done!");
|
||||
},
|
||||
});
|
|
@ -39,6 +39,7 @@ export type TRoleButtonsConfigItem = t.TypeOf<typeof RoleButtonsConfigItem>;
|
|||
|
||||
export const ConfigSchema = t.type({
|
||||
buttons: t.record(t.string, RoleButtonsConfigItem),
|
||||
can_reset: t.boolean,
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue