mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 10:25:01 +00:00
initial
This commit is contained in:
parent
3b98c3bdc1
commit
57b9540edf
15 changed files with 57 additions and 20 deletions
|
@ -84,6 +84,7 @@ const defaultOptions = {
|
|||
can_deletecase: false,
|
||||
can_act_as_other: false,
|
||||
create_cases_for_manual_actions: true,
|
||||
reason_aliases: {},
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveMember, resolveUser } from "../../../utils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { modActionsCmd } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
|
||||
const opts = {
|
||||
mod: ct.member({ option: true }),
|
||||
|
@ -60,8 +59,8 @@ export const AddCaseCmd = modActionsCmd({
|
|||
sendErrorMessage(pluginData, msg.channel, "Cannot add case: invalid case type");
|
||||
return;
|
||||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||
const config = pluginData.config.get();
|
||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]))!;
|
||||
|
||||
// Create the case
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
|
|
|
@ -11,6 +11,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
|
|||
import { isBanned } from "../functions/isBanned";
|
||||
import { IgnoredEventType, modActionsCmd } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
|
||||
const opts = {
|
||||
mod: ct.member({ option: true }),
|
||||
|
@ -61,8 +62,8 @@ export const ForcebanCmd = modActionsCmd({
|
|||
|
||||
mod = args.mod;
|
||||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||
const config = pluginData.config.get();
|
||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]))!;
|
||||
|
||||
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { waitForReply } from "knub/dist/helpers";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -11,6 +10,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
|
|||
import { isBanned } from "../functions/isBanned";
|
||||
import { IgnoredEventType, modActionsCmd } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
|
||||
export const MassunbanCmd = modActionsCmd({
|
||||
trigger: "massunban",
|
||||
|
@ -37,8 +37,11 @@ export const MassunbanCmd = modActionsCmd({
|
|||
sendErrorMessage(pluginData, msg.channel, "Cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, [...msg.attachments.values()]);
|
||||
const config = pluginData.config.get();
|
||||
const unbanReason = parseReason(
|
||||
config,
|
||||
formatReasonWithAttachments(unbanReasonReply.content, [...msg.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
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { waitForReply } from "knub/dist/helpers";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
|
@ -9,6 +8,7 @@ import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginU
|
|||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { modActionsCmd } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
|
||||
export const MassmuteCmd = modActionsCmd({
|
||||
trigger: "massmute",
|
||||
|
@ -40,7 +40,11 @@ export const MassmuteCmd = modActionsCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, [...msg.attachments.values()]);
|
||||
const config = pluginData.config.get();
|
||||
const muteReason = parseReason(
|
||||
config,
|
||||
formatReasonWithAttachments(muteReasonReceived.content, [...msg.attachments.values()]),
|
||||
);
|
||||
|
||||
// Verify we can act upon all users
|
||||
for (const userId of args.userIds) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -11,6 +10,7 @@ import { ignoreEvent } from "../functions/ignoreEvent";
|
|||
import { IgnoredEventType, modActionsCmd } from "../types";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { clearExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
|
||||
const opts = {
|
||||
mod: ct.member({ option: true }),
|
||||
|
@ -49,7 +49,8 @@ export const UnbanCmd = modActionsCmd({
|
|||
}
|
||||
|
||||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
|
||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||
const config = pluginData.config.get();
|
||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]));
|
||||
|
||||
try {
|
||||
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
|
||||
|
|
|
@ -7,6 +7,7 @@ import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
|||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { isBanned } from "../functions/isBanned";
|
||||
import { parseReason } from "../functions/parseReason";
|
||||
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
|
||||
import { warnMember } from "../functions/warnMember";
|
||||
import { modActionsCmd } from "../types";
|
||||
|
@ -63,7 +64,7 @@ export const WarnCmd = modActionsCmd({
|
|||
}
|
||||
|
||||
const config = pluginData.config.get();
|
||||
const reason = formatReasonWithAttachments(args.reason, [...msg.attachments.values()]);
|
||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]))!;
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);
|
||||
|
|
|
@ -9,6 +9,7 @@ import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
|||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { isBanned } from "./isBanned";
|
||||
import { kickMember } from "./kickMember";
|
||||
import { parseReason } from "./parseReason";
|
||||
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
|
||||
|
||||
export async function actualKickMemberCmd(
|
||||
|
@ -67,7 +68,8 @@ export async function actualKickMemberCmd(
|
|||
return;
|
||||
}
|
||||
|
||||
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
||||
const config = pluginData.config.get();
|
||||
const reason = parseReason(config, formatReasonWithAttachments(args.reason, msg.attachments));
|
||||
|
||||
const kickResult = await kickMember(pluginData, memberToKick, reason, {
|
||||
contactMethods,
|
||||
|
|
|
@ -9,6 +9,7 @@ import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
|||
import { MuteResult } from "../../Mutes/types";
|
||||
import { ModActionsPluginType } from "../types";
|
||||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { parseReason } from "./parseReason";
|
||||
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
|
||||
|
||||
/**
|
||||
|
@ -42,7 +43,10 @@ export async function actualMuteUserCmd(
|
|||
}
|
||||
|
||||
const timeUntilUnmute = args.time && humanizeDuration(args.time);
|
||||
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined;
|
||||
const config = pluginData.config.get();
|
||||
const reason = args.reason
|
||||
? parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]))
|
||||
: undefined;
|
||||
|
||||
let muteResult: MuteResult;
|
||||
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
|
||||
|
|
|
@ -6,6 +6,7 @@ import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pl
|
|||
import { asSingleLine, UnknownUser } from "../../../utils";
|
||||
import { ModActionsPluginType } from "../types";
|
||||
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
|
||||
import { parseReason } from "./parseReason";
|
||||
|
||||
export async function actualUnmuteCmd(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
|
@ -27,7 +28,10 @@ export async function actualUnmuteCmd(
|
|||
pp = msg.author;
|
||||
}
|
||||
|
||||
const reason = args.reason ? formatReasonWithAttachments(args.reason, [...msg.attachments.values()]) : undefined;
|
||||
const config = pluginData.config.get();
|
||||
const reason = args.reason
|
||||
? parseReason(config, formatReasonWithAttachments(args.reason, [...msg.attachments.values()]))
|
||||
: undefined;
|
||||
|
||||
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
|
||||
const result = await mutesPlugin.unmuteUser(user.id, args.time, {
|
||||
|
|
|
@ -20,6 +20,7 @@ import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
|||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
|
||||
import { parseReason } from "./parseReason";
|
||||
|
||||
/**
|
||||
* Ban the specified user id, whether or not they're actually on the server at the time. Generates a case.
|
||||
|
@ -39,6 +40,7 @@ export async function banUserId(
|
|||
error: "Invalid user",
|
||||
};
|
||||
}
|
||||
if (reason) reason = parseReason(config, reason);
|
||||
|
||||
// Attempt to message the user *before* banning them, as doing it after may not be possible
|
||||
let notifyResult: UserNotificationResult = { method: null, success: true };
|
||||
|
|
|
@ -10,6 +10,7 @@ import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from
|
|||
import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
||||
import { ignoreEvent } from "./ignoreEvent";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "./parseReason";
|
||||
|
||||
/**
|
||||
* Kick the specified server member. Generates a case.
|
||||
|
@ -25,6 +26,7 @@ export async function kickMember(
|
|||
// 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) {
|
||||
reason = parseReason(config, reason);
|
||||
const contactMethods = kickOptions?.contactMethods
|
||||
? kickOptions.contactMethods
|
||||
: getDefaultContactMethods(pluginData, "kick");
|
||||
|
|
12
backend/src/plugins/ModActions/functions/parseReason.ts
Normal file
12
backend/src/plugins/ModActions/functions/parseReason.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
const MAX_REASON_LENGTH = 512;
|
||||
|
||||
export function parseReason(config: any, reason?: string): string | undefined {
|
||||
if (!reason) return reason;
|
||||
if (config?.reason_aliases) {
|
||||
reason = config.reason_aliases![reason.toLowerCase()] ?? reason;
|
||||
}
|
||||
if (reason!.length > MAX_REASON_LENGTH) {
|
||||
reason = reason!.substring(0, MAX_REASON_LENGTH - 6) + " [...]";
|
||||
}
|
||||
return reason;
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
import { GuildMember, Snowflake } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
|
||||
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
|
||||
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
||||
|
@ -10,6 +9,7 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|||
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
|
||||
import { getDefaultContactMethods } from "./getDefaultContactMethods";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { parseReason } from "./parseReason";
|
||||
|
||||
export async function warnMember(
|
||||
pluginData: GuildPluginData<ModActionsPluginType>,
|
||||
|
@ -18,7 +18,7 @@ export async function warnMember(
|
|||
warnOptions: WarnOptions = {},
|
||||
): Promise<WarnResult> {
|
||||
const config = pluginData.config.get();
|
||||
|
||||
reason = parseReason(config, reason)!;
|
||||
let notifyResult: UserNotificationResult;
|
||||
if (config.warn_message) {
|
||||
const warnMessage = await renderTemplate(
|
||||
|
|
|
@ -46,6 +46,7 @@ export const ConfigSchema = t.type({
|
|||
can_deletecase: t.boolean,
|
||||
can_act_as_other: t.boolean,
|
||||
create_cases_for_manual_actions: t.boolean,
|
||||
reason_aliases: tNullable(t.record(t.string, t.string)),
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue