mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-14 13:57:19 +00:00
Allow clean to hard stop at a certain ID
This commit is contained in:
parent
dda4313b26
commit
6ab19c8093
1 changed files with 12 additions and 1 deletions
|
@ -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 { snowflakeToTimestamp } from "src/utils/snowflakeToTimestamp";
|
||||||
|
|
||||||
const MAX_CLEAN_COUNT = 150;
|
const MAX_CLEAN_COUNT = 150;
|
||||||
const MAX_CLEAN_TIME = 1 * DAYS;
|
const MAX_CLEAN_TIME = 1 * DAYS;
|
||||||
|
@ -63,6 +64,7 @@ export const CleanCmd = utilityCmd({
|
||||||
bots: ct.switchOption({ shortcut: "b" }),
|
bots: ct.switchOption({ shortcut: "b" }),
|
||||||
"has-invites": ct.switchOption({ shortcut: "i" }),
|
"has-invites": ct.switchOption({ shortcut: "i" }),
|
||||||
match: ct.regex({ option: true, shortcut: "m" }),
|
match: ct.regex({ option: true, shortcut: "m" }),
|
||||||
|
"to-id": ct.anyId({ option: true, shortcut: "id" }),
|
||||||
},
|
},
|
||||||
|
|
||||||
async run({ message: msg, args, pluginData }) {
|
async run({ message: msg, args, pluginData }) {
|
||||||
|
@ -95,6 +97,8 @@ export const CleanCmd = utilityCmd({
|
||||||
const messagesToClean = [];
|
const messagesToClean = [];
|
||||||
let beforeId = msg.id;
|
let beforeId = msg.id;
|
||||||
const timeCutoff = msg.timestamp - MAX_CLEAN_TIME;
|
const timeCutoff = msg.timestamp - MAX_CLEAN_TIME;
|
||||||
|
const upToMsgId = args["to-id"];
|
||||||
|
let foundId = false;
|
||||||
|
|
||||||
while (messagesToClean.length < args.count) {
|
while (messagesToClean.length < args.count) {
|
||||||
const potentialMessagesToClean = await pluginData.state.savedMessages.getLatestByChannelBeforeId(
|
const potentialMessagesToClean = await pluginData.state.savedMessages.getLatestByChannelBeforeId(
|
||||||
|
@ -110,6 +114,10 @@ export const CleanCmd = utilityCmd({
|
||||||
if (args.user && message.user_id !== args.user) continue;
|
if (args.user && message.user_id !== args.user) continue;
|
||||||
if (args.bots && !message.is_bot) continue;
|
if (args.bots && !message.is_bot) continue;
|
||||||
if (args["has-invites"] && getInviteCodesInString(contentString).length === 0) continue;
|
if (args["has-invites"] && getInviteCodesInString(contentString).length === 0) continue;
|
||||||
|
if (upToMsgId != null && message.id < upToMsgId) {
|
||||||
|
foundId = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (moment.utc(message.posted_at).valueOf() < timeCutoff) continue;
|
if (moment.utc(message.posted_at).valueOf() < timeCutoff) continue;
|
||||||
if (args.match && !(await pluginData.state.regexRunner.exec(args.match, contentString).catch(allowTimeout))) {
|
if (args.match && !(await pluginData.state.regexRunner.exec(args.match, contentString).catch(allowTimeout))) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -123,7 +131,10 @@ export const CleanCmd = utilityCmd({
|
||||||
|
|
||||||
beforeId = potentialMessagesToClean[potentialMessagesToClean.length - 1].id;
|
beforeId = potentialMessagesToClean[potentialMessagesToClean.length - 1].id;
|
||||||
|
|
||||||
if (moment.utc(potentialMessagesToClean[potentialMessagesToClean.length - 1].posted_at).valueOf() < timeCutoff) {
|
if (
|
||||||
|
foundId ||
|
||||||
|
moment.utc(potentialMessagesToClean[potentialMessagesToClean.length - 1].posted_at).valueOf() < timeCutoff
|
||||||
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue