Merge pull request #248 from DarkView/ch_contextToHardcode

Change ContextMenu to hardcoded default actions
This commit is contained in:
Miikka 2021-08-17 18:08:51 +03:00 committed by GitHub
commit 28fcc9c00b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 236 additions and 274 deletions

View file

@ -1,38 +1,34 @@
import { PluginOptions } from "knub"; import { PluginOptions } from "knub";
import { StrictValidationError } from "src/validatorUtils";
import { ConfigPreprocessorFn } from "knub/dist/config/configTypes";
import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks"; import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks";
import { LogsPlugin } from "../Logs/LogsPlugin"; import { LogsPlugin } from "../Logs/LogsPlugin";
import { MutesPlugin } from "../Mutes/MutesPlugin"; import { MutesPlugin } from "../Mutes/MutesPlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint"; import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { availableTypes } from "./actions/availableActions";
import { ContextClickedEvt } from "./events/ContextClickedEvt"; import { ContextClickedEvt } from "./events/ContextClickedEvt";
import { ConfigSchema, ContextMenuPluginType } from "./types"; import { ConfigSchema, ContextMenuPluginType } from "./types";
import { loadAllCommands } from "./utils/loadAllCommands"; import { loadAllCommands } from "./utils/loadAllCommands";
import { UtilityPlugin } from "../Utility/UtilityPlugin";
const defaultOptions: PluginOptions<ContextMenuPluginType> = { const defaultOptions: PluginOptions<ContextMenuPluginType> = {
config: { config: {
context_actions: {}, can_use: false,
user_muteindef: false,
user_mute1d: false,
user_mute1h: false,
user_info: false,
message_clean10: false,
message_clean25: false,
message_clean50: false,
}, },
}; overrides: [
{
const configPreprocessor: ConfigPreprocessorFn<ContextMenuPluginType> = options => { level: ">=50",
if (options.config.context_actions) { config: {
for (const [name, contextMenu] of Object.entries(options.config.context_actions)) { can_use: true,
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>()({ export const ContextMenuPlugin = zeppelinGuildPlugin<ContextMenuPluginType>()({
@ -40,7 +36,6 @@ export const ContextMenuPlugin = zeppelinGuildPlugin<ContextMenuPluginType>()({
configSchema: ConfigSchema, configSchema: ConfigSchema,
defaultOptions, defaultOptions,
configPreprocessor,
// prettier-ignore // prettier-ignore
events: [ events: [
@ -57,5 +52,5 @@ export const ContextMenuPlugin = zeppelinGuildPlugin<ContextMenuPluginType>()({
loadAllCommands(pluginData); loadAllCommands(pluginData);
}, },
dependencies: [MutesPlugin, LogsPlugin], dependencies: [MutesPlugin, LogsPlugin, UtilityPlugin],
}); });

View file

@ -1,19 +0,0 @@
import * as t from "io-ts";
import { ContextActionBlueprint } from "../helpers";
import { CleanAction } from "./clean";
import { MuteAction } from "./mute";
export const availableActions: Record<string, ContextActionBlueprint<any>> = {
mute: MuteAction,
clean: CleanAction,
};
export const AvailableActions = t.type({
mute: MuteAction.configType,
clean: CleanAction.configType,
});
export const availableTypes: Record<string, string[]> = {
mute: ["USER"],
clean: ["MESSAGE"],
};

View file

@ -1,64 +1,51 @@
import { TextChannel } from "discord.js"; import { ContextMenuInteraction, TextChannel } from "discord.js";
import * as t from "io-ts"; import { GuildPluginData } from "knub";
import { canActOn } from "src/pluginUtils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { UtilityPlugin } from "../../../plugins/Utility/UtilityPlugin"; import { UtilityPlugin } from "../../../plugins/Utility/UtilityPlugin";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { tNullable } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { contextMenuAction } from "../helpers"; import { ContextMenuPluginType } from "../types";
export const CleanAction = contextMenuAction({ export async function cleanAction(
configType: t.type({ pluginData: GuildPluginData<ContextMenuPluginType>,
amount: tNullable(t.number), amount: number,
targetUserOnly: tNullable(t.boolean), interaction: ContextMenuInteraction,
"delete-pins": tNullable(t.boolean), ) {
}), interaction.deferReply({ ephemeral: true });
const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
const userCfg = await pluginData.config.getMatchingConfig({
channelId: interaction.channelId,
member: executingMember,
});
const utility = pluginData.getPlugin(UtilityPlugin);
defaultConfig: { if (!userCfg.can_use || !(await utility.hasPermission(executingMember, interaction.channelId, "can_clean"))) {
amount: 10, await interaction.followUp({ content: "Cannot clean: insufficient permissions" });
targetUserOnly: false, return;
"delete-pins": false, }
},
async apply({ pluginData, actionConfig, actionName, interaction }) { const targetMessage = interaction.channel
interaction.deferReply({ ephemeral: true }); ? await interaction.channel.messages.fetch(interaction.targetId)
const targetMessage = interaction.channel : await (pluginData.guild.channels.resolve(interaction.channelId) as TextChannel).messages.fetch(
? await interaction.channel.messages.fetch(interaction.targetId) interaction.targetId,
: await (pluginData.guild.channels.resolve(interaction.channelId) as TextChannel).messages.fetch(
interaction.targetId,
);
const amount = actionConfig.amount ?? 10;
const targetUserOnly = actionConfig.targetUserOnly ?? false;
const deletePins = actionConfig["delete-pins"] ?? false;
const user = targetUserOnly ? targetMessage.author.id : undefined;
const targetMember = await pluginData.guild.members.fetch(targetMessage.author.id);
const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
const utility = pluginData.getPlugin(UtilityPlugin);
if (targetUserOnly && !canActOn(pluginData, executingMember, targetMember)) {
interaction.followUp({ ephemeral: true, content: "Cannot clean users messages: insufficient permissions" });
return;
}
try {
interaction.followUp(`Cleaning... Amount: ${amount}, User Only: ${targetUserOnly}, Pins: ${deletePins}`);
utility.clean(
{ count: amount, user, channel: targetMessage.channel.id, "delete-pins": deletePins },
targetMessage,
); );
} catch (e) {
interaction.followUp({ ephemeral: true, content: "Plugin error, please check your BOT_ALERTs" });
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) { const targetUserOnly = false;
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, { const deletePins = false;
body: `Failed to clean in <#${interaction.channelId}> in ContextMenu action \`${actionName}\``, const user = undefined;
});
} else { try {
throw e; interaction.followUp(`Cleaning... Amount: ${amount}, User Only: ${targetUserOnly}, Pins: ${deletePins}`);
} utility.clean({ count: amount, user, channel: targetMessage.channel.id, "delete-pins": deletePins }, targetMessage);
} catch (e) {
interaction.followUp({ ephemeral: true, content: "Plugin error, please check your BOT_ALERTs" });
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Failed to clean in <#${interaction.channelId}> in ContextMenu action \`clean\`:_ ${e}`,
});
} else {
throw e;
} }
}, }
}); }

View file

@ -1,83 +1,66 @@
import { ContextMenuInteraction } from "discord.js";
import humanizeDuration from "humanize-duration"; import humanizeDuration from "humanize-duration";
import * as t from "io-ts"; import { GuildPluginData } from "knub";
import { ModActionsPlugin } from "src/plugins/ModActions/ModActionsPlugin";
import { canActOn } from "src/pluginUtils"; import { canActOn } from "src/pluginUtils";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { convertDelayStringToMS, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS } from "../../../utils";
import { CaseArgs } from "../../Cases/types"; import { CaseArgs } from "../../Cases/types";
import { LogsPlugin } from "../../Logs/LogsPlugin"; import { LogsPlugin } from "../../Logs/LogsPlugin";
import { MutesPlugin } from "../../Mutes/MutesPlugin"; import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { contextMenuAction } from "../helpers"; import { ContextMenuPluginType } from "../types";
import { resolveActionContactMethods } from "../utils/resolveActionContactMethods";
export const MuteAction = contextMenuAction({ export async function muteAction(
configType: t.type({ pluginData: GuildPluginData<ContextMenuPluginType>,
reason: tNullable(t.string), duration: string | undefined,
duration: tNullable(tDelayString), interaction: ContextMenuInteraction,
notify: tNullable(t.string), ) {
notifyChannel: tNullable(t.string), interaction.deferReply({ ephemeral: true });
remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])), const userCfg = await pluginData.config.getMatchingConfig({
postInCaseLog: tNullable(t.boolean), channelId: interaction.channelId,
hide_case: tNullable(t.boolean), member: executingMember,
}), });
defaultConfig: { const modactions = pluginData.getPlugin(ModActionsPlugin);
notify: null, // Use defaults from ModActions if (!userCfg.can_use || !(await modactions.hasMutePermission(executingMember, interaction.channelId))) {
hide_case: false, await interaction.followUp({ content: "Cannot mute: insufficient permissions" });
}, return;
}
async apply({ pluginData, actionConfig, actionName, interaction }) { const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
const duration = actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : undefined; const mutes = pluginData.getPlugin(MutesPlugin);
const reason = actionConfig.reason || "Context Menu Action"; const userId = interaction.targetId;
const contactMethods = actionConfig.notify ? resolveActionContactMethods(pluginData, actionConfig) : undefined; const targetMember = await pluginData.guild.members.fetch(interaction.targetId);
const rolesToRemove = actionConfig.remove_roles_on_mute;
const rolesToRestore = actionConfig.restore_roles_on_mute;
const caseArgs: Partial<CaseArgs> = { if (!canActOn(pluginData, executingMember, targetMember)) {
modId: pluginData.client.user!.id, interaction.followUp({ ephemeral: true, content: "Cannot mute: insufficient permissions" });
automatic: true, return;
postInCaseLogOverride: actionConfig.postInCaseLog ?? undefined, }
hide: Boolean(actionConfig.hide_case),
};
interaction.deferReply({ ephemeral: true }); const caseArgs: Partial<CaseArgs> = {
const mutes = pluginData.getPlugin(MutesPlugin); modId: executingMember.id,
const userId = interaction.targetId; };
const targetMember = await pluginData.guild.members.fetch(interaction.targetId);
const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
if (!canActOn(pluginData, executingMember, targetMember)) { try {
interaction.followUp({ ephemeral: true, content: "Cannot mute: insufficient permissions" }); const result = await mutes.muteUser(userId, durationMs, "Context Menu Action", { caseArgs });
return;
const muteMessage = `Muted **${result.case.user_name}** ${
durationMs ? `for ${humanizeDuration(durationMs)}` : "indefinitely"
} (Case #${result.case.case_number}) (user notified via ${result.notifyResult.method ??
"dm"})\nPlease update the new case with the \`update\` command`;
interaction.followUp({ ephemeral: true, content: muteMessage });
} catch (e) {
interaction.followUp({ ephemeral: true, content: "Plugin error, please check your BOT_ALERTs" });
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Failed to mute <@!${userId}> in ContextMenu action \`mute\` because a mute role has not been specified in server config`,
});
} else {
throw e;
} }
}
try { }
const result = await mutes.muteUser(
userId,
duration,
reason,
{ contactMethods, caseArgs, isAutomodAction: true },
rolesToRemove,
rolesToRestore,
);
const muteMessage = `Muted **${result.case.user_name}** ${
duration ? `for ${humanizeDuration(duration)}` : "indefinitely"
} (Case #${result.case.case_number}) (user notified via ${result.notifyResult.method ??
"dm"})\nPlease update the new case with the \`update\` command`;
interaction.followUp({ ephemeral: true, content: muteMessage });
} catch (e) {
interaction.followUp({ ephemeral: true, content: "Plugin error, please check your BOT_ALERTs" });
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Failed to mute <@!${userId}> in ContextMenu action \`${actionName}\` because a mute role has not been specified in server config`,
});
} else {
throw e;
}
}
},
});

View file

@ -0,0 +1,28 @@
import { ContextMenuInteraction } from "discord.js";
import { GuildPluginData } from "knub";
import { UtilityPlugin } from "../../../plugins/Utility/UtilityPlugin";
import { ContextMenuPluginType } from "../types";
export async function userInfoAction(
pluginData: GuildPluginData<ContextMenuPluginType>,
interaction: ContextMenuInteraction,
) {
interaction.deferReply({ ephemeral: true });
const executingMember = await pluginData.guild.members.fetch(interaction.user.id);
const userCfg = await pluginData.config.getMatchingConfig({
channelId: interaction.channelId,
member: executingMember,
});
const utility = pluginData.getPlugin(UtilityPlugin);
if (userCfg.can_use && (await utility.hasPermission(executingMember, interaction.channelId, "can_userinfo"))) {
const embed = await utility.userInfo(interaction.targetId, interaction.user.id);
if (!embed) {
await interaction.followUp({ content: "Cannot info: internal error" });
return;
}
await interaction.followUp({ embeds: [embed] });
} else {
await interaction.followUp({ content: "Cannot info: insufficient permissions" });
}
}

View file

@ -1,25 +0,0 @@
import { ContextMenuInteraction } from "discord.js";
import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { Awaitable } from "knub/dist/utils";
import { ContextMenuPluginType } from "./types";
type ContextActionApplyFn<TConfigType> = (meta: {
actionName: string;
pluginData: GuildPluginData<ContextMenuPluginType>;
actionConfig: TConfigType;
interaction: ContextMenuInteraction;
}) => Awaitable<void>;
export interface ContextActionBlueprint<TConfigType extends t.Any> {
configType: TConfigType;
defaultConfig: Partial<t.TypeOf<TConfigType>>;
apply: ContextActionApplyFn<t.TypeOf<TConfigType>>;
}
export function contextMenuAction<TConfigType extends t.Any>(
blueprint: ContextActionBlueprint<TConfigType>,
): ContextActionBlueprint<TConfigType> {
return blueprint;
}

View file

@ -1,29 +1,17 @@
import * as t from "io-ts"; import * as t from "io-ts";
import { BasePluginType, typedGuildCommand, typedGuildEventListener } from "knub"; import { BasePluginType, typedGuildEventListener } from "knub";
import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks"; import { GuildContextMenuLinks } from "../../data/GuildContextMenuLinks";
import { tNullable } from "../../utils";
import { AvailableActions } from "./actions/availableActions";
export enum ContextMenuTypes {
USER = 2,
MESSAGE = 3,
}
export const ContextMenuTypeNameToNumber: Record<string, number> = {
USER: 2,
MESSAGE: 3,
};
const ContextActionOpts = t.type({
enabled: tNullable(t.boolean),
label: t.string,
type: t.keyof(ContextMenuTypes),
action: t.partial(AvailableActions.props),
});
export type TContextActionOpts = t.TypeOf<typeof ContextActionOpts>;
export const ConfigSchema = t.type({ export const ConfigSchema = t.type({
context_actions: t.record(t.string, ContextActionOpts), can_use: t.boolean,
user_muteindef: t.boolean,
user_mute1d: t.boolean,
user_mute1h: t.boolean,
user_info: t.boolean,
message_clean10: t.boolean,
message_clean25: t.boolean,
message_clean50: t.boolean,
}); });
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>; export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
@ -34,5 +22,4 @@ export interface ContextMenuPluginType extends BasePluginType {
}; };
} }
export const contextMenuCmd = typedGuildCommand<ContextMenuPluginType>();
export const contextMenuEvt = typedGuildEventListener<ContextMenuPluginType>(); export const contextMenuEvt = typedGuildEventListener<ContextMenuPluginType>();

View file

@ -1,7 +1,7 @@
import { ContextMenuInteraction } from "discord.js"; import { ContextMenuInteraction } from "discord.js";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { availableActions } from "../actions/availableActions";
import { ContextMenuPluginType } from "../types"; import { ContextMenuPluginType } from "../types";
import { hardcodedActions } from "./hardcodedContextOptions";
export async function routeContextAction( export async function routeContextAction(
pluginData: GuildPluginData<ContextMenuPluginType>, pluginData: GuildPluginData<ContextMenuPluginType>,
@ -9,20 +9,5 @@ export async function routeContextAction(
) { ) {
const contextLink = await pluginData.state.contextMenuLinks.get(interaction.commandId); const contextLink = await pluginData.state.contextMenuLinks.get(interaction.commandId);
if (!contextLink) return; if (!contextLink) return;
const contextActions = Object.entries(pluginData.config.get().context_actions); hardcodedActions[contextLink.action_name](pluginData, interaction);
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;
}
} }

View file

@ -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),
};

View file

@ -1,22 +1,27 @@
import { ApplicationCommandData } from "discord.js"; import { ApplicationCommandData, Constants } from "discord.js";
import { LogType } from "src/data/LogType"; import { LogType } from "../../../data/LogType";
import { LogsPlugin } from "src/plugins/Logs/LogsPlugin"; import { LogsPlugin } from "../../../plugins/Logs/LogsPlugin";
import { GuildPluginData } from "knub"; import { GuildPluginData } from "knub";
import { ContextMenuPluginType, ContextMenuTypeNameToNumber } from "../types"; import { ContextMenuPluginType } from "../types";
import { hardcodedContext } from "./hardcodedContextOptions";
export async function loadAllCommands(pluginData: GuildPluginData<ContextMenuPluginType>) { export async function loadAllCommands(pluginData: GuildPluginData<ContextMenuPluginType>) {
const comms = await pluginData.client.application!.commands; const comms = await pluginData.client.application!.commands;
const actions = pluginData.config.get().context_actions; const cfg = pluginData.config.get();
const newCommands: ApplicationCommandData[] = []; const newCommands: ApplicationCommandData[] = [];
const addedNames: string[] = []; const addedNames: string[] = [];
for (const [name, configAction] of Object.entries(actions)) { for (const [name, label] of Object.entries(hardcodedContext)) {
if (!configAction.enabled) continue; if (!cfg[name]) continue;
const type = name.startsWith("user")
? Constants.ApplicationCommandTypes.USER
: Constants.ApplicationCommandTypes.MESSAGE;
const data: ApplicationCommandData = { const data: ApplicationCommandData = {
type: ContextMenuTypeNameToNumber[configAction.type], type,
name: configAction.label, name: label,
}; };
addedNames.push(name); addedNames.push(name);
newCommands.push(data); newCommands.push(data);
} }

View file

@ -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 [];
}

View file

@ -1,4 +1,4 @@
import { GuildMember, Message } from "discord.js"; import { GuildMember, Message, Snowflake } from "discord.js";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { GuildCases } from "../../data/GuildCases"; import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";
@ -38,6 +38,7 @@ import { CreateKickCaseOnManualKickEvt } from "./events/CreateKickCaseOnManualKi
import { CreateUnbanCaseOnManualUnbanEvt } from "./events/CreateUnbanCaseOnManualUnbanEvt"; import { CreateUnbanCaseOnManualUnbanEvt } from "./events/CreateUnbanCaseOnManualUnbanEvt";
import { PostAlertOnMemberJoinEvt } from "./events/PostAlertOnMemberJoinEvt"; import { PostAlertOnMemberJoinEvt } from "./events/PostAlertOnMemberJoinEvt";
import { banUserId } from "./functions/banUserId"; import { banUserId } from "./functions/banUserId";
import { hasMutePermission } from "./functions/hasMutePerm";
import { kickMember } from "./functions/kickMember"; import { kickMember } from "./functions/kickMember";
import { offModActionsEvent } from "./functions/offModActionsEvent"; import { offModActionsEvent } from "./functions/offModActionsEvent";
import { onModActionsEvent } from "./functions/onModActionsEvent"; import { onModActionsEvent } from "./functions/onModActionsEvent";
@ -181,6 +182,12 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
}; };
}, },
hasMutePermission(pluginData) {
return (member: GuildMember, channelId: Snowflake) => {
return hasMutePermission(pluginData, member, channelId);
};
},
on: mapToPublicFn(onModActionsEvent), on: mapToPublicFn(onModActionsEvent),
off: mapToPublicFn(offModActionsEvent), off: mapToPublicFn(offModActionsEvent),
getEventEmitter(pluginData) { getEventEmitter(pluginData) {

View file

@ -0,0 +1,11 @@
import { GuildMember, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { ModActionsPluginType } from "../types";
export async function hasMutePermission(
pluginData: GuildPluginData<ModActionsPluginType>,
member: GuildMember,
channelId: Snowflake,
) {
return (await pluginData.config.getMatchingConfig({ member, channelId })).can_mute;
}

View file

@ -1,3 +1,4 @@
import { GuildMember, MessageEmbedOptions, Snowflake } from "discord.js";
import { PluginOptions } from "knub"; import { PluginOptions } from "knub";
import { GuildArchives } from "../../data/GuildArchives"; import { GuildArchives } from "../../data/GuildArchives";
import { GuildCases } from "../../data/GuildCases"; import { GuildCases } from "../../data/GuildCases";
@ -36,6 +37,8 @@ import { UserInfoCmd } from "./commands/UserInfoCmd";
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd"; import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
import { VcmoveAllCmd, VcmoveCmd } from "./commands/VcmoveCmd"; import { VcmoveAllCmd, VcmoveCmd } from "./commands/VcmoveCmd";
import { AutoJoinThreadEvt, AutoJoinThreadSyncEvt } from "./events/AutoJoinThreadEvt"; import { AutoJoinThreadEvt, AutoJoinThreadSyncEvt } from "./events/AutoJoinThreadEvt";
import { getUserInfoEmbed } from "./functions/getUserInfoEmbed";
import { hasPermission } from "./functions/hasPermission";
import { activeReloads } from "./guildReloads"; import { activeReloads } from "./guildReloads";
import { refreshMembersIfNeeded } from "./refreshMembers"; import { refreshMembersIfNeeded } from "./refreshMembers";
import { ConfigSchema, UtilityPluginType } from "./types"; import { ConfigSchema, UtilityPluginType } from "./types";
@ -162,6 +165,18 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()({
cleanCmd(pluginData, args, msg); cleanCmd(pluginData, args, msg);
}; };
}, },
userInfo(pluginData) {
return (userId: Snowflake, requestMemberId?: Snowflake) => {
return getUserInfoEmbed(pluginData, userId, false, requestMemberId);
};
},
hasPermission(pluginData) {
return (member: GuildMember, channelId: Snowflake, permission: string) => {
return hasPermission(pluginData, member, channelId, permission);
};
},
}, },
beforeLoad(pluginData) { beforeLoad(pluginData) {

View file

@ -0,0 +1,12 @@
import { GuildMember, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { UtilityPluginType } from "../types";
export async function hasPermission(
pluginData: GuildPluginData<UtilityPluginType>,
member: GuildMember,
channelId: Snowflake,
permission: string,
) {
return (await pluginData.config.getMatchingConfig({ member, channelId }))[permission];
}