3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 22:21:51 +00:00

Used guildPluginSlashCommand instead of raw blueprints

This commit is contained in:
Lily Bergonzat 2024-03-05 05:05:03 +01:00
parent 7eff7bcaa6
commit cbec6101e0
27 changed files with 168 additions and 121 deletions

View file

@ -170,26 +170,26 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
description: "Moderation actions", description: "Moderation actions",
defaultMemberPermissions: "0", defaultMemberPermissions: "0",
subcommands: [ subcommands: [
{ type: "slash", ...AddCaseSlashCmd }, AddCaseSlashCmd,
{ type: "slash", ...BanSlashCmd }, BanSlashCmd,
{ type: "slash", ...CaseSlashCmd }, CaseSlashCmd,
{ type: "slash", ...CasesSlashCmd }, CasesSlashCmd,
{ type: "slash", ...DeleteCaseSlashCmd }, DeleteCaseSlashCmd,
{ type: "slash", ...ForceBanSlashCmd }, ForceBanSlashCmd,
{ type: "slash", ...ForceMuteSlashCmd }, ForceMuteSlashCmd,
{ type: "slash", ...ForceUnmuteSlashCmd }, ForceUnmuteSlashCmd,
{ type: "slash", ...HideCaseSlashCmd }, HideCaseSlashCmd,
{ type: "slash", ...KickSlashCmd }, KickSlashCmd,
{ type: "slash", ...MassBanSlashCmd }, MassBanSlashCmd,
{ type: "slash", ...MassMuteSlashSlashCmd }, MassMuteSlashSlashCmd,
{ type: "slash", ...MassUnbanSlashCmd }, MassUnbanSlashCmd,
{ type: "slash", ...MuteSlashCmd }, MuteSlashCmd,
{ type: "slash", ...NoteSlashCmd }, NoteSlashCmd,
{ type: "slash", ...UnbanSlashCmd }, UnbanSlashCmd,
{ type: "slash", ...UnhideCaseSlashCmd }, UnhideCaseSlashCmd,
{ type: "slash", ...UnmuteSlashCmd }, UnmuteSlashCmd,
{ type: "slash", ...UpdateSlashCmd }, UpdateSlashCmd,
{ type: "slash", ...WarnSlashCmd }, WarnSlashCmd,
], ],
}), }),
], ],

View file

@ -1,9 +1,12 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes"; import { CaseTypes } from "../../../../data/CaseTypes";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd"; import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -15,7 +18,7 @@ const opts = [
}), }),
]; ];
export const AddCaseSlashCmd = { export const AddCaseSlashCmd = modActionsSlashCmd({
name: "addcase", name: "addcase",
configPermission: "can_addcase", configPermission: "can_addcase",
description: "Add an arbitrary case to the specified user without taking any action", description: "Add an arbitrary case to the specified user without taking any action",
@ -38,7 +41,7 @@ export const AddCaseSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment"); const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
// The moderator who did the action is the message author or, if used, the specified -mod // The moderator who did the action is the message author or, if used, the specified -mod
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -52,13 +55,13 @@ export const AddCaseSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
actualAddCaseCmd( actualAddCaseCmd(
pluginData, pluginData,
interaction, interaction,
interaction.member, interaction.member as GuildMember,
mod, mod,
attachments, attachments,
options.user, options.user,
@ -66,4 +69,4 @@ export const AddCaseSlashCmd = {
options.reason || "", options.reason || "",
); );
}, },
}; });

View file

@ -1,11 +1,12 @@
import { ChannelType } from "discord.js"; import { ChannelType, GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS } from "../../../../utils"; import { UserNotificationMethod, convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualBanCmd } from "../../functions/actualCommands/actualBanCmd"; import { actualBanCmd } from "../../functions/actualCommands/actualBanCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -38,7 +39,7 @@ const opts = [
}), }),
]; ];
export const BanSlashCmd = { export const BanSlashCmd = modActionsSlashCmd({
name: "ban", name: "ban",
configPermission: "can_ban", configPermission: "can_ban",
description: "Ban or Tempban the specified member", description: "Ban or Tempban the specified member",
@ -58,7 +59,7 @@ export const BanSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -72,7 +73,7 @@ export const BanSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
let contactMethods: UserNotificationMethod[] | undefined; let contactMethods: UserNotificationMethod[] | undefined;
@ -96,9 +97,9 @@ export const BanSlashCmd = {
convertedTime, convertedTime,
options.reason || "", options.reason || "",
attachments, attachments,
interaction.member, interaction.member as GuildMember,
mod, mod,
contactMethods, contactMethods,
); );
}, },
}; });

View file

@ -1,11 +1,12 @@
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd"; import { actualCaseCmd } from "../../functions/actualCommands/actualCaseCmd";
import { modActionsSlashCmd } from "../../types";
const opts = [ const opts = [
slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }), slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }),
]; ];
export const CaseSlashCmd = { export const CaseSlashCmd = modActionsSlashCmd({
name: "case", name: "case",
configPermission: "can_view", configPermission: "can_view",
description: "Show information about a specific case", description: "Show information about a specific case",
@ -21,4 +22,4 @@ export const CaseSlashCmd = {
await interaction.deferReply({ ephemeral: options.show !== true }); await interaction.deferReply({ ephemeral: options.show !== true });
actualCaseCmd(pluginData, interaction, interaction.user.id, options["case-number"], options.show); actualCaseCmd(pluginData, interaction, interaction.user.id, options["case-number"], options.show);
}, },
}; });

View file

@ -1,5 +1,7 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualCasesCmd } from "../../functions/actualCommands/actualCasesCmd"; import { actualCasesCmd } from "../../functions/actualCommands/actualCasesCmd";
import { modActionsSlashCmd } from "../../types";
const opts = [ const opts = [
slashOptions.user({ name: "user", description: "The user to show cases for", required: false }), slashOptions.user({ name: "user", description: "The user to show cases for", required: false }),
@ -21,7 +23,7 @@ const opts = [
slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }), slashOptions.boolean({ name: "show", description: "To make the result visible to everyone", required: false }),
]; ];
export const CasesSlashCmd = { export const CasesSlashCmd = modActionsSlashCmd({
name: "cases", name: "cases",
configPermission: "can_view", configPermission: "can_view",
description: "Show a list of cases the specified user has or the specified mod made", description: "Show a list of cases the specified user has or the specified mod made",
@ -35,9 +37,9 @@ export const CasesSlashCmd = {
return actualCasesCmd( return actualCasesCmd(
pluginData, pluginData,
interaction, interaction,
options.mod, options.mod?.id ?? null,
options.user, options.user,
interaction.member, interaction.member as GuildMember,
options.notes, options.notes,
options.warns, options.warns,
options.mutes, options.mutes,
@ -51,4 +53,4 @@ export const CasesSlashCmd = {
options.show, options.show,
); );
}, },
}; });

View file

@ -1,9 +1,11 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualDeleteCaseCmd } from "../../functions/actualCommands/actualDeleteCaseCmd"; import { actualDeleteCaseCmd } from "../../functions/actualCommands/actualDeleteCaseCmd";
import { modActionsSlashCmd } from "../../types";
const opts = [slashOptions.boolean({ name: "force", description: "Whether or not to force delete", required: false })]; const opts = [slashOptions.boolean({ name: "force", description: "Whether or not to force delete", required: false })];
export const DeleteCaseSlashCmd = { export const DeleteCaseSlashCmd = modActionsSlashCmd({
name: "deletecase", name: "deletecase",
configPermission: "can_deletecase", configPermission: "can_deletecase",
description: "Delete the specified case. This operation can *not* be reversed.", description: "Delete the specified case. This operation can *not* be reversed.",
@ -21,9 +23,9 @@ export const DeleteCaseSlashCmd = {
actualDeleteCaseCmd( actualDeleteCaseCmd(
pluginData, pluginData,
interaction, interaction,
interaction.member, interaction.member as GuildMember,
options["case-number"].split(/[\s,]+/), options["case-number"].split(/\D+/).map(Number),
!!options.force, !!options.force,
); );
}, },
}; });

View file

