Context Menu Actions v1, clean and mute support with full options
This commit is contained in:
parent
2281dbcfef
commit
ff774aa5f6
19 changed files with 657 additions and 152 deletions
61
backend/src/plugins/ContextMenus/ContextMenuPlugin.ts
Normal file
61
backend/src/plugins/ContextMenus/ContextMenuPlugin.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { PluginOptions } from "knub";
|
||||
import { StrictValidationError } from "src/validatorUtils";
|
||||
import { ConfigPreprocessorFn } from "../../../../../Knub/dist/config/configTypes";
|
||||
import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { MutesPlugin } from "../Mutes/MutesPlugin";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { availableTypes } from "./actions/availableActions";
|
||||
import { ContextClickedEvt } from "./events/ContextClickedEvt";
|
||||
import { ConfigSchema, ContextMenuPluginType } from "./types";
|
||||
import { loadAllCommands } from "./utils/loadAllCommands";
|
||||
|
||||
const defaultOptions: PluginOptions<ContextMenuPluginType> = {
|
||||
config: {
|
||||
context_actions: {},
|
||||
},
|
||||
};
|
||||
|
||||
const configPreprocessor: ConfigPreprocessorFn<ContextMenuPluginType> = options => {
|
||||
if (options.config.context_actions) {
|
||||
for (const [name, contextMenu] of Object.entries(options.config.context_actions)) {
|
||||
if (Object.entries(contextMenu.action).length !== 1) {
|
||||
throw new StrictValidationError([`Invalid value for context_actions/${name}: Must have exactly one action.`]);
|
||||
}
|
||||
|
||||
const actionName = Object.entries(contextMenu.action)[0][0];
|
||||
if (!availableTypes[actionName].includes(contextMenu.type)) {
|
||||
throw new StrictValidationError([
|
||||
`Invalid value for context_actions/${name}/${actionName}: ${actionName} is not allowed on type ${contextMenu.type}.`,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
export const ContextMenuPlugin = zeppelinGuildPlugin<ContextMenuPluginType>()({
|
||||
name: "context_menu",
|
||||
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
configPreprocessor,
|
||||
|
||||
// prettier-ignore
|
||||
events: [
|
||||
ContextClickedEvt,
|
||||
],
|
||||
|
||||
beforeLoad(pluginData) {
|
||||
const { state, guild } = pluginData;
|
||||
|
||||
state.contextMenuLinks = new GuildContextMenuLinks(guild.id);
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
loadAllCommands(pluginData);
|
||||
},
|
||||
|
||||
dependencies: [MutesPlugin, LogsPlugin],
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue