Change ContextMenu to hardcoded default actions
Sadge (More complex self-defined stuff coming at some point tho)
This commit is contained in:
parent
3ddfb3b65a
commit
7cf75f3255
12 changed files with 183 additions and 272 deletions
|
@ -1,7 +1,7 @@
|
|||
import { ContextMenuInteraction } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { availableActions } from "../actions/availableActions";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
import { hardcodedActions } from "./hardcodedContextOptions";
|
||||
|
||||
export async function routeContextAction(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
|
@ -9,20 +9,5 @@ export async function routeContextAction(
|
|||
) {
|
||||
const contextLink = await pluginData.state.contextMenuLinks.get(interaction.commandId);
|
||||
if (!contextLink) return;
|
||||
const contextActions = Object.entries(pluginData.config.get().context_actions);
|
||||
|
||||
const configLink = contextActions.find(x => x[0] === contextLink.action_name);
|
||||
if (!configLink) return;
|
||||
|
||||
for (const [actionName, actionConfig] of Object.entries(configLink[1].action)) {
|
||||
if (actionConfig == null) return;
|
||||
const action = availableActions[actionName];
|
||||
action.apply({
|
||||
actionName,
|
||||
pluginData,
|
||||
actionConfig,
|
||||
interaction,
|
||||
});
|
||||
return;
|
||||
}
|
||||
hardcodedActions[contextLink.action_name](pluginData, interaction);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { cleanAction } from "../actions/clean";
|
||||
import { muteAction } from "../actions/mute";
|
||||
import { userInfoAction } from "../actions/userInfo";
|
||||
|
||||
export const hardcodedContext: Record<string, string> = {
|
||||
user_muteindef: "Mute Indefinitely",
|
||||
user_mute1d: "Mute for 1 day",
|
||||
user_mute1h: "Mute for 1 hour",
|
||||
user_info: "Get Info",
|
||||
message_clean10: "Clean 10 messages",
|
||||
message_clean25: "Clean 25 messages",
|
||||
message_clean50: "Clean 50 messages",
|
||||
};
|
||||
|
||||
export const hardcodedActions = {
|
||||
user_muteindef: (pluginData, interaction) => muteAction(pluginData, undefined, interaction),
|
||||
user_mute1d: (pluginData, interaction) => muteAction(pluginData, "1d", interaction),
|
||||
user_mute1h: (pluginData, interaction) => muteAction(pluginData, "1h", interaction),
|
||||
user_info: (pluginData, interaction) => userInfoAction(pluginData, interaction),
|
||||
message_clean10: (pluginData, interaction) => cleanAction(pluginData, 10, interaction),
|
||||
message_clean25: (pluginData, interaction) => cleanAction(pluginData, 25, interaction),
|
||||
message_clean50: (pluginData, interaction) => cleanAction(pluginData, 50, interaction),
|
||||
};
|
|
@ -1,22 +1,25 @@
|
|||
import { ApplicationCommandData } from "discord.js";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { LogsPlugin } from "src/plugins/Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { ContextMenuPluginType, ContextMenuTypeNameToNumber } from "../types";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
import { hardcodedContext } from "./hardcodedContextOptions";
|
||||
|
||||
export async function loadAllCommands(pluginData: GuildPluginData<ContextMenuPluginType>) {
|
||||
const comms = await pluginData.client.application!.commands;
|
||||
const actions = pluginData.config.get().context_actions;
|
||||
const cfg = pluginData.config.get();
|
||||
const newCommands: ApplicationCommandData[] = [];
|
||||
const addedNames: string[] = [];
|
||||
|
||||
for (const [name, configAction] of Object.entries(actions)) {
|
||||
if (!configAction.enabled) continue;
|
||||
for (const [name, label] of Object.entries(hardcodedContext)) {
|
||||
if (!cfg[name]) continue;
|
||||
|
||||
const type = name.startsWith("user") ? 2 : 3;
|
||||
const data: ApplicationCommandData = {
|
||||
type: ContextMenuTypeNameToNumber[configAction.type],
|
||||
name: configAction.label,
|
||||
type,
|
||||
name: label,
|
||||
};
|
||||
|
||||
addedNames.push(name);
|
||||
newCommands.push(data);
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
|
||||
import { ContextMenuPluginType } from "../types";
|
||||
|
||||
export function resolveActionContactMethods(
|
||||
pluginData: GuildPluginData<ContextMenuPluginType>,
|
||||
actionConfig: {
|
||||
notify?: string | null;
|
||||
notifyChannel?: string | null;
|
||||
},
|
||||
): UserNotificationMethod[] {
|
||||
if (actionConfig.notify === "dm") {
|
||||
return [{ type: "dm" }];
|
||||
} else if (actionConfig.notify === "channel") {
|
||||
if (!actionConfig.notifyChannel) {
|
||||
throw new RecoverablePluginError(ERRORS.NO_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
||||
const channel = pluginData.guild.channels.cache.get(actionConfig.notifyChannel as Snowflake);
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL);
|
||||
}
|
||||
|
||||
return [{ type: "channel", channel }];
|
||||
} else if (actionConfig.notify && disableUserNotificationStrings.includes(actionConfig.notify)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue