mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Automod work
This commit is contained in:
parent
140ba84544
commit
f657b169df
32 changed files with 1099 additions and 5 deletions
11
backend/src/plugins/Automod/actions/availableActions.ts
Normal file
11
backend/src/plugins/Automod/actions/availableActions.ts
Normal 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,
|
||||
});
|
28
backend/src/plugins/Automod/actions/clean.ts
Normal file
28
backend/src/plugins/Automod/actions/clean.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue