Finish preliminary rework, ready to test

This commit is contained in:
Dark 2021-06-02 04:07:50 +02:00
parent 57893e7f76
commit d0a1beb809
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
177 changed files with 854 additions and 707 deletions

View file

@ -7,7 +7,7 @@ import { GuildSavedMessages } from "../../data/GuildSavedMessages";
import { GuildMutes } from "../../data/GuildMutes";
import { onMessageCreate } from "./util/onMessageCreate";
import { clearOldRecentActions } from "./util/clearOldRecentActions";
import { SpamVoiceJoinEvt, SpamVoiceSwitchEvt } from "./events/SpamVoiceEvt";
import { SpamVoiceStateUpdateEvt } from "./events/SpamVoiceEvt";
import { trimPluginDescription } from "../../utils";
import { LogsPlugin } from "../Logs/LogsPlugin";
@ -60,8 +60,7 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()({
// prettier-ignore
events: [
SpamVoiceJoinEvt,
SpamVoiceSwitchEvt,
SpamVoiceStateUpdateEvt,
],
beforeLoad(pluginData) {

View file

@ -1,37 +1,13 @@
import { spamEvt, RecentActionType } from "../types";
import { logAndDetectOtherSpam } from "../util/logAndDetectOtherSpam";
export const SpamVoiceJoinEvt = spamEvt({
event: "voiceChannelJoin",
export const SpamVoiceStateUpdateEvt = spamEvt({
event: "voiceStateUpdate",
async listener(meta) {
const member = meta.args.member;
const channel = meta.args.newChannel;
const config = await meta.pluginData.config.getMatchingConfig({ member, channelId: channel.id });
const maxVoiceMoves = config.max_voice_moves;
if (maxVoiceMoves) {
logAndDetectOtherSpam(
meta.pluginData,
RecentActionType.VoiceChannelMove,
maxVoiceMoves,
member.id,
1,
"0",
Date.now(),
null,
"too many voice channel moves",
);
}
},
});
export const SpamVoiceSwitchEvt = spamEvt({
event: "voiceChannelSwitch",
async listener(meta) {
const member = meta.args.member;
const channel = meta.args.newChannel;
const member = meta.args.newState.member;
if (!member) return;
const channel = meta.args.newState.channel!;
const config = await meta.pluginData.config.getMatchingConfig({ member, channelId: channel.id });
const maxVoiceMoves = config.max_voice_moves;

View file

@ -23,6 +23,7 @@ import { clearRecentUserActions } from "./clearRecentUserActions";
import { saveSpamArchives } from "./saveSpamArchives";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { TextChannel } from "discord.js";
export async function logAndDetectMessageSpam(
pluginData: GuildPluginData<SpamPluginType>,
@ -122,7 +123,7 @@ export async function logAndDetectMessageSpam(
// Then, if enabled, remove the spam messages
if (spamConfig.clean !== false) {
msgIds.forEach(id => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
pluginData.client.deleteMessages(savedMessage.channel_id, msgIds).catch(noop);
(pluginData.guild.channels.cache.get(savedMessage.channel_id)! as TextChannel).bulkDelete(msgIds).catch(noop);
}
// Store the ID of the last handled message