@ -1,9 +1,11 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS } from "../../../../utils"; import { convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualForceBanCmd } from "../../functions/actualCommands/actualForceBanCmd"; import { actualForceBanCmd } from "../../functions/actualCommands/actualForceBanCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -15,7 +17,7 @@ const opts = [
}), }),
]; ];
export const ForceBanSlashCmd = { export const ForceBanSlashCmd = modActionsSlashCmd({
name: "forceban", name: "forceban",
configPermission: "can_ban", configPermission: "can_ban",
description: "Force-ban the specified user, even if they aren't on the server", description: "Force-ban the specified user, even if they aren't on the server",
@ -35,7 +37,7 @@ export const ForceBanSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -49,7 +51,7 @@ export const ForceBanSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null; const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
@ -58,6 +60,14 @@ export const ForceBanSlashCmd = {
return; return;
} }
actualForceBanCmd(pluginData, interaction, interaction.user.id, options.user, options.reason, attachments, mod); actualForceBanCmd(
pluginData,
interaction,
interaction.user.id,
options.user,
options.reason ?? "",
attachments,
mod,
);
}, },
}; });

View file

@ -1,11 +1,12 @@
import { ChannelType } from "discord.js"; import { ChannelType, GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS } from "../../../../utils"; import { UserNotificationMethod, convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd"; import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -33,7 +34,7 @@ const opts = [
}), }),
]; ];
export const ForceMuteSlashCmd = { export const ForceMuteSlashCmd = modActionsSlashCmd({
name: "forcemute", name: "forcemute",
configPermission: "can_mute", configPermission: "can_mute",
description: "Force-mute the specified user, even if they're not on the server", description: "Force-mute the specified user, even if they're not on the server",
@ -53,7 +54,7 @@ export const ForceMuteSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
let ppId: string | undefined; let ppId: string | undefined;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
@ -68,7 +69,7 @@ export const ForceMuteSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
ppId = interaction.user.id; ppId = interaction.user.id;
} }
@ -94,8 +95,8 @@ export const ForceMuteSlashCmd = {
mod, mod,
ppId, ppId,
convertedTime, convertedTime,
options.reason, options.reason ?? "",
contactMethods, contactMethods,
); );
}, },
}; });

View file

@ -1,9 +1,11 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS } from "../../../../utils"; import { convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd"; import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -16,7 +18,7 @@ const opts = [
}), }),
]; ];
export const ForceUnmuteSlashCmd = { export const ForceUnmuteSlashCmd = modActionsSlashCmd({
name: "forceunmute", name: "forceunmute",
configPermission: "can_mute", configPermission: "can_mute",
description: "Force-unmute the specified user, even if they're not on the server", description: "Force-unmute the specified user, even if they're not on the server",
@ -36,7 +38,7 @@ export const ForceUnmuteSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
let ppId: string | undefined; let ppId: string | undefined;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
@ -51,7 +53,7 @@ export const ForceUnmuteSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
ppId = interaction.user.id; ppId = interaction.user.id;
} }
@ -61,6 +63,6 @@ export const ForceUnmuteSlashCmd = {
return; return;
} }
actualUnmuteCmd(pluginData, interaction, options.user, attachments, mod, ppId, convertedTime, options.reason); actualUnmuteCmd(pluginData, interaction, options.user, attachments, mod, ppId, convertedTime, options.reason ?? "");
}, },
}; });

View file

@ -1,7 +1,8 @@
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualHideCaseCmd } from "../../functions/actualCommands/actualHideCaseCmd"; import { actualHideCaseCmd } from "../../functions/actualCommands/actualHideCaseCmd";
import { modActionsSlashCmd } from "../../types";
export const HideCaseSlashCmd = { export const HideCaseSlashCmd = modActionsSlashCmd({
name: "hidecase", name: "hidecase",
configPermission: "can_hidecase", configPermission: "can_hidecase",
description: "Hide the specified case so it doesn't appear in !cases or !info", description: "Hide the specified case so it doesn't appear in !cases or !info",
@ -13,6 +14,6 @@ export const HideCaseSlashCmd = {
async run({ interaction, options, pluginData }) { async run({ interaction, options, pluginData }) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
actualHideCaseCmd(pluginData, interaction, options["case-number"].split(/[\s,]+/).map(Number)); actualHideCaseCmd(pluginData, interaction, options["case-number"].split(/\D+/).map(Number));
}, },
}; });

View file

