3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Added Discord attachment link reaction, fixed emoji configuration and moved util functions

This commit is contained in:
Lily Bergonzat 2024-02-16 11:51:58 +01:00
parent a4c4b17a14
commit 592d037148
173 changed files with 1540 additions and 1170 deletions

View file

@ -203,7 +203,7 @@ if (env.DEBUG) {
}
logger.info("Connecting to database");
connect().then(async (connection) => {
connect().then(async () => {
const client = new Client({
partials: [Partials.User, Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction],
@ -315,9 +315,27 @@ connect().then(async (connection) => {
if (row) {
try {
const loaded = loadYamlSafely(row.config);
if (loaded.success_emoji || loaded.error_emoji) {
const deprecatedKeys = [] as string[];
const exampleConfig = `plugins:\n common:\n config:\n success_emoji: "👍"\n error_emoji: "👎"`;
if (loaded.success_emoji) {
deprecatedKeys.push("success_emoji");
}
if (loaded.error_emoji) {
deprecatedKeys.push("error_emoji");
}
logger.warn(`Deprecated config properties found in "${key}": ${deprecatedKeys.join(", ")}`);
logger.warn(`You can now configure those emojis in the "common" plugin config\n${exampleConfig}`);
}
// Remove deprecated properties some may still have in their config
delete loaded.success_emoji;
delete loaded.error_emoji;
return loaded;
} catch (err) {
logger.error(`Error while loading config "${key}": ${err.message}`);

View file

@ -7,8 +7,6 @@ import {
GuildMember,
Message,
MessageCreateOptions,
MessageMentionOptions,
ModalSubmitInteraction,
PermissionsBitField,
TextBasedChannel,
User,
@ -23,10 +21,9 @@ import {
PluginOverrideCriteria,
helpers,
} from "knub";
import { logger } from "./logger";
import { isStaff } from "./staff";
import { TZeppelinKnub } from "./types";
import { errorMessage, successMessage, tNullable } from "./utils";
import { tNullable } from "./utils";
import { Tail } from "./utils/typeUtils";
import { StrictValidationError, parseIoTsSchema } from "./validatorUtils";
@ -103,121 +100,50 @@ export function makeIoTsConfigParser<Schema extends t.Type<any>>(schema: Schema)
}
export function isContextInteraction(
context: TextBasedChannel | User | ChatInputCommandInteraction,
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
): context is ChatInputCommandInteraction {
return "commandId" in context && !!context.commandId;
}
export function sendContextResponse(
context: TextBasedChannel | User | ChatInputCommandInteraction,
export function isContextMessage(
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
): context is Message {
return "content" in context || "embeds" in context;
}
export async function getContextChannel(
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
): Promise<TextBasedChannel> {
if (isContextInteraction(context)) {
// context is ChatInputCommandInteraction
return context.channel!;
} else if ("username" in context) {
// context is User
return await (context as User).createDM();
} else if ("send" in context) {
// context is TextBaseChannel
return context as TextBasedChannel;
} else {
// context is Message
return context.channel;
}
}
export async function sendContextResponse(
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
response: string | Omit<MessageCreateOptions, "flags">,
): Promise<Message> {
if (isContextInteraction(context)) {
const options = { ...(typeof response === "string" ? { content: response } : response), fetchReply: true };
return (context.replied ? context.followUp(options) : context.reply(options)) as Promise<Message>;
} else {
} else if ("send" in context) {
return context.send(response);
} else {
return (await getContextChannel(context)).send(response);
}
}
export async function sendSuccessMessage(
pluginData: AnyPluginData<any>,
context: TextBasedChannel | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
responseInteraction?: ModalSubmitInteraction,
ephemeral = true,
): Promise<Message | undefined> {
const emoji = pluginData.fullConfig.success_emoji || undefined;
const formattedBody = successMessage(body, emoji);
const content: MessageCreateOptions = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
if (responseInteraction) {
await responseInteraction
.editReply({ content: formattedBody, embeds: [], components: [] })
.catch((err) => logger.error(`Interaction reply failed: ${err}`));
return;
}
if (!isContextInteraction(context)) {
// noinspection TypeScriptValidateJSTypes
return context
.send({ ...content }) // Force line break
.catch((err) => {
const channelInfo = "guild" in context ? `${context.id} (${context.guild.id})` : context.id;
logger.warn(`Failed to send success message to ${channelInfo}): ${err.code} ${err.message}`);
return undefined;
});
}
const replyMethod = context.replied ? "followUp" : "reply";
return context[replyMethod]({
content: formattedBody,
embeds: [],
components: [],
fetchReply: true,
ephemeral,
}).catch((err) => {
logger.error(`Context reply failed: ${err}`);
return undefined;
}) as Promise<Message>;
}
export async function sendErrorMessage(
pluginData: AnyPluginData<any>,
context: TextBasedChannel | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
responseInteraction?: ModalSubmitInteraction,
ephemeral = false,
): Promise<Message | undefined> {
const emoji = pluginData.fullConfig.error_emoji || undefined;
const formattedBody = errorMessage(body, emoji);
const content: MessageCreateOptions = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
if (responseInteraction) {
await responseInteraction
.editReply({ content: formattedBody, embeds: [], components: [] })
.catch((err) => logger.error(`Interaction reply failed: ${err}`));
return;
}
if (!isContextInteraction(context)) {
// noinspection TypeScriptValidateJSTypes
return context
.send({ ...content }) // Force line break
.catch((err) => {
const channelInfo = "guild" in context ? `${context.id} (${context.guild.id})` : context.id;
logger.warn(`Failed to send error message to ${channelInfo}): ${err.code} ${err.message}`);
return undefined;
});
}
const replyMethod = context.replied ? "followUp" : "reply";
return context[replyMethod]({
content: formattedBody,
embeds: [],
components: [],
fetchReply: true,
ephemeral,
}).catch((err) => {
logger.error(`Context reply failed: ${err}`);
return undefined;
}) as Promise<Message>;
}
export function getBaseUrl(pluginData: AnyPluginData<any>) {
const knub = pluginData.getKnubInstance() as TZeppelinKnub;
// @ts-expect-error

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { autoReactionsCmd } from "../types";
export const DisableAutoReactionsCmd = autoReactionsCmd({
@ -14,12 +14,12 @@ export const DisableAutoReactionsCmd = autoReactionsCmd({
async run({ message: msg, args, pluginData }) {
const autoReaction = await pluginData.state.autoReactions.getForChannel(args.channelId);
if (!autoReaction) {
sendErrorMessage(pluginData, msg.channel, `Auto-reactions aren't enabled in <#${args.channelId}>`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Auto-reactions aren't enabled in <#${args.channelId}>`);
return;
}
await pluginData.state.autoReactions.removeFromChannel(args.channelId);
pluginData.state.cache.delete(args.channelId);
sendSuccessMessage(pluginData, msg.channel, `Auto-reactions disabled in <#${args.channelId}>`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Auto-reactions disabled in <#${args.channelId}>`);
},
});

View file

@ -1,10 +1,10 @@
import { PermissionsBitField } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { canUseEmoji, customEmojiRegex, isEmoji } from "../../../utils";
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
import { missingPermissionError } from "../../../utils/missingPermissionError";
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { autoReactionsCmd } from "../types";
const requiredPermissions = readChannelPermissions | PermissionsBitField.Flags.AddReactions;
@ -25,17 +25,20 @@ export const NewAutoReactionsCmd = autoReactionsCmd({
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
const missingPermissions = getMissingChannelPermissions(me, args.channel, requiredPermissions);
if (missingPermissions) {
sendErrorMessage(
pluginData,
msg.channel,
`Cannot set auto-reactions for that channel. ${missingPermissionError(missingPermissions)}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
msg,
`Cannot set auto-reactions for that channel. ${missingPermissionError(missingPermissions)}`,
);
return;
}
for (const reaction of args.reactions) {
if (!isEmoji(reaction)) {
sendErrorMessage(pluginData, msg.channel, "One or more of the specified reactions were invalid!");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, "One or more of the specified reactions were invalid!");
return;
}
@ -45,7 +48,9 @@ export const NewAutoReactionsCmd = autoReactionsCmd({
if (customEmojiMatch) {
// Custom emoji
if (!canUseEmoji(pluginData.client, customEmojiMatch[2])) {
sendErrorMessage(pluginData, msg.channel, "I can only use regular emojis and custom emojis from this server");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, "I can only use regular emojis and custom emojis from this server");
return;
}
@ -60,6 +65,6 @@ export const NewAutoReactionsCmd = autoReactionsCmd({
await pluginData.state.autoReactions.set(args.channel.id, finalReactions);
pluginData.state.cache.delete(args.channel.id);
sendSuccessMessage(pluginData, msg.channel, `Auto-reactions set for <#${args.channel.id}>`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Auto-reactions set for <#${args.channel.id}>`);
},
});

View file

@ -42,6 +42,7 @@ export const BanAction = automodAction({
await modActions.banUserId(
userId,
reason,
reason,
{
contactMethods,
caseArgs,

View file

@ -37,7 +37,7 @@ export const KickAction = automodAction({
const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const member of membersToKick) {
if (!member) continue;
await modActions.kickMember(member, reason, { contactMethods, caseArgs, isAutomodAction: true });
await modActions.kickMember(member, reason, reason, { contactMethods, caseArgs, isAutomodAction: true });
}
},
});

View file

@ -48,6 +48,7 @@ export const MuteAction = automodAction({
userId,
duration,
reason,
reason,
{ contactMethods, caseArgs, isAutomodAction: true },
rolesToRemove,
rolesToRestore,

View file

@ -37,7 +37,7 @@ export const WarnAction = automodAction({
const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const member of membersToWarn) {
if (!member) continue;
await modActions.warnMember(member, reason, { contactMethods, caseArgs, isAutomodAction: true });
await modActions.warnMember(member, reason, reason, { contactMethods, caseArgs, isAutomodAction: true });
}
},
});

View file

@ -1,5 +1,5 @@
import { guildPluginMessageCommand } from "knub";
import { sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { setAntiraidLevel } from "../functions/setAntiraidLevel";
import { AutomodPluginType } from "../types";
@ -9,6 +9,6 @@ export const AntiraidClearCmd = guildPluginMessageCommand<AutomodPluginType>()({
async run({ pluginData, message }) {
await setAntiraidLevel(pluginData, null, message.author);
sendSuccessMessage(pluginData, message.channel, "Anti-raid turned **off**");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(message, "Anti-raid turned **off**");
},
});

View file

@ -1,6 +1,6 @@
import { guildPluginMessageCommand } from "knub";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { setAntiraidLevel } from "../functions/setAntiraidLevel";
import { AutomodPluginType } from "../types";
@ -15,11 +15,11 @@ export const SetAntiraidCmd = guildPluginMessageCommand<AutomodPluginType>()({
async run({ pluginData, message, args }) {
const config = pluginData.config.get();
if (!config.antiraid_levels.includes(args.level)) {
sendErrorMessage(pluginData, message.channel, "Unknown anti-raid level");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown anti-raid level");
return;
}
await setAntiraidLevel(pluginData, args.level, message.author);
sendSuccessMessage(pluginData, message.channel, `Anti-raid level set to **${args.level}**`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(message, `Anti-raid level set to **${args.level}**`);
},
});

View file

@ -3,7 +3,8 @@ import { AllowedGuilds } from "../../data/AllowedGuilds";
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
import { Configs } from "../../data/Configs";
import { GuildArchives } from "../../data/GuildArchives";
import { makeIoTsConfigParser, sendSuccessMessage } from "../../pluginUtils";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { CommonPlugin } from "../Common/CommonPlugin";
import { zeppelinGlobalPlugin } from "../ZeppelinPluginBlueprint";
import { getActiveReload, resetActiveReload } from "./activeReload";
import { AddDashboardUserCmd } from "./commands/AddDashboardUserCmd";
@ -77,7 +78,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
if (guild) {
const channel = guild.channels.cache.get(channelId as Snowflake);
if (channel instanceof TextChannel) {
sendSuccessMessage(pluginData, channel, "Global plugins reloaded!");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(channel, "Global plugins reloaded!");
}
}
}

View file

@ -1,7 +1,8 @@
import { ApiPermissions } from "@shared/apiPermissions";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { renderUserUsername } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const AddDashboardUserCmd = botControlCmd({
@ -19,7 +20,7 @@ export const AddDashboardUserCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
if (!guild) {
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
return;
}
@ -36,10 +37,11 @@ export const AddDashboardUserCmd = botControlCmd({
}
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUserUsername(user)}**, \`${user.id}\`)`);
sendSuccessMessage(
pluginData,
msg.channel,
`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`,
);
},
});

View file

@ -1,8 +1,8 @@
import { ApiPermissions } from "@shared/apiPermissions";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { DBDateFormat, isGuildInvite, resolveInvite } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { isEligible } from "../functions/isEligible";
import { botControlCmd } from "../types";
@ -18,19 +18,21 @@ export const AddServerFromInviteCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
if (!invite || !isGuildInvite(invite)) {
sendErrorMessage(pluginData, msg.channel, "Could not resolve invite"); // :D
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Could not resolve invite"); // :D
return;
}
const existing = await pluginData.state.allowedGuilds.find(invite.guild.id);
if (existing) {
sendErrorMessage(pluginData, msg.channel, "Server is already allowed!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is already allowed!");
return;
}
const { result, explanation } = await isEligible(pluginData, args.user, invite);
if (!result) {
sendErrorMessage(pluginData, msg.channel, `Could not add server because it's not eligible: ${explanation}`);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `Could not add server because it's not eligible: ${explanation}`);
return;
}
@ -51,6 +53,8 @@ export const AddServerFromInviteCmd = botControlCmd({
);
}
sendSuccessMessage(pluginData, msg.channel, "Server was eligible and is now allowed to use Zeppelin!");
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(msg, "Server was eligible and is now allowed to use Zeppelin!");
},
});

View file

@ -1,8 +1,9 @@
import { ApiPermissions } from "@shared/apiPermissions";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { DBDateFormat, isSnowflake } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const AllowServerCmd = botControlCmd({
@ -20,17 +21,17 @@ export const AllowServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
if (existing) {
sendErrorMessage(pluginData, msg.channel, "Server is already allowed!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is already allowed!");
return;
}
if (!isSnowflake(args.guildId)) {
sendErrorMessage(pluginData, msg.channel, "Invalid server ID!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid server ID!");
return;
}
if (args.userId && !isSnowflake(args.userId)) {
sendErrorMessage(pluginData, msg.channel, "Invalid user ID!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid user ID!");
return;
}
@ -51,6 +52,6 @@ export const AllowServerCmd = botControlCmd({
);
}
sendSuccessMessage(pluginData, msg.channel, "Server is now allowed to use Zeppelin!");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Server is now allowed to use Zeppelin!");
},
});

View file

@ -1,5 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const ChannelToServerCmd = botControlCmd({
@ -16,7 +17,7 @@ export const ChannelToServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const channel = pluginData.client.channels.cache.get(args.channelId);
if (!channel) {
sendErrorMessage(pluginData, msg.channel, "Channel not found in cache!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Channel not found in cache!");
return;
}

View file

@ -1,7 +1,8 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { noop } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const DisallowServerCmd = botControlCmd({
@ -18,7 +19,7 @@ export const DisallowServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
if (!existing) {
sendErrorMessage(pluginData, msg.channel, "That server is not allowed in the first place!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "That server is not allowed in the first place!");
return;
}
@ -27,6 +28,6 @@ export const DisallowServerCmd = botControlCmd({
.get(args.guildId as Snowflake)
?.leave()
.catch(noop);
sendSuccessMessage(pluginData, msg.channel, "Server removed!");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Server removed!");
},
});

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isGuildInvite, resolveInvite } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { isEligible } from "../functions/isEligible";
import { botControlCmd } from "../types";
@ -16,17 +16,17 @@ export const EligibleCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
if (!invite || !isGuildInvite(invite)) {
sendErrorMessage(pluginData, msg.channel, "Could not resolve invite");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Could not resolve invite");
return;
}
const { result, explanation } = await isEligible(pluginData, args.user, invite);
if (result) {
sendSuccessMessage(pluginData, msg.channel, `Server is eligible: ${explanation}`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Server is eligible: ${explanation}`);
return;
}
sendErrorMessage(pluginData, msg.channel, `Server is **NOT** eligible: ${explanation}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Server is **NOT** eligible: ${explanation}`);
},
});

View file

@ -1,6 +1,7 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const LeaveServerCmd = botControlCmd({
@ -16,7 +17,7 @@ export const LeaveServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "I am not in that guild");
return;
}
@ -26,10 +27,10 @@ export const LeaveServerCmd = botControlCmd({
try {
await pluginData.client.guilds.cache.get(args.guildId as Snowflake)?.leave();
} catch (e) {
sendErrorMessage(pluginData, msg.channel, `Failed to leave guild: ${e.message}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Failed to leave guild: ${e.message}`);
return;
}
sendSuccessMessage(pluginData, msg.channel, `Left guild **${guildName}**`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Left guild **${guildName}**`);
},
});

View file

@ -1,8 +1,8 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { AllowedGuild } from "../../../data/entities/AllowedGuild";
import { ApiPermissionAssignment } from "../../../data/entities/ApiPermissionAssignment";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { renderUserUsername, resolveUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const ListDashboardPermsCmd = botControlCmd({
@ -16,7 +16,7 @@ export const ListDashboardPermsCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
if (!args.user && !args.guildId) {
sendErrorMessage(pluginData, msg.channel, "Must specify at least guildId, user, or both.");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Must specify at least guildId, user, or both.");
return;
}
@ -24,7 +24,7 @@ export const ListDashboardPermsCmd = botControlCmd({
if (args.guildId) {
guild = await pluginData.state.allowedGuilds.find(args.guildId);
if (!guild) {
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
return;
}
}
@ -33,7 +33,7 @@ export const ListDashboardPermsCmd = botControlCmd({
if (args.user) {
existingUserAssignment = await pluginData.state.apiPermissionAssignments.getByUserId(args.user.id);
if (existingUserAssignment.length === 0) {
sendErrorMessage(pluginData, msg.channel, "The user has no assigned permissions.");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "The user has no assigned permissions.");
return;
}
}
@ -54,11 +54,9 @@ export const ListDashboardPermsCmd = botControlCmd({
}
if (finalMessage === "") {
sendErrorMessage(
pluginData,
msg.channel,
`The user ${userInfo} has no assigned permissions on the specified server.`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `The user ${userInfo} has no assigned permissions on the specified server.`);
return;
}
// Else display all users that have permissions on the specified guild
@ -67,7 +65,9 @@ export const ListDashboardPermsCmd = botControlCmd({
const existingGuildAssignment = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
if (existingGuildAssignment.length === 0) {
sendErrorMessage(pluginData, msg.channel, `The server ${guildInfo} has no assigned permissions.`);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `The server ${guildInfo} has no assigned permissions.`);
return;
}
@ -80,6 +80,6 @@ export const ListDashboardPermsCmd = botControlCmd({
}
}
await sendSuccessMessage(pluginData, msg.channel, finalMessage.trim(), {});
await pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, finalMessage.trim(), {});
},
});

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { renderUserUsername, resolveUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const ListDashboardUsersCmd = botControlCmd({
@ -14,7 +14,7 @@ export const ListDashboardUsersCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
if (!guild) {
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
return;
}
@ -30,11 +30,12 @@ export const ListDashboardUsersCmd = botControlCmd({
`<@!${user.id}> (**${renderUserUsername(user)}**, \`${user.id}\`): ${permission.permissions.join(", ")}`,
);
sendSuccessMessage(
pluginData,
msg.channel,
`The following users have dashboard access for **${guild.name}**:\n\n${userNameList.join("\n")}`,
{},
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`The following users have dashboard access for **${guild.name}**:\n\n${userNameList.join("\n")}`,
{},
);
},
});

View file

@ -1,7 +1,8 @@
import moment from "moment-timezone";
import { GuildArchives } from "../../../data/GuildArchives";
import { getBaseUrl, sendSuccessMessage } from "../../../pluginUtils";
import { getBaseUrl } from "../../../pluginUtils";
import { getRateLimitStats } from "../../../rateLimitStats";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const RateLimitPerformanceCmd = botControlCmd({
@ -13,7 +14,7 @@ export const RateLimitPerformanceCmd = botControlCmd({
async run({ pluginData, message: msg }) {
const logItems = getRateLimitStats();
if (logItems.length === 0) {
sendSuccessMessage(pluginData, msg.channel, `No rate limits hit`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `No rate limits hit`);
return;
}

View file

@ -1,4 +1,5 @@
import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { getActiveReload, setActiveReload } from "../activeReload";
import { botControlCmd } from "../types";
@ -14,7 +15,7 @@ export const ReloadGlobalPluginsCmd = botControlCmd({
const guildId = "guild" in message.channel ? message.channel.guild.id : null;
if (!guildId) {
sendErrorMessage(pluginData, message.channel, "This command can only be used in a server");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "This command can only be used in a server");
return;
}

View file

@ -1,6 +1,7 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const ReloadServerCmd = botControlCmd({
@ -16,18 +17,18 @@ export const ReloadServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "I am not in that guild");
return;
}
try {
await pluginData.getKnubInstance().reloadGuild(args.guildId);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, `Failed to reload guild: ${e.message}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Failed to reload guild: ${e.message}`);
return;
}
const guild = await pluginData.client.guilds.fetch(args.guildId as Snowflake);
sendSuccessMessage(pluginData, msg.channel, `Reloaded guild **${guild?.name || "???"}**`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Reloaded guild **${guild?.name || "???"}**`);
},
});

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isStaffPreFilter } from "../../../pluginUtils";
import { renderUserUsername } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { botControlCmd } from "../types";
export const RemoveDashboardUserCmd = botControlCmd({
@ -18,7 +19,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
if (!guild) {
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
return;
}
@ -35,10 +36,11 @@ export const RemoveDashboardUserCmd = botControlCmd({
}
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUserUsername(user)}**, \`${user.id}\`)`);
sendSuccessMessage(
pluginData,
msg.channel,
`The following users were removed from the dashboard for **${guild.name}**:\n\n${userNameList}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`The following users were removed from the dashboard for **${guild.name}**:\n\n${userNameList}`,
);
},
});

View file

@ -1,8 +1,9 @@
import { Snowflake } from "discord.js";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { isOwner, sendErrorMessage } from "../../../pluginUtils";
import { isOwner } from "../../../pluginUtils";
import { SECONDS, confirm, noop, renderUsername } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { rehostAttachment } from "../rehostAttachment";
import { channelArchiverCmd } from "../types";
@ -32,12 +33,12 @@ export const ArchiveChannelCmd = channelArchiverCmd({
async run({ message: msg, args, pluginData }) {
if (!args["attachment-channel"]) {
const confirmed = await confirm(msg.channel, msg.author.id, {
const confirmed = await confirm(msg, msg.author.id, {
content:
"No `-attachment-channel` specified. Continue? Attachments will not be available in the log if their message is deleted.",
});
if (!confirmed) {
sendErrorMessage(pluginData, msg.channel, "Canceled");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Canceled");
return;
}
}

View file

@ -0,0 +1,146 @@
import {
ChatInputCommandInteraction,
Message,
MessageCreateOptions,
MessageMentionOptions,
ModalSubmitInteraction,
TextBasedChannel,
User,
} from "discord.js";
import { PluginOptions } from "knub";
import { logger } from "../../logger";
import { isContextInteraction, makeIoTsConfigParser, sendContextResponse } from "../../pluginUtils";
import { errorMessage, successMessage } from "../../utils";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { getErrorEmoji, getSuccessEmoji } from "./functions/getEmoji";
import { CommonPluginType, ConfigSchema } from "./types";
const defaultOptions: PluginOptions<CommonPluginType> = {
config: {
success_emoji: "✅",
error_emoji: "❌",
},
};
export const CommonPlugin = zeppelinGuildPlugin<CommonPluginType>()({
name: "common",
showInDocs: false,
info: {
prettyName: "Common",
},
dependencies: () => [],
configParser: makeIoTsConfigParser(ConfigSchema),
defaultOptions,
public: {
getSuccessEmoji(pluginData) {
return () => getSuccessEmoji(pluginData);
},
getErrorEmoji(pluginData) {
return () => getErrorEmoji(pluginData);
},
sendSuccessMessage(pluginData) {
return async (
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
responseInteraction?: ModalSubmitInteraction,
ephemeral = true,
): Promise<Message | undefined> => {
const emoji = getSuccessEmoji(pluginData);
const formattedBody = successMessage(body, emoji);
const content: MessageCreateOptions = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
if (responseInteraction) {
await responseInteraction
.editReply({ content: formattedBody, embeds: [], components: [] })
.catch((err) => logger.error(`Interaction reply failed: ${err}`));
return;
}
if (!isContextInteraction(context)) {
// noinspection TypeScriptValidateJSTypes
return sendContextResponse(context, { ...content }) // Force line break
.catch((err) => {
const channelInfo =
"guild" in context && context.guild ? `${context.id} (${context.guild.id})` : context.id;
logger.warn(`Failed to send success message to ${channelInfo}): ${err.code} ${err.message}`);
return undefined;
});
}
const replyMethod = context.replied ? "followUp" : "reply";
return context[replyMethod]({
content: formattedBody,
embeds: [],
components: [],
fetchReply: true,
ephemeral,
}).catch((err) => {
logger.error(`Context reply failed: ${err}`);
return undefined;
}) as Promise<Message>;
};
},
sendErrorMessage(pluginData) {
return async (
context: TextBasedChannel | Message | User | ChatInputCommandInteraction,
body: string,
allowedMentions?: MessageMentionOptions,
responseInteraction?: ModalSubmitInteraction,
ephemeral = false,
): Promise<Message | undefined> => {
const emoji = getErrorEmoji(pluginData);
const formattedBody = errorMessage(body, emoji);
const content: MessageCreateOptions = allowedMentions
? { content: formattedBody, allowedMentions }
: { content: formattedBody };
if (responseInteraction) {
await responseInteraction
.editReply({ content: formattedBody, embeds: [], components: [] })
.catch((err) => logger.error(`Interaction reply failed: ${err}`));
return;
}
if (!isContextInteraction(context)) {
// noinspection TypeScriptValidateJSTypes
return sendContextResponse(context, { ...content }) // Force line break
.catch((err) => {
const channelInfo =
"guild" in context && context.guild ? `${context.id} (${context.guild.id})` : context.id;
logger.warn(`Failed to send error message to ${channelInfo}): ${err.code} ${err.message}`);
return undefined;
});
}
const replyMethod = context.replied ? "followUp" : "reply";
return context[replyMethod]({
content: formattedBody,
embeds: [],
components: [],
fetchReply: true,
ephemeral,
}).catch((err) => {
logger.error(`Context reply failed: ${err}`);
return undefined;
}) as Promise<Message>;
};
},
},
});

View file

@ -0,0 +1,10 @@
import { GuildPluginData } from "knub";
import { CommonPluginType } from "../types";
export function getSuccessEmoji(pluginData: GuildPluginData<CommonPluginType>) {
return pluginData.config.get().success_emoji ?? "✅";
}
export function getErrorEmoji(pluginData: GuildPluginData<CommonPluginType>) {
return pluginData.config.get().error_emoji ?? "❌";
}

View file

@ -0,0 +1,13 @@
import * as t from "io-ts";
import { BasePluginType } from "knub";
export const ConfigSchema = t.type({
success_emoji: t.string,
error_emoji: t.string,
});
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface CommonPluginType extends BasePluginType {
config: TConfigSchema;
}

View file

@ -55,7 +55,7 @@ async function banAction(
};
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
const result = await modactions.banUserId(target, reason, { caseArgs }, durationMs);
const result = await modactions.banUserId(target, reason, reason, { caseArgs }, durationMs);
if (result.status === "failed") {
await interactionToReply
.editReply({ content: "Error: Failed to ban user", embeds: [], components: [] })

View file

@ -68,7 +68,7 @@ async function muteAction(
const durationMs = duration ? convertDelayStringToMS(duration)! : undefined;
try {
const result = await mutes.muteUser(target, durationMs, reason, { caseArgs });
const result = await mutes.muteUser(target, durationMs, reason, reason, { caseArgs });
const messageResultText = result.notifyResult.text ? ` (${result.notifyResult.text})` : "";
const muteMessage = `Muted **${result.case.user_name}** ${

View file

@ -60,7 +60,7 @@ async function warnAction(
modId: executingMember.id,
};
const result = await modactions.warnMember(targetMember, reason, { caseArgs });
const result = await modactions.warnMember(targetMember, reason, reason, { caseArgs });
if (result.status === "failed") {
await interactionToReply
.editReply({ content: "Error: Failed to warn user", embeds: [], components: [] })

View file

@ -2,8 +2,8 @@ import { Snowflake, TextChannel } from "discord.js";
import { guildPluginMessageCommand } from "knub";
import { waitForReply } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { UnknownUser, resolveUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { changeCounterValue } from "../functions/changeCounterValue";
import { CountersPluginType } from "../types";
@ -45,22 +45,22 @@ export const AddCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
const counter = config.counters[args.counterName];
const counterId = pluginData.state.counterIds[args.counterName];
if (!counter || !counterId) {
sendErrorMessage(pluginData, message.channel, `Unknown counter: ${args.counterName}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Unknown counter: ${args.counterName}`);
return;
}
if (counter.can_edit === false) {
sendErrorMessage(pluginData, message.channel, `Missing permissions to edit this counter's value`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Missing permissions to edit this counter's value`);
return;
}
if (args.channel && !counter.per_channel) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-channel`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-channel`);
return;
}
if (args.user && !counter.per_user) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-user`);
return;
}
@ -69,13 +69,13 @@ export const AddCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which channel's counter value would you like to add to?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialChannel = pluginData.guild.channels.resolve(reply.content as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Channel is not a text channel, cancelling");
return;
}
@ -87,13 +87,13 @@ export const AddCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which user's counter value would you like to add to?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialUser = await resolveUser(pluginData.client, reply.content);
if (!potentialUser || potentialUser instanceof UnknownUser) {
sendErrorMessage(pluginData, message.channel, "Unknown user, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown user, cancelling");
return;
}
@ -105,13 +105,13 @@ export const AddCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send("How much would you like to add to the counter's value?");
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialAmount = parseInt(reply.content, 10);
if (!potentialAmount) {
sendErrorMessage(pluginData, message.channel, "Not a number, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Not a number, cancelling");
return;
}

View file

@ -1,7 +1,7 @@
import { guildPluginMessageCommand } from "knub";
import { sendErrorMessage } from "../../../pluginUtils";
import { trimMultilineString, ucfirst } from "../../../utils";
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { CountersPluginType } from "../types";
export const CountersListCmd = guildPluginMessageCommand<CountersPluginType>()({
@ -15,7 +15,7 @@ export const CountersListCmd = guildPluginMessageCommand<CountersPluginType>()({
const countersToShow = Array.from(Object.values(config.counters)).filter((c) => c.can_view !== false);
if (!countersToShow.length) {
sendErrorMessage(pluginData, message.channel, "No counters are configured for this server");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "No counters are configured for this server");
return;
}

View file

@ -1,7 +1,7 @@
import { guildPluginMessageCommand } from "knub";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { confirm, noop, trimMultilineString } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { resetAllCounterValues } from "../functions/resetAllCounterValues";
import { CountersPluginType } from "../types";
@ -18,17 +18,19 @@ export const ResetAllCounterValuesCmd = guildPluginMessageCommand<CountersPlugin
const counter = config.counters[args.counterName];
const counterId = pluginData.state.counterIds[args.counterName];
if (!counter || !counterId) {
sendErrorMessage(pluginData, message.channel, `Unknown counter: ${args.counterName}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Unknown counter: ${args.counterName}`);
return;
}
if (counter.can_reset_all === false) {
sendErrorMessage(pluginData, message.channel, `Missing permissions to reset all of this counter's values`);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(message, `Missing permissions to reset all of this counter's values`);
return;
}
const counterName = counter.name || args.counterName;
const confirmed = await confirm(message.channel, message.author.id, {
const confirmed = await confirm(message, message.author.id, {
content: trimMultilineString(`
Do you want to reset **ALL** values for counter **${counterName}**?
This will reset the counter for **all** users and channels.
@ -36,7 +38,7 @@ export const ResetAllCounterValuesCmd = guildPluginMessageCommand<CountersPlugin
`),
});
if (!confirmed) {
sendErrorMessage(pluginData, message.channel, "Cancelled");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelled");
return;
}
@ -47,7 +49,9 @@ export const ResetAllCounterValuesCmd = guildPluginMessageCommand<CountersPlugin
await resetAllCounterValues(pluginData, args.counterName);
loadingMessage?.delete().catch(noop);
sendSuccessMessage(pluginData, message.channel, `All counter values for **${counterName}** have been reset`);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(message, `All counter values for **${counterName}** have been reset`);
pluginData.getKnubInstance().reloadGuild(pluginData.guild.id);
},

View file

@ -2,8 +2,8 @@ import { Snowflake, TextChannel } from "discord.js";
import { guildPluginMessageCommand } from "knub";
import { waitForReply } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { UnknownUser, resolveUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { setCounterValue } from "../functions/setCounterValue";
import { CountersPluginType } from "../types";
@ -40,22 +40,22 @@ export const ResetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
const counter = config.counters[args.counterName];
const counterId = pluginData.state.counterIds[args.counterName];
if (!counter || !counterId) {
sendErrorMessage(pluginData, message.channel, `Unknown counter: ${args.counterName}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Unknown counter: ${args.counterName}`);
return;
}
if (counter.can_edit === false) {
sendErrorMessage(pluginData, message.channel, `Missing permissions to reset this counter's value`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Missing permissions to reset this counter's value`);
return;
}
if (args.channel && !counter.per_channel) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-channel`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-channel`);
return;
}
if (args.user && !counter.per_user) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-user`);
return;
}
@ -64,13 +64,13 @@ export const ResetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which channel's counter value would you like to reset?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialChannel = pluginData.guild.channels.resolve(reply.content as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Channel is not a text channel, cancelling");
return;
}
@ -82,13 +82,13 @@ export const ResetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which user's counter value would you like to reset?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialUser = await resolveUser(pluginData.client, reply.content);
if (!potentialUser || potentialUser instanceof UnknownUser) {
sendErrorMessage(pluginData, message.channel, "Unknown user, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown user, cancelling");
return;
}

View file

@ -2,8 +2,8 @@ import { Snowflake, TextChannel } from "discord.js";
import { guildPluginMessageCommand } from "knub";
import { waitForReply } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { UnknownUser, resolveUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { setCounterValue } from "../functions/setCounterValue";
import { CountersPluginType } from "../types";
@ -45,22 +45,22 @@ export const SetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
const counter = config.counters[args.counterName];
const counterId = pluginData.state.counterIds[args.counterName];
if (!counter || !counterId) {
sendErrorMessage(pluginData, message.channel, `Unknown counter: ${args.counterName}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Unknown counter: ${args.counterName}`);
return;
}
if (counter.can_edit === false) {
sendErrorMessage(pluginData, message.channel, `Missing permissions to edit this counter's value`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Missing permissions to edit this counter's value`);
return;
}
if (args.channel && !counter.per_channel) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-channel`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-channel`);
return;
}
if (args.user && !counter.per_user) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-user`);
return;
}
@ -69,13 +69,13 @@ export const SetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which channel's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialChannel = pluginData.guild.channels.resolve(reply.content as Snowflake);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Channel is not a text channel, cancelling");
return;
}
@ -87,13 +87,13 @@ export const SetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which user's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialUser = await resolveUser(pluginData.client, reply.content);
if (!potentialUser || potentialUser instanceof UnknownUser) {
sendErrorMessage(pluginData, message.channel, "Unknown user, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown user, cancelling");
return;
}
@ -105,13 +105,13 @@ export const SetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send("What would you like to set the counter's value to?");
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialValue = parseInt(reply.content, 10);
if (Number.isNaN(potentialValue)) {
sendErrorMessage(pluginData, message.channel, "Not a number, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Not a number, cancelling");
return;
}
@ -119,7 +119,7 @@ export const SetCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
}
if (value < 0) {
sendErrorMessage(pluginData, message.channel, "Cannot set counter value below 0");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cannot set counter value below 0");
return;
}

View file

@ -2,8 +2,8 @@ import { Snowflake } from "discord.js";
import { guildPluginMessageCommand } from "knub";
import { waitForReply } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { resolveUser, UnknownUser } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { CountersPluginType } from "../types";
export const ViewCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
@ -39,22 +39,22 @@ export const ViewCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
const counter = config.counters[args.counterName];
const counterId = pluginData.state.counterIds[args.counterName];
if (!counter || !counterId) {
sendErrorMessage(pluginData, message.channel, `Unknown counter: ${args.counterName}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Unknown counter: ${args.counterName}`);
return;
}
if (counter.can_view === false) {
sendErrorMessage(pluginData, message.channel, `Missing permissions to view this counter's value`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `Missing permissions to view this counter's value`);
return;
}
if (args.channel && !counter.per_channel) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-channel`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-channel`);
return;
}
if (args.user && !counter.per_user) {
sendErrorMessage(pluginData, message.channel, `This counter is not per-user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, `This counter is not per-user`);
return;
}
@ -63,13 +63,13 @@ export const ViewCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which channel's counter value would you like to view?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialChannel = pluginData.guild.channels.resolve(reply.content as Snowflake);
if (!potentialChannel?.isTextBased()) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Channel is not a text channel, cancelling");
return;
}
@ -81,13 +81,13 @@ export const ViewCounterCmd = guildPluginMessageCommand<CountersPluginType>()({
message.channel.send(`Which user's counter value would you like to view?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Cancelling");
return;
}
const potentialUser = await resolveUser(pluginData.client, reply.content);
if (!potentialUser || potentialUser instanceof UnknownUser) {
sendErrorMessage(pluginData, message.channel, "Unknown user, cancelling");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "Unknown user, cancelling");
return;
}

View file

@ -1,7 +1,7 @@
import { Message } from "discord.js";
import { GuildPluginData } from "knub";
import { sendErrorMessage } from "../../../pluginUtils";
import { TemplateSafeValueContainer } from "../../../templateFormatter";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { ActionError } from "../ActionError";
import { addRoleAction } from "../actions/addRoleAction";
import { createCaseAction } from "../actions/createCaseAction";
@ -39,7 +39,7 @@ export async function runEvent(
} catch (e) {
if (e instanceof ActionError) {
if (event.trigger.type === "command") {
sendErrorMessage(pluginData, (eventData.msg as Message).channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage((eventData.msg as Message).channel, e.message);
} else {
// TODO: Where to log action errors from other kinds of triggers?
}

View file

@ -2,8 +2,8 @@ import humanizeDuration from "humanize-duration";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { registerExpiringVCAlert } from "../../../data/loops/expiringVCAlertsLoop";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { MINUTES, SECONDS } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { locateUserCmd } from "../types";
export const FollowCmd = locateUserCmd({
@ -27,7 +27,9 @@ export const FollowCmd = locateUserCmd({
const active = args.active || false;
if (time < 30 * SECONDS) {
sendErrorMessage(pluginData, msg.channel, "Sorry, but the minimum duration for an alert is 30 seconds!");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, "Sorry, but the minimum duration for an alert is 30 seconds!");
return;
}
@ -46,19 +48,23 @@ export const FollowCmd = locateUserCmd({
}
if (active) {
sendSuccessMessage(
pluginData,
msg.channel,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify and move you.\nPlease make sure to be in a voice channel, otherwise i cannot move you!`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify and move you.\nPlease make sure to be in a voice channel, otherwise i cannot move you!`,
);
} else {
sendSuccessMessage(
pluginData,
msg.channel,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(time)} i will notify you`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify you`,
);
}
},
});

View file

@ -1,7 +1,7 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { clearExpiringVCAlert } from "../../../data/loops/expiringVCAlertsLoop";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { createChunkedMessage, sorter } from "../../../utils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { locateUserCmd } from "../types";
export const ListFollowCmd = locateUserCmd({
@ -13,7 +13,7 @@ export const ListFollowCmd = locateUserCmd({
async run({ message: msg, pluginData }) {
const alerts = await pluginData.state.alerts.getAlertsByRequestorId(msg.member.id);
if (alerts.length === 0) {
sendErrorMessage(pluginData, msg.channel, "You have no active alerts!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You have no active alerts!");
return;
}
@ -46,7 +46,7 @@ export const DeleteFollowCmd = locateUserCmd({
alerts.sort(sorter("expires_at"));
if (args.num > alerts.length || args.num <= 0) {
sendErrorMessage(pluginData, msg.channel, "Unknown alert!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown alert!");
return;
}
@ -54,6 +54,6 @@ export const DeleteFollowCmd = locateUserCmd({
clearExpiringVCAlert(toDelete);
await pluginData.state.alerts.delete(toDelete.id);
sendSuccessMessage(pluginData, msg.channel, "Alert deleted");
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Alert deleted");
},
});

View file

@ -1,6 +1,6 @@
import { GuildMember, GuildTextBasedChannel, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { LocateUserPluginType } from "../types";
export async function moveMember(
@ -16,10 +16,14 @@ export async function moveMember(
channel: target.voice.channelId,
});
} catch {
sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
return;
}
} else {
sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
}
}

View file

@ -1,7 +1,7 @@
import { GuildMember, GuildTextBasedChannel, Invite, VoiceChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { getInviteLink } from "knub/helpers";
import { sendErrorMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { LocateUserPluginType } from "../types";
import { createOrReuseInvite } from "./createOrReuseInvite";
@ -22,7 +22,7 @@ export async function sendWhere(
try {
invite = await createOrReuseInvite(voice);
} catch {
sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(channel, "Cannot create an invite to that channel!");
return;
}
channel.send({

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { saveMessagesToDB } from "../saveMessagesToDB";
import { messageSaverCmd } from "../types";
@ -18,13 +18,14 @@ export const SaveMessagesToDBCmd = messageSaverCmd({
const { savedCount, failed } = await saveMessagesToDB(pluginData, args.channel, args.ids.trim().split(" "));
if (failed.length) {
sendSuccessMessage(
pluginData,
msg.channel,
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`,
);
} else {
sendSuccessMessage(pluginData, msg.channel, `Saved ${savedCount} messages!`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Saved ${savedCount} messages!`);
}
},
});

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendSuccessMessage } from "../../../pluginUtils";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { saveMessagesToDB } from "../saveMessagesToDB";
import { messageSaverCmd } from "../types";
@ -19,13 +19,14 @@ export const SavePinsToDBCmd = messageSaverCmd({
const { savedCount, failed } = await saveMessagesToDB(pluginData, args.channel, [...pins.keys()]);
if (failed.length) {
sendSuccessMessage(
pluginData,
msg.channel,
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
msg,
`Saved ${savedCount} messages. The following messages could not be saved: ${failed.join(", ")}`,
);
} else {
sendSuccessMessage(pluginData, msg.channel, `Saved ${savedCount} messages!`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Saved ${savedCount} messages!`);
}
},
});

View file

@ -72,6 +72,7 @@ import { onModActionsEvent } from "./functions/onModActionsEvent";
import { updateCase } from "./functions/updateCase";
import { warnMember } from "./functions/warnMember";
import {
AttachmentLinkReactionType,
BanOptions,
ConfigSchema,
KickOptions,
@ -100,6 +101,8 @@ const defaultOptions = {
warn_notify_message:
"The user already has **{priorWarnings}** warnings!\n Please check their prior cases and assess whether or not to warn anyways.\n Proceed with the warning?",
ban_delete_message_days: 1,
attachment_link_reaction: "warn" as AttachmentLinkReactionType,
attachment_storing_channel: null,
can_note: false,
can_warn: false,
@ -217,26 +220,32 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()({
public: {
warnMember(pluginData) {
return (member: GuildMember, reason: string, warnOptions?: WarnOptions) => {
return warnMember(pluginData, member, reason, warnOptions);
return (member: GuildMember, reason: string, reasonWithAttachments: string, warnOptions?: WarnOptions) => {
return warnMember(pluginData, member, reason, reasonWithAttachments, warnOptions);
};
},
kickMember(pluginData) {
return (member: GuildMember, reason: string, kickOptions?: KickOptions) => {
kickMember(pluginData, member, reason, kickOptions);
return (member: GuildMember, reason: string, reasonWithAttachments: string, kickOptions?: KickOptions) => {
kickMember(pluginData, member, reason, reasonWithAttachments, kickOptions);
};
},
banUserId(pluginData) {
return (userId: string, reason?: string, banOptions?: BanOptions, banTime?: number) => {
return banUserId(pluginData, userId, reason, banOptions, banTime);
return (
userId: string,
reason?: string,
reasonWithAttachments?: string,
banOptions?: BanOptions,
banTime?: number,
) => {
return banUserId(pluginData, userId, reason, reasonWithAttachments, banOptions, banTime);
};
},
updateCase(pluginData) {
return (msg: Message, caseNumber: number | null, note: string) => {
updateCase(pluginData, msg.channel, msg.author, caseNumber ?? undefined, note, [...msg.attachments.values()]);
updateCase(pluginData, msg, msg.author, caseNumber ?? undefined, note, [...msg.attachments.values()]);
};
},

View file

@ -1,7 +1,8 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { CaseTypes } from "../../../../data/CaseTypes";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd";
import { modActionsMsgCmd } from "../../types";
@ -27,7 +28,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -35,7 +36,7 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -45,13 +46,13 @@ export const AddCaseMsgCmd = modActionsMsgCmd({
// Verify the case type is valid
const type: string = args.type[0].toUpperCase() + args.type.slice(1).toLowerCase();
if (!CaseTypes[type]) {
sendErrorMessage(pluginData, msg.channel, "Cannot add case: invalid case type");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot add case: invalid case type");
return;
}
actualAddCaseCmd(
pluginData,
msg.channel,
msg,
msg.member,
mod,
[...msg.attachments.values()],

View file

@ -1,7 +1,8 @@
import { slashOptions } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualAddCaseCmd } from "../../functions/actualCommands/actualAddCaseCmd";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -44,7 +45,9 @@ export const AddCaseSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualBanCmd } from "../../functions/actualCommands/actualBanCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsMsgCmd } from "../../types";
@ -37,7 +38,7 @@ export const BanMsgCmd = modActionsMsgCmd({
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -45,7 +46,7 @@ export const BanMsgCmd = modActionsMsgCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -56,13 +57,13 @@ export const BanMsgCmd = modActionsMsgCmd({
try {
contactMethods = readContactMethodsFromArgs(args) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
actualBanCmd(
pluginData,
msg.channel,
msg,
user,
args["time"] ? args["time"] : null,
args.reason || "",

View file

@ -1,8 +1,9 @@
import { ChannelType } from "discord.js";
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualBanCmd } from "../../functions/actualCommands/actualBanCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -49,7 +50,9 @@ export const BanSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -62,7 +65,9 @@ export const BanSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -73,13 +78,13 @@ export const BanSlashCmd = {
try {
contactMethods = readContactMethodsFromArgs(options) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, interaction, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, e.message);
return;
}
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}

View file

@ -14,6 +14,6 @@ export const CaseMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualCaseCmd(pluginData, msg.channel, msg.author.id, args.caseNumber);
actualCaseCmd(pluginData, msg, msg.author.id, args.caseNumber);
},
});

View file

@ -29,7 +29,7 @@ export const CasesModMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
return actualCasesCmd(
pluginData,
msg.channel,
msg,
args.mod,
null,
msg.author,

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { sendErrorMessage } from "../../../../pluginUtils";
import { resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualCasesCmd } from "../../functions/actualCommands/actualCasesCmd";
import { modActionsMsgCmd } from "../../types";
@ -33,13 +33,13 @@ export const CasesUserMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
return actualCasesCmd(
pluginData,
msg.channel,
msg,
args.mod,
user,
msg.author,

View file

@ -18,6 +18,6 @@ export const DeleteCaseMsgCmd = modActionsMsgCmd({
},
async run({ pluginData, message, args }) {
actualDeleteCaseCmd(pluginData, message.channel, message.member, args.caseNumber, args.force);
actualDeleteCaseCmd(pluginData, message, message.member, args.caseNumber, args.force);
},
});

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualForceBanCmd } from "../../functions/actualCommands/actualForceBanCmd";
import { isBanned } from "../../functions/isBanned";
import { modActionsMsgCmd } from "../../types";
@ -26,21 +27,21 @@ export const ForceBanMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
// If the user exists as a guild member, make sure we can act on them first
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (member && !canActOn(pluginData, msg.member, member)) {
sendErrorMessage(pluginData, msg.channel, "Cannot forceban this user: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot forceban this user: insufficient permissions");
return;
}
// Make sure the user isn't already banned
const banned = await isBanned(pluginData, user.id);
if (banned) {
sendErrorMessage(pluginData, msg.channel, `User is already banned`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User is already banned`);
return;
}
@ -48,13 +49,13 @@ export const ForceBanMsgCmd = modActionsMsgCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
mod = args.mod;
}
actualForceBanCmd(pluginData, msg.channel, msg.author.id, user, args.reason, [...msg.attachments.values()], mod);
actualForceBanCmd(pluginData, msg, msg.author.id, user, args.reason, [...msg.attachments.values()], mod);
},
});

View file

@ -1,7 +1,8 @@
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualForceBanCmd } from "../../functions/actualCommands/actualForceBanCmd";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -26,7 +27,9 @@ export const ForceBanSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -39,7 +42,9 @@ export const ForceBanSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -48,7 +53,7 @@ export const ForceBanSlashCmd = {
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsMsgCmd } from "../../types";
@ -35,7 +36,7 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -43,7 +44,7 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
// Make sure we're allowed to mute this user
if (memberToMute && !canActOn(pluginData, msg.member, memberToMute)) {
sendErrorMessage(pluginData, msg.channel, "Cannot mute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot mute: insufficient permissions");
return;
}
@ -53,7 +54,7 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -65,13 +66,13 @@ export const ForceMuteMsgCmd = modActionsMsgCmd({
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
actualMuteCmd(
pluginData,
msg.channel,
msg,
user,
[...msg.attachments.values()],
mod,

View file

@ -1,8 +1,9 @@
import { ChannelType } from "discord.js";
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -44,7 +45,9 @@ export const ForceMuteSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -58,7 +61,9 @@ export const ForceMuteSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -68,7 +73,7 @@ export const ForceMuteSlashCmd = {
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}
@ -76,7 +81,7 @@ export const ForceMuteSlashCmd = {
try {
contactMethods = readContactMethodsFromArgs(options) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, interaction, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, e.message);
return;
}

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { modActionsMsgCmd } from "../../types";
@ -32,13 +33,13 @@ export const ForceUnmuteMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
// Check if they're muted in the first place
if (!(await pluginData.state.mutes.isMuted(user.id))) {
sendErrorMessage(pluginData, msg.channel, "Cannot unmute: member is not muted");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot unmute: member is not muted");
return;
}
@ -47,7 +48,7 @@ export const ForceUnmuteMsgCmd = modActionsMsgCmd({
// Make sure we're allowed to unmute this member
if (memberToUnmute && !canActOn(pluginData, msg.member, memberToUnmute)) {
sendErrorMessage(pluginData, msg.channel, "Cannot unmute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot unmute: insufficient permissions");
return;
}
@ -57,7 +58,7 @@ export const ForceUnmuteMsgCmd = modActionsMsgCmd({
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -67,7 +68,7 @@ export const ForceUnmuteMsgCmd = modActionsMsgCmd({
actualUnmuteCmd(
pluginData,
msg.channel,
msg,
user,
[...msg.attachments.values()],
mod,

View file

@ -1,7 +1,8 @@
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -27,7 +28,9 @@ export const ForceUnmuteSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -41,7 +44,9 @@ export const ForceUnmuteSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -51,7 +56,7 @@ export const ForceUnmuteSlashCmd = {
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}

View file

@ -14,6 +14,6 @@ export const HideCaseMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualHideCaseCmd(pluginData, msg.channel, args.caseNum);
actualHideCaseCmd(pluginData, msg, args.caseNum);
},
});

View file

@ -1,7 +1,7 @@
import { hasPermission } from "knub/helpers";
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { sendErrorMessage } from "../../../../pluginUtils";
import { resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualKickCmd } from "../../functions/actualCommands/actualKickCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { modActionsMsgCmd } from "../../types";
@ -30,7 +30,7 @@ export const KickMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -38,7 +38,7 @@ export const KickMsgCmd = modActionsMsgCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(await pluginData.config.getForMessage(msg), "can_act_as_other"))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -49,13 +49,13 @@ export const KickMsgCmd = modActionsMsgCmd({
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
actualKickCmd(
pluginData,
msg.channel,
msg,
msg.member,
user,
args.reason,

View file

@ -1,8 +1,9 @@
import { ChannelType } from "discord.js";
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualKickCmd } from "../../functions/actualCommands/actualKickCmd";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -48,7 +49,9 @@ export const KickSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -61,7 +64,9 @@ export const KickSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -72,7 +77,7 @@ export const KickSlashCmd = {
try {
contactMethods = readContactMethodsFromArgs(options) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, interaction, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, e.message);
return;
}

View file

@ -14,6 +14,6 @@ export const MassBanMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualMassBanCmd(pluginData, msg.channel, args.userIds, msg.member);
actualMassBanCmd(pluginData, msg, args.userIds, msg.member);
},
});

View file

@ -14,6 +14,6 @@ export const MassMuteMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualMassMuteCmd(pluginData, msg.channel, args.userIds, msg.member);
actualMassMuteCmd(pluginData, msg, args.userIds, msg.member);
},
});

View file

@ -14,6 +14,6 @@ export const MassUnbanMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualMassBanCmd(pluginData, msg.channel, args.userIds, msg.member);
actualMassBanCmd(pluginData, msg, args.userIds, msg.member);
},
});

View file

@ -1,7 +1,8 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../../utils";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
@ -37,7 +38,7 @@ export const MuteMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -47,22 +48,20 @@ export const MuteMsgCmd = modActionsMsgCmd({
const _isBanned = await isBanned(pluginData, user.id);
const prefix = pluginData.fullConfig.prefix;
if (_isBanned) {
sendErrorMessage(
pluginData,
msg.channel,
`User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`);
return;
} else {
// Ask the mod if we should upgrade to a forcemute as the user is not on the server
const reply = await waitForButtonConfirm(
msg.channel,
msg,
{ content: "User not found on the server, forcemute instead?" },
{ confirmText: "Yes", cancelText: "No", restrictToId: msg.member.id },
);
if (!reply) {
sendErrorMessage(pluginData, msg.channel, "User not on server, mute cancelled by moderator");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "User not on server, mute cancelled by moderator");
return;
}
}
@ -70,7 +69,7 @@ export const MuteMsgCmd = modActionsMsgCmd({
// Make sure we're allowed to mute this member
if (memberToMute && !canActOn(pluginData, msg.member, memberToMute)) {
sendErrorMessage(pluginData, msg.channel, "Cannot mute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot mute: insufficient permissions");
return;
}
@ -80,7 +79,7 @@ export const MuteMsgCmd = modActionsMsgCmd({
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -92,13 +91,13 @@ export const MuteMsgCmd = modActionsMsgCmd({
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
actualMuteCmd(
pluginData,
msg.channel,
msg,
user,
[...msg.attachments.values()],
mod,

View file

@ -1,9 +1,10 @@
import { ChannelType } from "discord.js";
import { slashOptions } from "knub";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualMuteCmd } from "../../functions/actualCommands/actualMuteCmd";
import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
@ -46,7 +47,9 @@ export const MuteSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -57,11 +60,9 @@ export const MuteSlashCmd = {
const _isBanned = await isBanned(pluginData, options.user.id);
const prefix = pluginData.fullConfig.prefix;
if (_isBanned) {
sendErrorMessage(
pluginData,
interaction,
`User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, `User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`);
return;
} else {
// Ask the mod if we should upgrade to a forcemute as the user is not on the server
@ -72,7 +73,9 @@ export const MuteSlashCmd = {
);
if (!reply) {
sendErrorMessage(pluginData, interaction, "User not on server, mute cancelled by moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "User not on server, mute cancelled by moderator");
return;
}
}
@ -80,7 +83,7 @@ export const MuteSlashCmd = {
// Make sure we're allowed to mute this member
if (memberToMute && !canActOn(pluginData, interaction.member, memberToMute)) {
sendErrorMessage(pluginData, interaction, "Cannot mute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot mute: insufficient permissions");
return;
}
@ -93,7 +96,9 @@ export const MuteSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -103,7 +108,7 @@ export const MuteSlashCmd = {
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}
@ -111,7 +116,7 @@ export const MuteSlashCmd = {
try {
contactMethods = readContactMethodsFromArgs(options) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, interaction, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, e.message);
return;
}

View file

@ -1,6 +1,6 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { sendErrorMessage } from "../../../../pluginUtils";
import { resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualNoteCmd } from "../../functions/actualCommands/actualNoteCmd";
import { modActionsMsgCmd } from "../../types";
@ -17,15 +17,15 @@ export const NoteMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
if (!args.note && msg.attachments.size === 0) {
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Text or attachment required");
return;
}
actualNoteCmd(pluginData, msg.channel, msg.author, [...msg.attachments.values()], user, args.note || "");
actualNoteCmd(pluginData, msg, msg.author, [...msg.attachments.values()], user, args.note || "");
},
});

View file

@ -1,6 +1,6 @@
import { slashOptions } from "knub";
import { sendErrorMessage } from "../../../../pluginUtils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualNoteCmd } from "../../functions/actualCommands/actualNoteCmd";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -24,7 +24,9 @@ export const NoteSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.note || options.note.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnbanCmd } from "../../functions/actualCommands/actualUnbanCmd";
import { modActionsMsgCmd } from "../../types";
@ -25,7 +26,7 @@ export const UnbanMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -33,13 +34,13 @@ export const UnbanMsgCmd = modActionsMsgCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
mod = args.mod;
}
actualUnbanCmd(pluginData, msg.channel, msg.author.id, user, args.reason, [...msg.attachments.values()], mod);
actualUnbanCmd(pluginData, msg, msg.author.id, user, args.reason, [...msg.attachments.values()], mod);
},
});

View file

@ -1,6 +1,7 @@
import { slashOptions } from "knub";
import { hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { hasPermission } from "../../../../pluginUtils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualUnbanCmd } from "../../functions/actualCommands/actualUnbanCmd";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants";
@ -25,7 +26,9 @@ export const UnbanSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -38,7 +41,9 @@ export const UnbanSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}

View file

@ -14,6 +14,6 @@ export const UnhideCaseMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
actualHideCaseCmd(pluginData, msg.channel, args.caseNum);
actualHideCaseCmd(pluginData, msg, args.caseNum);
},
});

View file

@ -1,7 +1,8 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { resolveMember, resolveUser } from "../../../../utils";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { isBanned } from "../../functions/isBanned";
@ -35,7 +36,7 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -49,7 +50,7 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
!hasMuteRole &&
!memberToUnmute?.isCommunicationDisabled()
) {
sendErrorMessage(pluginData, msg.channel, "Cannot unmute: member is not muted");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot unmute: member is not muted");
return;
}
@ -57,22 +58,20 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
const banned = await isBanned(pluginData, user.id);
const prefix = pluginData.fullConfig.prefix;
if (banned) {
sendErrorMessage(
pluginData,
msg.channel,
`User is banned. Use \`${prefix}forceunmute\` to unmute them anyway.`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, `User is banned. Use \`${prefix}forceunmute\` to unmute them anyway.`);
return;
} else {
// Ask the mod if we should upgrade to a forceunmute as the user is not on the server
const reply = await waitForButtonConfirm(
msg.channel,
msg,
{ content: "User not on server, forceunmute instead?" },
{ confirmText: "Yes", cancelText: "No", restrictToId: msg.member.id },
);
if (!reply) {
sendErrorMessage(pluginData, msg.channel, "User not on server, unmute cancelled by moderator");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "User not on server, unmute cancelled by moderator");
return;
}
}
@ -80,7 +79,7 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
// Make sure we're allowed to unmute this member
if (memberToUnmute && !canActOn(pluginData, msg.member, memberToUnmute)) {
sendErrorMessage(pluginData, msg.channel, "Cannot unmute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot unmute: insufficient permissions");
return;
}
@ -90,7 +89,7 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You don't have permission to use -mod");
return;
}
@ -100,7 +99,7 @@ export const UnmuteMsgCmd = modActionsMsgCmd({
actualUnmuteCmd(
pluginData,
msg.channel,
msg,
user,
[...msg.attachments.values()],
mod,

View file

@ -1,8 +1,9 @@
import { slashOptions } from "knub";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { convertDelayStringToMS, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { actualUnmuteCmd } from "../../functions/actualCommands/actualUnmuteCmd";
import { isBanned } from "../../functions/isBanned";
@ -30,7 +31,9 @@ export const UnmuteSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -45,7 +48,7 @@ export const UnmuteSlashCmd = {
!hasMuteRole &&
!memberToUnmute?.isCommunicationDisabled()
) {
sendErrorMessage(pluginData, interaction, "Cannot unmute: member is not muted");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot unmute: member is not muted");
return;
}
@ -53,11 +56,9 @@ export const UnmuteSlashCmd = {
const banned = await isBanned(pluginData, options.user.id);
const prefix = pluginData.fullConfig.prefix;
if (banned) {
sendErrorMessage(
pluginData,
interaction,
`User is banned. Use \`${prefix}forceunmute\` to unmute them anyway.`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, `User is banned. Use \`${prefix}forceunmute\` to unmute them anyway.`);
return;
} else {
// Ask the mod if we should upgrade to a forceunmute as the user is not on the server
@ -68,7 +69,9 @@ export const UnmuteSlashCmd = {
);
if (!reply) {
sendErrorMessage(pluginData, interaction, "User not on server, unmute cancelled by moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "User not on server, unmute cancelled by moderator");
return;
}
}
@ -76,7 +79,7 @@ export const UnmuteSlashCmd = {
// Make sure we're allowed to unmute this member
if (memberToUnmute && !canActOn(pluginData, interaction.member, memberToUnmute)) {
sendErrorMessage(pluginData, interaction, "Cannot unmute: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot unmute: insufficient permissions");
return;
}
@ -89,7 +92,9 @@ export const UnmuteSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -99,7 +104,7 @@ export const UnmuteSlashCmd = {
const convertedTime = options.time ? convertDelayStringToMS(options.time) : null;
if (options.time && !convertedTime) {
sendErrorMessage(pluginData, interaction, `Could not convert ${options.time} to a delay`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `Could not convert ${options.time} to a delay`);
return;
}

View file

@ -19,6 +19,6 @@ export const UpdateMsgCmd = modActionsMsgCmd({
],
async run({ pluginData, message: msg, args }) {
await updateCase(pluginData, msg.channel, msg.author, args.caseNumber, args.note, [...msg.attachments.values()]);
await updateCase(pluginData, msg, msg.author, args.caseNumber, args.note, [...msg.attachments.values()]);
},
});

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../../commandTypes";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { errorMessage, resolveMember, resolveUser } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualWarnCmd } from "../../functions/actualCommands/actualWarnCmd";
import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
@ -23,7 +24,7 @@ export const WarnMsgCmd = modActionsMsgCmd({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user.id) {
sendErrorMessage(pluginData, msg.channel, `User not found`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found`);
return;
}
@ -32,9 +33,9 @@ export const WarnMsgCmd = modActionsMsgCmd({
if (!memberToWarn) {
const _isBanned = await isBanned(pluginData, user.id);
if (_isBanned) {
sendErrorMessage(pluginData, msg.channel, `User is banned`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User is banned`);
} else {
sendErrorMessage(pluginData, msg.channel, `User not found on the server`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `User not found on the server`);
}
return;
@ -42,7 +43,7 @@ export const WarnMsgCmd = modActionsMsgCmd({
// Make sure we're allowed to warn this member
if (!canActOn(pluginData, msg.member, memberToWarn)) {
sendErrorMessage(pluginData, msg.channel, "Cannot warn: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Cannot warn: insufficient permissions");
return;
}
@ -61,13 +62,13 @@ export const WarnMsgCmd = modActionsMsgCmd({
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, e.message);
return;
}
actualWarnCmd(
pluginData,
msg.channel,
msg,
msg.author.id,
mod,
memberToWarn,

View file

@ -1,8 +1,9 @@
import { ChannelType } from "discord.js";
import { slashOptions } from "knub";
import { canActOn, hasPermission, sendErrorMessage } from "../../../../pluginUtils";
import { canActOn, hasPermission } from "../../../../pluginUtils";
import { UserNotificationMethod, resolveMember } from "../../../../utils";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { actualWarnCmd } from "../../functions/actualCommands/actualWarnCmd";
import { isBanned } from "../../functions/isBanned";
import { readContactMethodsFromArgs } from "../../functions/readContactMethodsFromArgs";
@ -44,7 +45,9 @@ export const WarnSlashCmd = {
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
if ((!options.reason || options.reason.trim() === "") && attachments.length < 1) {
sendErrorMessage(pluginData, interaction, "Text or attachment required", undefined, undefined, true);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "Text or attachment required", undefined, undefined, true);
return;
}
@ -54,9 +57,9 @@ export const WarnSlashCmd = {
if (!memberToWarn) {
const _isBanned = await isBanned(pluginData, options.user.id);
if (_isBanned) {
sendErrorMessage(pluginData, interaction, `User is banned`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `User is banned`);
} else {
sendErrorMessage(pluginData, interaction, `User not found on the server`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, `User not found on the server`);
}
return;
@ -64,7 +67,7 @@ export const WarnSlashCmd = {
// Make sure we're allowed to warn this member
if (!canActOn(pluginData, interaction.member, memberToWarn)) {
sendErrorMessage(pluginData, interaction, "Cannot warn: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, "Cannot warn: insufficient permissions");
return;
}
@ -76,7 +79,9 @@ export const WarnSlashCmd = {
if (options.mod) {
if (!canActAsOther) {
sendErrorMessage(pluginData, interaction, "You don't have permission to act as another moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
@ -87,7 +92,7 @@ export const WarnSlashCmd = {
try {
contactMethods = readContactMethodsFromArgs(options) ?? undefined;
} catch (e) {
sendErrorMessage(pluginData, interaction, e.message);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(interaction, e.message);
return;
}

View file

@ -1,17 +1,19 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { Case } from "../../../../data/entities/Case";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { canActOn } from "../../../../pluginUtils";
import { UnknownUser, renderUserUsername, resolveMember } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
export async function actualAddCaseCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: GuildMember,
mod: GuildMember,
attachments: Array<Attachment>,
@ -19,14 +21,20 @@ export async function actualAddCaseCmd(
type: keyof CaseTypes,
reason: string,
) {
// If the user exists as a guild member, make sure we can act on them first
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (member && !canActOn(pluginData, author, member)) {
sendErrorMessage(pluginData, context, "Cannot add case on this user: insufficient permissions");
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const formattedReason = formatReasonWithAttachments(reason, attachments);
// If the user exists as a guild member, make sure we can act on them first
const member = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (member && !canActOn(pluginData, author, member)) {
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Cannot add case on this user: insufficient permissions");
return;
}
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
// Create the case
const casesPlugin = pluginData.getPlugin(CasesPlugin);
@ -39,9 +47,11 @@ export async function actualAddCaseCmd(
});
if (user) {
sendSuccessMessage(pluginData, context, `Case #${theCase.case_number} created for **${renderUserUsername(user)}**`);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `Case #${theCase.case_number} created for **${renderUserUsername(user)}**`);
} else {
sendSuccessMessage(pluginData, context, `Case #${theCase.case_number} created`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, `Case #${theCase.case_number} created`);
}
// Log the action

View file

@ -1,23 +1,25 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { getMemberLevel } from "knub/helpers";
import { CaseTypes } from "../../../../data/CaseTypes";
import { clearExpiringTempban, registerExpiringTempban } from "../../../../data/loops/expiringTempbansLoop";
import { canActOn, isContextInteraction, sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { canActOn, getContextChannel } from "../../../../pluginUtils";
import { UnknownUser, UserNotificationMethod, renderUserUsername, resolveMember } from "../../../../utils";
import { banLock } from "../../../../utils/lockNameHelpers";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { ModActionsPluginType } from "../../types";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { banUserId } from "../banUserId";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { isBanned } from "../isBanned";
export async function actualBanCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
user: User | UnknownUser,
time: number | null,
reason: string,
@ -27,8 +29,13 @@ export async function actualBanCmd(
contactMethods?: UserNotificationMethod[],
deleteDays?: number,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id);
const formattedReason = formatReasonWithAttachments(reason, attachments);
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const formattedReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
// acquire a lock because of the needed user-inputs below (if banned/not on server)
const lock = await pluginData.locks.acquire(banLock(user));
@ -47,7 +54,7 @@ export async function actualBanCmd(
);
if (!reply) {
sendErrorMessage(pluginData, context, "User not on server, ban cancelled by moderator");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "User not on server, ban cancelled by moderator");
lock.unlock();
return;
} else {
@ -57,7 +64,7 @@ export async function actualBanCmd(
// Abort if trying to ban user indefinitely if they are already banned indefinitely
if (!existingTempban && !time) {
sendErrorMessage(pluginData, context, `User is already banned indefinitely.`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User is already banned indefinitely.`);
return;
}
@ -69,7 +76,9 @@ export async function actualBanCmd(
);
if (!reply) {
sendErrorMessage(pluginData, context, "User already banned, update cancelled by moderator");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "User already banned, update cancelled by moderator");
lock.unlock();
return;
}
@ -114,11 +123,12 @@ export async function actualBanCmd(
});
}
sendSuccessMessage(
pluginData,
context,
`Ban updated to ${time ? "expire in " + humanizeDuration(time) + " from now" : "indefinite"}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Ban updated to ${time ? "expire in " + humanizeDuration(time) + " from now" : "indefinite"}`,
);
lock.unlock();
return;
}
@ -127,24 +137,26 @@ export async function actualBanCmd(
if (!forceban && !canActOn(pluginData, author, memberToBan!)) {
const ourLevel = getMemberLevel(pluginData, author);
const targetLevel = getMemberLevel(pluginData, memberToBan!);
sendErrorMessage(
pluginData,
context,
`Cannot ban: target permission level is equal or higher to yours, ${targetLevel} >= ${ourLevel}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
context,
`Cannot ban: target permission level is equal or higher to yours, ${targetLevel} >= ${ourLevel}`,
);
lock.unlock();
return;
}
const matchingConfig = await pluginData.config.getMatchingConfig({
member: author,
channel: isContextInteraction(context) ? context.channel : context,
channel: await getContextChannel(context),
});
const deleteMessageDays = deleteDays ?? matchingConfig.ban_delete_message_days;
const banResult = await banUserId(
pluginData,
user.id,
formattedReason,
formattedReasonWithAttachments,
{
contactMethods,
caseArgs: {
@ -158,7 +170,7 @@ export async function actualBanCmd(
);
if (banResult.status === "failed") {
sendErrorMessage(pluginData, context, `Failed to ban member: ${banResult.error}`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Failed to ban member: ${banResult.error}`);
lock.unlock();
return;
}
@ -178,5 +190,5 @@ export async function actualBanCmd(
}
lock.unlock();
sendSuccessMessage(pluginData, context, response);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, response);
}

View file

@ -1,19 +1,20 @@
import { ChatInputCommandInteraction, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, Message } from "discord.js";
import { GuildPluginData } from "knub";
import { sendContextResponse, sendErrorMessage } from "../../../../pluginUtils";
import { sendContextResponse } from "../../../../pluginUtils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { ModActionsPluginType } from "../../types";
export async function actualCaseCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
authorId: string,
caseNumber: number,
) {
const theCase = await pluginData.state.cases.findByCaseNumber(caseNumber);
if (!theCase) {
sendErrorMessage(pluginData, context, "Case not found");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Case not found");
return;
}

View file

@ -1,10 +1,10 @@
import { APIEmbed, ChatInputCommandInteraction, TextBasedChannel, User } from "discord.js";
import { APIEmbed, ChatInputCommandInteraction, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { In } from "typeorm";
import { FindOptionsWhere } from "typeorm/find-options/FindOptionsWhere";
import { CaseTypes } from "../../../../data/CaseTypes";
import { Case } from "../../../../data/entities/Case";
import { sendContextResponse, sendErrorMessage } from "../../../../pluginUtils";
import { sendContextResponse } from "../../../../pluginUtils";
import {
UnknownUser,
chunkArray,
@ -18,6 +18,7 @@ import { createPaginatedMessage } from "../../../../utils/createPaginatedMessage
import { getChunkedEmbedFields } from "../../../../utils/getChunkedEmbedFields";
import { getGuildPrefix } from "../../../../utils/getGuildPrefix";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { ModActionsPluginType } from "../../types";
const casesPerPage = 5;
@ -25,7 +26,7 @@ const maxExpandedCases = 8;
async function sendExpandedCases(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
casesCount: number,
cases: Case[],
) {
@ -45,7 +46,7 @@ async function sendExpandedCases(
async function casesUserCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: User,
modId: string | null,
user: User | UnknownUser,
@ -137,7 +138,7 @@ async function casesUserCmd(
async function casesModCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: User,
modId: string | null,
mod: User | UnknownUser,
@ -152,7 +153,7 @@ async function casesModCmd(
const totalCases = await casesPlugin.getTotalCasesByMod(modId ?? author.id, caseFilters);
if (totalCases === 0) {
sendErrorMessage(pluginData, context, `No cases by **${modName}**`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `No cases by **${modName}**`);
return;
}
@ -211,7 +212,7 @@ async function casesModCmd(
export async function actualCasesCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
modId: string | null,
user: User | UnknownUser | null,
author: User,

View file

@ -1,21 +1,17 @@
import { ChatInputCommandInteraction, GuildMember, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, GuildMember, Message } from "discord.js";
import { GuildPluginData, helpers } from "knub";
import { Case } from "../../../../data/entities/Case";
import {
isContextInteraction,
sendContextResponse,
sendErrorMessage,
sendSuccessMessage,
} from "../../../../pluginUtils";
import { getContextChannel, sendContextResponse } from "../../../../pluginUtils";
import { SECONDS } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { TimeAndDatePlugin } from "../../../TimeAndDate/TimeAndDatePlugin";
import { ModActionsPluginType } from "../../types";
export async function actualDeleteCaseCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: GuildMember,
caseNumbers: number[],
force: boolean,
@ -35,7 +31,7 @@ export async function actualDeleteCaseCmd(
}
if (failed.length === caseNumbers.length) {
sendErrorMessage(pluginData, context, "None of the cases were found!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "None of the cases were found!");
return;
}
@ -50,7 +46,7 @@ export async function actualDeleteCaseCmd(
const reply = await helpers.waitForReply(
pluginData.client,
isContextInteraction(context) ? context.channel! : context,
await getContextChannel(context),
author.id,
15 * SECONDS,
);
@ -87,9 +83,13 @@ export async function actualDeleteCaseCmd(
: "";
const amt = validCases.length - cancelled;
if (amt === 0) {
sendErrorMessage(pluginData, context, "All deletions were cancelled, no cases were deleted.");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "All deletions were cancelled, no cases were deleted.");
return;
}
sendSuccessMessage(pluginData, context, `${amt} case${amt === 1 ? " was" : "s were"} deleted!${failedAddendum}`);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `${amt} case${amt === 1 ? " was" : "s were"} deleted!${failedAddendum}`);
}

View file

@ -1,25 +1,31 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Snowflake, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake, User } from "discord.js";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { LogType } from "../../../../data/LogType";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { DAYS, MINUTES, UnknownUser } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
export async function actualForceBanCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
authorId: string,
user: User | UnknownUser,
reason: string,
attachments: Array<Attachment>,
mod: GuildMember,
) {
const formattedReason = formatReasonWithAttachments(reason, attachments);
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const formattedReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
@ -28,10 +34,10 @@ export async function actualForceBanCmd(
// FIXME: Use banUserId()?
await pluginData.guild.bans.create(user.id as Snowflake, {
deleteMessageSeconds: (1 * DAYS) / MINUTES,
reason: formattedReason ?? undefined,
reason: formattedReasonWithAttachments ?? undefined,
});
} catch {
sendErrorMessage(pluginData, context, "Failed to forceban member");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Failed to forceban member");
return;
}
@ -46,7 +52,9 @@ export async function actualForceBanCmd(
});
// Confirm the action
sendSuccessMessage(pluginData, context, `Member forcebanned (Case #${createdCase.case_number})`);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `Member forcebanned (Case #${createdCase.case_number})`);
// Log the action
pluginData.getPlugin(LogsPlugin).logMemberForceban({

View file

@ -1,11 +1,11 @@
import { ChatInputCommandInteraction, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, Message } from "discord.js";
import { GuildPluginData } from "knub";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { ModActionsPluginType } from "../../types";
export async function actualHideCaseCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
caseNumbers: number[],
) {
const failed: number[] = [];
@ -21,7 +21,7 @@ export async function actualHideCaseCmd(
}
if (failed.length === caseNumbers.length) {
sendErrorMessage(pluginData, context, "None of the cases were found!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "None of the cases were found!");
return;
}
const failedAddendum =
@ -30,9 +30,10 @@ export async function actualHideCaseCmd(
: "";
const amt = caseNumbers.length - failed.length;
sendSuccessMessage(
pluginData,
context,
`${amt} case${amt === 1 ? " is" : "s are"} now hidden! Use \`unhidecase\` to unhide them.${failedAddendum}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`${amt} case${amt === 1 ? " is" : "s are"} now hidden! Use \`unhidecase\` to unhide them.${failedAddendum}`,
);
}

View file

@ -1,7 +1,7 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { canActOn } from "../../../../pluginUtils";
import {
DAYS,
SECONDS,
@ -10,15 +10,17 @@ import {
renderUserUsername,
resolveMember,
} from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
import { isBanned } from "../isBanned";
import { kickMember } from "../kickMember";
export async function actualKickCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: GuildMember,
user: User | UnknownUser,
reason: string,
@ -27,14 +29,18 @@ export async function actualKickCmd(
contactMethods?: UserNotificationMethod[],
clean?: boolean,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const memberToKick = await resolveMember(pluginData.client, pluginData.guild, user.id);
if (!memberToKick) {
const banned = await isBanned(pluginData, user.id);
if (banned) {
sendErrorMessage(pluginData, context, `User is banned`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User is banned`);
} else {
sendErrorMessage(pluginData, context, `User not found on the server`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User not found on the server`);
}
return;
@ -42,13 +48,14 @@ export async function actualKickCmd(
// Make sure we're allowed to kick this member
if (!canActOn(pluginData, author, memberToKick)) {
sendErrorMessage(pluginData, context, "Cannot kick: insufficient permissions");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cannot kick: insufficient permissions");
return;
}
const formattedReason = formatReasonWithAttachments(reason, attachments);
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const formattedReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
const kickResult = await kickMember(pluginData, memberToKick, formattedReason, {
const kickResult = await kickMember(pluginData, memberToKick, formattedReason, formattedReasonWithAttachments, {
contactMethods,
caseArgs: {
modId: mod.id,
@ -63,7 +70,7 @@ export async function actualKickCmd(
try {
await memberToKick.ban({ deleteMessageSeconds: (1 * DAYS) / SECONDS, reason: "kick -clean" });
} catch {
sendErrorMessage(pluginData, context, "Failed to ban the user to clean messages (-clean)");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Failed to ban the user to clean messages (-clean)");
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, memberToKick.id);
@ -72,12 +79,14 @@ export async function actualKickCmd(
try {
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
} catch {
sendErrorMessage(pluginData, context, "Failed to unban the user after banning them (-clean)");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Failed to unban the user after banning them (-clean)");
}
}
if (kickResult.status === "failed") {
sendErrorMessage(pluginData, context, `Failed to kick user`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Failed to kick user`);
return;
}
@ -85,5 +94,5 @@ export async function actualKickCmd(
let response = `Kicked **${renderUserUsername(memberToKick.user)}** (Case #${kickResult.case.case_number})`;
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
sendSuccessMessage(pluginData, context, response);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, response);
}

View file

@ -1,55 +1,58 @@
import { ChatInputCommandInteraction, GuildMember, Snowflake, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { waitForReply } from "knub/helpers";
import { CaseTypes } from "../../../../data/CaseTypes";
import { LogType } from "../../../../data/LogType";
import { humanizeDurationShort } from "../../../../humanizeDurationShort";
import {
canActOn,
isContextInteraction,
sendContextResponse,
sendErrorMessage,
sendSuccessMessage,
} from "../../../../pluginUtils";
import { canActOn, getContextChannel, isContextInteraction, sendContextResponse } from "../../../../pluginUtils";
import { DAYS, MINUTES, SECONDS, noop } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
export async function actualMassBanCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
userIds: string[],
author: GuildMember,
) {
// Limit to 100 users at once (arbitrary?)
if (userIds.length > 100) {
sendErrorMessage(pluginData, context, `Can only massban max 100 users at once`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Can only massban max 100 users at once`);
return;
}
// Ask for ban reason (cleaner this way instead of trying to cram it into the args)
sendContextResponse(context, "Ban reason? `cancel` to cancel");
const banReasonReply = await waitForReply(
pluginData.client,
isContextInteraction(context) ? context.channel! : context,
author.id,
);
const banReasonReply = await waitForReply(pluginData.client, await getContextChannel(context), author.id);
if (!banReasonReply || !banReasonReply.content || banReasonReply.content.toLowerCase().trim() === "cancel") {
sendErrorMessage(pluginData, context, "Cancelled");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled");
return;
}
const banReason = formatReasonWithAttachments(banReasonReply.content, [...banReasonReply.attachments.values()]);
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, banReasonReply.content)) {
return;
}
const banReason = await formatReasonWithMessageLinkForAttachments(pluginData, banReasonReply.content, context, [
...banReasonReply.attachments.values(),
]);
const banReasonWithAttachments = formatReasonWithAttachments(banReasonReply.content, [
...banReasonReply.attachments.values(),
]);
// Verify we can act on each of the users specified
for (const userId of userIds) {
const member = pluginData.guild.members.cache.get(userId as Snowflake); // TODO: Get members on demand?
if (member && !canActOn(pluginData, author, member)) {
sendErrorMessage(pluginData, context, "Cannot massban one or more users: insufficient permissions");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Cannot massban one or more users: insufficient permissions");
return;
}
}
@ -87,7 +90,7 @@ export async function actualMassBanCmd(
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const messageConfig = isContextInteraction(context)
? await pluginData.config.getForInteraction(context)
: await pluginData.config.getForChannel(context);
: await pluginData.config.getForChannel(await getContextChannel(context));
const deleteDays = messageConfig.ban_delete_message_days;
for (const [i, userId] of userIds.entries()) {
@ -103,7 +106,7 @@ export async function actualMassBanCmd(
await pluginData.guild.bans.create(userId as Snowflake, {
deleteMessageSeconds: (deleteDays * DAYS) / SECONDS,
reason: banReason,
reason: banReasonWithAttachments,
});
await casesPlugin.createCase({
@ -134,7 +137,7 @@ export async function actualMassBanCmd(
const successfulBanCount = userIds.length - failedBans.length;
if (successfulBanCount === 0) {
// All bans failed - don't create a log entry and notify the user
sendErrorMessage(pluginData, context, "All bans failed. Make sure the IDs are valid.");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "All bans failed. Make sure the IDs are valid.");
} else {
// Some or all bans were successful. Create a log entry for the mass ban and notify the user.
pluginData.getPlugin(LogsPlugin).logMassBan({
@ -144,19 +147,18 @@ export async function actualMassBanCmd(
});
if (failedBans.length) {
sendSuccessMessage(
pluginData,
context,
`Banned ${successfulBanCount} users in ${formattedTimeTaken}, ${failedBans.length} failed: ${failedBans.join(
" ",
)}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Banned ${successfulBanCount} users in ${formattedTimeTaken}, ${
failedBans.length
} failed: ${failedBans.join(" ")}`,
);
} else {
sendSuccessMessage(
pluginData,
context,
`Banned ${successfulBanCount} users successfully in ${formattedTimeTaken}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `Banned ${successfulBanCount} users successfully in ${formattedTimeTaken}`);
}
}
});

View file

@ -1,49 +1,48 @@
import { ChatInputCommandInteraction, GuildMember, Snowflake, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { waitForReply } from "knub/helpers";
import { LogType } from "../../../../data/LogType";
import { logger } from "../../../../logger";
import {
canActOn,
isContextInteraction,
sendContextResponse,
sendErrorMessage,
sendSuccessMessage,
} from "../../../../pluginUtils";
import { canActOn, getContextChannel, sendContextResponse } from "../../../../pluginUtils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
export async function actualMassMuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
userIds: string[],
author: GuildMember,
) {
// Limit to 100 users at once (arbitrary?)
if (userIds.length > 100) {
sendErrorMessage(pluginData, context, `Can only massmute max 100 users at once`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Can only massmute max 100 users at once`);
return;
}
// Ask for mute reason
sendContextResponse(context, "Mute reason? `cancel` to cancel");
const muteReasonReceived = await waitForReply(
pluginData.client,
isContextInteraction(context) ? context.channel! : context,
author.id,
);
const muteReasonReceived = await waitForReply(pluginData.client, await getContextChannel(context), author.id);
if (
!muteReasonReceived ||
!muteReasonReceived.content ||
muteReasonReceived.content.toLowerCase().trim() === "cancel"
) {
sendErrorMessage(pluginData, context, "Cancelled");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled");
return;
}
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, [
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, muteReasonReceived.content)) {
return;
}
const muteReason = await formatReasonWithMessageLinkForAttachments(pluginData, muteReasonReceived.content, context, [
...muteReasonReceived.attachments.values(),
]);
const muteReasonWithAttachments = formatReasonWithAttachments(muteReasonReceived.content, [
...muteReasonReceived.attachments.values(),
]);
@ -51,7 +50,9 @@ export async function actualMassMuteCmd(
for (const userId of userIds) {
const member = pluginData.guild.members.cache.get(userId as Snowflake);
if (member && !canActOn(pluginData, author, member)) {
sendErrorMessage(pluginData, context, "Cannot massmute one or more users: insufficient permissions");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Cannot massmute one or more users: insufficient permissions");
return;
}
}
@ -72,7 +73,7 @@ export async function actualMassMuteCmd(
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
for (const userId of userIds) {
try {
await mutesPlugin.muteUser(userId, 0, `Mass mute: ${muteReason}`, {
await mutesPlugin.muteUser(userId, 0, `Mass mute: ${muteReason}`, `Mass mute: ${muteReasonWithAttachments}`, {
caseArgs: {
modId,
},
@ -89,7 +90,7 @@ export async function actualMassMuteCmd(
const successfulMuteCount = userIds.length - failedMutes.length;
if (successfulMuteCount === 0) {
// All mutes failed
sendErrorMessage(pluginData, context, "All mutes failed. Make sure the IDs are valid.");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "All mutes failed. Make sure the IDs are valid.");
} else {
// Success on all or some mutes
pluginData.getPlugin(LogsPlugin).logMassMute({
@ -98,13 +99,14 @@ export async function actualMassMuteCmd(
});
if (failedMutes.length) {
sendSuccessMessage(
pluginData,
context,
`Muted ${successfulMuteCount} users, ${failedMutes.length} failed: ${failedMutes.join(" ")}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Muted ${successfulMuteCount} users, ${failedMutes.length} failed: ${failedMutes.join(" ")}`,
);
} else {
sendSuccessMessage(pluginData, context, `Muted ${successfulMuteCount} users successfully`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, `Muted ${successfulMuteCount} users successfully`);
}
}
}

View file

@ -1,46 +1,45 @@
import { ChatInputCommandInteraction, GuildMember, Snowflake, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, GuildMember, Message, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { waitForReply } from "knub/helpers";
import { CaseTypes } from "../../../../data/CaseTypes";
import { LogType } from "../../../../data/LogType";
import {
isContextInteraction,
sendContextResponse,
sendErrorMessage,
sendSuccessMessage,
} from "../../../../pluginUtils";
import { getContextChannel, sendContextResponse } from "../../../../pluginUtils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
import { isBanned } from "../isBanned";
export async function actualMassUnbanCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
userIds: string[],
author: GuildMember,
) {
// Limit to 100 users at once (arbitrary?)
if (userIds.length > 100) {
sendErrorMessage(pluginData, context, `Can only mass-unban max 100 users at once`);
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `Can only mass-unban max 100 users at once`);
return;
}
// Ask for unban reason (cleaner this way instead of trying to cram it into the args)
sendContextResponse(context, "Unban reason? `cancel` to cancel");
const unbanReasonReply = await waitForReply(
pluginData.client,
isContextInteraction(context) ? context.channel! : context,
author.id,
);
const unbanReasonReply = await waitForReply(pluginData.client, await getContextChannel(context), author.id);
if (!unbanReasonReply || !unbanReasonReply.content || unbanReasonReply.content.toLowerCase().trim() === "cancel") {
sendErrorMessage(pluginData, context, "Cancelled");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Cancelled");
return;
}
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, [...unbanReasonReply.attachments.values()]);
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, unbanReasonReply.content)) {
return;
}
const unbanReason = await formatReasonWithMessageLinkForAttachments(pluginData, unbanReasonReply.content, context, [
...unbanReasonReply.attachments.values(),
]);
// Ignore automatic unban cases and logs for these users
// We'll create our own cases below and post a single "mass unbanned" log instead
@ -83,7 +82,9 @@ export async function actualMassUnbanCmd(
const successfulUnbanCount = userIds.length - failedUnbans.length;
if (successfulUnbanCount === 0) {
// All unbans failed - don't create a log entry and notify the user
sendErrorMessage(pluginData, context, "All unbans failed. Make sure the IDs are valid and banned.");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "All unbans failed. Make sure the IDs are valid and banned.");
} else {
// Some or all unbans were successful. Create a log entry for the mass unban and notify the user.
pluginData.getPlugin(LogsPlugin).logMassUnban({
@ -110,13 +111,16 @@ export async function actualMassUnbanCmd(
});
}
sendSuccessMessage(
pluginData,
context,
`Unbanned ${successfulUnbanCount} users, ${failedUnbans.length} failed:\n${failedMsg}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Unbanned ${successfulUnbanCount} users, ${failedUnbans.length} failed:\n${failedMsg}`,
);
} else {
sendSuccessMessage(pluginData, context, `Unbanned ${successfulUnbanCount} users successfully`);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `Unbanned ${successfulUnbanCount} users successfully`);
}
}
}

View file

@ -1,9 +1,8 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { ERRORS, RecoverablePluginError } from "../../../../RecoverablePluginError";
import { logger } from "../../../../logger";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import {
UnknownUser,
UserNotificationMethod,
@ -11,10 +10,12 @@ import {
isDiscordAPIError,
renderUserUsername,
} from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { MuteResult } from "../../../Mutes/types";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
/**
* The actual function run by both !mute and !forcemute.
@ -22,23 +23,32 @@ import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
*/
export async function actualMuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
user: User | UnknownUser,
attachments: Array<Attachment>,
attachments: Attachment[],
mod: GuildMember,
ppId?: string,
time?: number,
reason?: string,
contactMethods?: UserNotificationMethod[],
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const timeUntilUnmute = time && humanizeDuration(time);
const formattedReason = reason ? formatReasonWithAttachments(reason, attachments) : undefined;
const formattedReason =
reason || attachments.length > 0
? await formatReasonWithMessageLinkForAttachments(pluginData, reason ?? "", context, attachments)
: undefined;
const formattedReasonWithAttachments =
reason || attachments.length > 0 ? formatReasonWithAttachments(reason ?? "", attachments) : undefined;
let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
try {
muteResult = await mutesPlugin.muteUser(user.id, time, formattedReason, {
muteResult = await mutesPlugin.muteUser(user.id, time, formattedReason, formattedReasonWithAttachments, {
contactMethods,
caseArgs: {
modId: mod.id,
@ -47,9 +57,11 @@ export async function actualMuteCmd(
});
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
sendErrorMessage(pluginData, context, "Could not mute the user: no mute role set in config");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Could not mute the user: no mute role set in config");
} else if (isDiscordAPIError(e) && e.code === 10007) {
sendErrorMessage(pluginData, context, "Could not mute the user: unknown member");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Could not mute the user: unknown member");
} else {
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);
if (user.id == null) {
@ -57,7 +69,7 @@ export async function actualMuteCmd(
// tslint:disable-next-line:no-console
console.trace("[DEBUG] Null user.id for mute");
}
sendErrorMessage(pluginData, context, "Could not mute the user");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Could not mute the user");
}
return;
@ -92,5 +104,5 @@ export async function actualMuteCmd(
}
if (muteResult.notifyResult.text) response += ` (${muteResult.notifyResult.text})`;
sendSuccessMessage(pluginData, context, response);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, response);
}

View file

@ -1,23 +1,28 @@
import { Attachment, ChatInputCommandInteraction, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, Message, User } from "discord.js";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { sendSuccessMessage } from "../../../../pluginUtils";
import { UnknownUser, renderUserUsername } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
export async function actualNoteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
author: User,
attachments: Array<Attachment>,
user: User | UnknownUser,
note: string,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, note)) {
return;
}
const userName = renderUserUsername(user);
const reason = formatReasonWithAttachments(note, attachments);
const reason = await formatReasonWithMessageLinkForAttachments(pluginData, note, context, attachments);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({
@ -34,14 +39,15 @@ export async function actualNoteCmd(
reason,
});
sendSuccessMessage(
pluginData,
context,
`Note added on **${userName}** (Case #${createdCase.case_number})`,
undefined,
undefined,
true,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Note added on **${userName}** (Case #${createdCase.case_number})`,
undefined,
undefined,
true,
);
pluginData.state.events.emit("note", user.id, reason);
}

View file

@ -1,33 +1,40 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, Snowflake, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, Snowflake, User } from "discord.js";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { LogType } from "../../../../data/LogType";
import { clearExpiringTempban } from "../../../../data/loops/expiringTempbansLoop";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { UnknownUser } from "../../../../utils";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { LogsPlugin } from "../../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { ignoreEvent } from "../ignoreEvent";
export async function actualUnbanCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
authorId: string,
user: User | UnknownUser,
reason: string,
attachments: Array<Attachment>,
mod: GuildMember,
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
const formattedReason = formatReasonWithAttachments(reason, attachments);
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
try {
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
await pluginData.guild.bans.remove(user.id as Snowflake, formattedReason ?? undefined);
} catch {
sendErrorMessage(pluginData, context, "Failed to unban member; are you sure they're banned?");
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(context, "Failed to unban member; are you sure they're banned?");
return;
}
@ -49,7 +56,7 @@ export async function actualUnbanCmd(
}
// Confirm the action
sendSuccessMessage(pluginData, context, `Member unbanned (Case #${createdCase.case_number})`);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(context, `Member unbanned (Case #${createdCase.case_number})`);
// Log the action
pluginData.getPlugin(LogsPlugin).logMemberUnban({

View file

@ -1,11 +1,11 @@
import { ChatInputCommandInteraction, TextBasedChannel } from "discord.js";
import { ChatInputCommandInteraction, Message } from "discord.js";
import { GuildPluginData } from "knub";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { ModActionsPluginType } from "../../types";
export async function actualUnhideCaseCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
caseNumbers: number[],
) {
const failed: number[] = [];
@ -21,7 +21,7 @@ export async function actualUnhideCaseCmd(
}
if (failed.length === caseNumbers.length) {
sendErrorMessage(pluginData, context, "None of the cases were found!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "None of the cases were found!");
return;
}
@ -31,9 +31,7 @@ export async function actualUnhideCaseCmd(
: "";
const amt = caseNumbers.length - failed.length;
sendSuccessMessage(
pluginData,
context,
`${amt} case${amt === 1 ? " is" : "s are"} no longer hidden!${failedAddendum}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(context, `${amt} case${amt === 1 ? " is" : "s are"} no longer hidden!${failedAddendum}`);
}

View file

@ -1,15 +1,16 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel, User } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { UnknownUser, asSingleLine, renderUserUsername } from "../../../../utils";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { MutesPlugin } from "../../../Mutes/MutesPlugin";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
export async function actualUnmuteCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
user: User | UnknownUser,
attachments: Array<Attachment>,
mod: GuildMember,
@ -17,25 +18,31 @@ export async function actualUnmuteCmd(
time?: number,
reason?: string,
) {
const parsedReason = reason ? formatReasonWithAttachments(reason, attachments) : undefined;
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const formattedReason =
reason || attachments.length > 0
? await formatReasonWithMessageLinkForAttachments(pluginData, reason ?? "", context, attachments)
: undefined;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const result = await mutesPlugin.unmuteUser(user.id, time, {
modId: mod.id,
ppId: ppId ?? undefined,
reason: parsedReason,
reason: formattedReason,
});
if (!result) {
sendErrorMessage(pluginData, context, "User is not muted!");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "User is not muted!");
return;
}
// Confirm the action to the moderator
if (time) {
const timeUntilUnmute = time && humanizeDuration(time);
sendSuccessMessage(
pluginData,
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(
context,
asSingleLine(`
Unmuting **${renderUserUsername(user)}**
@ -43,8 +50,7 @@ export async function actualUnmuteCmd(
`),
);
} else {
sendSuccessMessage(
pluginData,
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(
context,
asSingleLine(`
Unmuted **${renderUserUsername(user)}**

View file

@ -1,17 +1,18 @@
import { Attachment, ChatInputCommandInteraction, GuildMember, TextBasedChannel } from "discord.js";
import { Attachment, ChatInputCommandInteraction, GuildMember, Message } from "discord.js";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../../pluginUtils";
import { UserNotificationMethod, renderUserUsername } from "../../../../utils";
import { waitForButtonConfirm } from "../../../../utils/waitForInteraction";
import { CasesPlugin } from "../../../Cases/CasesPlugin";
import { CommonPlugin } from "../../../Common/CommonPlugin";
import { ModActionsPluginType } from "../../types";
import { formatReasonWithAttachments } from "../formatReasonWithAttachments";
import { handleAttachmentLinkDetectionAndGetRestriction } from "../attachmentLinkReaction";
import { formatReasonWithAttachments, formatReasonWithMessageLinkForAttachments } from "../formatReasonForAttachments";
import { warnMember } from "../warnMember";
export async function actualWarnCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | ChatInputCommandInteraction,
context: Message | ChatInputCommandInteraction,
authorId: string,
mod: GuildMember,
memberToWarn: GuildMember,
@ -19,8 +20,13 @@ export async function actualWarnCmd(
attachments: Attachment[],
contactMethods?: UserNotificationMethod[],
) {
if (await handleAttachmentLinkDetectionAndGetRestriction(pluginData, context, reason)) {
return;
}
const config = pluginData.config.get();
const formattedReason = formatReasonWithAttachments(reason, attachments);
const formattedReason = await formatReasonWithMessageLinkForAttachments(pluginData, reason, context, attachments);
const formattedReasonWithAttachments = formatReasonWithAttachments(reason, attachments);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);
@ -31,12 +37,12 @@ export async function actualWarnCmd(
{ confirmText: "Yes", cancelText: "No", restrictToId: authorId },
);
if (!reply) {
sendErrorMessage(pluginData, context, "Warn cancelled by moderator");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Warn cancelled by moderator");
return;
}
}
const warnResult = await warnMember(pluginData, memberToWarn, formattedReason, {
const warnResult = await warnMember(pluginData, memberToWarn, formattedReason, formattedReasonWithAttachments, {
contactMethods,
caseArgs: {
modId: mod.id,
@ -47,15 +53,16 @@ export async function actualWarnCmd(
});
if (warnResult.status === "failed") {
sendErrorMessage(pluginData, context, "Failed to warn user");
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, "Failed to warn user");
return;
}
const messageResultText = warnResult.notifyResult.text ? ` (${warnResult.notifyResult.text})` : "";
sendSuccessMessage(
pluginData,
context,
`Warned **${renderUserUsername(memberToWarn.user)}** (Case #${warnResult.case.case_number})${messageResultText}`,
);
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
context,
`Warned **${renderUserUsername(memberToWarn.user)}** (Case #${warnResult.case.case_number})${messageResultText}`,
);
}

View file

@ -0,0 +1,51 @@
import { ChatInputCommandInteraction, Message, TextBasedChannel } from "discord.js";
import { AnyPluginData, GuildPluginData } from "knub";
import { CommonPlugin } from "../../Common/CommonPlugin";
import { ModActionsPluginType } from "../types";
export function shouldReactToAttachmentLink(pluginData: GuildPluginData<ModActionsPluginType>) {
const config = pluginData.config.get();
return !config.attachment_link_reaction || config.attachment_link_reaction !== "none";
}
export function attachmentLinkShouldRestrict(pluginData: GuildPluginData<ModActionsPluginType>) {
return pluginData.config.get().attachment_link_reaction === "restrict";
}
export function detectAttachmentLink(reason: string | null | undefined) {
return reason && /https:\/\/(cdn|media)\.discordapp\.(com|net)\/(ephemeral-)?attachments/gu.test(reason);
}
export function sendAttachmentLinkDetectionErrorMessage(
pluginData: AnyPluginData<any>,
context: TextBasedChannel | Message | ChatInputCommandInteraction,
restricted = false,
) {
const emoji = pluginData.getPlugin(CommonPlugin).getErrorEmoji();
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(
context,
"You manually added a Discord attachment link to the reason. This link will only work for a limited time.\n" +
"You should instead **re-upload** the attachment with the command, in the same message.\n\n" +
(restricted ? `${emoji} **Command canceled.** ${emoji}` : "").trim(),
);
}
export async function handleAttachmentLinkDetectionAndGetRestriction(
pluginData: GuildPluginData<ModActionsPluginType>,
context: TextBasedChannel | Message | ChatInputCommandInteraction,
reason: string | null | undefined,
) {
if (!shouldReactToAttachmentLink(pluginData) || !detectAttachmentLink(reason)) {
return false;
}
const restricted = attachmentLinkShouldRestrict(pluginData);
sendAttachmentLinkDetectionErrorMessage(pluginData, context, restricted);
return restricted;
}

View file

@ -30,6 +30,7 @@ export async function banUserId(
pluginData: GuildPluginData<ModActionsPluginType>,
userId: string,
reason?: string,
reasonWithAttachments?: string,
banOptions: BanOptions = {},
banTime?: number,
): Promise<BanResult> {
@ -45,7 +46,7 @@ export async function banUserId(
// Attempt to message the user *before* banning them, as doing it after may not be possible
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason && member) {
if (reasonWithAttachments && member) {
const contactMethods = banOptions?.contactMethods
? banOptions.contactMethods
: getDefaultContactMethods(pluginData, "ban");
@ -56,7 +57,7 @@ export async function banUserId(
config.ban_message,
new TemplateSafeValueContainer({
guildName: pluginData.guild.name,
reason,
reason: reasonWithAttachments,
moderator: banOptions.caseArgs?.modId
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
: null,
@ -69,7 +70,7 @@ export async function banUserId(
config.tempban_message,
new TemplateSafeValueContainer({
guildName: pluginData.guild.name,
reason,
reason: reasonWithAttachments,
moderator: banOptions.caseArgs?.modId
? userToTemplateSafeUser(await resolveUser(pluginData.client, banOptions.caseArgs.modId))
: null,

View file

@ -10,7 +10,6 @@ import { resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../types";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { ignoreEvent } from "./ignoreEvent";
import { isBanned } from "./isBanned";
@ -21,11 +20,9 @@ export async function clearTempban(pluginData: GuildPluginData<ModActionsPluginT
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, tempban.user_id);
const reason = formatReasonWithAttachments(
`Tempban timed out.
Tempbanned at: \`${tempban.created_at} UTC\``,
[],
);
const reason = `Tempban timed out.
Tempbanned at: \`${tempban.created_at} UTC\``;
try {
ignoreEvent(pluginData, IgnoredEventType.Unban, tempban.user_id);
await pluginData.guild.bans.remove(tempban.user_id as Snowflake, reason ?? undefined);

View file

@ -0,0 +1,36 @@
import { Attachment, ChatInputCommandInteraction, Message, TextBasedChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { isContextMessage } from "../../../pluginUtils";
import { ModActionsPluginType } from "../types";
export async function formatReasonWithMessageLinkForAttachments(
pluginData: GuildPluginData<ModActionsPluginType>,
reason: string,
context: Message | ChatInputCommandInteraction,
attachments: Attachment[],
) {
if (isContextMessage(context)) {
return context.attachments.size > 0 ? ((reason || "") + " " + context.url).trim() : reason;
}
if (attachments.length < 1) {
return reason;
}
const attachmentChannelId = pluginData.config.get().attachment_storing_channel;
const channel = attachmentChannelId
? (pluginData.guild.channels.cache.get(attachmentChannelId) as TextBasedChannel) ?? context.channel
: context.channel;
const message = await channel!.send({
content: `Storing ${attachments.length} attachment${attachments.length === 1 ? "" : "s"}`,
files: attachments.map((a) => a.url),
});
return ((reason || "") + " " + message.url).trim();
}
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
const attachmentUrls = attachments.map((a) => a.url);
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
}

View file

@ -1,6 +0,0 @@
import { Attachment } from "discord.js";
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
const attachmentUrls = attachments.map((a) => a.url);
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
}

View file

@ -18,13 +18,14 @@ export async function kickMember(
pluginData: GuildPluginData<ModActionsPluginType>,
member: GuildMember,
reason?: string,
reasonWithAttachments?: string,
kickOptions: KickOptions = {},
): Promise<KickResult> {
const config = pluginData.config.get();
// Attempt to message the user *before* kicking them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason && member) {
if (reasonWithAttachments && member) {
const contactMethods = kickOptions?.contactMethods
? kickOptions.contactMethods
: getDefaultContactMethods(pluginData, "kick");
@ -35,7 +36,7 @@ export async function kickMember(
config.kick_message,
new TemplateSafeValueContainer({
guildName: pluginData.guild.name,
reason,
reason: reasonWithAttachments,
moderator: kickOptions.caseArgs?.modId
? userToTemplateSafeUser(await resolveUser(pluginData.client, kickOptions.caseArgs.modId))
: null,

Some files were not shown because too many files have changed in this diff Show more