From ecef27f1e6c320df0b8974ed6d51a655b51a12de Mon Sep 17 00:00:00 2001 From: janderedev Date: Tue, 3 May 2022 14:52:07 +0200 Subject: [PATCH] restructure commands --- bot/src/bot/commands/{ => admin}/botadm.ts | 17 +++++++------- bot/src/bot/commands/{ => admin}/eval.ts | 8 +++---- .../bot/commands/{ => admin}/shell_eval.ts | 7 +++--- .../{ => configuration}/bot_managers.ts | 11 +++++----- .../commands/{ => configuration}/botctl.ts | 14 ++++++------ .../commands/{ => configuration}/bridge.ts | 12 +++++----- .../bot/commands/{ => configuration}/login.ts | 14 ++++++------ .../commands/{ => configuration}/logout.ts | 12 +++++----- .../commands/{ => configuration}/moderator.ts | 12 +++++----- .../commands/{ => configuration}/prefix.ts | 13 +++++------ .../commands/{ => configuration}/settings.ts | 6 ++--- .../commands/{ => configuration}/whitelist.ts | 12 +++++----- bot/src/bot/commands/{ => misc}/avatar.ts | 8 +++---- bot/src/bot/commands/{ => misc}/debug.ts | 8 +++---- bot/src/bot/commands/{ => misc}/help.ts | 8 +++---- bot/src/bot/commands/{ => misc}/ping.ts | 9 ++++---- bot/src/bot/commands/{ => misc}/test.ts | 6 ++--- bot/src/bot/commands/{ => moderation}/ban.ts | 20 ++++++++--------- bot/src/bot/commands/{ => moderation}/kick.ts | 16 +++++++------- bot/src/bot/commands/{ => moderation}/nick.ts | 8 +++---- .../bot/commands/{ => moderation}/purge.ts | 8 +++---- .../bot/commands/{ => moderation}/unban.ts | 14 +++++------- .../bot/commands/{ => moderation}/votekick.ts | 15 ++++++------- bot/src/bot/commands/{ => moderation}/warn.ts | 14 ++++++------ .../bot/commands/{ => moderation}/warns.ts | 16 +++++++------- bot/src/bot/modules/command_handler.ts | 22 +++++++++++++++---- bot/src/bot/modules/event_handler.ts | 3 +-- bot/src/bot/util.ts | 2 +- bot/src/index.ts | 2 +- 29 files changed, 158 insertions(+), 159 deletions(-) rename bot/src/bot/commands/{ => admin}/botadm.ts (95%) rename bot/src/bot/commands/{ => admin}/eval.ts (84%) rename bot/src/bot/commands/{ => admin}/shell_eval.ts (82%) rename bot/src/bot/commands/{ => configuration}/bot_managers.ts (88%) rename bot/src/bot/commands/{ => configuration}/botctl.ts (88%) rename bot/src/bot/commands/{ => configuration}/bridge.ts (96%) rename bot/src/bot/commands/{ => configuration}/login.ts (86%) rename bot/src/bot/commands/{ => configuration}/logout.ts (84%) rename bot/src/bot/commands/{ => configuration}/moderator.ts (85%) rename bot/src/bot/commands/{ => configuration}/prefix.ts (86%) rename bot/src/bot/commands/{ => configuration}/settings.ts (66%) rename bot/src/bot/commands/{ => configuration}/whitelist.ts (93%) rename bot/src/bot/commands/{ => misc}/avatar.ts (91%) rename bot/src/bot/commands/{ => misc}/debug.ts (91%) rename bot/src/bot/commands/{ => misc}/help.ts (94%) rename bot/src/bot/commands/{ => misc}/ping.ts (66%) rename bot/src/bot/commands/{ => misc}/test.ts (74%) rename bot/src/bot/commands/{ => moderation}/ban.ts (89%) rename bot/src/bot/commands/{ => moderation}/kick.ts (84%) rename bot/src/bot/commands/{ => moderation}/nick.ts (90%) rename bot/src/bot/commands/{ => moderation}/purge.ts (93%) rename bot/src/bot/commands/{ => moderation}/unban.ts (87%) rename bot/src/bot/commands/{ => moderation}/votekick.ts (91%) rename bot/src/bot/commands/{ => moderation}/warn.ts (91%) rename bot/src/bot/commands/{ => moderation}/warns.ts (93%) diff --git a/bot/src/bot/commands/botadm.ts b/bot/src/bot/commands/admin/botadm.ts similarity index 95% rename from bot/src/bot/commands/botadm.ts rename to bot/src/bot/commands/admin/botadm.ts index f2dce12..03eda96 100644 --- a/bot/src/bot/commands/botadm.ts +++ b/bot/src/bot/commands/admin/botadm.ts @@ -1,16 +1,15 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { client, dbs } from "../.."; -import { commands, DEFAULT_PREFIX, ownerIDs } from "../modules/command_handler"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { client, dbs } from "../../.."; +import { commands, DEFAULT_PREFIX, ownerIDs } from "../../modules/command_handler"; import child_process from 'child_process'; import fs from 'fs'; import path from 'path'; -import { wordlist } from "../modules/user_scan"; +import { wordlist } from "../../modules/user_scan"; import { User } from "@janderedev/revolt.js/dist/maps/Users"; -import { adminBotLog } from "../logging"; -import CommandCategory from "../../struct/commands/CommandCategory"; -import { parseUserOrId } from "../util"; -import { Permission } from "@janderedev/revolt.js/dist/permissions/definitions"; +import { adminBotLog } from "../../logging"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import { parseUserOrId } from "../../util"; const BLACKLIST_BAN_REASON = `This user is globally blacklisted and has been banned automatically. If you wish to opt out of the global blacklist, run '/botctl ignore_blacklist yes'.`; const BLACKLIST_MESSAGE = (username: string) => `\`@${username}\` has been banned automatically. Check the ban reason for more info.`; diff --git a/bot/src/bot/commands/eval.ts b/bot/src/bot/commands/admin/eval.ts similarity index 84% rename from bot/src/bot/commands/eval.ts rename to bot/src/bot/commands/admin/eval.ts index bf6ca76..537fb1f 100644 --- a/bot/src/bot/commands/eval.ts +++ b/bot/src/bot/commands/admin/eval.ts @@ -1,9 +1,7 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; import { inspect } from 'util'; -import { client } from "../.."; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; export default { name: 'eval', diff --git a/bot/src/bot/commands/shell_eval.ts b/bot/src/bot/commands/admin/shell_eval.ts similarity index 82% rename from bot/src/bot/commands/shell_eval.ts rename to bot/src/bot/commands/admin/shell_eval.ts index 7efb4ef..5427449 100644 --- a/bot/src/bot/commands/shell_eval.ts +++ b/bot/src/bot/commands/admin/shell_eval.ts @@ -1,8 +1,7 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; import { exec } from 'child_process'; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; export default { name: 'shell', diff --git a/bot/src/bot/commands/bot_managers.ts b/bot/src/bot/commands/configuration/bot_managers.ts similarity index 88% rename from bot/src/bot/commands/bot_managers.ts rename to bot/src/bot/commands/configuration/bot_managers.ts index c483444..2bf6e7f 100644 --- a/bot/src/bot/commands/bot_managers.ts +++ b/bot/src/bot/commands/configuration/bot_managers.ts @@ -1,10 +1,9 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { hasPerm, parseUser } from "../util"; -import ServerConfig from "../../struct/ServerConfig"; -import { client, dbs } from "../.."; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { hasPerm, parseUser } from "../../util"; +import { client, dbs } from "../../.."; import { User } from "@janderedev/revolt.js/dist/maps/Users"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; const SYNTAX = '/admin add @user; /admin remove @user; /admin list'; diff --git a/bot/src/bot/commands/botctl.ts b/bot/src/bot/commands/configuration/botctl.ts similarity index 88% rename from bot/src/bot/commands/botctl.ts rename to bot/src/bot/commands/configuration/botctl.ts index 8905128..d764eb0 100644 --- a/bot/src/bot/commands/botctl.ts +++ b/bot/src/bot/commands/configuration/botctl.ts @@ -1,11 +1,11 @@ import { FindOneResult } from "monk"; -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 { scanServer } from "../modules/user_scan"; -import { isBotManager, NO_MANAGER_MSG } from "../util"; +import { 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 { scanServer } from "../../modules/user_scan"; +import { isBotManager, NO_MANAGER_MSG } from "../../util"; let userscans: string[] = []; diff --git a/bot/src/bot/commands/bridge.ts b/bot/src/bot/commands/configuration/bridge.ts similarity index 96% rename from bot/src/bot/commands/bridge.ts rename to bot/src/bot/commands/configuration/bridge.ts index 8195472..81af2b2 100644 --- a/bot/src/bot/commands/bridge.ts +++ b/bot/src/bot/commands/configuration/bridge.ts @@ -1,12 +1,12 @@ import { Message } from "@janderedev/revolt.js"; import { ulid } from "ulid"; import { SendableEmbed } from "revolt-api"; -import { dbs } from "../.."; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { DEFAULT_PREFIX } from "../modules/command_handler"; -import { isBotManager, isModerator, NO_MANAGER_MSG } from "../util"; +import { dbs } from "../../.."; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { DEFAULT_PREFIX } from "../../modules/command_handler"; +import { isBotManager, isModerator, NO_MANAGER_MSG } from "../../util"; const DISCORD_INVITE_URL = 'https://discord.com/api/oauth2/authorize?client_id=965692929643524136&permissions=536996864&scope=bot%20applications.commands'; // todo: read this from env or smth diff --git a/bot/src/bot/commands/login.ts b/bot/src/bot/commands/configuration/login.ts similarity index 86% rename from bot/src/bot/commands/login.ts rename to bot/src/bot/commands/configuration/login.ts index 9cd8e29..0d9cccf 100644 --- a/bot/src/bot/commands/login.ts +++ b/bot/src/bot/commands/configuration/login.ts @@ -1,11 +1,11 @@ import { FindOneResult } from "monk"; -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 logger from "../logger"; -import { DEFAULT_PREFIX } from "../modules/command_handler"; +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 logger from "../../logger"; +import { DEFAULT_PREFIX } from "../../modules/command_handler"; export default { name: 'login', diff --git a/bot/src/bot/commands/logout.ts b/bot/src/bot/commands/configuration/logout.ts similarity index 84% rename from bot/src/bot/commands/logout.ts rename to bot/src/bot/commands/configuration/logout.ts index 4f5bebb..7341bfc 100644 --- a/bot/src/bot/commands/logout.ts +++ b/bot/src/bot/commands/configuration/logout.ts @@ -1,10 +1,8 @@ -import { FindOneResult, FindResult } from "monk"; -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 { DEFAULT_PREFIX } from "../modules/command_handler"; +import { dbs } from "../../.."; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { DEFAULT_PREFIX } from "../../modules/command_handler"; export default { name: 'logout', diff --git a/bot/src/bot/commands/moderator.ts b/bot/src/bot/commands/configuration/moderator.ts similarity index 85% rename from bot/src/bot/commands/moderator.ts rename to bot/src/bot/commands/configuration/moderator.ts index 2a4702c..f92bf4d 100644 --- a/bot/src/bot/commands/moderator.ts +++ b/bot/src/bot/commands/configuration/moderator.ts @@ -1,11 +1,9 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; -import { isBotManager, NO_MANAGER_MSG, parseUser } from "../util"; -import ServerConfig from "../../struct/ServerConfig"; -import { client, dbs } from "../.."; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { isBotManager, NO_MANAGER_MSG, parseUser } from "../../util"; +import { client, dbs } from "../../.."; import { User } from "@janderedev/revolt.js/dist/maps/Users"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; const SYNTAX = '/mod add @user; /mod remove @user; /mod list'; diff --git a/bot/src/bot/commands/prefix.ts b/bot/src/bot/commands/configuration/prefix.ts similarity index 86% rename from bot/src/bot/commands/prefix.ts rename to bot/src/bot/commands/configuration/prefix.ts index 665f11d..a088413 100644 --- a/bot/src/bot/commands/prefix.ts +++ b/bot/src/bot/commands/configuration/prefix.ts @@ -1,10 +1,9 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { client, dbs } from "../.."; -import ServerConfig from "../../struct/ServerConfig"; -import { DEFAULT_PREFIX } from "../modules/command_handler"; -import { isBotManager, NO_MANAGER_MSG } from "../util"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { client, dbs } from "../../.."; +import { DEFAULT_PREFIX } from "../../modules/command_handler"; +import { isBotManager, NO_MANAGER_MSG } from "../../util"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; const SYNTAX = '/prefix set [new prefix]; /prefix get; prefix clear'; const MENTION_TEXT = 'You can also @mention me instead of using the prefix.'; diff --git a/bot/src/bot/commands/settings.ts b/bot/src/bot/commands/configuration/settings.ts similarity index 66% rename from bot/src/bot/commands/settings.ts rename to bot/src/bot/commands/configuration/settings.ts index 4d0af53..b3da7b0 100644 --- a/bot/src/bot/commands/settings.ts +++ b/bot/src/bot/commands/configuration/settings.ts @@ -1,6 +1,6 @@ -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; export default { name: 'settings', diff --git a/bot/src/bot/commands/whitelist.ts b/bot/src/bot/commands/configuration/whitelist.ts similarity index 93% rename from bot/src/bot/commands/whitelist.ts rename to bot/src/bot/commands/configuration/whitelist.ts index 5c6be4f..8bff1c4 100644 --- a/bot/src/bot/commands/whitelist.ts +++ b/bot/src/bot/commands/configuration/whitelist.ts @@ -1,10 +1,10 @@ import { User } from "@janderedev/revolt.js/dist/maps/Users"; -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 { isBotManager, NO_MANAGER_MSG, parseUser } from "../util"; +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 { isBotManager, NO_MANAGER_MSG, parseUser } from "../../util"; const SYNTAX = '/whitelist add @user; /whitelist remove @user; /whitelist list'; diff --git a/bot/src/bot/commands/avatar.ts b/bot/src/bot/commands/misc/avatar.ts similarity index 91% rename from bot/src/bot/commands/avatar.ts rename to bot/src/bot/commands/misc/avatar.ts index c96b1ea..4c7e4ac 100644 --- a/bot/src/bot/commands/avatar.ts +++ b/bot/src/bot/commands/misc/avatar.ts @@ -1,9 +1,9 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import axios from "axios"; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../util"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../../util"; export default { name: 'avatar', diff --git a/bot/src/bot/commands/debug.ts b/bot/src/bot/commands/misc/debug.ts similarity index 91% rename from bot/src/bot/commands/debug.ts rename to bot/src/bot/commands/misc/debug.ts index fb90185..2c97333 100644 --- a/bot/src/bot/commands/debug.ts +++ b/bot/src/bot/commands/misc/debug.ts @@ -1,8 +1,8 @@ import { decodeTime } from "ulid"; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { ULID_REGEX } from "../util"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { ULID_REGEX } from "../../util"; export default { name: 'debug', diff --git a/bot/src/bot/commands/help.ts b/bot/src/bot/commands/misc/help.ts similarity index 94% rename from bot/src/bot/commands/help.ts rename to bot/src/bot/commands/misc/help.ts index 1925e0f..ab1d4c6 100644 --- a/bot/src/bot/commands/help.ts +++ b/bot/src/bot/commands/misc/help.ts @@ -1,7 +1,7 @@ -import Command from "../../struct/commands/SimpleCommand"; -import { commands, DEFAULT_PREFIX, ownerIDs } from "../modules/command_handler"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import Command from "../../../struct/commands/SimpleCommand"; +import { commands, DEFAULT_PREFIX, ownerIDs } from "../../modules/command_handler"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; const categories: { [key in CommandCategory]: { friendlyName: string, diff --git a/bot/src/bot/commands/ping.ts b/bot/src/bot/commands/misc/ping.ts similarity index 66% rename from bot/src/bot/commands/ping.ts rename to bot/src/bot/commands/misc/ping.ts index b0a2715..cf5c57b 100644 --- a/bot/src/bot/commands/ping.ts +++ b/bot/src/bot/commands/misc/ping.ts @@ -1,8 +1,7 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; -import { client } from "../.."; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { client } from "../../.."; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; export default { name: 'ping', diff --git a/bot/src/bot/commands/test.ts b/bot/src/bot/commands/misc/test.ts similarity index 74% rename from bot/src/bot/commands/test.ts rename to bot/src/bot/commands/misc/test.ts index a43a8bf..aa5e08a 100644 --- a/bot/src/bot/commands/test.ts +++ b/bot/src/bot/commands/misc/test.ts @@ -1,6 +1,6 @@ -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; export default { name: 'test', diff --git a/bot/src/bot/commands/ban.ts b/bot/src/bot/commands/moderation/ban.ts similarity index 89% rename from bot/src/bot/commands/ban.ts rename to bot/src/bot/commands/moderation/ban.ts index d99e1db..aad4bbd 100644 --- a/bot/src/bot/commands/ban.ts +++ b/bot/src/bot/commands/moderation/ban.ts @@ -1,16 +1,16 @@ import { ulid } from "ulid"; -import { client } from "../../index"; -import Infraction from "../../struct/antispam/Infraction"; -import InfractionType from "../../struct/antispam/InfractionType"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import TempBan from "../../struct/TempBan"; -import { fetchUsername, logModAction } from "../modules/mod_logs"; -import { storeTempBan } from "../modules/tempbans"; -import { isModerator, NO_MANAGER_MSG, parseUserOrId, storeInfraction } from "../util"; +import { client } from "../../../index"; +import Infraction from "../../../struct/antispam/Infraction"; +import InfractionType from "../../../struct/antispam/InfractionType"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import TempBan from "../../../struct/TempBan"; +import { fetchUsername, logModAction } from "../../modules/mod_logs"; +import { storeTempBan } from "../../modules/tempbans"; +import { isModerator, NO_MANAGER_MSG, parseUserOrId, storeInfraction } from "../../util"; import Day from 'dayjs'; import RelativeTime from 'dayjs/plugin/relativeTime'; -import CommandCategory from "../../struct/commands/CommandCategory"; +import CommandCategory from "../../../struct/commands/CommandCategory"; Day.extend(RelativeTime); diff --git a/bot/src/bot/commands/kick.ts b/bot/src/bot/commands/moderation/kick.ts similarity index 84% rename from bot/src/bot/commands/kick.ts rename to bot/src/bot/commands/moderation/kick.ts index ddccc32..bb4db66 100644 --- a/bot/src/bot/commands/kick.ts +++ b/bot/src/bot/commands/moderation/kick.ts @@ -1,13 +1,13 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import { ulid } from "ulid"; -import { client } from "../.."; -import Infraction from "../../struct/antispam/Infraction"; -import InfractionType from "../../struct/antispam/InfractionType"; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { logModAction } from "../modules/mod_logs"; -import { isModerator, NO_MANAGER_MSG, parseUser, storeInfraction } from "../util"; +import { client } from "../../../"; +import Infraction from "../../../struct/antispam/Infraction"; +import InfractionType from "../../../struct/antispam/InfractionType"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { logModAction } from "../../modules/mod_logs"; +import { isModerator, NO_MANAGER_MSG, parseUser, storeInfraction } from "../../util"; export default { name: 'kick', diff --git a/bot/src/bot/commands/nick.ts b/bot/src/bot/commands/moderation/nick.ts similarity index 90% rename from bot/src/bot/commands/nick.ts rename to bot/src/bot/commands/moderation/nick.ts index 671a2e7..ad2d63f 100644 --- a/bot/src/bot/commands/nick.ts +++ b/bot/src/bot/commands/moderation/nick.ts @@ -1,9 +1,9 @@ import { Member } from "@janderedev/revolt.js/dist/maps/Members"; import axios from "axios"; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../util"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { hasPerm, isModerator, NO_MANAGER_MSG, parseUser } from "../../util"; export default { name: 'nick', diff --git a/bot/src/bot/commands/purge.ts b/bot/src/bot/commands/moderation/purge.ts similarity index 93% rename from bot/src/bot/commands/purge.ts rename to bot/src/bot/commands/moderation/purge.ts index 07de003..ab263aa 100644 --- a/bot/src/bot/commands/purge.ts +++ b/bot/src/bot/commands/moderation/purge.ts @@ -1,9 +1,9 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; import { decodeTime } from 'ulid'; -import { isModerator, parseUser } from "../util"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import { isModerator, parseUser } from "../../util"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; const SYNTAX = '/purge [SELECTOR] [@user?[, @user?[, ...]]]; where SELECTOR: [number] || [messageID]-[messageID]'; const MAX_PURGE_AMOUNT = 100; diff --git a/bot/src/bot/commands/unban.ts b/bot/src/bot/commands/moderation/unban.ts similarity index 87% rename from bot/src/bot/commands/unban.ts rename to bot/src/bot/commands/moderation/unban.ts index 245a604..605ced8 100644 --- a/bot/src/bot/commands/unban.ts +++ b/bot/src/bot/commands/moderation/unban.ts @@ -1,11 +1,9 @@ -import { FindResult } from "monk"; -import { client, dbs } from "../.."; -import CommandCategory from "../../struct/commands/CommandCategory"; -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import TempBan from "../../struct/TempBan"; -import { removeTempBan } from "../modules/tempbans"; -import { isModerator, NO_MANAGER_MSG, parseUser, ULID_REGEX, USER_MENTION_REGEX } from "../util"; +import { dbs } from "../../../"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { removeTempBan } from "../../modules/tempbans"; +import { isModerator, NO_MANAGER_MSG, parseUser, ULID_REGEX, USER_MENTION_REGEX } from "../../util"; export default { name: 'unban', diff --git a/bot/src/bot/commands/votekick.ts b/bot/src/bot/commands/moderation/votekick.ts similarity index 91% rename from bot/src/bot/commands/votekick.ts rename to bot/src/bot/commands/moderation/votekick.ts index 1608293..1dfee0b 100644 --- a/bot/src/bot/commands/votekick.ts +++ b/bot/src/bot/commands/moderation/votekick.ts @@ -1,13 +1,12 @@ import { FindResult } from "monk"; import { ulid } from "ulid"; -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 { logModAction } from "../modules/mod_logs"; -import { storeTempBan } from "../modules/tempbans"; -import { getPermissionLevel, isModerator, parseUser } from "../util"; +import { client, dbs } from "../../../"; +import CommandCategory from "../../../struct/commands/CommandCategory"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import { logModAction } from "../../modules/mod_logs"; +import { storeTempBan } from "../../modules/tempbans"; +import { getPermissionLevel, isModerator, parseUser } from "../../util"; type VoteEntry = { id: string; diff --git a/bot/src/bot/commands/warn.ts b/bot/src/bot/commands/moderation/warn.ts similarity index 91% rename from bot/src/bot/commands/warn.ts rename to bot/src/bot/commands/moderation/warn.ts index e75d174..69efcda 100644 --- a/bot/src/bot/commands/warn.ts +++ b/bot/src/bot/commands/moderation/warn.ts @@ -1,11 +1,11 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { dedupeArray, embed, EmbedColor, isModerator, NO_MANAGER_MSG, parseUserOrId, sanitizeMessageContent, storeInfraction } from "../util"; -import Infraction from "../../struct/antispam/Infraction"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { dedupeArray, embed, EmbedColor, isModerator, NO_MANAGER_MSG, parseUserOrId, sanitizeMessageContent, storeInfraction } from "../../util"; +import Infraction from "../../../struct/antispam/Infraction"; import { ulid } from "ulid"; -import InfractionType from "../../struct/antispam/InfractionType"; -import { fetchUsername, logModAction } from "../modules/mod_logs"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import InfractionType from "../../../struct/antispam/InfractionType"; +import { fetchUsername, logModAction } from "../../modules/mod_logs"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; import { SendableEmbed } from "revolt-api"; import { User } from "@janderedev/revolt.js"; diff --git a/bot/src/bot/commands/warns.ts b/bot/src/bot/commands/moderation/warns.ts similarity index 93% rename from bot/src/bot/commands/warns.ts rename to bot/src/bot/commands/moderation/warns.ts index 3c47207..2e16a8a 100644 --- a/bot/src/bot/commands/warns.ts +++ b/bot/src/bot/commands/moderation/warns.ts @@ -1,14 +1,14 @@ -import SimpleCommand from "../../struct/commands/SimpleCommand"; -import { client, dbs } from "../.."; -import Infraction from "../../struct/antispam/Infraction"; -import InfractionType from "../../struct/antispam/InfractionType"; -import { isModerator, NO_MANAGER_MSG, parseUserOrId, uploadFile } from "../util"; +import SimpleCommand from "../../../struct/commands/SimpleCommand"; +import { client, dbs } from "../../.."; +import Infraction from "../../../struct/antispam/Infraction"; +import InfractionType from "../../../struct/antispam/InfractionType"; +import { isModerator, NO_MANAGER_MSG, parseUserOrId, uploadFile } from "../../util"; import Day from 'dayjs'; import RelativeTime from 'dayjs/plugin/relativeTime'; import Xlsx from 'xlsx'; -import { fetchUsername } from "../modules/mod_logs"; -import MessageCommandContext from "../../struct/MessageCommandContext"; -import CommandCategory from "../../struct/commands/CommandCategory"; +import { fetchUsername } from "../../modules/mod_logs"; +import MessageCommandContext from "../../../struct/MessageCommandContext"; +import CommandCategory from "../../../struct/commands/CommandCategory"; Day.extend(RelativeTime); diff --git a/bot/src/bot/modules/command_handler.ts b/bot/src/bot/modules/command_handler.ts index 5e401b0..8016c97 100644 --- a/bot/src/bot/modules/command_handler.ts +++ b/bot/src/bot/modules/command_handler.ts @@ -3,13 +3,12 @@ import logger from "../logger"; import { client, dbs } from "../../index"; import fs from 'fs'; import path from 'path'; -import ServerConfig from "../../struct/ServerConfig"; import { antispam } from "./antispam"; import checkCustomRules from "./custom_rules/custom_rules"; import MessageCommandContext from "../../struct/MessageCommandContext"; import { fileURLToPath } from 'url'; import { getOwnMemberInServer, hasPermForChannel } from "../util"; -import { isSudo, updateSudoTimeout } from "../commands/botadm"; +import { isSudo, updateSudoTimeout } from "../commands/admin/botadm"; import { metrics } from "./metrics"; // thanks a lot esm @@ -26,9 +25,9 @@ let commands: SimpleCommand[]; (async () => { commands = (await Promise.all( - fs.readdirSync(path.join(dirname, '..', 'commands')) + dirTreeSync(path.join(dirname, '..', 'commands')) .filter(file => file.endsWith('.js')) - .map(async file => await import(path.join(dirname, '..', 'commands', file)) as SimpleCommand) + .map(async file => await import(file) as SimpleCommand) )).map(c => (c as any).default) client.on('message/update', async msg => { @@ -144,4 +143,19 @@ let commands: SimpleCommand[]; }); })(); +function dirTreeSync(dir: string): string[] { + const paths: string[] = []; + + const files = fs.readdirSync(dir, { withFileTypes: true }); + for (const file of files) { + if (file.isDirectory()) { + paths.push(...dirTreeSync(path.join(dir, file.name))); + } else if (file.isFile()) { + paths.push(path.join(dir, file.name)); + } + } + + return paths; +} + export { DEFAULT_PREFIX, commands, ownerIDs } diff --git a/bot/src/bot/modules/event_handler.ts b/bot/src/bot/modules/event_handler.ts index 6e10d92..c4e7166 100644 --- a/bot/src/bot/modules/event_handler.ts +++ b/bot/src/bot/modules/event_handler.ts @@ -1,9 +1,8 @@ -import { Permission } from "@janderedev/revolt.js/dist/permissions/definitions"; import { ulid } from "ulid"; import { client, dbs } from "../.."; import Infraction from "../../struct/antispam/Infraction"; import InfractionType from "../../struct/antispam/InfractionType"; -import { BLACKLIST_BAN_REASON, BLACKLIST_MESSAGE } from "../commands/botadm"; +import { BLACKLIST_BAN_REASON, BLACKLIST_MESSAGE } from "../commands/admin/botadm"; import logger from "../logger"; import { hasPermForChannel, storeInfraction } from "../util"; import { DEFAULT_PREFIX } from "./command_handler"; diff --git a/bot/src/bot/util.ts b/bot/src/bot/util.ts index 28ff56d..9cbba4e 100644 --- a/bot/src/bot/util.ts +++ b/bot/src/bot/util.ts @@ -13,7 +13,7 @@ import { ulid } from "ulid"; import { Channel } from "@janderedev/revolt.js/dist/maps/Channels"; import { Permission } from "@janderedev/revolt.js/dist/permissions/definitions"; import { Message } from "@janderedev/revolt.js/dist/maps/Messages"; -import { isSudo } from "./commands/botadm"; +import { isSudo } from "./commands/admin/botadm"; import { SendableEmbed } from "revolt-api"; const NO_MANAGER_MSG = '🔒 Missing permission'; diff --git a/bot/src/index.ts b/bot/src/index.ts index 0a968d1..c7fcf8c 100644 --- a/bot/src/index.ts +++ b/bot/src/index.ts @@ -9,7 +9,7 @@ import ServerConfig from './struct/ServerConfig'; import Infraction from './struct/antispam/Infraction'; import PendingLogin from './struct/PendingLogin'; import TempBan from './struct/TempBan'; -import { VoteEntry } from './bot/commands/votekick'; +import { VoteEntry } from './bot/commands/moderation/votekick'; import ScannedUser from './struct/ScannedUser'; import BridgeRequest from './struct/BridgeRequest'; import BridgeConfig from './struct/BridgeConfig';