mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Add -update/-up argument to automatically update latest/chosen case with !clean (#173)
This commit is contained in:
parent
dfc1bf2ba0
commit
20b1c869cd
5 changed files with 93 additions and 52 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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`);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
44
backend/src/plugins/ModActions/functions/updateCase.ts
Normal file
44
backend/src/plugins/ModActions/functions/updateCase.ts
Normal 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`);
|
||||||
|
}
|
|
@ -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,
|
||||||
|
|
||||||
|
|
|
@ -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!`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue