3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Automod work

This commit is contained in:
Dragory 2020-07-27 20:42:10 +03:00
parent 140ba84544
commit f657b169df
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
32 changed files with 1099 additions and 5 deletions

View file

@ -0,0 +1,11 @@
import * as t from "io-ts";
import { CleanAction } from "./clean";
import { AutomodActionBlueprint } from "../helpers";
export const availableActions: Record<string, AutomodActionBlueprint<any>> = {
clean: CleanAction,
};
export const AvailableActions = t.type({
clean: CleanAction.configType,
});

View file

@ -0,0 +1,28 @@
import * as t from "io-ts";
import { automodAction } from "../helpers";
import { LogType } from "../../../data/LogType";
export const CleanAction = automodAction({
configType: t.boolean,
async apply({ pluginData, contexts }) {
const messageIdsToDeleteByChannelId: Map<string, string[]> = new Map();
for (const context of contexts) {
if (context.message) {
if (!messageIdsToDeleteByChannelId.has(context.message.channel_id)) {
messageIdsToDeleteByChannelId.set(context.message.channel_id, []);
}
messageIdsToDeleteByChannelId.get(context.message.channel_id).push(context.message.id);
}
}
for (const [channelId, messageIds] of messageIdsToDeleteByChannelId.entries()) {
for (const id of messageIds) {
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id);
}
await pluginData.client.deleteMessages(channelId, messageIds);
}
},
});