Update to new Knub 30 beta. Code clean-up.
This commit is contained in:
parent
5d579446c5
commit
2f470dc37a
299 changed files with 1075 additions and 1004 deletions
|
@ -1,10 +1,10 @@
|
|||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { PluginOptions } from "knub";
|
||||
import { ConfigSchema, SpamPluginType } from "./types";
|
||||
import { GuildLogs } from "src/data/GuildLogs";
|
||||
import { GuildArchives } from "src/data/GuildArchives";
|
||||
import { GuildSavedMessages } from "src/data/GuildSavedMessages";
|
||||
import { GuildMutes } from "src/data/GuildMutes";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildArchives } from "../../data/GuildArchives";
|
||||
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";
|
||||
|
@ -42,7 +42,7 @@ const defaultOptions: PluginOptions<SpamPluginType> = {
|
|||
],
|
||||
};
|
||||
|
||||
export const SpamPlugin = zeppelinPlugin<SpamPluginType>()("spam", {
|
||||
export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()("spam", {
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "Spam protection",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { spamEvent, RecentActionType } from "../types";
|
||||
import { spamEvt, RecentActionType } from "../types";
|
||||
import { logAndDetectOtherSpam } from "../util/logAndDetectOtherSpam";
|
||||
|
||||
export const SpamVoiceJoinEvt = spamEvent({
|
||||
export const SpamVoiceJoinEvt = spamEvt({
|
||||
event: "voiceChannelJoin",
|
||||
|
||||
async listener(meta) {
|
||||
|
@ -26,7 +26,7 @@ export const SpamVoiceJoinEvt = spamEvent({
|
|||
},
|
||||
});
|
||||
|
||||
export const SpamVoiceSwitchEvt = spamEvent({
|
||||
export const SpamVoiceSwitchEvt = spamEvt({
|
||||
event: "voiceChannelSwitch",
|
||||
|
||||
async listener(meta) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, eventListener } from "knub";
|
||||
import { tNullable } from "src/utils";
|
||||
import { GuildLogs } from "src/data/GuildLogs";
|
||||
import { GuildArchives } from "src/data/GuildArchives";
|
||||
import { GuildSavedMessages } from "src/data/GuildSavedMessages";
|
||||
import { GuildMutes } from "src/data/GuildMutes";
|
||||
import { BasePluginType, guildEventListener } from "knub";
|
||||
import { tNullable } from "../../utils";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildArchives } from "../../data/GuildArchives";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildMutes } from "../../data/GuildMutes";
|
||||
|
||||
const BaseSingleSpamConfig = t.type({
|
||||
interval: t.number,
|
||||
|
@ -75,4 +75,4 @@ export interface SpamPluginType extends BasePluginType {
|
|||
};
|
||||
}
|
||||
|
||||
export const spamEvent = eventListener<SpamPluginType>();
|
||||
export const spamEvt = guildEventListener<SpamPluginType>();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType, RecentActionType } from "../types";
|
||||
|
||||
export function addRecentAction(
|
||||
pluginData: PluginData<SpamPluginType>,
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
type: RecentActionType,
|
||||
userId: string,
|
||||
actionGroupId: string,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType } from "../types";
|
||||
|
||||
const MAX_INTERVAL = 300;
|
||||
|
||||
export function clearOldRecentActions(pluginData) {
|
||||
export function clearOldRecentActions(pluginData: GuildPluginData<SpamPluginType>) {
|
||||
// TODO: Figure out expiry time from longest interval in the config?
|
||||
const expiryTimestamp = Date.now() - 1000 * MAX_INTERVAL;
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(action => action.timestamp >= expiryTimestamp);
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import { RecentActionType } from "../types";
|
||||
import { RecentActionType, SpamPluginType } from "../types";
|
||||
import { GuildPluginData } from "knub";
|
||||
|
||||
export function clearRecentUserActions(pluginData, type: RecentActionType, userId: string, actionGroupId: string) {
|
||||
export function clearRecentUserActions(
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
type: RecentActionType,
|
||||
userId: string,
|
||||
actionGroupId: string,
|
||||
) {
|
||||
pluginData.state.recentActions = pluginData.state.recentActions.filter(action => {
|
||||
return action.type !== type || action.userId !== userId || action.actionGroupId !== actionGroupId;
|
||||
});
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { RecentActionType } from "../types";
|
||||
import { RecentActionType, SpamPluginType } from "../types";
|
||||
import { GuildPluginData } from "knub";
|
||||
|
||||
export function getRecentActionCount(
|
||||
pluginData,
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
type: RecentActionType,
|
||||
userId: string,
|
||||
actionGroupId: string,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { RecentActionType } from "../types";
|
||||
import { RecentActionType, SpamPluginType } from "../types";
|
||||
import { GuildPluginData } from "knub";
|
||||
|
||||
export function getRecentActions(
|
||||
pluginData,
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
type: RecentActionType,
|
||||
userId: string,
|
||||
actionGroupId: string,
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import { SavedMessage } from "src/data/entities/SavedMessage";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { RecentActionType, SpamPluginType, TBaseSingleSpamConfig } from "../types";
|
||||
import moment from "moment-timezone";
|
||||
import { MuteResult } from "src/plugins/Mutes/types";
|
||||
import { convertDelayStringToMS, DBDateFormat, noop, resolveMember, stripObjectToScalars, trimLines } from "src/utils";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { CaseTypes } from "src/data/CaseTypes";
|
||||
import { logger } from "src/logger";
|
||||
import { PluginData } from "knub";
|
||||
import { MutesPlugin } from "src/plugins/Mutes/MutesPlugin";
|
||||
import { CasesPlugin } from "src/plugins/Cases/CasesPlugin";
|
||||
import { MuteResult } from "../../../plugins/Mutes/types";
|
||||
import {
|
||||
convertDelayStringToMS,
|
||||
DBDateFormat,
|
||||
noop,
|
||||
resolveMember,
|
||||
stripObjectToScalars,
|
||||
trimLines,
|
||||
} from "../../../utils";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { logger } from "../../../logger";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { addRecentAction } from "./addRecentAction";
|
||||
import { getRecentActionCount } from "./getRecentActionCount";
|
||||
import { getRecentActions } from "./getRecentActions";
|
||||
|
@ -18,7 +25,7 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
|
|||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
|
||||
export async function logAndDetectMessageSpam(
|
||||
pluginData: PluginData<SpamPluginType>,
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
savedMessage: SavedMessage,
|
||||
type: RecentActionType,
|
||||
spamConfig: TBaseSingleSpamConfig,
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType, RecentActionType } from "../types";
|
||||
import { addRecentAction } from "./addRecentAction";
|
||||
import { getRecentActionCount } from "./getRecentActionCount";
|
||||
import { resolveMember, convertDelayStringToMS, stripObjectToScalars } from "src/utils";
|
||||
import { MutesPlugin } from "src/plugins/Mutes/MutesPlugin";
|
||||
import { CasesPlugin } from "src/plugins/Cases/CasesPlugin";
|
||||
import { CaseTypes } from "src/data/CaseTypes";
|
||||
import { resolveMember, convertDelayStringToMS, stripObjectToScalars } from "../../../utils";
|
||||
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
|
||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { clearRecentUserActions } from "./clearRecentUserActions";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
export async function logAndDetectOtherSpam(
|
||||
pluginData: PluginData<SpamPluginType>,
|
||||
pluginData: GuildPluginData<SpamPluginType>,
|
||||
type: RecentActionType,
|
||||
spamConfig: any,
|
||||
userId: string,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType, RecentActionType } from "../types";
|
||||
import { SavedMessage } from "src/data/entities/SavedMessage";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { logAndDetectMessageSpam } from "./logAndDetectMessageSpam";
|
||||
|
||||
export async function logCensor(pluginData: PluginData<SpamPluginType>, savedMessage: SavedMessage) {
|
||||
export async function logCensor(pluginData: GuildPluginData<SpamPluginType>, savedMessage: SavedMessage) {
|
||||
const member = pluginData.guild.members.get(savedMessage.user_id);
|
||||
const config = pluginData.config.getMatchingConfig({
|
||||
userId: savedMessage.user_id,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType, RecentActionType } from "../types";
|
||||
import { SavedMessage } from "src/data/entities/SavedMessage";
|
||||
import { getUserMentions, getRoleMentions, getUrlsInString, getEmojiInString } from "src/utils";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import { getUserMentions, getRoleMentions, getUrlsInString, getEmojiInString } from "../../../utils";
|
||||
import { logAndDetectMessageSpam } from "./logAndDetectMessageSpam";
|
||||
|
||||
export async function onMessageCreate(pluginData: PluginData<SpamPluginType>, savedMessage: SavedMessage) {
|
||||
export async function onMessageCreate(pluginData: GuildPluginData<SpamPluginType>, savedMessage: SavedMessage) {
|
||||
if (savedMessage.is_bot) return;
|
||||
|
||||
const member = pluginData.guild.members.get(savedMessage.user_id);
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { SavedMessage } from "src/data/entities/SavedMessage";
|
||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||
import moment from "moment-timezone";
|
||||
import { getBaseUrl } from "src/pluginUtils";
|
||||
import { getBaseUrl } from "../../../pluginUtils";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { SpamPluginType } from "../types";
|
||||
|
||||
const SPAM_ARCHIVE_EXPIRY_DAYS = 90;
|
||||
|
||||
export async function saveSpamArchives(pluginData, savedMessages: SavedMessage[]) {
|
||||
export async function saveSpamArchives(pluginData: GuildPluginData<SpamPluginType>, savedMessages: SavedMessage[]) {
|
||||
const expiresAt = moment.utc().add(SPAM_ARCHIVE_EXPIRY_DAYS, "days");
|
||||
const archiveId = await pluginData.state.archives.createFromSavedMessages(savedMessages, pluginData.guild, expiresAt);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue