From fe62ee88cda050e19074c98efe11ea3b7087f1a7 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Sat, 9 Jul 2022 09:45:15 +0200 Subject: [PATCH] start moving types into shared library --- bot/src/bot/commands/configuration/login.ts | 2 +- bot/src/bot/commands/configuration/whitelist.ts | 2 +- bot/src/bot/commands/moderation/ban.ts | 4 ++-- bot/src/bot/commands/moderation/kick.ts | 4 ++-- bot/src/bot/commands/moderation/warn.ts | 4 ++-- bot/src/bot/commands/moderation/warns.ts | 6 +++--- bot/src/bot/modules/antispam.ts | 8 ++++---- bot/src/bot/modules/api/server_details.ts | 2 +- bot/src/bot/modules/api_communication.ts | 2 +- .../bot/modules/custom_rules/actions/delete.ts | 2 +- .../modules/custom_rules/actions/sendMessage.ts | 2 +- bot/src/bot/modules/custom_rules/actions/warn.ts | 6 +++--- .../custom_rules/message_content_trigger.ts | 2 +- bot/src/bot/modules/event_handler.ts | 4 ++-- bot/src/bot/modules/mod_logs.ts | 4 +--- bot/src/bot/modules/tempbans.ts | 2 +- bot/src/bot/util.ts | 8 ++++---- bot/src/index.ts | 16 ++++++++-------- bot/src/struct/commands/SimpleCommand.ts | 2 +- {bot/src/struct => lib/types}/BridgeConfig.ts | 0 {bot/src/struct => lib/types}/BridgeRequest.ts | 0 {bot/src/struct => lib/types}/BridgedMessage.ts | 0 {bot/src/struct => lib/types}/DbUser.ts | 0 {bot/src/struct => lib/types}/LogConfig.ts | 0 {bot/src/struct => lib/types}/LogMessage.ts | 0 {bot/src/struct => lib/types}/PendingLogin.ts | 0 {bot/src/struct => lib/types}/ServerConfig.ts | 0 {bot/src/struct => lib/types}/TempBan.ts | 0 .../types}/antispam/AntispamRule.ts | 0 .../types}/antispam/AutomodSettings.ts | 0 .../struct => lib/types}/antispam/CustomRule.ts | 0 .../types}/antispam/CustomRuleAction.ts | 0 .../types}/antispam/CustomRuleTrigger.ts | 0 .../struct => lib/types}/antispam/Infraction.ts | 0 .../types}/antispam/InfractionType.ts | 0 .../types}/antispam/ModerationAction.ts | 0 36 files changed, 40 insertions(+), 42 deletions(-) rename {bot/src/struct => lib/types}/BridgeConfig.ts (100%) rename {bot/src/struct => lib/types}/BridgeRequest.ts (100%) rename {bot/src/struct => lib/types}/BridgedMessage.ts (100%) rename {bot/src/struct => lib/types}/DbUser.ts (100%) rename {bot/src/struct => lib/types}/LogConfig.ts (100%) rename {bot/src/struct => lib/types}/LogMessage.ts (100%) rename {bot/src/struct => lib/types}/PendingLogin.ts (100%) rename {bot/src/struct => lib/types}/ServerConfig.ts (100%) rename {bot/src/struct => lib/types}/TempBan.ts (100%) rename {bot/src/struct => lib/types}/antispam/AntispamRule.ts (100%) rename {bot/src/struct => lib/types}/antispam/AutomodSettings.ts (100%) rename {bot/src/struct => lib/types}/antispam/CustomRule.ts (100%) rename {bot/src/struct => lib/types}/antispam/CustomRuleAction.ts (100%) rename {bot/src/struct => lib/types}/antispam/CustomRuleTrigger.ts (100%) rename {bot/src/struct => lib/types}/antispam/Infraction.ts (100%) rename {bot/src/struct => lib/types}/antispam/InfractionType.ts (100%) rename {bot/src/struct => lib/types}/antispam/ModerationAction.ts (100%) diff --git a/bot/src/bot/commands/configuration/login.ts b/bot/src/bot/commands/configuration/login.ts index 0d9cccf..cf896a7 100644 --- a/bot/src/bot/commands/configuration/login.ts +++ b/bot/src/bot/commands/configuration/login.ts @@ -3,7 +3,7 @@ import { client, dbs } from "../../.."; import CommandCategory from "../../../struct/commands/CommandCategory"; import SimpleCommand from "../../../struct/commands/SimpleCommand"; import MessageCommandContext from "../../../struct/MessageCommandContext"; -import PendingLogin from "../../../struct/PendingLogin"; +import PendingLogin from "automod/types/PendingLogin"; import logger from "../../logger"; import { DEFAULT_PREFIX } from "../../modules/command_handler"; diff --git a/bot/src/bot/commands/configuration/whitelist.ts b/bot/src/bot/commands/configuration/whitelist.ts index 8bff1c4..96f679c 100644 --- a/bot/src/bot/commands/configuration/whitelist.ts +++ b/bot/src/bot/commands/configuration/whitelist.ts @@ -3,7 +3,7 @@ import { client, dbs } from "../../.."; import CommandCategory from "../../../struct/commands/CommandCategory"; import SimpleCommand from "../../../struct/commands/SimpleCommand"; import MessageCommandContext from "../../../struct/MessageCommandContext"; -import ServerConfig from "../../../struct/ServerConfig"; +import ServerConfig from "automod/types/ServerConfig"; import { isBotManager, NO_MANAGER_MSG, parseUser } from "../../util"; const SYNTAX = '/whitelist add @user; /whitelist remove @user; /whitelist list'; diff --git a/bot/src/bot/commands/moderation/ban.ts b/bot/src/bot/commands/moderation/ban.ts index 9f54936..2d59b2a 100644 --- a/bot/src/bot/commands/moderation/ban.ts +++ b/bot/src/bot/commands/moderation/ban.ts @@ -1,7 +1,7 @@ import { ulid } from "ulid"; import { client } from "../../../index"; -import Infraction from "../../../struct/antispam/Infraction"; -import InfractionType from "../../../struct/antispam/InfractionType"; +import Infraction from "automod/types/antispam/Infraction"; +import InfractionType from "automod/types/antispam/InfractionType"; import SimpleCommand from "../../../struct/commands/SimpleCommand"; import { fetchUsername, logModAction } from "../../modules/mod_logs"; import { storeTempBan } from "../../modules/tempbans"; diff --git a/bot/src/bot/commands/moderation/kick.ts b/bot/src/bot/commands/moderation/kick.ts index 8dc9b62..7318b6e 100644 --- a/bot/src/bot/commands/moderation/kick.ts +++ b/bot/src/bot/commands/moderation/kick.ts @@ -2,8 +2,8 @@ import { User } from "@janderedev/revolt.js"; import { SendableEmbed } from "revolt-api"; import { ulid } from "ulid"; import { client } from "../../../"; -import Infraction from "../../../struct/antispam/Infraction"; -import InfractionType from "../../../struct/antispam/InfractionType"; +import Infraction from "automod/types/antispam/Infraction"; +import InfractionType from "automod/types/antispam/InfractionType"; import CommandCategory from "../../../struct/commands/CommandCategory"; import SimpleCommand from "../../../struct/commands/SimpleCommand"; import logger from "../../logger"; diff --git a/bot/src/bot/commands/moderation/warn.ts b/bot/src/bot/commands/moderation/warn.ts index 2eeccf3..07a35e0 100644 --- a/bot/src/bot/commands/moderation/warn.ts +++ b/bot/src/bot/commands/moderation/warn.ts @@ -1,8 +1,8 @@ import SimpleCommand from "../../../struct/commands/SimpleCommand"; import { dedupeArray, embed, EmbedColor, generateInfractionDMEmbed, getDmChannel, isModerator, NO_MANAGER_MSG, parseUserOrId, sanitizeMessageContent, storeInfraction } from "../../util"; -import Infraction from "../../../struct/antispam/Infraction"; +import Infraction from "automod/types/antispam/Infraction"; import { ulid } from "ulid"; -import InfractionType from "../../../struct/antispam/InfractionType"; +import InfractionType from "automod/types/antispam/InfractionType"; import { fetchUsername, logModAction } from "../../modules/mod_logs"; import CommandCategory from "../../../struct/commands/CommandCategory"; import { SendableEmbed } from "revolt-api"; diff --git a/bot/src/bot/commands/moderation/warns.ts b/bot/src/bot/commands/moderation/warns.ts index 2e16a8a..bed65eb 100644 --- a/bot/src/bot/commands/moderation/warns.ts +++ b/bot/src/bot/commands/moderation/warns.ts @@ -1,7 +1,7 @@ import SimpleCommand from "../../../struct/commands/SimpleCommand"; -import { client, dbs } from "../../.."; -import Infraction from "../../../struct/antispam/Infraction"; -import InfractionType from "../../../struct/antispam/InfractionType"; +import { dbs } from "../../.."; +import Infraction from "automod/types/antispam/Infraction"; +import InfractionType from "automod/types/antispam/InfractionType"; import { isModerator, NO_MANAGER_MSG, parseUserOrId, uploadFile } from "../../util"; import Day from 'dayjs'; import RelativeTime from 'dayjs/plugin/relativeTime'; diff --git a/bot/src/bot/modules/antispam.ts b/bot/src/bot/modules/antispam.ts index 5cc5956..edc35b4 100644 --- a/bot/src/bot/modules/antispam.ts +++ b/bot/src/bot/modules/antispam.ts @@ -1,10 +1,10 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; import { ulid } from "ulid"; import { dbs } from "../.."; -import AntispamRule from "../../struct/antispam/AntispamRule"; -import Infraction from "../../struct/antispam/Infraction"; -import InfractionType from "../../struct/antispam/InfractionType"; -import ModerationAction from "../../struct/antispam/ModerationAction"; +import AntispamRule from "automod/types/antispam/AntispamRule"; +import Infraction from "automod/types/antispam/Infraction"; +import InfractionType from "automod/types/antispam/InfractionType"; +import ModerationAction from "automod/types/antispam/ModerationAction"; import logger from "../logger"; import { isModerator, storeInfraction } from "../util"; diff --git a/bot/src/bot/modules/api/server_details.ts b/bot/src/bot/modules/api/server_details.ts index 297fb8a..229308b 100644 --- a/bot/src/bot/modules/api/server_details.ts +++ b/bot/src/bot/modules/api/server_details.ts @@ -1,7 +1,7 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import { User } from "@janderedev/revolt.js/dist/maps/Users"; import { client, dbs } from "../../.."; -import ServerConfig from "../../../struct/ServerConfig"; +import ServerConfig from "automod/types/ServerConfig"; import { getPermissionLevel } from "../../util"; import { wsEvents, WSResponse } from "../api_communication"; diff --git a/bot/src/bot/modules/api_communication.ts b/bot/src/bot/modules/api_communication.ts index 5cf3531..86885a4 100644 --- a/bot/src/bot/modules/api_communication.ts +++ b/bot/src/bot/modules/api_communication.ts @@ -8,7 +8,7 @@ import crypto from 'crypto'; import { client as bot, dbs } from '../..'; import { EventEmitter } from "events"; import { parseUser } from "../util"; -import PendingLogin from "../../struct/PendingLogin"; +import PendingLogin from "automod/types/PendingLogin"; import { ulid } from "ulid"; const wsEvents = new EventEmitter(); diff --git a/bot/src/bot/modules/custom_rules/actions/delete.ts b/bot/src/bot/modules/custom_rules/actions/delete.ts index ea065aa..75c1ceb 100644 --- a/bot/src/bot/modules/custom_rules/actions/delete.ts +++ b/bot/src/bot/modules/custom_rules/actions/delete.ts @@ -1,5 +1,5 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; -import CustomRuleAction from "../../../../struct/antispam/CustomRuleAction"; +import CustomRuleAction from "automod/types/antispam/CustomRuleAction"; async function execute(message: Message, action: CustomRuleAction) { setTimeout(() => message.delete().catch(console.warn), (action.duration ?? 0) * 1000); diff --git a/bot/src/bot/modules/custom_rules/actions/sendMessage.ts b/bot/src/bot/modules/custom_rules/actions/sendMessage.ts index b1172cf..d30333a 100644 --- a/bot/src/bot/modules/custom_rules/actions/sendMessage.ts +++ b/bot/src/bot/modules/custom_rules/actions/sendMessage.ts @@ -1,6 +1,6 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; import { client } from "../../../.."; -import CustomRuleAction from "../../../../struct/antispam/CustomRuleAction"; +import CustomRuleAction from "automod/types/antispam/CustomRuleAction"; async function execute(message: Message, action: CustomRuleAction) { let text = action.text || "Error: No text specified for `sendMessage` action"; diff --git a/bot/src/bot/modules/custom_rules/actions/warn.ts b/bot/src/bot/modules/custom_rules/actions/warn.ts index 56fa028..0d5e6b5 100644 --- a/bot/src/bot/modules/custom_rules/actions/warn.ts +++ b/bot/src/bot/modules/custom_rules/actions/warn.ts @@ -1,9 +1,9 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; -import CustomRuleAction from "../../../../struct/antispam/CustomRuleAction"; +import CustomRuleAction from "automod/types/antispam/CustomRuleAction"; import { storeInfraction } from '../../../util'; -import Infraction from "../../../../struct/antispam/Infraction"; +import Infraction from "automod/types/antispam/Infraction"; import { ulid } from "ulid"; -import InfractionType from "../../../../struct/antispam/InfractionType"; +import InfractionType from "automod/types/antispam/InfractionType"; async function execute(message: Message, action: CustomRuleAction) { let warnMsg = action.text diff --git a/bot/src/bot/modules/custom_rules/message_content_trigger.ts b/bot/src/bot/modules/custom_rules/message_content_trigger.ts index 5bf5c9d..d4d8ff7 100644 --- a/bot/src/bot/modules/custom_rules/message_content_trigger.ts +++ b/bot/src/bot/modules/custom_rules/message_content_trigger.ts @@ -1,6 +1,6 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; import { client } from "../../.."; -import CustomRuleTrigger from "../../../struct/antispam/CustomRuleTrigger"; +import CustomRuleTrigger from "automod/types/antispam/CustomRuleTrigger"; import VM from 'vm'; let ruleTimeouts: Map = new Map(); diff --git a/bot/src/bot/modules/event_handler.ts b/bot/src/bot/modules/event_handler.ts index 3d3c110..200c249 100644 --- a/bot/src/bot/modules/event_handler.ts +++ b/bot/src/bot/modules/event_handler.ts @@ -1,8 +1,8 @@ import { ulid } from "ulid"; import crypto from "crypto"; import { client, dbs } from "../.."; -import Infraction from "../../struct/antispam/Infraction"; -import InfractionType from "../../struct/antispam/InfractionType"; +import Infraction from "automod/types/antispam/Infraction"; +import InfractionType from "automod/types/antispam/InfractionType"; import { BLACKLIST_BAN_REASON, BLACKLIST_MESSAGE } from "../commands/admin/botadm"; import logger from "../logger"; import { hasPermForChannel, storeInfraction } from "../util"; diff --git a/bot/src/bot/modules/mod_logs.ts b/bot/src/bot/modules/mod_logs.ts index 3b5b3ea..d2a58ed 100644 --- a/bot/src/bot/modules/mod_logs.ts +++ b/bot/src/bot/modules/mod_logs.ts @@ -1,9 +1,7 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import { Server } from "@janderedev/revolt.js/dist/maps/Servers"; import { client, dbs } from "../.."; -import Infraction from "../../struct/antispam/Infraction"; -import LogMessage from "../../struct/LogMessage"; -import ServerConfig from "../../struct/ServerConfig"; +import LogMessage from "automod/types/LogMessage"; import logger from "../logger"; import { getAutumnURL, sanitizeMessageContent, sendLogMessage } from "../util"; diff --git a/bot/src/bot/modules/tempbans.ts b/bot/src/bot/modules/tempbans.ts index 3401d68..a458990 100644 --- a/bot/src/bot/modules/tempbans.ts +++ b/bot/src/bot/modules/tempbans.ts @@ -1,6 +1,6 @@ import { FindResult } from "monk"; import { client, dbs } from "../.."; -import TempBan from "../../struct/TempBan"; +import TempBan from "automod/types/TempBan"; import logger from "../logger"; // Array of ban IDs which should not get processed in this session diff --git a/bot/src/bot/util.ts b/bot/src/bot/util.ts index 01421d3..5aa2ed2 100644 --- a/bot/src/bot/util.ts +++ b/bot/src/bot/util.ts @@ -1,12 +1,12 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import { User } from "@janderedev/revolt.js/dist/maps/Users"; import { client, dbs } from ".."; -import Infraction from "../struct/antispam/Infraction"; +import Infraction from "automod/types/antispam/Infraction"; import FormData from 'form-data'; import axios from 'axios'; import { Server } from "@janderedev/revolt.js/dist/maps/Servers"; -import LogConfig from "../struct/LogConfig"; -import LogMessage from "../struct/LogMessage"; +import LogConfig from "automod/types/LogConfig"; +import LogMessage from "automod/types/LogMessage"; import { ColorResolvable, MessageEmbed } from "discord.js"; import logger from "./logger"; import { ulid } from "ulid"; @@ -16,7 +16,7 @@ import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; import { isSudo } from "./commands/admin/botadm"; import { SendableEmbed } from "revolt-api"; import MessageCommandContext from "../struct/MessageCommandContext"; -import ServerConfig from "../struct/ServerConfig"; +import ServerConfig from "automod/types/ServerConfig"; const NO_MANAGER_MSG = '🔒 Missing permission'; const ULID_REGEX = /^[0-9A-HJ-KM-NP-TV-Z]{26}$/i; diff --git a/bot/src/index.ts b/bot/src/index.ts index 08da4a2..c5ab13a 100644 --- a/bot/src/index.ts +++ b/bot/src/index.ts @@ -4,15 +4,15 @@ config(); import logger from './bot/logger'; import AutomodClient, { login } from './struct/AutomodClient'; import MongoDB from './bot/db'; -import DbUser from './struct/DbUser'; -import ServerConfig from './struct/ServerConfig'; -import Infraction from './struct/antispam/Infraction'; -import PendingLogin from './struct/PendingLogin'; -import TempBan from './struct/TempBan'; +import DbUser from 'automod/types/DbUser'; +import ServerConfig from 'automod/types/ServerConfig'; +import Infraction from 'automod/types/antispam/Infraction'; +import PendingLogin from 'automod/types/PendingLogin'; +import TempBan from 'automod/types/TempBan'; import { VoteEntry } from './bot/commands/moderation/votekick'; -import BridgeRequest from './struct/BridgeRequest'; -import BridgeConfig from './struct/BridgeConfig'; -import BridgedMessage from './struct/BridgedMessage'; +import BridgeRequest from 'automod/types/BridgeRequest'; +import BridgeConfig from 'automod/types/BridgeConfig'; +import BridgedMessage from 'automod/types/BridgedMessage'; logger.info('Initializing client'); diff --git a/bot/src/struct/commands/SimpleCommand.ts b/bot/src/struct/commands/SimpleCommand.ts index f042bd7..f562f41 100644 --- a/bot/src/struct/commands/SimpleCommand.ts +++ b/bot/src/struct/commands/SimpleCommand.ts @@ -1,6 +1,6 @@ import CommandCategory from "./CommandCategory"; import MessageCommandContext from "../MessageCommandContext"; -import ServerConfig from "../ServerConfig"; +import ServerConfig from "automod/types/ServerConfig"; /** * A basic command, consisting of basic attributes diff --git a/bot/src/struct/BridgeConfig.ts b/lib/types/BridgeConfig.ts similarity index 100% rename from bot/src/struct/BridgeConfig.ts rename to lib/types/BridgeConfig.ts diff --git a/bot/src/struct/BridgeRequest.ts b/lib/types/BridgeRequest.ts similarity index 100% rename from bot/src/struct/BridgeRequest.ts rename to lib/types/BridgeRequest.ts diff --git a/bot/src/struct/BridgedMessage.ts b/lib/types/BridgedMessage.ts similarity index 100% rename from bot/src/struct/BridgedMessage.ts rename to lib/types/BridgedMessage.ts diff --git a/bot/src/struct/DbUser.ts b/lib/types/DbUser.ts similarity index 100% rename from bot/src/struct/DbUser.ts rename to lib/types/DbUser.ts diff --git a/bot/src/struct/LogConfig.ts b/lib/types/LogConfig.ts similarity index 100% rename from bot/src/struct/LogConfig.ts rename to lib/types/LogConfig.ts diff --git a/bot/src/struct/LogMessage.ts b/lib/types/LogMessage.ts similarity index 100% rename from bot/src/struct/LogMessage.ts rename to lib/types/LogMessage.ts diff --git a/bot/src/struct/PendingLogin.ts b/lib/types/PendingLogin.ts similarity index 100% rename from bot/src/struct/PendingLogin.ts rename to lib/types/PendingLogin.ts diff --git a/bot/src/struct/ServerConfig.ts b/lib/types/ServerConfig.ts similarity index 100% rename from bot/src/struct/ServerConfig.ts rename to lib/types/ServerConfig.ts diff --git a/bot/src/struct/TempBan.ts b/lib/types/TempBan.ts similarity index 100% rename from bot/src/struct/TempBan.ts rename to lib/types/TempBan.ts diff --git a/bot/src/struct/antispam/AntispamRule.ts b/lib/types/antispam/AntispamRule.ts similarity index 100% rename from bot/src/struct/antispam/AntispamRule.ts rename to lib/types/antispam/AntispamRule.ts diff --git a/bot/src/struct/antispam/AutomodSettings.ts b/lib/types/antispam/AutomodSettings.ts similarity index 100% rename from bot/src/struct/antispam/AutomodSettings.ts rename to lib/types/antispam/AutomodSettings.ts diff --git a/bot/src/struct/antispam/CustomRule.ts b/lib/types/antispam/CustomRule.ts similarity index 100% rename from bot/src/struct/antispam/CustomRule.ts rename to lib/types/antispam/CustomRule.ts diff --git a/bot/src/struct/antispam/CustomRuleAction.ts b/lib/types/antispam/CustomRuleAction.ts similarity index 100% rename from bot/src/struct/antispam/CustomRuleAction.ts rename to lib/types/antispam/CustomRuleAction.ts diff --git a/bot/src/struct/antispam/CustomRuleTrigger.ts b/lib/types/antispam/CustomRuleTrigger.ts similarity index 100% rename from bot/src/struct/antispam/CustomRuleTrigger.ts rename to lib/types/antispam/CustomRuleTrigger.ts diff --git a/bot/src/struct/antispam/Infraction.ts b/lib/types/antispam/Infraction.ts similarity index 100% rename from bot/src/struct/antispam/Infraction.ts rename to lib/types/antispam/Infraction.ts diff --git a/bot/src/struct/antispam/InfractionType.ts b/lib/types/antispam/InfractionType.ts similarity index 100% rename from bot/src/struct/antispam/InfractionType.ts rename to lib/types/antispam/InfractionType.ts diff --git a/bot/src/struct/antispam/ModerationAction.ts b/lib/types/antispam/ModerationAction.ts similarity index 100% rename from bot/src/struct/antispam/ModerationAction.ts rename to lib/types/antispam/ModerationAction.ts