From dd7939b79b6b10045a48b139d6e66d9f4f0bb47c Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Thu, 20 Aug 2020 17:33:00 +0200 Subject: [PATCH 1/2] Ignore pins unless -pins option is used --- backend/src/plugins/Utility/commands/CleanCmd.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/plugins/Utility/commands/CleanCmd.ts b/backend/src/plugins/Utility/commands/CleanCmd.ts index e3341c5f..72770082 100644 --- a/backend/src/plugins/Utility/commands/CleanCmd.ts +++ b/backend/src/plugins/Utility/commands/CleanCmd.ts @@ -61,6 +61,7 @@ export const CleanCmd = utilityCmd({ user: ct.userId({ option: true, shortcut: "u" }), channel: ct.channelId({ option: true, shortcut: "c" }), bots: ct.switchOption({ shortcut: "b" }), + pins: ct.switchOption({ shortcut: "p" }), "has-invites": ct.switchOption({ shortcut: "i" }), match: ct.regex({ option: true, shortcut: "m" }), }, @@ -96,6 +97,12 @@ export const CleanCmd = utilityCmd({ let beforeId = msg.id; const timeCutoff = msg.timestamp - MAX_CLEAN_TIME; + const deletePins = args.pins != null ? args.pins : false; + let pins = []; + if (!deletePins) { + pins = await msg.channel.getPins(); + } + while (messagesToClean.length < args.count) { const potentialMessagesToClean = await pluginData.state.savedMessages.getLatestByChannelBeforeId( targetChannel.id, @@ -109,6 +116,7 @@ export const CleanCmd = utilityCmd({ const contentString = message.data.content || ""; if (args.user && message.user_id !== args.user) continue; if (args.bots && !message.is_bot) continue; + if (!deletePins && pins.find(x => x.id === message.id) != null) continue; if (args["has-invites"] && getInviteCodesInString(contentString).length === 0) continue; if (moment.utc(message.posted_at).valueOf() < timeCutoff) continue; if (args.match && !(await pluginData.state.regexRunner.exec(args.match, contentString).catch(allowTimeout))) { From ab445b7019671b792f96e4ba8165914d1a4f1c5b Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Thu, 20 Aug 2020 17:37:08 +0200 Subject: [PATCH 2/2] rename option to delete-pins for more clarity --- backend/src/plugins/Utility/commands/CleanCmd.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Utility/commands/CleanCmd.ts b/backend/src/plugins/Utility/commands/CleanCmd.ts index 72770082..44ed26d1 100644 --- a/backend/src/plugins/Utility/commands/CleanCmd.ts +++ b/backend/src/plugins/Utility/commands/CleanCmd.ts @@ -61,7 +61,7 @@ export const CleanCmd = utilityCmd({ user: ct.userId({ option: true, shortcut: "u" }), channel: ct.channelId({ option: true, shortcut: "c" }), bots: ct.switchOption({ shortcut: "b" }), - pins: ct.switchOption({ shortcut: "p" }), + "delete-pins": ct.switchOption({ shortcut: "p" }), "has-invites": ct.switchOption({ shortcut: "i" }), match: ct.regex({ option: true, shortcut: "m" }), }, @@ -97,7 +97,7 @@ export const CleanCmd = utilityCmd({ let beforeId = msg.id; const timeCutoff = msg.timestamp - MAX_CLEAN_TIME; - const deletePins = args.pins != null ? args.pins : false; + const deletePins = args["delete-pins"] != null ? args["delete-pins"] : false; let pins = []; if (!deletePins) { pins = await msg.channel.getPins();