@ -1,11 +1,12 @@
import { ChannelType } from "discord.js"; import { ChannelType, GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod } from "../../../../utils"; import { UserNotificationMethod, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualKickCmd } from "../../functions/actualCommands/actualKickCmd"; import { actualKickCmd } from "../../functions/actualCommands/actualKickCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -37,7 +38,7 @@ const opts = [
}), }),
]; ];
export const KickSlashCmd = { export const KickSlashCmd = modActionsSlashCmd({
name: "kick", name: "kick",
configPermission: "can_kick", configPermission: "can_kick",
description: "Kick the specified member", description: "Kick the specified member",
@ -57,7 +58,7 @@ export const KickSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -71,7 +72,7 @@ export const KickSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
let contactMethods: UserNotificationMethod[] | undefined; let contactMethods: UserNotificationMethod[] | undefined;
@ -85,7 +86,7 @@ export const KickSlashCmd = {
actualKickCmd( actualKickCmd(
pluginData, pluginData,
interaction, interaction,
interaction.member, interaction.member as GuildMember,
options.user, options.user,
options.reason || "", options.reason || "",
attachments, attachments,
@ -94,4 +95,4 @@ export const KickSlashCmd = {
options.clean, options.clean,
); );
}, },
}; });

View file

@ -1,7 +1,9 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMassBanCmd } from "../../functions/actualCommands/actualMassBanCmd"; import { actualMassBanCmd } from "../../functions/actualCommands/actualMassBanCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -12,7 +14,7 @@ const opts = [
}), }),
]; ];
export const MassBanSlashCmd = { export const MassBanSlashCmd = modActionsSlashCmd({
name: "massban", name: "massban",
configPermission: "can_massban", configPermission: "can_massban",
description: "Mass-ban a list of user IDs", description: "Mass-ban a list of user IDs",
@ -39,10 +41,10 @@ export const MassBanSlashCmd = {
actualMassBanCmd( actualMassBanCmd(
pluginData, pluginData,
interaction, interaction,
options["user-ids"].split(/[\s,\r\n]+/), options["user-ids"].split(/\D+/),
interaction.member, interaction.member as GuildMember,
options.reason || "", options.reason || "",
attachments, attachments,
); );
}, },
}; });

View file

@ -1,7 +1,9 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMassMuteCmd } from "../../functions/actualCommands/actualMassMuteCmd"; import { actualMassMuteCmd } from "../../functions/actualCommands/actualMassMuteCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -12,7 +14,7 @@ const opts = [
}), }),
]; ];
export const MassMuteSlashSlashCmd = { export const MassMuteSlashSlashCmd = modActionsSlashCmd({
name: "massmute", name: "massmute",
configPermission: "can_massmute", configPermission: "can_massmute",
description: "Mass-mute a list of user IDs", description: "Mass-mute a list of user IDs",
@ -39,10 +41,10 @@ export const MassMuteSlashSlashCmd = {
actualMassMuteCmd( actualMassMuteCmd(
pluginData, pluginData,
interaction, interaction,
options["user-ids"].split(/[\s,\r\n]+/), options["user-ids"].split(/\D+/),
interaction.member, interaction.member as GuildMember,
options.reason || "", options.reason || "",
attachments, attachments,
); );
}, },
}; });

View file

@ -1,7 +1,9 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMassUnbanCmd } from "../../functions/actualCommands/actualMassUnbanCmd"; import { actualMassUnbanCmd } from "../../functions/actualCommands/actualMassUnbanCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -12,7 +14,7 @@ const opts = [
}), }),
]; ];
export const MassUnbanSlashCmd = { export const MassUnbanSlashCmd = modActionsSlashCmd({
name: "massunban", name: "massunban",
configPermission: "can_massunban", configPermission: "can_massunban",
description: "Mass-unban a list of user IDs", description: "Mass-unban a list of user IDs",
@ -40,9 +42,9 @@ export const MassUnbanSlashCmd = {
pluginData, pluginData,
interaction, interaction,
options["user-ids"].split(/[\s,\r\n]+/), options["user-ids"].split(/[\s,\r\n]+/),
interaction.member, interaction.member as GuildMember,
options.reason || "", options.reason || "",
attachments, attachments,
); );
}, },
}; });

View file

@ -1,4 +1,4 @@
import { ChannelType } from "discord.js"; import { ChannelType, GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { canActOn, hasPermission } from "../../../../pluginUtils"; import { canActOn, hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS, resolveMember } from "../../../../utils"; import { UserNotificationMethod, convertDelayStringToMS, resolveMember } from "../../../../utils";
@ -8,6 +8,7 @@ import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd"; import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { isBanned } from "../../functions/isBanned"; import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -35,7 +36,7 @@ const opts = [
}), }),
]; ];
export const MuteSlashCmd = { export const MuteSlashCmd = modActionsSlashCmd({
name: "mute", name: "mute",
configPermission: "can_mute", configPermission: "can_mute",
description: "Mute the specified member", description: "Mute the specified member",
@ -61,7 +62,7 @@ export const MuteSlashCmd = {
const reply = await waitForButtonConfirm( const reply = await waitForButtonConfirm(
interaction, interaction,
{ content: "User not found on the server, forcemute instead?" }, { content: "User not found on the server, forcemute instead?" },
{ confirmText: "Yes", cancelText: "No", restrictToId: interaction.member.id }, { confirmText: "Yes", cancelText: "No", restrictToId: interaction.user.id },
); );
if (!reply) { if (!reply) {
@ -74,12 +75,12 @@ export const MuteSlashCmd = {
} }
// Make sure we're allowed to mute this member // Make sure we're allowed to mute this member
if (memberToMute && !canActOn(pluginData, interaction.member, memberToMute)) { if (memberToMute && !canActOn(pluginData, interaction.member as GuildMember, memberToMute)) {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot mute: insufficient permissions"); pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot mute: insufficient permissions");
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
let ppId: string | undefined; let ppId: string | undefined;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
@ -94,7 +95,7 @@ export const MuteSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
ppId = interaction.user.id; ppId = interaction.user.id;
} }
@ -124,4 +125,4 @@ export const MuteSlashCmd = {
contactMethods, contactMethods,
); );
}, },
}; });

View file

@ -2,6 +2,7 @@ import { slashOptions } from "knub";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualNoteCmd } from "../../functions/actualCommands/actualNoteCmd"; import { actualNoteCmd } from "../../functions/actualCommands/actualNoteCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -12,7 +13,7 @@ const opts = [
}), }),
]; ];
export const NoteSlashCmd = { export const NoteSlashCmd = modActionsSlashCmd({
name: "note", name: "note",
configPermission: "can_note", configPermission: "can_note",
description: "Add a note to the specified user", description: "Add a note to the specified user",
@ -34,4 +35,4 @@ export const NoteSlashCmd = {
actualNoteCmd(pluginData, interaction, interaction.user, attachments, options.user, options.note || ""); actualNoteCmd(pluginData, interaction, interaction.user, attachments, options.user, options.note || "");
}, },
}; });

View file

@ -1,8 +1,11 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { hasPermission } from "../../../../pluginUtils"; import { hasPermission } from "../../../../pluginUtils";
import { resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin"; import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnbanCmd } from "../../functions/actualCommands/actualUnbanCmd"; import { actualUnbanCmd } from "../../functions/actualCommands/actualUnbanCmd";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -14,7 +17,7 @@ const opts = [
}), }),
]; ];
export const UnbanSlashCmd = { export const UnbanSlashCmd = modActionsSlashCmd({
name: "unban", name: "unban",
configPermission: "can_unban", configPermission: "can_unban",
description: "Unban the specified member", description: "Unban the specified member",
@ -34,7 +37,7 @@ export const UnbanSlashCmd = {
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -48,9 +51,9 @@ export const UnbanSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
actualUnbanCmd(pluginData, interaction, interaction.user.id, options.user, options.reason, attachments, mod); actualUnbanCmd(pluginData, interaction, interaction.user.id, options.user, options.reason ?? "", attachments, mod);
}, },
}; });

View file

@ -1,7 +1,8 @@
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { actualUnhideCaseCmd } from "../../functions/actualCommands/actualUnhideCaseCmd"; import { actualUnhideCaseCmd } from "../../functions/actualCommands/actualUnhideCaseCmd";
import { modActionsSlashCmd } from "../../types";
export const UnhideCaseSlashCmd = { export const UnhideCaseSlashCmd = modActionsSlashCmd({
name: "unhidecase", name: "unhidecase",
configPermission: "can_hidecase", configPermission: "can_hidecase",
description: "Un-hide the specified case", description: "Un-hide the specified case",
@ -13,6 +14,6 @@ export const UnhideCaseSlashCmd = {
async run({ interaction, options, pluginData }) { async run({ interaction, options, pluginData }) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
actualUnhideCaseCmd(pluginData, interaction, options["case-number"].split(/[\s,]+/).map(Number)); actualUnhideCaseCmd(pluginData, interaction, options["case-number"].split(/\D+/).map(Number));
}, },
}; });

View file

@ -1,3 +1,4 @@
import { GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { canActOn, hasPermission } from "../../../../pluginUtils"; import { canActOn, hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS, resolveMember } from "../../../../utils"; import { convertDelayStringToMS, resolveMember } from "../../../../utils";
@ -7,6 +8,7 @@ import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin"; import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd"; import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { isBanned } from "../../functions/isBanned"; import { isBanned } from "../../functions/isBanned";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -19,7 +21,7 @@ const opts = [
}), }),
]; ];
export const UnmuteSlashCmd = { export const UnmuteSlashCmd = modActionsSlashCmd({
name: "unmute", name: "unmute",
configPermission: "can_mute", configPermission: "can_mute",
description: "Unmute the specified member", description: "Unmute the specified member",
@ -79,12 +81,12 @@ export const UnmuteSlashCmd = {
} }
// Make sure we're allowed to unmute this member // Make sure we're allowed to unmute this member
if (memberToUnmute && !canActOn(pluginData, interaction.member, memberToUnmute)) { if (memberToUnmute && !canActOn(pluginData, interaction.member as GuildMember, memberToUnmute)) {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot unmute: insufficient permissions"); pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot unmute: insufficient permissions");
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
let ppId: string | undefined; let ppId: string | undefined;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
@ -99,7 +101,7 @@ export const UnmuteSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
ppId = interaction.user.id; ppId = interaction.user.id;
} }
@ -111,4 +113,4 @@ export const UnmuteSlashCmd = {
actualUnmuteCmd(pluginData, interaction, options.user, attachments, mod, ppId, convertedTime, options.reason); actualUnmuteCmd(pluginData, interaction, options.user, attachments, mod, ppId, convertedTime, options.reason);
}, },
}; });

View file

@ -1,6 +1,7 @@
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions"; import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { updateCase } from "../../functions/updateCase"; import { updateCase } from "../../functions/updateCase";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_UPDATE } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_UPDATE } from "../constants";
const opts = [ const opts = [
@ -12,7 +13,7 @@ const opts = [
}), }),
]; ];
export const UpdateSlashCmd = { export const UpdateSlashCmd = modActionsSlashCmd({
name: "update", name: "update",
configPermission: "can_note", configPermission: "can_note",
description: "Update the specified case (or your latest case) by adding more notes to it", description: "Update the specified case (or your latest case) by adding more notes to it",
@ -27,9 +28,9 @@ export const UpdateSlashCmd = {
pluginData, pluginData,
interaction, interaction,
interaction.user, interaction.user,
options.caseNumber, options["case-number"] ? Number(options["case-number"]) : null,
options.note, options.reason ?? "",
retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_UPDATE, options, "attachment"), retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_UPDATE, options, "attachment"),
); );
}, },
}; });

View file

@ -1,4 +1,4 @@
import { ChannelType } from "discord.js"; import { ChannelType, GuildMember } from "discord.js";
import { slashOptions } from "knub"; import { slashOptions } from "knub";
import { canActOn, hasPermission } from "../../../../pluginUtils"; import { canActOn, hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, resolveMember } from "../../../../utils"; import { UserNotificationMethod, resolveMember } from "../../../../utils";
@ -7,6 +7,7 @@ import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualWarnCmd } from "../../functions/actualCommands/actualWarnCmd"; import { actualWarnCmd } from "../../functions/actualCommands/actualWarnCmd";
import { isBanned } from "../../functions/isBanned"; import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs"; import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsSlashCmd } from "../../types";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants"; import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
const opts = [ const opts = [
@ -33,7 +34,7 @@ const opts = [
}), }),
]; ];
export const WarnSlashCmd = { export const WarnSlashCmd = modActionsSlashCmd({
name: "warn", name: "warn",
configPermission: "can_warn", configPermission: "can_warn",
description: "Send a warning to the specified user", description: "Send a warning to the specified user",
@ -67,12 +68,12 @@ export const WarnSlashCmd = {
} }
// Make sure we're allowed to warn this member // Make sure we're allowed to warn this member
if (!canActOn(pluginData, interaction.member, memberToWarn)) { if (!canActOn(pluginData, interaction.member as GuildMember, memberToWarn)) {
await pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot warn: insufficient permissions"); await pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot warn: insufficient permissions");
return; return;
} }
let mod = interaction.member; let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", { const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel, channel: interaction.channel,
member: interaction.member, member: interaction.member,
@ -86,7 +87,7 @@ export const WarnSlashCmd = {
return; return;
} }
mod = options.mod; mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
} }
let contactMethods: UserNotificationMethod[] | undefined; let contactMethods: UserNotificationMethod[] | undefined;
@ -108,4 +109,4 @@ export const WarnSlashCmd = {
contactMethods, contactMethods,
); );
}, },
}; });

View file

@ -20,7 +20,7 @@ export async function actualKickCmd(
attachments: Attachment[], attachments: Attachment[],
mod: GuildMember, mod: GuildMember,
contactMethods?: UserNotificationMethod[], contactMethods?: UserNotificationMethod[],
clean?: boolean, clean?: boolean | null,
) { ) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return; return;

View file

@ -29,7 +29,7 @@ export async function actualMuteCmd(
mod: GuildMember, mod: GuildMember,
ppId?: string, ppId?: string,
time?: number, time?: number,
reason?: string, reason?: string | null,
contactMethods?: UserNotificationMethod[], contactMethods?: UserNotificationMethod[],
) { ) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {

View file

@ -16,7 +16,7 @@ export async function actualUnmuteCmd(
mod: GuildMember, mod: GuildMember,
ppId?: string, ppId?: string,
time?: number, time?: number,
reason?: string, reason?: string | null,
) { ) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) { if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return; return;

View file

@ -2,8 +2,8 @@ import { GuildTextBasedChannel } from "discord.js";
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils"; import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
export function readContactMethodsFromArgs(args: { export function readContactMethodsFromArgs(args: {
notify?: string; notify?: string | null;
"notify-channel"?: GuildTextBasedChannel; "notify-channel"?: GuildTextBasedChannel | null;
}): null | UserNotificationMethod[] { }): null | UserNotificationMethod[] {
if (args.notify) { if (args.notify) {
if (args.notify === "dm") { if (args.notify === "dm") {

View file

@ -13,7 +13,7 @@ export async function updateCase(
pluginData: GuildPluginData<ModActionsPluginType>, pluginData: GuildPluginData<ModActionsPluginType>,
context: Message | ChatInputCommandInteraction, context: Message | ChatInputCommandInteraction,
author: User, author: User,
caseNumber?: number, caseNumber?: number | null,
note = "", note = "",
attachments: Attachment[] = [], attachments: Attachment[] = [],
) { ) {

View file

@ -1,6 +1,12 @@
import { ChatInputCommandInteraction, Message } from "discord.js"; import { ChatInputCommandInteraction, Message } from "discord.js";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand, guildPluginSlashGroup } from "knub"; import {
BasePluginType,
guildPluginEventListener,
guildPluginMessageCommand,
guildPluginSlashCommand,
guildPluginSlashGroup,
} from "knub";
import z from "zod"; import z from "zod";
import { Queue } from "../../Queue"; import { Queue } from "../../Queue";
import { GuildCases } from "../../data/GuildCases"; import { GuildCases } from "../../data/GuildCases";
@ -152,4 +158,5 @@ export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban"
export const modActionsMsgCmd = guildPluginMessageCommand<ModActionsPluginType>(); export const modActionsMsgCmd = guildPluginMessageCommand<ModActionsPluginType>();
export const modActionsSlashGroup = guildPluginSlashGroup<ModActionsPluginType>(); export const modActionsSlashGroup = guildPluginSlashGroup<ModActionsPluginType>();
export const modActionsSlashCmd = guildPluginSlashCommand<ModActionsPluginType>();
export const modActionsEvt = guildPluginEventListener<ModActionsPluginType>(); export const modActionsEvt = guildPluginEventListener<ModActionsPluginType>();