Merge branch 'master' of github.com:Dragory/ZeppelinBot

This commit is contained in:
Dragory 2021-04-28 22:40:02 +03:00
commit 3d549b4e78
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
27 changed files with 208 additions and 93 deletions

View file

@ -235,14 +235,20 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
pluginData.state.modActionsListeners.set("note", (userId: string) => pluginData.state.modActionsListeners.set("note", (userId: string) =>
runAutomodOnModAction(pluginData, "note", userId), runAutomodOnModAction(pluginData, "note", userId),
); );
pluginData.state.modActionsListeners.set("warn", (userId: string) => pluginData.state.modActionsListeners.set(
runAutomodOnModAction(pluginData, "warn", userId), "warn",
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
runAutomodOnModAction(pluginData, "warn", userId, reason, isAutomodAction),
); );
pluginData.state.modActionsListeners.set("kick", (userId: string) => pluginData.state.modActionsListeners.set(
runAutomodOnModAction(pluginData, "kick", userId), "kick",
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
runAutomodOnModAction(pluginData, "kick", userId, reason, isAutomodAction),
); );
pluginData.state.modActionsListeners.set("ban", (userId: string) => pluginData.state.modActionsListeners.set(
runAutomodOnModAction(pluginData, "ban", userId), "ban",
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
runAutomodOnModAction(pluginData, "ban", userId, reason, isAutomodAction),
); );
pluginData.state.modActionsListeners.set("unban", (userId: string) => pluginData.state.modActionsListeners.set("unban", (userId: string) =>
runAutomodOnModAction(pluginData, "unban", userId), runAutomodOnModAction(pluginData, "unban", userId),
@ -251,7 +257,11 @@ export const AutomodPlugin = zeppelinGuildPlugin<AutomodPluginType>()("automod",
const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter(); const mutesEvents = pluginData.getPlugin(MutesPlugin).getEventEmitter();
pluginData.state.mutesListeners = new Map(); pluginData.state.mutesListeners = new Map();
pluginData.state.mutesListeners.set("mute", (userId: string) => runAutomodOnModAction(pluginData, "mute", userId)); pluginData.state.mutesListeners.set(
"mute",
(userId: string, reason: string | undefined, isAutomodAction: boolean) =>
runAutomodOnModAction(pluginData, "mute", userId, reason, isAutomodAction),
);
pluginData.state.mutesListeners.set("unmute", (userId: string) => pluginData.state.mutesListeners.set("unmute", (userId: string) =>
runAutomodOnModAction(pluginData, "unmute", userId), runAutomodOnModAction(pluginData, "unmute", userId),
); );

View file

@ -35,7 +35,12 @@ export const BanAction = automodAction({
const modActions = pluginData.getPlugin(ModActionsPlugin); const modActions = pluginData.getPlugin(ModActionsPlugin);
for (const userId of userIdsToBan) { for (const userId of userIdsToBan) {
await modActions.banUserId(userId, reason, { contactMethods, caseArgs, deleteMessageDays }); await modActions.banUserId(userId, reason, {
contactMethods,
caseArgs,
deleteMessageDays,
isAutomodAction: true,
});
} }
}, },
}); });

View file

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

View file

@ -51,7 +51,14 @@ export const MuteAction = automodAction({
const mutes = pluginData.getPlugin(MutesPlugin); const mutes = pluginData.getPlugin(MutesPlugin);
for (const userId of userIdsToMute) { for (const userId of userIdsToMute) {
try { try {
await mutes.muteUser(userId, duration, reason, { contactMethods, caseArgs }, rolesToRemove, rolesToRestore); await mutes.muteUser(
userId,
duration,
reason,
{ contactMethods, caseArgs, isAutomodAction: true },
rolesToRemove,
rolesToRestore,
);
} catch (e) { } catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) { if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, { pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {

View file

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

View file

@ -9,6 +9,7 @@ export async function runAutomodOnModAction(
modAction: ModActionType, modAction: ModActionType,
userId: string, userId: string,
reason?: string, reason?: string,
isAutomodAction: boolean = false,
) { ) {
const user = await resolveUser(pluginData.client, userId); const user = await resolveUser(pluginData.client, userId);
@ -18,6 +19,7 @@ export async function runAutomodOnModAction(
modAction: { modAction: {
type: modAction, type: modAction,
reason, reason,
isAutomodAction,
}, },
}; };

View file

@ -64,9 +64,9 @@ export const pluginInfo: ZeppelinGuildPluginBlueprint["info"] = {
reason: 'Auto-muted for spam' reason: 'Auto-muted for spam'
my_second_filter: my_second_filter:
triggers: triggers:
- message_spam: - emoji_spam:
amount: 5 amount: 2
within: 10s within: 5s
actions: actions:
clean: true clean: true
overrides: overrides:

View file

@ -5,13 +5,25 @@ import { automodTrigger } from "../helpers";
interface BanTriggerResultType {} interface BanTriggerResultType {}
export const BanTrigger = automodTrigger<BanTriggerResultType>()({ export const BanTrigger = automodTrigger<BanTriggerResultType>()({
configType: t.type({}), configType: t.type({
defaultConfig: {}, manual: t.boolean,
automatic: t.boolean,
}),
async match({ context }) { defaultConfig: {
manual: true,
automatic: true,
},
async match({ context, triggerConfig }) {
if (context.modAction?.type !== "ban") { if (context.modAction?.type !== "ban") {
return; return;
} }
console.log(context);
// If automatic && automatic turned off -> return
if (context.modAction.isAutomodAction && !triggerConfig.automatic) return;
// If manual && manual turned off -> return
if (!context.modAction.isAutomodAction && !triggerConfig.manual) return;
return { return {
extra: {}, extra: {},

View file

@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
interface KickTriggerResultType {} interface KickTriggerResultType {}
export const KickTrigger = automodTrigger<KickTriggerResultType>()({ export const KickTrigger = automodTrigger<KickTriggerResultType>()({
configType: t.type({}), configType: t.type({
defaultConfig: {}, manual: t.boolean,
automatic: t.boolean,
}),
async match({ context }) { defaultConfig: {
manual: true,
automatic: true,
},
async match({ context, triggerConfig }) {
if (context.modAction?.type !== "kick") { if (context.modAction?.type !== "kick") {
return; return;
} }
// If automatic && automatic turned off -> return
if (context.modAction.isAutomodAction && !triggerConfig.automatic) return;
// If manual && manual turned off -> return
if (!context.modAction.isAutomodAction && !triggerConfig.manual) return;
return { return {
extra: {}, extra: {},

View file

@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
interface MuteTriggerResultType {} interface MuteTriggerResultType {}
export const MuteTrigger = automodTrigger<MuteTriggerResultType>()({ export const MuteTrigger = automodTrigger<MuteTriggerResultType>()({
configType: t.type({}), configType: t.type({
defaultConfig: {}, manual: t.boolean,
automatic: t.boolean,
}),
async match({ context }) { defaultConfig: {
manual: true,
automatic: true,
},
async match({ context, triggerConfig }) {
if (context.modAction?.type !== "mute") { if (context.modAction?.type !== "mute") {
return; return;
} }
// If automatic && automatic turned off -> return
if (context.modAction.isAutomodAction && !triggerConfig.automatic) return;
// If manual && manual turned off -> return
if (!context.modAction.isAutomodAction && !triggerConfig.manual) return;
return { return {
extra: {}, extra: {},

View file

@ -5,13 +5,24 @@ import { automodTrigger } from "../helpers";
interface WarnTriggerResultType {} interface WarnTriggerResultType {}
export const WarnTrigger = automodTrigger<WarnTriggerResultType>()({ export const WarnTrigger = automodTrigger<WarnTriggerResultType>()({
configType: t.type({}), configType: t.type({
defaultConfig: {}, manual: t.boolean,
automatic: t.boolean,
}),
async match({ context }) { defaultConfig: {
manual: true,
automatic: true,
},
async match({ context, triggerConfig }) {
if (context.modAction?.type !== "warn") { if (context.modAction?.type !== "warn") {
return; return;
} }
// If automatic && automatic turned off -> return
if (context.modAction.isAutomodAction && !triggerConfig.automatic) return;
// If manual && manual turned off -> return
if (!context.modAction.isAutomodAction && !triggerConfig.manual) return;
return { return {
extra: {}, extra: {},

View file

@ -122,6 +122,7 @@ export interface AutomodContext {
modAction?: { modAction?: {
type: ModActionType; type: ModActionType;
reason?: string; reason?: string;
isAutomodAction: boolean;
}; };
antiraid?: { antiraid?: {
level: string | null; level: string | null;

View file

@ -67,7 +67,7 @@ export const SetCounterCmd = guildCommand<CountersPluginType>()({
let channel = args.channel; let channel = args.channel;
if (!channel && counter.per_channel) { if (!channel && counter.per_channel) {
message.channel.createMessage(`Which channel's counter value would you like to add to?`); message.channel.createMessage(`Which channel's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id); const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) { if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling"); sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -85,7 +85,7 @@ export const SetCounterCmd = guildCommand<CountersPluginType>()({
let user = args.user; let user = args.user;
if (!user && counter.per_user) { if (!user && counter.per_user) {
message.channel.createMessage(`Which user's counter value would you like to add to?`); message.channel.createMessage(`Which user's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id); const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) { if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling"); sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -103,7 +103,7 @@ export const SetCounterCmd = guildCommand<CountersPluginType>()({
let value = args.value; let value = args.value;
if (!value) { if (!value) {
message.channel.createMessage("How much would you like to add to the counter's value?"); message.channel.createMessage("What would you like to set the counter's value to?");
const reply = await waitForReply(pluginData.client, message.channel, message.author.id); const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) { if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling"); sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -111,7 +111,7 @@ export const SetCounterCmd = guildCommand<CountersPluginType>()({
} }
const potentialValue = parseInt(reply.content, 10); const potentialValue = parseInt(reply.content, 10);
if (!potentialValue) { if (Number.isNaN(potentialValue)) {
sendErrorMessage(pluginData, message.channel, "Not a number, cancelling"); sendErrorMessage(pluginData, message.channel, "Not a number, cancelling");
return; return;
} }

View file

@ -30,7 +30,7 @@ import { GuildCases } from "../../data/GuildCases";
import { GuildLogs } from "../../data/GuildLogs"; import { GuildLogs } from "../../data/GuildLogs";
import { ForceUnmuteCmd } from "./commands/ForceunmuteCmd"; import { ForceUnmuteCmd } from "./commands/ForceunmuteCmd";
import { warnMember } from "./functions/warnMember"; import { warnMember } from "./functions/warnMember";
import { Member } from "eris"; import { Member, Message } from "eris";
import { kickMember } from "./functions/kickMember"; import { kickMember } from "./functions/kickMember";
import { banUserId } from "./functions/banUserId"; import { banUserId } from "./functions/banUserId";
import { MassmuteCmd } from "./commands/MassmuteCmd"; import { MassmuteCmd } from "./commands/MassmuteCmd";
@ -43,6 +43,7 @@ import { EventEmitter } from "events";
import { mapToPublicFn } from "../../pluginUtils"; import { mapToPublicFn } from "../../pluginUtils";
import { onModActionsEvent } from "./functions/onModActionsEvent"; import { onModActionsEvent } from "./functions/onModActionsEvent";
import { offModActionsEvent } from "./functions/offModActionsEvent"; import { offModActionsEvent } from "./functions/offModActionsEvent";
import { updateCase } from "./functions/updateCase";
const defaultOptions = { const defaultOptions = {
config: { config: {
@ -170,6 +171,12 @@ export const ModActionsPlugin = zeppelinGuildPlugin<ModActionsPluginType>()("mod
}; };
}, },
updateCase(pluginData) {
return (msg: Message, caseNumber: number | null, note: string) => {
updateCase(pluginData, msg, { caseNumber, note });
};
},
on: mapToPublicFn(onModActionsEvent), on: mapToPublicFn(onModActionsEvent),
off: mapToPublicFn(offModActionsEvent), off: mapToPublicFn(offModActionsEvent),
getEventEmitter(pluginData) { getEventEmitter(pluginData) {

View file

@ -17,7 +17,7 @@ const opts = {
const casesPerPage = 5; const casesPerPage = 5;
export const CasesModCmd = modActionsCmd({ export const CasesModCmd = modActionsCmd({
trigger: ["cases", "modlogs"], trigger: ["cases", "modlogs", "infractions"],
permission: "can_view", permission: "can_view",
description: "Show the most recent 5 cases by the specified -mod", description: "Show the most recent 5 cases by the specified -mod",

View file

@ -1,11 +1,6 @@
import { modActionsCmd } from "../types"; import { modActionsCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes"; import { commandTypeHelpers as ct } from "../../../commandTypes";
import { Case } from "../../../data/entities/Case"; import { updateCase } from "../functions/updateCase";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogType } from "../../../data/LogType";
import { CaseTypes } from "../../../data/CaseTypes";
export const UpdateCmd = modActionsCmd({ export const UpdateCmd = modActionsCmd({
trigger: ["update", "reason"], trigger: ["update", "reason"],
@ -24,39 +19,6 @@ export const UpdateCmd = modActionsCmd({
], ],
async run({ pluginData, message: msg, args }) { async run({ pluginData, message: msg, args }) {
let theCase: Case | undefined; await updateCase(pluginData, msg, args);
if (args.caseNumber != null) {
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
} else {
theCase = await pluginData.state.cases.findLatestByModId(msg.author.id);
}
if (!theCase) {
sendErrorMessage(pluginData, msg.channel, "Case not found");
return;
}
if (!args.note && msg.attachments.length === 0) {
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
return;
}
const note = formatReasonWithAttachments(args.note, msg.attachments);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
await casesPlugin.createCaseNote({
caseId: theCase.id,
modId: msg.author.id,
body: note,
});
pluginData.state.serverLogs.log(LogType.CASE_UPDATE, {
mod: msg.author,
caseNumber: theCase.case_number,
caseType: CaseTypes[theCase.type],
note,
});
sendSuccessMessage(pluginData, msg.channel, `Case \`#${theCase.case_number}\` updated`);
}, },
}); });

View file

@ -112,7 +112,5 @@ export const WarnCmd = modActionsCmd({
msg.channel, msg.channel,
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`, `Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
); );
pluginData.state.events.emit("warn", user.id, reason);
}, },
}); });

View file

@ -127,7 +127,7 @@ export async function banUserId(
banTime: banTime ? humanizeDuration(banTime) : null, banTime: banTime ? humanizeDuration(banTime) : null,
}); });
pluginData.state.events.emit("ban", user.id, reason); pluginData.state.events.emit("ban", user.id, reason, banOptions.isAutomodAction);
return { return {
status: "success", status: "success",

View file

@ -85,7 +85,7 @@ export async function kickMember(
reason, reason,
}); });
pluginData.state.events.emit("kick", member.id, reason); pluginData.state.events.emit("kick", member.id, reason, kickOptions.isAutomodAction);
return { return {
status: "success", status: "success",

View file

@ -0,0 +1,44 @@
import { Message } from "eris";
import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
export async function updateCase(pluginData, msg: Message, args) {
let theCase: Case | undefined;
if (args.caseNumber != null) {
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
} else {
theCase = await pluginData.state.cases.findLatestByModId(msg.author.id);
}
if (!theCase) {
sendErrorMessage(pluginData, msg.channel, "Case not found");
return;
}
if (!args.note && msg.attachments.length === 0) {
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
return;
}
const note = formatReasonWithAttachments(args.note, msg.attachments);
const casesPlugin = pluginData.getPlugin(CasesPlugin);
await casesPlugin.createCaseNote({
caseId: theCase.id,
modId: msg.author.id,
body: note,
});
pluginData.state.serverLogs.log(LogType.CASE_UPDATE, {
mod: msg.author,
caseNumber: theCase.case_number,
caseType: CaseTypes[theCase.type],
note,
});
sendSuccessMessage(pluginData, msg.channel, `Case \`#${theCase.case_number}\` updated`);
}

View file

@ -82,6 +82,8 @@ export async function warnMember(
reason, reason,
}); });
pluginData.state.events.emit("warn", member.id, reason, warnOptions.isAutomodAction);
return { return {
status: "success", status: "success",
case: createdCase, case: createdCase,

View file

@ -48,9 +48,9 @@ export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface ModActionsEvents { export interface ModActionsEvents {
note: (userId: string, reason?: string) => void; note: (userId: string, reason?: string) => void;
warn: (userId: string, reason?: string) => void; warn: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
kick: (userId: string, reason?: string) => void; kick: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
ban: (userId: string, reason?: string) => void; ban: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
unban: (userId: string, reason?: string) => void; unban: (userId: string, reason?: string) => void;
// mute/unmute are in the Mutes plugin // mute/unmute are in the Mutes plugin
} }
@ -126,17 +126,20 @@ export interface WarnOptions {
caseArgs?: Partial<CaseArgs> | null; caseArgs?: Partial<CaseArgs> | null;
contactMethods?: UserNotificationMethod[] | null; contactMethods?: UserNotificationMethod[] | null;
retryPromptChannel?: TextChannel | null; retryPromptChannel?: TextChannel | null;
isAutomodAction?: boolean;
} }
export interface KickOptions { export interface KickOptions {
caseArgs?: Partial<CaseArgs>; caseArgs?: Partial<CaseArgs>;
contactMethods?: UserNotificationMethod[]; contactMethods?: UserNotificationMethod[];
isAutomodAction?: boolean;
} }
export interface BanOptions { export interface BanOptions {
caseArgs?: Partial<CaseArgs>; caseArgs?: Partial<CaseArgs>;
contactMethods?: UserNotificationMethod[]; contactMethods?: UserNotificationMethod[];
deleteMessageDays?: number; deleteMessageDays?: number;
isAutomodAction?: boolean;
} }
export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban"; export type ModActionType = "note" | "warn" | "mute" | "unmute" | "kick" | "ban" | "unban";

View file

@ -241,7 +241,7 @@ export async function muteUser(
lock.unlock(); lock.unlock();
pluginData.state.events.emit("mute", user.id, reason); pluginData.state.events.emit("mute", user.id, reason, muteOptions.isAutomodAction);
return { return {
case: theCase, case: theCase,

View file

@ -34,7 +34,7 @@ export const ConfigSchema = t.type({
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>; export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
export interface MutesEvents { export interface MutesEvents {
mute: (userId: string, reason?: string) => void; mute: (userId: string, reason?: string, isAutomodAction?: boolean) => void;
unmute: (userId: string, reason?: string) => void; unmute: (userId: string, reason?: string) => void;
} }
@ -75,6 +75,7 @@ export type UnmuteResult = {
export interface MuteOptions { export interface MuteOptions {
caseArgs?: Partial<CaseArgs>; caseArgs?: Partial<CaseArgs>;
contactMethods?: UserNotificationMethod[]; contactMethods?: UserNotificationMethod[];
isAutomodAction?: boolean;
} }
export const mutesCmd = guildCommand<MutesPluginType>(); export const mutesCmd = guildCommand<MutesPluginType>();

View file

@ -7,7 +7,7 @@ import { remindersCmd } from "../types";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
export const RemindCmd = remindersCmd({ export const RemindCmd = remindersCmd({
trigger: ["remind", "remindme"], trigger: ["remind", "remindme", "reminder"],
usage: "!remind 3h Remind me of this in 3 hours please", usage: "!remind 3h Remind me of this in 3 hours please",
permission: "can_use", permission: "can_use",

View file

@ -35,6 +35,7 @@ import { SnowflakeInfoCmd } from "./commands/SnowflakeInfoCmd";
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners"; import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners";
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin"; import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd"; import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
import { ModActionsPlugin } from "../ModActions/ModActionsPlugin";
import { refreshMembersIfNeeded } from "./refreshMembers"; import { refreshMembersIfNeeded } from "./refreshMembers";
const defaultOptions: PluginOptions<UtilityPluginType> = { const defaultOptions: PluginOptions<UtilityPluginType> = {
@ -106,7 +107,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()("utility",
prettyName: "Utility", prettyName: "Utility",
}, },
dependencies: [TimeAndDatePlugin], dependencies: [TimeAndDatePlugin, ModActionsPlugin],
configSchema: ConfigSchema, configSchema: ConfigSchema,
defaultOptions, defaultOptions,

View file

@ -8,6 +8,7 @@ import { GuildPluginData } from "knub";
import { SavedMessage } from "../../../data/entities/SavedMessage"; import { SavedMessage } from "../../../data/entities/SavedMessage";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { allowTimeout } from "../../../RegExpRunner"; import { allowTimeout } from "../../../RegExpRunner";
import { ModActionsPlugin } from "../../../plugins/ModActions/ModActionsPlugin";
const MAX_CLEAN_COUNT = 150; const MAX_CLEAN_COUNT = 150;
const MAX_CLEAN_TIME = 1 * DAYS; const MAX_CLEAN_TIME = 1 * DAYS;
@ -49,23 +50,36 @@ async function cleanMessages(
return { archiveUrl }; return { archiveUrl };
} }
const opts = {
user: ct.userId({ option: true, shortcut: "u" }),
channel: ct.channelId({ option: true, shortcut: "c" }),
bots: ct.switchOption({ shortcut: "b" }),
"delete-pins": ct.switchOption({ shortcut: "p" }),
"has-invites": ct.switchOption({ shortcut: "i" }),
match: ct.regex({ option: true, shortcut: "m" }),
"to-id": ct.anyId({ option: true, shortcut: "id" }),
};
export const CleanCmd = utilityCmd({ export const CleanCmd = utilityCmd({
trigger: ["clean", "clear"], trigger: ["clean", "clear"],
description: "Remove a number of recent messages", description: "Remove a number of recent messages",
usage: "!clean 20", usage: "!clean 20",
permission: "can_clean", permission: "can_clean",
signature: { signature: [
count: ct.number(), {
count: ct.number(),
update: ct.number({ option: true, shortcut: "up" }),
user: ct.userId({ option: true, shortcut: "u" }), ...opts,
channel: ct.channelId({ option: true, shortcut: "c" }), },
bots: ct.switchOption({ shortcut: "b" }), {
"delete-pins": ct.switchOption({ shortcut: "p" }), count: ct.number(),
"has-invites": ct.switchOption({ shortcut: "i" }), update: ct.switchOption({ shortcut: "up" }),
match: ct.regex({ option: true, shortcut: "m" }),
"to-id": ct.anyId({ option: true, shortcut: "id" }), ...opts,
}, },
],
async run({ message: msg, args, pluginData }) { async run({ message: msg, args, pluginData }) {
if (args.count > MAX_CLEAN_COUNT || args.count <= 0) { if (args.count > MAX_CLEAN_COUNT || args.count <= 0) {
@ -155,6 +169,19 @@ export const CleanCmd = utilityCmd({
responseText += ` in <#${targetChannel.id}>\n${cleanResult.archiveUrl}`; responseText += ` in <#${targetChannel.id}>\n${cleanResult.archiveUrl}`;
} }
if (args.update) {
const modActions = pluginData.getPlugin(ModActionsPlugin);
const channelId = targetChannel.id !== msg.channel.id ? targetChannel.id : msg.channel.id;
const updateMessage = `Cleaned ${messagesToClean.length} ${
messagesToClean.length === 1 ? "message" : "messages"
} in <#${channelId}>: ${cleanResult.archiveUrl}`;
if (typeof args.update === "number") {
modActions.updateCase(msg, args.update, updateMessage);
} else {
modActions.updateCase(msg, null, updateMessage);
}
}
responseMsg = await sendSuccessMessage(pluginData, msg.channel, responseText); responseMsg = await sendSuccessMessage(pluginData, msg.channel, responseText);
} else { } else {
responseMsg = await sendErrorMessage(pluginData, msg.channel, `Found no messages to clean!`); responseMsg = await sendErrorMessage(pluginData, msg.channel, `Found no messages to clean!`);