3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-08 11:37:20 +00:00

feat: update to djs 14.19.3, node 22, zod 4

This commit is contained in:
Dragory 2025-05-22 22:35:48 +00:00
parent 595e1a0556
commit 09eb8e92f2
No known key found for this signature in database
189 changed files with 1244 additions and 900 deletions

View file

@ -0,0 +1,49 @@
import { GuildPluginData } from "knub";
import { UtilityPluginType } from "../types.js";
import { GuildBasedChannel, Snowflake, TextBasedChannel, User } from "discord.js";
import { SavedMessage } from "../../../data/entities/SavedMessage.js";
import { LogType } from "../../../data/LogType.js";
import { chunkArray } from "../../../utils.js";
import { getBaseUrl } from "../../../pluginUtils.js";
import { LogsPlugin } from "../../Logs/LogsPlugin.js";
export async function cleanMessages(
pluginData: GuildPluginData<UtilityPluginType>,
channel: GuildBasedChannel & TextBasedChannel,
savedMessages: SavedMessage[],
mod: User,
) {
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, savedMessages[0].id);
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, savedMessages[0].id);
// Delete & archive in ID order
savedMessages = Array.from(savedMessages).sort((a, b) => (a.id > b.id ? 1 : -1));
const idsToDelete = savedMessages.map((m) => m.id) as Snowflake[];
// Make sure the deletions aren't double logged
idsToDelete.forEach((id) => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, idsToDelete[0]);
// Actually delete the messages (in chunks of 100)
const chunks = chunkArray(idsToDelete, 100);
await Promise.all(
chunks.map((chunk) =>
Promise.all([channel.bulkDelete(chunk), pluginData.state.savedMessages.markBulkAsDeleted(chunk)]),
),
);
// Create an archive
const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild);
const baseUrl = getBaseUrl(pluginData);
const archiveUrl = pluginData.state.archives.getUrl(baseUrl, archiveId);
pluginData.getPlugin(LogsPlugin).logClean({
mod,
channel,
count: savedMessages.length,
archiveUrl,
});
return { archiveUrl };
}