From fd675ca9d60cc06d892ebc36a1b9624f15233f20 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 29 Jun 2021 20:48:27 -0400 Subject: don't judge part 1 --- src/arguments/duration.ts | 4 +- src/bot.ts | 2 +- src/commands/config/muteRole.ts | 6 +- src/commands/config/prefix.ts | 6 +- src/commands/config/welcomeChannel.ts | 6 +- src/commands/dev/eval.ts | 10 +- src/commands/dev/reload.ts | 6 +- src/commands/dev/setLevel.ts | 6 +- src/commands/dev/superUser.ts | 4 +- src/commands/info/botInfo.ts | 2 +- src/commands/info/help.ts | 6 +- src/commands/info/ping.ts | 4 +- src/commands/info/pronouns.ts | 4 +- src/commands/moderation/ban.ts | 2 +- src/commands/moderation/kick.ts | 4 +- src/commands/moderation/modlog.ts | 2 +- src/commands/moderation/mute.ts | 2 +- src/commands/moderation/role.ts | 2 +- src/commands/moderation/warn.ts | 2 +- src/commands/moulberry-bush/capePerms.ts | 4 +- src/commands/moulberry-bush/giveawayPing.ts | 4 +- src/commands/moulberry-bush/level.ts | 4 +- src/commands/moulberry-bush/rule.ts | 4 +- src/inhibitors/blacklist/guildBlacklist.ts | 6 +- src/inhibitors/blacklist/userBlacklist.ts | 6 +- src/inhibitors/commands/disabledCommand.ts | 8 +- src/inhibitors/noCache.ts | 6 +- src/lib/extensions/BushArgumentOptions.ts | 59 --- src/lib/extensions/BushArgumentTypeCaster.ts | 4 - src/lib/extensions/BushClient.ts | 223 --------- src/lib/extensions/BushClientUtil.ts | 536 --------------------- src/lib/extensions/BushCommand.ts | 57 --- src/lib/extensions/BushCommandHandler.ts | 91 ---- src/lib/extensions/BushCommandUtil.ts | 10 - src/lib/extensions/BushGuild.ts | 22 - src/lib/extensions/BushGuildMember.ts | 15 - src/lib/extensions/BushInhibitor.ts | 15 - src/lib/extensions/BushInhinitorHandler.ts | 6 - src/lib/extensions/BushListener.ts | 6 - src/lib/extensions/BushListenerHandler.ts | 6 - src/lib/extensions/BushMessage.ts | 21 - src/lib/extensions/BushSlashMessage.ts | 20 - src/lib/extensions/BushTask.ts | 6 - src/lib/extensions/BushTaskHandler.ts | 11 - src/lib/extensions/BushUser.ts | 19 - .../discord-akairo/BushArgumentOptions.ts | 59 +++ .../discord-akairo/BushArgumentTypeCaster.ts | 4 + src/lib/extensions/discord-akairo/BushClient.ts | 233 +++++++++ .../extensions/discord-akairo/BushClientUtil.ts | 536 +++++++++++++++++++++ src/lib/extensions/discord-akairo/BushCommand.ts | 57 +++ .../discord-akairo/BushCommandHandler.ts | 90 ++++ .../extensions/discord-akairo/BushCommandUtil.ts | 10 + src/lib/extensions/discord-akairo/BushInhibitor.ts | 15 + .../discord-akairo/BushInhinitorHandler.ts | 6 + src/lib/extensions/discord-akairo/BushListener.ts | 6 + .../discord-akairo/BushListenerHandler.ts | 6 + .../extensions/discord-akairo/BushSlashMessage.ts | 20 + src/lib/extensions/discord-akairo/BushTask.ts | 6 + .../extensions/discord-akairo/BushTaskHandler.ts | 11 + .../extensions/discord.js/BushCategoryChannel.ts | 16 + src/lib/extensions/discord.js/BushDMChannel.ts | 14 + src/lib/extensions/discord.js/BushGuild.ts | 20 + src/lib/extensions/discord.js/BushGuildChannel.ts | 11 + src/lib/extensions/discord.js/BushGuildEmoji.ts | 15 + .../discord.js/BushGuildEmojiRoleManager.ts | 13 + src/lib/extensions/discord.js/BushGuildMember.ts | 13 + src/lib/extensions/discord.js/BushMessage.ts | 26 + .../extensions/discord.js/BushMessageManager.ts | 14 + src/lib/extensions/discord.js/BushNewsChannel.ts | 16 + src/lib/extensions/discord.js/BushRole.ts | 13 + src/lib/extensions/discord.js/BushStoreChannel.ts | 16 + src/lib/extensions/discord.js/BushTextChannel.ts | 13 + src/lib/extensions/discord.js/BushThreadChannel.ts | 23 + src/lib/extensions/discord.js/BushThreadManager.ts | 11 + src/lib/extensions/discord.js/BushThreadMember.ts | 14 + .../discord.js/BushThreadMemberManager.ts | 23 + src/lib/extensions/discord.js/BushUser.ts | 19 + src/lib/extensions/discord.js/BushVoiceChannel.ts | 12 + src/lib/models/Guild.ts | 2 +- src/lib/utils/BushLogger.ts | 2 +- src/listeners/client/ready.ts | 2 +- src/listeners/commands/commandBlocked.ts | 6 +- src/listeners/commands/commandError.ts | 4 +- .../commands/commandMissingPermissions.ts | 6 +- src/listeners/commands/commandStarted.ts | 4 +- src/listeners/commands/slashBlocked.ts | 6 +- src/listeners/commands/slashCommandError.ts | 6 +- src/listeners/commands/slashMissingPermissions.ts | 2 +- src/listeners/commands/slashStarted.ts | 6 +- src/listeners/guild/syncUnban.ts | 4 +- src/listeners/message/level.ts | 2 +- src/listeners/other/consoleListener.ts | 2 +- src/listeners/other/promiseRejection.ts | 2 +- src/tasks/unban.ts | 2 +- src/tasks/unmute.ts | 2 +- src/tasks/updateCache.ts | 4 +- 96 files changed, 1454 insertions(+), 1220 deletions(-) delete mode 100644 src/lib/extensions/BushArgumentOptions.ts delete mode 100644 src/lib/extensions/BushArgumentTypeCaster.ts delete mode 100644 src/lib/extensions/BushClient.ts delete mode 100644 src/lib/extensions/BushClientUtil.ts delete mode 100644 src/lib/extensions/BushCommand.ts delete mode 100644 src/lib/extensions/BushCommandHandler.ts delete mode 100644 src/lib/extensions/BushCommandUtil.ts delete mode 100644 src/lib/extensions/BushGuild.ts delete mode 100644 src/lib/extensions/BushGuildMember.ts delete mode 100644 src/lib/extensions/BushInhibitor.ts delete mode 100644 src/lib/extensions/BushInhinitorHandler.ts delete mode 100644 src/lib/extensions/BushListener.ts delete mode 100644 src/lib/extensions/BushListenerHandler.ts delete mode 100644 src/lib/extensions/BushMessage.ts delete mode 100644 src/lib/extensions/BushSlashMessage.ts delete mode 100644 src/lib/extensions/BushTask.ts delete mode 100644 src/lib/extensions/BushTaskHandler.ts delete mode 100644 src/lib/extensions/BushUser.ts create mode 100644 src/lib/extensions/discord-akairo/BushArgumentOptions.ts create mode 100644 src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts create mode 100644 src/lib/extensions/discord-akairo/BushClient.ts create mode 100644 src/lib/extensions/discord-akairo/BushClientUtil.ts create mode 100644 src/lib/extensions/discord-akairo/BushCommand.ts create mode 100644 src/lib/extensions/discord-akairo/BushCommandHandler.ts create mode 100644 src/lib/extensions/discord-akairo/BushCommandUtil.ts create mode 100644 src/lib/extensions/discord-akairo/BushInhibitor.ts create mode 100644 src/lib/extensions/discord-akairo/BushInhinitorHandler.ts create mode 100644 src/lib/extensions/discord-akairo/BushListener.ts create mode 100644 src/lib/extensions/discord-akairo/BushListenerHandler.ts create mode 100644 src/lib/extensions/discord-akairo/BushSlashMessage.ts create mode 100644 src/lib/extensions/discord-akairo/BushTask.ts create mode 100644 src/lib/extensions/discord-akairo/BushTaskHandler.ts create mode 100644 src/lib/extensions/discord.js/BushCategoryChannel.ts create mode 100644 src/lib/extensions/discord.js/BushDMChannel.ts create mode 100644 src/lib/extensions/discord.js/BushGuild.ts create mode 100644 src/lib/extensions/discord.js/BushGuildChannel.ts create mode 100644 src/lib/extensions/discord.js/BushGuildEmoji.ts create mode 100644 src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts create mode 100644 src/lib/extensions/discord.js/BushGuildMember.ts create mode 100644 src/lib/extensions/discord.js/BushMessage.ts create mode 100644 src/lib/extensions/discord.js/BushMessageManager.ts create mode 100644 src/lib/extensions/discord.js/BushNewsChannel.ts create mode 100644 src/lib/extensions/discord.js/BushRole.ts create mode 100644 src/lib/extensions/discord.js/BushStoreChannel.ts create mode 100644 src/lib/extensions/discord.js/BushTextChannel.ts create mode 100644 src/lib/extensions/discord.js/BushThreadChannel.ts create mode 100644 src/lib/extensions/discord.js/BushThreadManager.ts create mode 100644 src/lib/extensions/discord.js/BushThreadMember.ts create mode 100644 src/lib/extensions/discord.js/BushThreadMemberManager.ts create mode 100644 src/lib/extensions/discord.js/BushUser.ts create mode 100644 src/lib/extensions/discord.js/BushVoiceChannel.ts (limited to 'src') diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index 7b7a922..6007b4e 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,5 +1,5 @@ -import { BushArgumentTypeCaster } from '../lib/extensions/BushArgumentTypeCaster'; -import { BushMessage } from '../lib/extensions/BushMessage'; +import { BushArgumentTypeCaster } from '../lib/extensions/discord-akairo/BushArgumentTypeCaster'; +import { BushMessage } from '../lib/extensions/discord.js/BushMessage'; import { BushConstants } from '../lib/utils/BushConstants'; export const durationTypeCaster: BushArgumentTypeCaster = async (_message: BushMessage, phrase): Promise => { diff --git a/src/bot.ts b/src/bot.ts index ee7ce92..5e2d10c 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,5 +1,5 @@ -import { BushClient } from './lib/extensions/BushClient'; import * as config from './config/options'; +import { BushClient } from './lib/extensions/discord-akairo/BushClient'; const client: BushClient = new BushClient(config); client.start(); diff --git a/src/commands/config/muteRole.ts b/src/commands/config/muteRole.ts index 2dc34c3..2b2f938 100644 --- a/src/commands/config/muteRole.ts +++ b/src/commands/config/muteRole.ts @@ -1,7 +1,7 @@ import { Role } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import AllowedMentions from '../../lib/utils/AllowedMentions'; export default class MuteRoleCommand extends BushCommand { diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index b788d17..1551205 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class PrefixCommand extends BushCommand { constructor() { diff --git a/src/commands/config/welcomeChannel.ts b/src/commands/config/welcomeChannel.ts index d531c7d..2d66a25 100644 --- a/src/commands/config/welcomeChannel.ts +++ b/src/commands/config/welcomeChannel.ts @@ -1,7 +1,7 @@ import { Channel } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class WelcomeChannelCommand extends BushCommand { public constructor() { diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index a1c2d87..fc6e7e8 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -4,9 +4,9 @@ import { Constants } from 'discord-akairo'; import { CommandInteraction, MessageEmbed, MessageEmbedOptions, Util } from 'discord.js'; import { transpile } from 'typescript'; import { inspect, promisify } from 'util'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; const clean = (text) => { if (typeof text === 'string') { @@ -135,8 +135,8 @@ export default class EvalCommand extends BushCommand { show_proto: boolean; } ): Promise { - // if (!message.author.isOwner()) - // return await message.util.reply(`${this.client.util.emojis.error} Only my developers can run this command.`); + if (!message.author.isOwner()) + return await message.util.reply(`${this.client.util.emojis.error} Only my developers can run this command.`); if (message.util.isSlash) { await (message as BushSlashMessage).interaction.defer({ ephemeral: args.silent }); } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 656bb34..82dde4c 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class ReloadCommand extends BushCommand { constructor() { diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index 6c8131a..9903013 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -1,7 +1,7 @@ import { User } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import { Level } from '../../lib/models'; import AllowedMentions from '../../lib/utils/AllowedMentions'; diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index 773209c..8bbc391 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,7 +1,7 @@ import { Constants } from 'discord-akairo'; import { User } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import { Global } from '../../lib/models'; export default class SuperUserCommand extends BushCommand { diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index 3db4151..b77a271 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,6 +1,6 @@ import { Message, MessageEmbed } from 'discord.js'; import { duration } from 'moment'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; export default class BotInfoCommand extends BushCommand { constructor() { diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index b58d73c..6e14d96 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,7 +1,7 @@ import { MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class HelpCommand extends BushCommand { constructor() { diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index 6584ab5..45cfd22 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,6 +1,6 @@ import { Message, MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; export default class PingCommand extends BushCommand { constructor() { diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 60d0c1a..538ec64 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,7 +1,7 @@ import { Message, MessageEmbed, User } from 'discord.js'; import got, { HTTPError } from 'got'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; export const pronounMapping = { unspecified: 'Unspecified', diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 7ce222a..9df1c2a 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,7 +1,7 @@ import { Argument } from 'discord-akairo'; import { CommandInteraction, Message, User } from 'discord.js'; import moment from 'moment'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; import { Ban, Guild, ModLog, ModLogType } from '../../lib/models'; /* const durationAliases: Record = { diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 748753f..a666c8e 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,6 +1,6 @@ import { CommandInteraction, GuildMember, Message } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; import { Guild, ModLog, ModLogType } from '../../lib/models'; export default class KickCommand extends BushCommand { diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index e32df42..27018f1 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -2,7 +2,7 @@ import { stripIndent } from 'common-tags'; import { Argument } from 'discord-akairo'; import { Message, MessageEmbed } from 'discord.js'; import moment from 'moment'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; import { ModLog } from '../../lib/models'; export default class ModlogCommand extends BushCommand { diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 9b6ad70..88fcc69 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -1,7 +1,7 @@ import { Argument } from 'discord-akairo'; import { CommandInteraction, Message, User } from 'discord.js'; import moment from 'moment'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; import { Guild, ModLog, ModLogType, Mute } from '../../lib/models'; export default class MuteCommand extends BushCommand { diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index f0918f0..d1f8e00 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { GuildMember, Message, Role } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; export default class RoleCommand extends BushCommand { diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index d48049b..c146db0 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,5 +1,5 @@ import { GuildMember, Message } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; import { Guild, ModLog, ModLogType } from '../../lib/models'; export default class WarnCommand extends BushCommand { diff --git a/src/commands/moulberry-bush/capePerms.ts b/src/commands/moulberry-bush/capePerms.ts index d1850c8..b6508d0 100644 --- a/src/commands/moulberry-bush/capePerms.ts +++ b/src/commands/moulberry-bush/capePerms.ts @@ -1,8 +1,8 @@ import { Constants } from 'discord-akairo'; import { MessageEmbed } from 'discord.js'; import got from 'got'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class CapePermissionsCommand extends BushCommand { private nameMap = { diff --git a/src/commands/moulberry-bush/giveawayPing.ts b/src/commands/moulberry-bush/giveawayPing.ts index 19163d7..40f782d 100644 --- a/src/commands/moulberry-bush/giveawayPing.ts +++ b/src/commands/moulberry-bush/giveawayPing.ts @@ -1,5 +1,5 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import AllowedMentions from '../../lib/utils/AllowedMentions'; export default class GiveawayPingCommand extends BushCommand { diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index e37fa2e..c81c555 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,6 +1,6 @@ import { Message, User } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; import { Level } from '../../lib/models'; /* import canvas from 'canvas'; diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index 9aa41e0..2bcbb8d 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -1,7 +1,7 @@ import { Argument, Constants } from 'discord-akairo'; import { MessageEmbed, User } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import AllowedMentions from '../../lib/utils/AllowedMentions'; const rules = [ diff --git a/src/inhibitors/blacklist/guildBlacklist.ts b/src/inhibitors/blacklist/guildBlacklist.ts index 4c541e8..103e89b 100644 --- a/src/inhibitors/blacklist/guildBlacklist.ts +++ b/src/inhibitors/blacklist/guildBlacklist.ts @@ -1,6 +1,6 @@ -import { BushInhibitor } from '../../lib/extensions/BushInhibitor'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushInhibitor } from '../../lib/extensions/discord-akairo/BushInhibitor'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class GuildBlacklistInhibitor extends BushInhibitor { constructor() { diff --git a/src/inhibitors/blacklist/userBlacklist.ts b/src/inhibitors/blacklist/userBlacklist.ts index 73ad846..6772188 100644 --- a/src/inhibitors/blacklist/userBlacklist.ts +++ b/src/inhibitors/blacklist/userBlacklist.ts @@ -1,6 +1,6 @@ -import { BushInhibitor } from '../../lib/extensions/BushInhibitor'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushInhibitor } from '../../lib/extensions/discord-akairo/BushInhibitor'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class UserBlacklistInhibitor extends BushInhibitor { constructor() { diff --git a/src/inhibitors/commands/disabledCommand.ts b/src/inhibitors/commands/disabledCommand.ts index caf7bf7..5b47ce3 100644 --- a/src/inhibitors/commands/disabledCommand.ts +++ b/src/inhibitors/commands/disabledCommand.ts @@ -1,7 +1,7 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushInhibitor } from '../../lib/extensions/BushInhibitor'; -import { BushMessage } from '../../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushInhibitor } from '../../lib/extensions/discord-akairo/BushInhibitor'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class DisabledCommandInhibitor extends BushInhibitor { constructor() { diff --git a/src/inhibitors/noCache.ts b/src/inhibitors/noCache.ts index a8f52d7..fe2e522 100644 --- a/src/inhibitors/noCache.ts +++ b/src/inhibitors/noCache.ts @@ -1,6 +1,6 @@ -import { BushInhibitor } from '../lib/extensions/BushInhibitor'; -import { BushMessage } from '../lib/extensions/BushMessage'; -import { BushSlashMessage } from '../lib/extensions/BushSlashMessage'; +import { BushInhibitor } from '../lib/extensions/discord-akairo/BushInhibitor'; +import { BushSlashMessage } from '../lib/extensions/discord-akairo/BushSlashMessage'; +import { BushMessage } from '../lib/extensions/discord.js/BushMessage'; export default class noCacheInhibitor extends BushInhibitor { constructor() { diff --git a/src/lib/extensions/BushArgumentOptions.ts b/src/lib/extensions/BushArgumentOptions.ts deleted file mode 100644 index bbbc04b..0000000 --- a/src/lib/extensions/BushArgumentOptions.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { ArgumentOptions, ArgumentTypeCaster } from 'discord-akairo'; - -type BushArgumentType = - | 'string' - | 'lowercase' - | 'uppercase' - | 'charCodes' - | 'number' - | 'integer' - | 'bigint' - | 'emojint' - | 'url' - | 'date' - | 'color' - | 'user' - | 'users' - | 'member' - | 'members' - | 'relevant' - | 'relevants' - | 'channel' - | 'channels' - | 'textChannel' - | 'textChannels' - | 'voiceChannel' - | 'voiceChannels' - | 'categoryChannel' - | 'categoryChannels' - | 'newsChannel' - | 'newsChannels' - | 'storeChannel' - | 'storeChannels' - | 'role' - | 'roles' - | 'emoji' - | 'emojis' - | 'guild' - | 'guilds' - | 'message' - | 'guildMessage' - | 'relevantMessage' - | 'invite' - | 'userMention' - | 'memberMention' - | 'channelMention' - | 'roleMention' - | 'emojiMention' - | 'commandAlias' - | 'command' - | 'inhibitor' - | 'listener' - | 'duration' - | (string | string[])[] - | RegExp - | string; - -export interface BushArgumentOptions extends ArgumentOptions { - type?: BushArgumentType | ArgumentTypeCaster; -} diff --git a/src/lib/extensions/BushArgumentTypeCaster.ts b/src/lib/extensions/BushArgumentTypeCaster.ts deleted file mode 100644 index e000063..0000000 --- a/src/lib/extensions/BushArgumentTypeCaster.ts +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { BushMessage } from './BushMessage'; - -export type BushArgumentTypeCaster = (message: BushMessage, phrase: string) => any; diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts deleted file mode 100644 index 8dd8277..0000000 --- a/src/lib/extensions/BushClient.ts +++ /dev/null @@ -1,223 +0,0 @@ -import chalk from 'chalk'; -import { AkairoClient } from 'discord-akairo'; -import { - Guild, - Intents, - Message, - MessageEditOptions, - MessageOptions, - MessagePayload, - ReplyMessageOptions, - Snowflake, - UserResolvable -} from 'discord.js'; -import * as path from 'path'; -import { exit } from 'process'; -import readline from 'readline'; -import { Sequelize } from 'sequelize'; -import { durationTypeCaster } from '../../arguments/duration'; -import * as config from '../../config/options'; -import UpdateCacheTask from '../../tasks/updateCache'; -import * as Models from '../models'; -import AllowedMentions from '../utils/AllowedMentions'; -import { BushCache } from '../utils/BushCache'; -import { BushConstants } from '../utils/BushConstants'; -import { BushLogger } from '../utils/BushLogger'; -import { BushClientUtil } from './BushClientUtil'; -import { BushCommandHandler } from './BushCommandHandler'; -import { BushInhibitorHandler } from './BushInhinitorHandler'; -import { BushListenerHandler } from './BushListenerHandler'; -import { BushTaskHandler } from './BushTaskHandler'; - -export type BotConfig = typeof config; -export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions; -export type BushEditMessageType = string | MessageEditOptions | MessagePayload; -export type BushSendMessageType = string | MessagePayload | MessageOptions; - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -export class BushClient extends AkairoClient { - public config: BotConfig; - public listenerHandler: BushListenerHandler; - public inhibitorHandler: BushInhibitorHandler; - public commandHandler: BushCommandHandler; - public taskHandler: BushTaskHandler; - public declare util: BushClientUtil; - public declare ownerID: Snowflake[]; - public db: Sequelize; - public logger: BushLogger; - public constants = BushConstants; - public cache = BushCache; - constructor(config: BotConfig) { - super( - { - ownerID: config.owners, - intents: Intents.ALL - }, - { - allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default - intents: Intents.ALL - } - ); - - // Set token - this.token = config.credentials.token; - - // Set config - this.config = config; - - // Create listener handler - this.listenerHandler = new BushListenerHandler(this, { - directory: path.join(__dirname, '..', '..', 'listeners'), - automateCategories: true - }); - - // Create inhibitor handler - this.inhibitorHandler = new BushInhibitorHandler(this, { - directory: path.join(__dirname, '..', '..', 'inhibitors'), - automateCategories: true - }); - - // Create task handler - this.taskHandler = new BushTaskHandler(this, { - directory: path.join(__dirname, '..', '..', 'tasks') - }); - - // Create command handler - this.commandHandler = new BushCommandHandler(this, { - directory: path.join(__dirname, '..', '..', 'commands'), - prefix: async ({ guild }: { guild: Guild }) => { - if (this.config.dev) return 'dev '; - const row = await Models.Guild.findByPk(guild.id); - return (row?.prefix || this.config.prefix) as string; - }, - allowMention: true, - handleEdits: true, - commandUtil: true, - commandUtilLifetime: 300_000, - argumentDefaults: { - prompt: { - start: 'Placeholder argument prompt. If you see this please tell the devs.', - retry: 'Placeholder failed argument prompt. If you see this please tell the devs.', - modifyStart: (_: Message, str: string): string => `${str}\n\n Type \`cancel\` to cancel the command`, - modifyRetry: (_: Message, str: string): string => - `${str.replace('{error}', this.util.emojis.error)}\n\n Type \`cancel\` to cancel the command`, - timeout: 'You took too long the command has been cancelled', - ended: 'You exceeded the maximum amount of tries the command has been cancelled', - cancel: 'The command has been cancelled', - retries: 3, - time: 3e4 - }, - otherwise: '' - }, - - automateCategories: false, - autoRegisterSlashCommands: true - }); - - this.util = new BushClientUtil(this); - this.db = new Sequelize(this.config.dev ? 'bushbot-dev' : 'bushbot', this.config.db.username, this.config.db.password, { - dialect: 'postgres', - host: this.config.db.host, - port: this.config.db.port, - logging: this.config.logging.db ? (a) => this.logger.debug(a) : false - }); - this.logger = new BushLogger(this); - } - - get console(): BushLogger { - return this.logger; - } - - get consts(): typeof BushConstants { - return this.constants; - } - - // Initialize everything - private async _init(): Promise { - this.commandHandler.useListenerHandler(this.listenerHandler); - this.commandHandler.useInhibitorHandler(this.inhibitorHandler); - this.commandHandler.ignorePermissions = this.config.owners; - this.commandHandler.ignoreCooldown = this.config.owners.concat(this.cache.global.superUsers); - this.listenerHandler.setEmitters({ - client: this, - commandHandler: this.commandHandler, - listenerHandler: this.listenerHandler, - inhibitorHandler: this.inhibitorHandler, - taskHandler: this.taskHandler, - process, - stdin: rl, - gateway: this.ws - }); - this.commandHandler.resolver.addTypes({ - duration: durationTypeCaster - }); - // loads all the handlers - const loaders = { - commands: this.commandHandler, - listeners: this.listenerHandler, - inhibitors: this.inhibitorHandler, - tasks: this.taskHandler - }; - for (const loader of Object.keys(loaders)) { - try { - loaders[loader].loadAll(); - await this.logger.success('Startup', `Successfully loaded <<${loader}>>.`, false); - } catch (e) { - await this.logger.error('Startup', `Unable to load loader <<${loader}>> with error:\n${e?.stack}`, false); - } - } - await this.dbPreInit(); - await new UpdateCacheTask().init(this); - this.console.success('Startup', `Successfully created <>.`, false); - this.taskHandler.startAll(); - } - - public async dbPreInit(): Promise { - try { - await this.db.authenticate(); - Models.Global.initModel(this.db); - Models.Guild.initModel(this.db, this); - Models.ModLog.initModel(this.db); - Models.Ban.initModel(this.db); - Models.Mute.initModel(this.db); - Models.Level.initModel(this.db); - Models.StickyRole.initModel(this.db); - await this.db.sync({ alter: true }); // Sync all tables to fix everything if updated - await this.console.success('Startup', `Successfully connected to <>.`, false); - } catch (error) { - await this.console.error('Startup', `Failed to connect to <> with error:\n` + error?.stack, false); - } - } - - /** Starts the bot */ - public async start(): Promise { - try { - await this._init(); - await this.login(this.token); - } catch (e) { - await this.console.error('Start', chalk.red(e.stack), false); - exit(2); - } - } - - /** Logs out, terminates the connection to Discord, and destroys the client. */ - public destroy(relogin = false): void | Promise { - super.destroy(); - if (relogin) { - return this.login(this.token); - } - } - - public isOwner(user: UserResolvable): boolean { - return this.config.owners.includes(this.users.resolveID(user)); - } - public isSuperUser(user: UserResolvable): boolean { - const userID = this.users.resolveID(user); - return !!BushCache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID); - } -} diff --git a/src/lib/extensions/BushClientUtil.ts b/src/lib/extensions/BushClientUtil.ts deleted file mode 100644 index 680f6af..0000000 --- a/src/lib/extensions/BushClientUtil.ts +++ /dev/null @@ -1,536 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { exec } from 'child_process'; -import { ClientUtil } from 'discord-akairo'; -import { APIMessage } from 'discord-api-types'; -import { - ButtonInteraction, - ColorResolvable, - CommandInteraction, - Constants, - GuildMember, - Message, - MessageActionRow, - MessageButton, - MessageComponentInteraction, - MessageEditOptions, - MessageEmbed, - MessageOptions, - MessagePayload, - Snowflake, - TextChannel, - User, - Util, - WebhookEditMessageOptions -} from 'discord.js'; -import got from 'got'; -import { promisify } from 'util'; -import { Global } from '../models'; -import { BushCache } from '../utils/BushCache'; -import { BushClient } from './BushClient'; -import { BushMessage } from './BushMessage'; - -interface hastebinRes { - key: string; -} - -export interface uuidRes { - uuid: string; - username: string; - username_history?: { username: string }[] | null; - textures: { - custom: boolean; - slim: boolean; - skin: { - url: string; - data: string; - }; - raw: { - value: string; - signature: string; - }; - }; - created_at: string; -} - -interface bushColors { - default: '#1FD8F1'; - error: '#EF4947'; - warn: '#FEBA12'; - success: '#3BB681'; - info: '#3B78FF'; - red: '#ff0000'; - blue: '#0055ff'; - aqua: '#00bbff'; - purple: '#8400ff'; - blurple: '#5440cd'; - pink: '#ff00e6'; - green: '#00ff1e'; - darkGreen: '#008f11'; - gold: '#b59400'; - yellow: '#ffff00'; - white: '#ffffff'; - gray: '#a6a6a6'; - lightGray: '#cfcfcf'; - darkGray: '#7a7a7a'; - black: '#000000'; - orange: '#E86100'; -} -export class BushClientUtil extends ClientUtil { - /** The client of this ClientUtil */ - public declare client: BushClient; - /** The hastebin urls used to post to hastebin, attempts to post in order */ - public hasteURLs: string[] = [ - 'https://hst.sh', - 'https://hasteb.in', - 'https://hastebin.com', - 'https://mystb.in', - 'https://haste.clicksminuteper.net', - 'https://paste.pythondiscord.com', - 'https://haste.unbelievaboat.com', - 'https://haste.tyman.tech' - ]; - public paginateEmojis = { - beginning: '853667381335162910', - back: '853667410203770881', - stop: '853667471110570034', - forward: '853667492680564747', - end: '853667514915225640' - }; - - /** A simple promise exec method */ - private exec = promisify(exec); - - /** - * Creates this client util - * @param client The client to initialize with - */ - constructor(client: BushClient) { - super(client); - } - - /** - * Maps an array of user ids to user objects. - * @param ids The list of IDs to map - * @returns The list of users mapped - */ - public async mapIDs(ids: Snowflake[]): Promise { - return await Promise.all(ids.map((id) => this.client.users.fetch(id))); - } - - /** - * Capitalizes the first letter of the given text - * @param text The text to capitalize - * @returns The capitalized text - */ - public capitalize(text: string): string { - return text.charAt(0).toUpperCase() + text.slice(1); - } - - /** - * Runs a shell command and gives the output - * @param command The shell command to run - * @returns The stdout and stderr of the shell command - */ - public async shell(command: string): Promise<{ - stdout: string; - stderr: string; - }> { - return await this.exec(command); - } - - /** - * Posts text to hastebin - * @param content The text to post - * @returns The url of the posted text - */ - public async haste(content: string): Promise { - for (const url of this.hasteURLs) { - try { - const res: hastebinRes = await got.post(`${url}/documents`, { body: content }).json(); - return `${url}/${res.key}`; - } catch (e) { - this.client.console.error('Haste', `Unable to upload haste to ${url}`); - } - } - return 'Unable to post'; - } - - /** - * Resolves a user-provided string into a user object, if possible - * @param text The text to try and resolve - * @returns The user resolved or null - */ - public async resolveUserAsync(text: string): Promise { - const idReg = /\d{17,19}/; - const idMatch = text.match(idReg); - if (idMatch) { - try { - return await this.client.users.fetch(text as Snowflake); - } catch { - // pass - } - } - const mentionReg = /<@!?(?\d{17,19})>/; - const mentionMatch = text.match(mentionReg); - if (mentionMatch) { - try { - return await this.client.users.fetch(mentionMatch.groups.id as Snowflake); - } catch { - // pass - } - } - const user = this.client.users.cache.find((u) => u.username === text); - if (user) return user; - return null; - } - - /** - * Appends the correct ordinal to the given number - * @param n The number to append an ordinal to - * @returns The number with the ordinal - */ - public ordinal(n: number): string { - const s = ['th', 'st', 'nd', 'rd'], - v = n % 100; - return n + (s[(v - 20) % 10] || s[v] || s[0]); - } - - /** - * Chunks an array to the specified size - * @param arr The array to chunk - * @param perChunk The amount of items per chunk - * @returns The chunked array - */ - public chunk(arr: T[], perChunk: number): T[][] { - return arr.reduce((all, one, i) => { - const ch = Math.floor(i / perChunk); - all[ch] = [].concat(all[ch] || [], one); - return all; - }, []); - } - - /** Commonly Used Colors */ - public colors: bushColors = { - default: '#1FD8F1', - error: '#EF4947', - warn: '#FEBA12', - success: '#3BB681', - info: '#3B78FF', - red: '#ff0000', - blue: '#0055ff', - aqua: '#00bbff', - purple: '#8400ff', - blurple: '#5440cd', - pink: '#ff00e6', - green: '#00ff1e', - darkGreen: '#008f11', - gold: '#b59400', - yellow: '#ffff00', - white: '#ffffff', - gray: '#a6a6a6', - lightGray: '#cfcfcf', - darkGray: '#7a7a7a', - black: '#000000', - orange: '#E86100' - }; - - /** Commonly Used Emojis */ - public emojis = { - success: '<:checkmark:837109864101707807>', - warn: '<:warn:848726900876247050>', - error: '<:error:837123021016924261>', - successFull: '<:checkmark_full:850118767576088646>', - warnFull: '<:warn_full:850118767391539312>', - errorFull: '<:error_full:850118767295201350>', - mad: '<:mad:783046135392239626>', - join: '<:join:850198029809614858>', - leave: '<:leave:850198048205307919>', - loading: '' - }; - - /** - * A simple utility to create and embed with the needed style for the bot - */ - public createEmbed(color?: ColorResolvable, author?: User | GuildMember): MessageEmbed { - if (author instanceof GuildMember) { - author = author.user; // Convert to User if GuildMember - } - let embed = new MessageEmbed().setTimestamp(); - if (author) - embed = embed.setAuthor( - author.username, - author.displayAvatarURL({ dynamic: true }), - `https://discord.com/users/${author.id}` - ); - if (color) embed = embed.setColor(color); - return embed; - } - - public async mcUUID(username: string): Promise { - const apiRes = (await got.get(`https://api.ashcon.app/mojang/v2/user/${username}`).json()) as uuidRes; - return apiRes.uuid.replace(/-/g, ''); - } - - /** Paginates an array of embeds using buttons. */ - public async buttonPaginate( - message: BushMessage, - embeds: MessageEmbed[], - text: string | null = null, - deleteOnExit?: boolean - ): Promise { - if (deleteOnExit === undefined) deleteOnExit = true; - - embeds.forEach((_e, i) => { - embeds[i] = embeds[i].setFooter(`Page ${i + 1}/${embeds.length}`); - }); - - const style = Constants.MessageButtonStyles.PRIMARY; - let curPage = 0; - if (typeof embeds !== 'object') throw 'embeds must be an object'; - const msg: Message = await message.util.reply({ - content: text, - embeds: [embeds[curPage]], - components: [getPaginationRow()] - }); - const filter = (interaction: ButtonInteraction) => - interaction.customID.startsWith('paginate_') && interaction.message == msg; - const collector = msg.createMessageComponentInteractionCollector({ filter, time: 300000 }); - collector.on('collect', async (interaction: MessageComponentInteraction) => { - if (interaction.user.id == message.author.id || this.client.config.owners.includes(interaction.user.id)) { - switch (interaction.customID) { - case 'paginate_beginning': { - curPage = 0; - await edit(interaction); - break; - } - case 'paginate_back': { - curPage--; - await edit(interaction); - break; - } - case 'paginate_stop': { - if (deleteOnExit) { - await interaction.deferUpdate().catch(() => undefined); - if (msg.deletable && !msg.deleted) { - await msg.delete(); - } - } else { - await interaction - ?.update({ content: `${text ? text + '\n' : ''}Command closed by user.`, embeds: [], components: [] }) - .catch(() => undefined); - } - return; - } - case 'paginate_next': { - curPage++; - await edit(interaction); - break; - } - case 'paginate_end': { - curPage = embeds.length - 1; - await edit(interaction); - break; - } - } - } else { - return await interaction?.deferUpdate().catch(() => undefined); - } - }); - - collector.on('end', async () => { - await msg.edit({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow(true)] }).catch(() => undefined); - }); - - async function edit(interaction: MessageComponentInteraction): Promise { - return await interaction - ?.update({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow()] }) - .catch(() => undefined); - } - const paginateEmojis = this.paginateEmojis; - function getPaginationRow(disableAll = false): MessageActionRow { - return new MessageActionRow().addComponents( - new MessageButton({ - style, - customID: 'paginate_beginning', - emoji: paginateEmojis.beginning, - disabled: disableAll || curPage == 0 - }), - new MessageButton({ - style, - customID: 'paginate_back', - emoji: paginateEmojis.back, - disabled: disableAll || curPage == 0 - }), - new MessageButton({ style, customID: 'paginate_stop', emoji: paginateEmojis.stop, disabled: disableAll }), - new MessageButton({ - style, - customID: 'paginate_next', - emoji: paginateEmojis.forward, - disabled: disableAll || curPage == embeds.length - 1 - }), - new MessageButton({ - style, - customID: 'paginate_end', - emoji: paginateEmojis.end, - disabled: disableAll || curPage == embeds.length - 1 - }) - ); - } - } - - /** Sends a message with a button for the user to delete it. */ - public async sendWithDeleteButton(message: BushMessage, options: MessageOptions): Promise { - updateOptions(); - const msg = await message.util.reply(options as MessageOptions & { split?: false }); - const filter = (interaction: ButtonInteraction) => interaction.customID == 'paginate__stop' && interaction.message == msg; - const collector = msg.createMessageComponentInteractionCollector({ filter, time: 300000 }); - collector.on('collect', async (interaction: MessageComponentInteraction) => { - if (interaction.user.id == message.author.id || this.client.config.owners.includes(interaction.user.id)) { - await interaction.deferUpdate().catch(() => undefined); - if (msg.deletable && !msg.deleted) { - await msg.delete(); - } - return; - } else { - return await interaction?.deferUpdate().catch(() => undefined); - } - }); - - collector.on('end', async () => { - updateOptions(true, true); - await msg.edit(options as MessageEditOptions).catch(() => undefined); - }); - - const paginateEmojis = this.paginateEmojis; - function updateOptions(edit?: boolean, disable?: boolean) { - if (edit == undefined) edit = false; - if (disable == undefined) disable = false; - options.components = [ - new MessageActionRow().addComponents( - new MessageButton({ - style: Constants.MessageButtonStyles.PRIMARY, - customID: 'paginate__stop', - emoji: paginateEmojis.stop, - disabled: disable - }) - ) - ]; - if (edit) { - options.reply = undefined; - } - } - } - - /** - * Surrounds text in a code block with the specified language and puts it in a hastebin if its too long. - * - * * Embed Description Limit = 2048 characters - * * Embed Field Limit = 1024 characters - */ - public async codeblock(code: string, length: number, language: 'ts' | 'js' | 'sh' | 'json' | '' = ''): Promise { - let hasteOut = ''; - const tildes = '```'; - const formattingLength = 2 * tildes.length + language.length + 2 * '\n'.length; - if (code.length + formattingLength > length) hasteOut = 'Too large to display. Hastebin: ' + (await this.haste(code)); - - const code2 = code.length > length ? code.substring(0, length - (hasteOut.length + '\n'.length + formattingLength)) : code; - return ( - tildes + language + '\n' + Util.cleanCodeBlockContent(code2) + '\n' + tildes + (hasteOut.length ? '\n' + hasteOut : '') - ); - } - - public async slashRespond( - interaction: CommandInteraction, - responseOptions: string | MessagePayload | WebhookEditMessageOptions - ): Promise { - let newResponseOptions: string | MessagePayload | WebhookEditMessageOptions = {}; - if (typeof responseOptions === 'string') { - newResponseOptions.content = responseOptions; - } else { - newResponseOptions = responseOptions; - } - if (interaction.replied || interaction.deferred) { - //@ts-expect-error: stop being dumb - delete newResponseOptions.ephemeral; // Cannot change a preexisting message to be ephemeral - return (await interaction.editReply(newResponseOptions)) as Message | APIMessage; - } else { - await interaction.reply(newResponseOptions); - return await interaction.fetchReply().catch(() => undefined); - } - } - - /** Gets the channel configs as a TextChannel */ - public async getConfigChannel(channel: 'log' | 'error' | 'dm'): Promise { - return (await this.client.channels.fetch(this.client.config.channels[channel])) as TextChannel; - } - - /** - * Takes an array and combines the elements using the supplied conjunction. - * - * @param {string[]} array The array to combine. - * @param {string} conjunction The conjunction to use. - * @param {string} ifEmpty What to return if the array is empty. - * @returns The combined elements or `ifEmpty` - * - * @example - * const permissions = oxford(['ADMINISTRATOR', 'SEND_MESSAGES', 'MANAGE_MESSAGES'], 'and', 'none'); - * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES - */ - public oxford(array: string[], conjunction: string, ifEmpty: string): string { - const l = array.length; - if (!l) return ifEmpty; - if (l < 2) return array[0]; - if (l < 3) return array.join(` ${conjunction} `); - array = array.slice(); - array[l - 1] = `${conjunction} ${array[l - 1]}`; - return array.join(', '); - } - - public async insertOrRemoveFromGlobal( - action: 'add' | 'remove', - key: keyof typeof BushCache['global'], - value: any - ): Promise { - const environment = this.client.config.dev ? 'development' : 'production'; - const row = await Global.findByPk(environment); - const oldValue: any[] = row[key]; - let newValue: any[]; - if (action === 'add') { - if (!oldValue.includes(action)) oldValue.push(value); - newValue = oldValue; - } else { - newValue = oldValue.filter((ae) => ae !== value); - } - row[key] = newValue; - this.client.cache.global[key] = newValue; - return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e)); - } - - /** - * Surrounds a string to the begging an end of each element in an array. - * - * @param {string[]} array The array you want to surround. - * @param {string} surroundChar1 The character placed in the beginning of the element (or end if surroundChar2 isn't supplied). - * @param {string} [surroundChar2=surroundChar1] The character placed in the end of the element. - * @returns {string[]} - */ - public surroundArray(array: string[], surroundChar1: string, surroundChar2?: string): string[] { - const newArray = []; - array.forEach((a) => { - newArray.push(`${surroundChar1}${a}${surroundChar2 || surroundChar1}`); - }); - return newArray; - } - - // public createModLogEntry( - // user: User | Snowflake, - // guild: Guild | Snowflake, - // reason?: string, - // type?: ModLogType, - // duration?: number, - // moderator: User | Snowflake - // ): ModLog { - - // } -} diff --git a/src/lib/extensions/BushCommand.ts b/src/lib/extensions/BushCommand.ts deleted file mode 100644 index f22a628..0000000 --- a/src/lib/extensions/BushCommand.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { ArgumentGenerator, ArgumentOptions, ArgumentPromptOptions, Command, CommandOptions } from 'discord-akairo'; -import { Snowflake } from 'discord.js'; -import { BushClient } from './BushClient'; -import { BushCommandHandler } from './BushCommandHandler'; -import { BushMessage } from './BushMessage'; -import { BushSlashMessage } from './BushSlashMessage'; - -export interface BushArgumentOptions extends ArgumentOptions { - id: string; - description?: string; - prompt?: ArgumentPromptOptions; -} - -export interface BushCommandOptions extends CommandOptions { - hidden?: boolean; - restrictedChannels?: Snowflake[]; - restrictedGuilds?: Snowflake[]; - description: { - content: string; - usage: string | string[]; - examples: string | string[]; - }; - args?: BushArgumentOptions[] | ArgumentGenerator; - category: string; -} - -export class BushCommand extends Command { - public declare client: BushClient; - - public declare handler: BushCommandHandler; - - public options: BushCommandOptions; - - /** The channels the command is limited to run in. */ - public restrictedChannels: Snowflake[]; - - /** The guilds the command is limited to run in. */ - public restrictedGuilds: Snowflake[]; - - /** Whether the command is hidden from the help command. */ - public hidden: boolean; - - constructor(id: string, options?: BushCommandOptions) { - super(id, options); - this.options = options; - this.hidden = options.hidden || false; - this.restrictedChannels = options.restrictedChannels; - this.restrictedGuilds = options.restrictedGuilds; - } - - public exec(message: BushMessage, args: any): any; - public exec(message: BushMessage | BushSlashMessage, args: any): any { - super.exec(message, args); - } -} diff --git a/src/lib/extensions/BushCommandHandler.ts b/src/lib/extensions/BushCommandHandler.ts deleted file mode 100644 index aeea101..0000000 --- a/src/lib/extensions/BushCommandHandler.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { Category, CommandHandler, CommandHandlerOptions } from 'discord-akairo'; -import { Collection } from 'discord.js'; -import { BushConstants } from '../utils/BushConstants'; -import { BushClient } from './BushClient'; -import { BushCommand } from './BushCommand'; -import { BushMessage } from './BushMessage'; - -export type BushCommandHandlerOptions = CommandHandlerOptions; - -const CommandHandlerEvents = BushConstants.CommandHandlerEvents; -const BlockedReasons = BushConstants.BlockedReasons; - -export class BushCommandHandler extends CommandHandler { - public declare client: BushClient; - public declare modules: Collection; - public declare categories: Collection>; - public constructor(client: BushClient, options: CommandHandlerOptions) { - super(client, options); - this.client = client; - } - - public async runPostTypeInhibitors(message: BushMessage, command: BushCommand, slash = false): Promise { - if (command.ownerOnly) { - const isOwner = this.client.isOwner(message.author); - if (!isOwner) { - this.emit( - slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, - message, - command, - BlockedReasons.OWNER - ); - return true; - } - } - - if (command.superUserOnly) { - const isSuperUser = this.client.isSuperUser(message.author); - if (!isSuperUser) { - this.emit( - slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, - message, - command, - BlockedReasons.OWNER - ); - return true; - } - } - - if (command.channel === 'guild' && !message.guild) { - this.emit( - slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, - message, - command, - BlockedReasons.GUILD - ); - return true; - } - - if (command.channel === 'dm' && message.guild) { - this.emit( - slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, - message, - command, - BlockedReasons.DM - ); - return true; - } - if (command.restrictedChannels?.length && message.channel) { - if (!command.restrictedChannels.includes(message.channel.id)) { - this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, BlockedReasons.RESTRICTED_CHANNEL); - return true; - } - } - if (command.restrictedGuilds?.length && message.guild) { - if (!command.restrictedGuilds.includes(message.guild.id)) { - this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, BlockedReasons.RESTRICTED_GUILD); - return true; - } - } - if (await this.runPermissionChecks(message, command)) { - return true; - } - const reason = this.inhibitorHandler ? await this.inhibitorHandler.test('post', message, command) : null; - if (reason != null) { - this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, reason); - return true; - } - return !!this.runCooldowns(message, command); - } -} diff --git a/src/lib/extensions/BushCommandUtil.ts b/src/lib/extensions/BushCommandUtil.ts deleted file mode 100644 index b4084bd..0000000 --- a/src/lib/extensions/BushCommandUtil.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { CommandUtil, ParsedComponentData } from 'discord-akairo'; -import { BushCommand } from './BushCommand'; - -export interface BushParsedComponentData extends ParsedComponentData { - command?: BushCommand; -} - -export class BushCommandUtil extends CommandUtil { - declare parsed?: BushParsedComponentData; -} diff --git a/src/lib/extensions/BushGuild.ts b/src/lib/extensions/BushGuild.ts deleted file mode 100644 index 1d7b3c8..0000000 --- a/src/lib/extensions/BushGuild.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Guild, Structures } from 'discord.js'; -import { Guild as GuildDB, GuildModel } from '../models/Guild'; -import { BushClient } from './BushClient'; - -export class BushGuild extends Guild { - public declare client: BushClient; - public constructor(client: BushClient, data: unknown) { - super(client, data); - } - - public async getSetting(setting: K): Promise { - return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id })).get(setting); - } - - public async setSetting(setting: K, value: GuildDB[K]): Promise { - const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); - row[setting] = value; - return await row.save(); - } -} - -Structures.extend('Guild', () => BushGuild); diff --git a/src/lib/extensions/BushGuildMember.ts b/src/lib/extensions/BushGuildMember.ts deleted file mode 100644 index 2bb0601..0000000 --- a/src/lib/extensions/BushGuildMember.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { GuildMember, Structures } from 'discord.js'; -import { BushClient } from './BushClient'; -import { BushGuild } from './BushGuild'; -import { BushUser } from './BushUser'; - -export class BushGuildMember extends GuildMember { - public declare client: BushClient; - public declare guild: BushGuild; - public declare BushUser: BushUser; - public constructor(client: BushClient, data: unknown, guild: BushGuild) { - super(client, data, guild); - } -} - -Structures.extend('GuildMember', () => BushGuildMember); diff --git a/src/lib/extensions/BushInhibitor.ts b/src/lib/extensions/BushInhibitor.ts deleted file mode 100644 index 602ff65..0000000 --- a/src/lib/extensions/BushInhibitor.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { Inhibitor } from 'discord-akairo'; -import { BushClient } from './BushClient'; -import { BushCommand } from './BushCommand'; -import { BushMessage } from './BushMessage'; -import { BushSlashMessage } from './BushSlashMessage'; - -export class BushInhibitor extends Inhibitor { - public declare client: BushClient; - - public exec(message: BushMessage, command: BushCommand): any; - public exec(message: BushMessage | BushSlashMessage, command: BushCommand): any { - super.exec(message, command); - } -} diff --git a/src/lib/extensions/BushInhinitorHandler.ts b/src/lib/extensions/BushInhinitorHandler.ts deleted file mode 100644 index 2a947da..0000000 --- a/src/lib/extensions/BushInhinitorHandler.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { InhibitorHandler } from 'discord-akairo'; -import { BushClient } from './BushClient'; - -export class BushInhibitorHandler extends InhibitorHandler { - public declare client: BushClient; -} diff --git a/src/lib/extensions/BushListener.ts b/src/lib/extensions/BushListener.ts deleted file mode 100644 index e555e89..0000000 --- a/src/lib/extensions/BushListener.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Listener } from 'discord-akairo'; -import { BushClient } from './BushClient'; - -export class BushListener extends Listener { - public declare client: BushClient; -} diff --git a/src/lib/extensions/BushListenerHandler.ts b/src/lib/extensions/BushListenerHandler.ts deleted file mode 100644 index 28615fc..0000000 --- a/src/lib/extensions/BushListenerHandler.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { ListenerHandler } from 'discord-akairo'; -import { BushClient } from './BushClient'; - -export class BushListenerHandler extends ListenerHandler { - declare client: BushClient; -} diff --git a/src/lib/extensions/BushMessage.ts b/src/lib/extensions/BushMessage.ts deleted file mode 100644 index 6293c55..0000000 --- a/src/lib/extensions/BushMessage.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { DMChannel, Message, NewsChannel, Structures, TextChannel } from 'discord.js'; -import { BushClient } from './BushClient'; -import { BushCommandUtil } from './BushCommandUtil'; -import { BushGuild } from './BushGuild'; -import { BushGuildMember } from './BushGuildMember'; -import { BushUser } from './BushUser'; - -export class BushMessage extends Message { - public declare client: BushClient; - public declare util: BushCommandUtil; - public declare guild: BushGuild; - public declare member: BushGuildMember; - public declare author: BushUser; - public constructor(client: BushClient, data: unknown, channel: TextChannel | DMChannel | NewsChannel) { - super(client, data, channel); - this.client = client; - this.channel = channel; - } -} - -Structures.extend('Message', () => BushMessage); diff --git a/src/lib/extensions/BushSlashMessage.ts b/src/lib/extensions/BushSlashMessage.ts deleted file mode 100644 index 33ca11f..0000000 --- a/src/lib/extensions/BushSlashMessage.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AkairoMessage } from 'discord-akairo'; -import { CommandInteraction } from 'discord.js'; -import { BushClient } from './BushClient'; -import { BushCommandUtil } from './BushCommandUtil'; -import { BushGuild } from './BushGuild'; -import { BushUser } from './BushUser'; - -export class BushSlashMessage extends AkairoMessage { - public declare client: BushClient; - public declare util: BushCommandUtil; - public declare guild: BushGuild; - public declare author: BushUser; - public constructor( - client: BushClient, - interaction: CommandInteraction, - { slash, replied }: { slash?: boolean; replied?: boolean } - ) { - super(client, interaction, { slash, replied }); - } -} diff --git a/src/lib/extensions/BushTask.ts b/src/lib/extensions/BushTask.ts deleted file mode 100644 index 06d0602..0000000 --- a/src/lib/extensions/BushTask.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Task } from 'discord-akairo'; -import { BushClient } from './BushClient'; - -export class BushTask extends Task { - public declare client: BushClient; -} diff --git a/src/lib/extensions/BushTaskHandler.ts b/src/lib/extensions/BushTaskHandler.ts deleted file mode 100644 index 588988d..0000000 --- a/src/lib/extensions/BushTaskHandler.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { AkairoHandlerOptions, TaskHandler } from 'discord-akairo'; -import { BushClient } from './BushClient'; - -export type BushTaskHandlerOptions = AkairoHandlerOptions; - -export class BushTaskHandler extends TaskHandler { - public constructor(client: BushClient, options: BushTaskHandlerOptions) { - super(client, options); - } - declare client: BushClient; -} diff --git a/src/lib/extensions/BushUser.ts b/src/lib/extensions/BushUser.ts deleted file mode 100644 index 53fd449..0000000 --- a/src/lib/extensions/BushUser.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Structures, User } from 'discord.js'; -import { BushClient } from './BushClient'; - -export class BushUser extends User { - public declare client: BushClient; - public constructor(client: BushClient, data: unknown) { - super(client, data); - } - - public isOwner(): boolean { - return this.client.isOwner(this); - } - - public isSuperUser(): boolean { - return this.client.isSuperUser(this); - } -} - -Structures.extend('User', () => BushUser); diff --git a/src/lib/extensions/discord-akairo/BushArgumentOptions.ts b/src/lib/extensions/discord-akairo/BushArgumentOptions.ts new file mode 100644 index 0000000..bbbc04b --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushArgumentOptions.ts @@ -0,0 +1,59 @@ +import { ArgumentOptions, ArgumentTypeCaster } from 'discord-akairo'; + +type BushArgumentType = + | 'string' + | 'lowercase' + | 'uppercase' + | 'charCodes' + | 'number' + | 'integer' + | 'bigint' + | 'emojint' + | 'url' + | 'date' + | 'color' + | 'user' + | 'users' + | 'member' + | 'members' + | 'relevant' + | 'relevants' + | 'channel' + | 'channels' + | 'textChannel' + | 'textChannels' + | 'voiceChannel' + | 'voiceChannels' + | 'categoryChannel' + | 'categoryChannels' + | 'newsChannel' + | 'newsChannels' + | 'storeChannel' + | 'storeChannels' + | 'role' + | 'roles' + | 'emoji' + | 'emojis' + | 'guild' + | 'guilds' + | 'message' + | 'guildMessage' + | 'relevantMessage' + | 'invite' + | 'userMention' + | 'memberMention' + | 'channelMention' + | 'roleMention' + | 'emojiMention' + | 'commandAlias' + | 'command' + | 'inhibitor' + | 'listener' + | 'duration' + | (string | string[])[] + | RegExp + | string; + +export interface BushArgumentOptions extends ArgumentOptions { + type?: BushArgumentType | ArgumentTypeCaster; +} diff --git a/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts new file mode 100644 index 0000000..9afcf8b --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushArgumentTypeCaster.ts @@ -0,0 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { BushMessage } from '../discord.js/BushMessage'; + +export type BushArgumentTypeCaster = (message: BushMessage, phrase: string) => any; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts new file mode 100644 index 0000000..c18fe80 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -0,0 +1,233 @@ +import chalk from 'chalk'; +import { AkairoClient } from 'discord-akairo'; +import { + Guild, + Intents, + Message, + MessageEditOptions, + MessageOptions, + MessagePayload, + ReplyMessageOptions, + Snowflake, + Structures, + UserResolvable +} from 'discord.js'; +import * as path from 'path'; +import { exit } from 'process'; +import readline from 'readline'; +import { Sequelize } from 'sequelize'; +import { durationTypeCaster } from '../../../arguments/duration'; +import * as config from '../../../config/options'; +import UpdateCacheTask from '../../../tasks/updateCache'; +import * as Models from '../../models'; +import AllowedMentions from '../../utils/AllowedMentions'; +import { BushCache } from '../../utils/BushCache'; +import { BushConstants } from '../../utils/BushConstants'; +import { BushLogger } from '../../utils/BushLogger'; +import { BushGuild } from '../discord.js/BushGuild'; +import { BushGuildMember } from '../discord.js/BushGuildMember'; +import { BushMessage } from '../discord.js/BushMessage'; +import { BushUser } from '../discord.js/BushUser'; +import { BushClientUtil } from './BushClientUtil'; +import { BushCommandHandler } from './BushCommandHandler'; +import { BushInhibitorHandler } from './BushInhinitorHandler'; +import { BushListenerHandler } from './BushListenerHandler'; +import { BushTaskHandler } from './BushTaskHandler'; + +export type BotConfig = typeof config; +export type BushReplyMessageType = string | MessagePayload | ReplyMessageOptions; +export type BushEditMessageType = string | MessageEditOptions | MessagePayload; +export type BushSendMessageType = string | MessagePayload | MessageOptions; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false +}); + +export class BushClient extends AkairoClient { + public config: BotConfig; + public listenerHandler: BushListenerHandler; + public inhibitorHandler: BushInhibitorHandler; + public commandHandler: BushCommandHandler; + public taskHandler: BushTaskHandler; + public declare util: BushClientUtil; + public declare ownerID: Snowflake[]; + public db: Sequelize; + public logger: BushLogger; + public constants = BushConstants; + public cache = BushCache; + constructor(config: BotConfig) { + super( + { + ownerID: config.owners, + intents: Intents.ALL + }, + { + allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default + intents: Intents.ALL + } + ); + + // Set token + this.token = config.credentials.token; + + // Set config + this.config = config; + + // Create listener handler + this.listenerHandler = new BushListenerHandler(this, { + directory: path.join(__dirname, '..', '..', 'listeners'), + automateCategories: true + }); + + // Create inhibitor handler + this.inhibitorHandler = new BushInhibitorHandler(this, { + directory: path.join(__dirname, '..', '..', 'inhibitors'), + automateCategories: true + }); + + // Create task handler + this.taskHandler = new BushTaskHandler(this, { + directory: path.join(__dirname, '..', '..', 'tasks') + }); + + // Create command handler + this.commandHandler = new BushCommandHandler(this, { + directory: path.join(__dirname, '..', '..', 'commands'), + prefix: async ({ guild }: { guild: Guild }) => { + if (this.config.dev) return 'dev '; + const row = await Models.Guild.findByPk(guild.id); + return (row?.prefix || this.config.prefix) as string; + }, + allowMention: true, + handleEdits: true, + commandUtil: true, + commandUtilLifetime: 300_000, + argumentDefaults: { + prompt: { + start: 'Placeholder argument prompt. If you see this please tell the devs.', + retry: 'Placeholder failed argument prompt. If you see this please tell the devs.', + modifyStart: (_: Message, str: string): string => `${str}\n\n Type \`cancel\` to cancel the command`, + modifyRetry: (_: Message, str: string): string => + `${str.replace('{error}', this.util.emojis.error)}\n\n Type \`cancel\` to cancel the command`, + timeout: 'You took too long the command has been cancelled', + ended: 'You exceeded the maximum amount of tries the command has been cancelled', + cancel: 'The command has been cancelled', + retries: 3, + time: 3e4 + }, + otherwise: '' + }, + + automateCategories: false, + autoRegisterSlashCommands: true + }); + + this.util = new BushClientUtil(this); + this.db = new Sequelize(this.config.dev ? 'bushbot-dev' : 'bushbot', this.config.db.username, this.config.db.password, { + dialect: 'postgres', + host: this.config.db.host, + port: this.config.db.port, + logging: this.config.logging.db ? (a) => this.logger.debug(a) : false + }); + this.logger = new BushLogger(this); + } + + get console(): BushLogger { + return this.logger; + } + + get consts(): typeof BushConstants { + return this.constants; + } + + // Initialize everything + private async _init(): Promise { + Structures.extend('User', () => BushUser); + Structures.extend('Guild', () => BushGuild); + Structures.extend('GuildMember', () => BushGuildMember); + Structures.extend('Message', () => BushMessage); + + this.commandHandler.useListenerHandler(this.listenerHandler); + this.commandHandler.useInhibitorHandler(this.inhibitorHandler); + this.commandHandler.ignorePermissions = this.config.owners; + this.commandHandler.ignoreCooldown = this.config.owners.concat(this.cache.global.superUsers); + this.listenerHandler.setEmitters({ + client: this, + commandHandler: this.commandHandler, + listenerHandler: this.listenerHandler, + inhibitorHandler: this.inhibitorHandler, + taskHandler: this.taskHandler, + process, + stdin: rl, + gateway: this.ws + }); + this.commandHandler.resolver.addTypes({ + duration: durationTypeCaster + }); + // loads all the handlers + const loaders = { + commands: this.commandHandler, + listeners: this.listenerHandler, + inhibitors: this.inhibitorHandler, + tasks: this.taskHandler + }; + for (const loader of Object.keys(loaders)) { + try { + loaders[loader].loadAll(); + await this.logger.success('Startup', `Successfully loaded <<${loader}>>.`, false); + } catch (e) { + await this.logger.error('Startup', `Unable to load loader <<${loader}>> with error:\n${e?.stack}`, false); + } + } + await this.dbPreInit(); + await new UpdateCacheTask().init(this); + this.console.success('Startup', `Successfully created <>.`, false); + this.taskHandler.startAll(); + } + + public async dbPreInit(): Promise { + try { + await this.db.authenticate(); + Models.Global.initModel(this.db); + Models.Guild.initModel(this.db, this); + Models.ModLog.initModel(this.db); + Models.Ban.initModel(this.db); + Models.Mute.initModel(this.db); + Models.Level.initModel(this.db); + Models.StickyRole.initModel(this.db); + await this.db.sync({ alter: true }); // Sync all tables to fix everything if updated + await this.console.success('Startup', `Successfully connected to <>.`, false); + } catch (error) { + await this.console.error('Startup', `Failed to connect to <> with error:\n` + error?.stack, false); + } + } + + /** Starts the bot */ + public async start(): Promise { + try { + await this._init(); + await this.login(this.token); + } catch (e) { + await this.console.error('Start', chalk.red(e.stack), false); + exit(2); + } + } + + /** Logs out, terminates the connection to Discord, and destroys the client. */ + public destroy(relogin = false): void | Promise { + super.destroy(); + if (relogin) { + return this.login(this.token); + } + } + + public isOwner(user: UserResolvable): boolean { + return this.config.owners.includes(this.users.resolveID(user)); + } + public isSuperUser(user: UserResolvable): boolean { + const userID = this.users.resolveID(user); + return !!BushCache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID); + } +} diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts new file mode 100644 index 0000000..94ad10c --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -0,0 +1,536 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { exec } from 'child_process'; +import { ClientUtil } from 'discord-akairo'; +import { APIMessage } from 'discord-api-types'; +import { + ButtonInteraction, + ColorResolvable, + CommandInteraction, + Constants, + GuildMember, + Message, + MessageActionRow, + MessageButton, + MessageComponentInteraction, + MessageEditOptions, + MessageEmbed, + MessageOptions, + MessagePayload, + Snowflake, + TextChannel, + User, + Util, + WebhookEditMessageOptions +} from 'discord.js'; +import got from 'got'; +import { promisify } from 'util'; +import { Global } from '../../models'; +import { BushCache } from '../../utils/BushCache'; +import { BushMessage } from '../discord.js/BushMessage'; +import { BushClient } from './BushClient'; + +interface hastebinRes { + key: string; +} + +export interface uuidRes { + uuid: string; + username: string; + username_history?: { username: string }[] | null; + textures: { + custom: boolean; + slim: boolean; + skin: { + url: string; + data: string; + }; + raw: { + value: string; + signature: string; + }; + }; + created_at: string; +} + +interface bushColors { + default: '#1FD8F1'; + error: '#EF4947'; + warn: '#FEBA12'; + success: '#3BB681'; + info: '#3B78FF'; + red: '#ff0000'; + blue: '#0055ff'; + aqua: '#00bbff'; + purple: '#8400ff'; + blurple: '#5440cd'; + pink: '#ff00e6'; + green: '#00ff1e'; + darkGreen: '#008f11'; + gold: '#b59400'; + yellow: '#ffff00'; + white: '#ffffff'; + gray: '#a6a6a6'; + lightGray: '#cfcfcf'; + darkGray: '#7a7a7a'; + black: '#000000'; + orange: '#E86100'; +} +export class BushClientUtil extends ClientUtil { + /** The client of this ClientUtil */ + public declare readonly client: BushClient; + /** The hastebin urls used to post to hastebin, attempts to post in order */ + public hasteURLs: string[] = [ + 'https://hst.sh', + 'https://hasteb.in', + 'https://hastebin.com', + 'https://mystb.in', + 'https://haste.clicksminuteper.net', + 'https://paste.pythondiscord.com', + 'https://haste.unbelievaboat.com', + 'https://haste.tyman.tech' + ]; + public paginateEmojis = { + beginning: '853667381335162910', + back: '853667410203770881', + stop: '853667471110570034', + forward: '853667492680564747', + end: '853667514915225640' + }; + + /** A simple promise exec method */ + private exec = promisify(exec); + + /** + * Creates this client util + * @param client The client to initialize with + */ + constructor(client: BushClient) { + super(client); + } + + /** + * Maps an array of user ids to user objects. + * @param ids The list of IDs to map + * @returns The list of users mapped + */ + public async mapIDs(ids: Snowflake[]): Promise { + return await Promise.all(ids.map((id) => this.client.users.fetch(id))); + } + + /** + * Capitalizes the first letter of the given text + * @param text The text to capitalize + * @returns The capitalized text + */ + public capitalize(text: string): string { + return text.charAt(0).toUpperCase() + text.slice(1); + } + + /** + * Runs a shell command and gives the output + * @param command The shell command to run + * @returns The stdout and stderr of the shell command + */ + public async shell(command: string): Promise<{ + stdout: string; + stderr: string; + }> { + return await this.exec(command); + } + + /** + * Posts text to hastebin + * @param content The text to post + * @returns The url of the posted text + */ + public async haste(content: string): Promise { + for (const url of this.hasteURLs) { + try { + const res: hastebinRes = await got.post(`${url}/documents`, { body: content }).json(); + return `${url}/${res.key}`; + } catch (e) { + this.client.console.error('Haste', `Unable to upload haste to ${url}`); + } + } + return 'Unable to post'; + } + + /** + * Resolves a user-provided string into a user object, if possible + * @param text The text to try and resolve + * @returns The user resolved or null + */ + public async resolveUserAsync(text: string): Promise { + const idReg = /\d{17,19}/; + const idMatch = text.match(idReg); + if (idMatch) { + try { + return await this.client.users.fetch(text as Snowflake); + } catch { + // pass + } + } + const mentionReg = /<@!?(?\d{17,19})>/; + const mentionMatch = text.match(mentionReg); + if (mentionMatch) { + try { + return await this.client.users.fetch(mentionMatch.groups.id as Snowflake); + } catch { + // pass + } + } + const user = this.client.users.cache.find((u) => u.username === text); + if (user) return user; + return null; + } + + /** + * Appends the correct ordinal to the given number + * @param n The number to append an ordinal to + * @returns The number with the ordinal + */ + public ordinal(n: number): string { + const s = ['th', 'st', 'nd', 'rd'], + v = n % 100; + return n + (s[(v - 20) % 10] || s[v] || s[0]); + } + + /** + * Chunks an array to the specified size + * @param arr The array to chunk + * @param perChunk The amount of items per chunk + * @returns The chunked array + */ + public chunk(arr: T[], perChunk: number): T[][] { + return arr.reduce((all, one, i) => { + const ch = Math.floor(i / perChunk); + all[ch] = [].concat(all[ch] || [], one); + return all; + }, []); + } + + /** Commonly Used Colors */ + public colors: bushColors = { + default: '#1FD8F1', + error: '#EF4947', + warn: '#FEBA12', + success: '#3BB681', + info: '#3B78FF', + red: '#ff0000', + blue: '#0055ff', + aqua: '#00bbff', + purple: '#8400ff', + blurple: '#5440cd', + pink: '#ff00e6', + green: '#00ff1e', + darkGreen: '#008f11', + gold: '#b59400', + yellow: '#ffff00', + white: '#ffffff', + gray: '#a6a6a6', + lightGray: '#cfcfcf', + darkGray: '#7a7a7a', + black: '#000000', + orange: '#E86100' + }; + + /** Commonly Used Emojis */ + public emojis = { + success: '<:checkmark:837109864101707807>', + warn: '<:warn:848726900876247050>', + error: '<:error:837123021016924261>', + successFull: '<:checkmark_full:850118767576088646>', + warnFull: '<:warn_full:850118767391539312>', + errorFull: '<:error_full:850118767295201350>', + mad: '<:mad:783046135392239626>', + join: '<:join:850198029809614858>', + leave: '<:leave:850198048205307919>', + loading: '' + }; + + /** + * A simple utility to create and embed with the needed style for the bot + */ + public createEmbed(color?: ColorResolvable, author?: User | GuildMember): MessageEmbed { + if (author instanceof GuildMember) { + author = author.user; // Convert to User if GuildMember + } + let embed = new MessageEmbed().setTimestamp(); + if (author) + embed = embed.setAuthor( + author.username, + author.displayAvatarURL({ dynamic: true }), + `https://discord.com/users/${author.id}` + ); + if (color) embed = embed.setColor(color); + return embed; + } + + public async mcUUID(username: string): Promise { + const apiRes = (await got.get(`https://api.ashcon.app/mojang/v2/user/${username}`).json()) as uuidRes; + return apiRes.uuid.replace(/-/g, ''); + } + + /** Paginates an array of embeds using buttons. */ + public async buttonPaginate( + message: BushMessage, + embeds: MessageEmbed[], + text: string | null = null, + deleteOnExit?: boolean + ): Promise { + if (deleteOnExit === undefined) deleteOnExit = true; + + embeds.forEach((_e, i) => { + embeds[i] = embeds[i].setFooter(`Page ${i + 1}/${embeds.length}`); + }); + + const style = Constants.MessageButtonStyles.PRIMARY; + let curPage = 0; + if (typeof embeds !== 'object') throw 'embeds must be an object'; + const msg: Message = await message.util.reply({ + content: text, + embeds: [embeds[curPage]], + components: [getPaginationRow()] + }); + const filter = (interaction: ButtonInteraction) => + interaction.customID.startsWith('paginate_') && interaction.message == msg; + const collector = msg.createMessageComponentInteractionCollector({ filter, time: 300000 }); + collector.on('collect', async (interaction: MessageComponentInteraction) => { + if (interaction.user.id == message.author.id || this.client.config.owners.includes(interaction.user.id)) { + switch (interaction.customID) { + case 'paginate_beginning': { + curPage = 0; + await edit(interaction); + break; + } + case 'paginate_back': { + curPage--; + await edit(interaction); + break; + } + case 'paginate_stop': { + if (deleteOnExit) { + await interaction.deferUpdate().catch(() => undefined); + if (msg.deletable && !msg.deleted) { + await msg.delete(); + } + } else { + await interaction + ?.update({ content: `${text ? text + '\n' : ''}Command closed by user.`, embeds: [], components: [] }) + .catch(() => undefined); + } + return; + } + case 'paginate_next': { + curPage++; + await edit(interaction); + break; + } + case 'paginate_end': { + curPage = embeds.length - 1; + await edit(interaction); + break; + } + } + } else { + return await interaction?.deferUpdate().catch(() => undefined); + } + }); + + collector.on('end', async () => { + await msg.edit({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow(true)] }).catch(() => undefined); + }); + + async function edit(interaction: MessageComponentInteraction): Promise { + return await interaction + ?.update({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow()] }) + .catch(() => undefined); + } + const paginateEmojis = this.paginateEmojis; + function getPaginationRow(disableAll = false): MessageActionRow { + return new MessageActionRow().addComponents( + new MessageButton({ + style, + customID: 'paginate_beginning', + emoji: paginateEmojis.beginning, + disabled: disableAll || curPage == 0 + }), + new MessageButton({ + style, + customID: 'paginate_back', + emoji: paginateEmojis.back, + disabled: disableAll || curPage == 0 + }), + new MessageButton({ style, customID: 'paginate_stop', emoji: paginateEmojis.stop, disabled: disableAll }), + new MessageButton({ + style, + customID: 'paginate_next', + emoji: paginateEmojis.forward, + disabled: disableAll || curPage == embeds.length - 1 + }), + new MessageButton({ + style, + customID: 'paginate_end', + emoji: paginateEmojis.end, + disabled: disableAll || curPage == embeds.length - 1 + }) + ); + } + } + + /** Sends a message with a button for the user to delete it. */ + public async sendWithDeleteButton(message: BushMessage, options: MessageOptions): Promise { + updateOptions(); + const msg = await message.util.reply(options as MessageOptions & { split?: false }); + const filter = (interaction: ButtonInteraction) => interaction.customID == 'paginate__stop' && interaction.message == msg; + const collector = msg.createMessageComponentInteractionCollector({ filter, time: 300000 }); + collector.on('collect', async (interaction: MessageComponentInteraction) => { + if (interaction.user.id == message.author.id || this.client.config.owners.includes(interaction.user.id)) { + await interaction.deferUpdate().catch(() => undefined); + if (msg.deletable && !msg.deleted) { + await msg.delete(); + } + return; + } else { + return await interaction?.deferUpdate().catch(() => undefined); + } + }); + + collector.on('end', async () => { + updateOptions(true, true); + await msg.edit(options as MessageEditOptions).catch(() => undefined); + }); + + const paginateEmojis = this.paginateEmojis; + function updateOptions(edit?: boolean, disable?: boolean) { + if (edit == undefined) edit = false; + if (disable == undefined) disable = false; + options.components = [ + new MessageActionRow().addComponents( + new MessageButton({ + style: Constants.MessageButtonStyles.PRIMARY, + customID: 'paginate__stop', + emoji: paginateEmojis.stop, + disabled: disable + }) + ) + ]; + if (edit) { + options.reply = undefined; + } + } + } + + /** + * Surrounds text in a code block with the specified language and puts it in a hastebin if its too long. + * + * * Embed Description Limit = 2048 characters + * * Embed Field Limit = 1024 characters + */ + public async codeblock(code: string, length: number, language: 'ts' | 'js' | 'sh' | 'json' | '' = ''): Promise { + let hasteOut = ''; + const tildes = '```'; + const formattingLength = 2 * tildes.length + language.length + 2 * '\n'.length; + if (code.length + formattingLength > length) hasteOut = 'Too large to display. Hastebin: ' + (await this.haste(code)); + + const code2 = code.length > length ? code.substring(0, length - (hasteOut.length + '\n'.length + formattingLength)) : code; + return ( + tildes + language + '\n' + Util.cleanCodeBlockContent(code2) + '\n' + tildes + (hasteOut.length ? '\n' + hasteOut : '') + ); + } + + public async slashRespond( + interaction: CommandInteraction, + responseOptions: string | MessagePayload | WebhookEditMessageOptions + ): Promise { + let newResponseOptions: string | MessagePayload | WebhookEditMessageOptions = {}; + if (typeof responseOptions === 'string') { + newResponseOptions.content = responseOptions; + } else { + newResponseOptions = responseOptions; + } + if (interaction.replied || interaction.deferred) { + //@ts-expect-error: stop being dumb + delete newResponseOptions.ephemeral; // Cannot change a preexisting message to be ephemeral + return (await interaction.editReply(newResponseOptions)) as Message | APIMessage; + } else { + await interaction.reply(newResponseOptions); + return await interaction.fetchReply().catch(() => undefined); + } + } + + /** Gets the channel configs as a TextChannel */ + public async getConfigChannel(channel: 'log' | 'error' | 'dm'): Promise { + return (await this.client.channels.fetch(this.client.config.channels[channel])) as TextChannel; + } + + /** + * Takes an array and combines the elements using the supplied conjunction. + * + * @param {string[]} array The array to combine. + * @param {string} conjunction The conjunction to use. + * @param {string} ifEmpty What to return if the array is empty. + * @returns The combined elements or `ifEmpty` + * + * @example + * const permissions = oxford(['ADMINISTRATOR', 'SEND_MESSAGES', 'MANAGE_MESSAGES'], 'and', 'none'); + * console.log(permissions); // ADMINISTRATOR, SEND_MESSAGES and MANAGE_MESSAGES + */ + public oxford(array: string[], conjunction: string, ifEmpty: string): string { + const l = array.length; + if (!l) return ifEmpty; + if (l < 2) return array[0]; + if (l < 3) return array.join(` ${conjunction} `); + array = array.slice(); + array[l - 1] = `${conjunction} ${array[l - 1]}`; + return array.join(', '); + } + + public async insertOrRemoveFromGlobal( + action: 'add' | 'remove', + key: keyof typeof BushCache['global'], + value: any + ): Promise { + const environment = this.client.config.dev ? 'development' : 'production'; + const row = await Global.findByPk(environment); + const oldValue: any[] = row[key]; + let newValue: any[]; + if (action === 'add') { + if (!oldValue.includes(action)) oldValue.push(value); + newValue = oldValue; + } else { + newValue = oldValue.filter((ae) => ae !== value); + } + row[key] = newValue; + this.client.cache.global[key] = newValue; + return await row.save().catch((e) => this.client.logger.error('insertOrRemoveFromGlobal', e)); + } + + /** + * Surrounds a string to the begging an end of each element in an array. + * + * @param {string[]} array The array you want to surround. + * @param {string} surroundChar1 The character placed in the beginning of the element (or end if surroundChar2 isn't supplied). + * @param {string} [surroundChar2=surroundChar1] The character placed in the end of the element. + * @returns {string[]} + */ + public surroundArray(array: string[], surroundChar1: string, surroundChar2?: string): string[] { + const newArray = []; + array.forEach((a) => { + newArray.push(`${surroundChar1}${a}${surroundChar2 || surroundChar1}`); + }); + return newArray; + } + + // public createModLogEntry( + // user: User | Snowflake, + // guild: Guild | Snowflake, + // reason?: string, + // type?: ModLogType, + // duration?: number, + // moderator: User | Snowflake + // ): ModLog { + + // } +} diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts new file mode 100644 index 0000000..b7071b5 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -0,0 +1,57 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { ArgumentGenerator, ArgumentOptions, ArgumentPromptOptions, Command, CommandOptions } from 'discord-akairo'; +import { Snowflake } from 'discord.js'; +import { BushMessage } from '../discord.js/BushMessage'; +import { BushClient } from './BushClient'; +import { BushCommandHandler } from './BushCommandHandler'; +import { BushSlashMessage } from './BushSlashMessage'; + +export interface BushArgumentOptions extends ArgumentOptions { + id: string; + description?: string; + prompt?: ArgumentPromptOptions; +} + +export interface BushCommandOptions extends CommandOptions { + hidden?: boolean; + restrictedChannels?: Snowflake[]; + restrictedGuilds?: Snowflake[]; + description: { + content: string; + usage: string | string[]; + examples: string | string[]; + }; + args?: BushArgumentOptions[] | ArgumentGenerator; + category: string; +} + +export class BushCommand extends Command { + public declare client: BushClient; + + public declare handler: BushCommandHandler; + + public options: BushCommandOptions; + + /** The channels the command is limited to run in. */ + public restrictedChannels: Snowflake[]; + + /** The guilds the command is limited to run in. */ + public restrictedGuilds: Snowflake[]; + + /** Whether the command is hidden from the help command. */ + public hidden: boolean; + + constructor(id: string, options?: BushCommandOptions) { + super(id, options); + this.options = options; + this.hidden = options.hidden || false; + this.restrictedChannels = options.restrictedChannels; + this.restrictedGuilds = options.restrictedGuilds; + } + + public exec(message: BushMessage, args: any): any; + public exec(message: BushMessage | BushSlashMessage, args: any): any { + super.exec(message, args); + } +} diff --git a/src/lib/extensions/discord-akairo/BushCommandHandler.ts b/src/lib/extensions/discord-akairo/BushCommandHandler.ts new file mode 100644 index 0000000..09baf2e --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushCommandHandler.ts @@ -0,0 +1,90 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Category, CommandHandler, CommandHandlerOptions } from 'discord-akairo'; +import { Collection } from 'discord.js'; +import { BushConstants } from '../../utils/BushConstants'; +import { BushMessage } from '../discord.js/BushMessage'; +import { BushClient } from './BushClient'; +import { BushCommand } from './BushCommand'; + +export type BushCommandHandlerOptions = CommandHandlerOptions; + +const CommandHandlerEvents = BushConstants.CommandHandlerEvents; +const BlockedReasons = BushConstants.BlockedReasons; + +export class BushCommandHandler extends CommandHandler { + public declare client: BushClient; + public declare modules: Collection; + public declare categories: Collection>; + public constructor(client: BushClient, options: CommandHandlerOptions) { + super(client, options); + } + + public async runPostTypeInhibitors(message: BushMessage, command: BushCommand, slash = false): Promise { + if (command.ownerOnly) { + const isOwner = this.client.isOwner(message.author); + if (!isOwner) { + this.emit( + slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, + message, + command, + BlockedReasons.OWNER + ); + return true; + } + } + + if (command.superUserOnly) { + const isSuperUser = this.client.isSuperUser(message.author); + if (!isSuperUser) { + this.emit( + slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, + message, + command, + BlockedReasons.OWNER + ); + return true; + } + } + + if (command.channel === 'guild' && !message.guild) { + this.emit( + slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, + message, + command, + BlockedReasons.GUILD + ); + return true; + } + + if (command.channel === 'dm' && message.guild) { + this.emit( + slash ? CommandHandlerEvents.SLASH_BLOCKED : CommandHandlerEvents.COMMAND_BLOCKED, + message, + command, + BlockedReasons.DM + ); + return true; + } + if (command.restrictedChannels?.length && message.channel) { + if (!command.restrictedChannels.includes(message.channel.id)) { + this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, BlockedReasons.RESTRICTED_CHANNEL); + return true; + } + } + if (command.restrictedGuilds?.length && message.guild) { + if (!command.restrictedGuilds.includes(message.guild.id)) { + this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, BlockedReasons.RESTRICTED_GUILD); + return true; + } + } + if (await this.runPermissionChecks(message, command)) { + return true; + } + const reason = this.inhibitorHandler ? await this.inhibitorHandler.test('post', message, command) : null; + if (reason != null) { + this.emit(CommandHandlerEvents.COMMAND_BLOCKED, message, command, reason); + return true; + } + return !!this.runCooldowns(message, command); + } +} diff --git a/src/lib/extensions/discord-akairo/BushCommandUtil.ts b/src/lib/extensions/discord-akairo/BushCommandUtil.ts new file mode 100644 index 0000000..b4084bd --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushCommandUtil.ts @@ -0,0 +1,10 @@ +import { CommandUtil, ParsedComponentData } from 'discord-akairo'; +import { BushCommand } from './BushCommand'; + +export interface BushParsedComponentData extends ParsedComponentData { + command?: BushCommand; +} + +export class BushCommandUtil extends CommandUtil { + declare parsed?: BushParsedComponentData; +} diff --git a/src/lib/extensions/discord-akairo/BushInhibitor.ts b/src/lib/extensions/discord-akairo/BushInhibitor.ts new file mode 100644 index 0000000..ae91494 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushInhibitor.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Inhibitor } from 'discord-akairo'; +import { BushMessage } from '../discord.js/BushMessage'; +import { BushClient } from './BushClient'; +import { BushCommand } from './BushCommand'; +import { BushSlashMessage } from './BushSlashMessage'; + +export class BushInhibitor extends Inhibitor { + public declare client: BushClient; + + public exec(message: BushMessage, command: BushCommand): any; + public exec(message: BushMessage | BushSlashMessage, command: BushCommand): any { + super.exec(message, command); + } +} diff --git a/src/lib/extensions/discord-akairo/BushInhinitorHandler.ts b/src/lib/extensions/discord-akairo/BushInhinitorHandler.ts new file mode 100644 index 0000000..2a947da --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushInhinitorHandler.ts @@ -0,0 +1,6 @@ +import { InhibitorHandler } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushInhibitorHandler extends InhibitorHandler { + public declare client: BushClient; +} diff --git a/src/lib/extensions/discord-akairo/BushListener.ts b/src/lib/extensions/discord-akairo/BushListener.ts new file mode 100644 index 0000000..e555e89 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushListener.ts @@ -0,0 +1,6 @@ +import { Listener } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushListener extends Listener { + public declare client: BushClient; +} diff --git a/src/lib/extensions/discord-akairo/BushListenerHandler.ts b/src/lib/extensions/discord-akairo/BushListenerHandler.ts new file mode 100644 index 0000000..28615fc --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushListenerHandler.ts @@ -0,0 +1,6 @@ +import { ListenerHandler } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushListenerHandler extends ListenerHandler { + declare client: BushClient; +} diff --git a/src/lib/extensions/discord-akairo/BushSlashMessage.ts b/src/lib/extensions/discord-akairo/BushSlashMessage.ts new file mode 100644 index 0000000..9e9f994 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushSlashMessage.ts @@ -0,0 +1,20 @@ +import { AkairoMessage } from 'discord-akairo'; +import { CommandInteraction } from 'discord.js'; +import { BushGuild } from '../discord.js/BushGuild'; +import { BushUser } from '../discord.js/BushUser'; +import { BushClient } from './BushClient'; +import { BushCommandUtil } from './BushCommandUtil'; + +export class BushSlashMessage extends AkairoMessage { + public declare client: BushClient; + public declare util: BushCommandUtil; + public declare guild: BushGuild; + public declare author: BushUser; + public constructor( + client: BushClient, + interaction: CommandInteraction, + { slash, replied }: { slash?: boolean; replied?: boolean } + ) { + super(client, interaction, { slash, replied }); + } +} diff --git a/src/lib/extensions/discord-akairo/BushTask.ts b/src/lib/extensions/discord-akairo/BushTask.ts new file mode 100644 index 0000000..06d0602 --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushTask.ts @@ -0,0 +1,6 @@ +import { Task } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export class BushTask extends Task { + public declare client: BushClient; +} diff --git a/src/lib/extensions/discord-akairo/BushTaskHandler.ts b/src/lib/extensions/discord-akairo/BushTaskHandler.ts new file mode 100644 index 0000000..588988d --- /dev/null +++ b/src/lib/extensions/discord-akairo/BushTaskHandler.ts @@ -0,0 +1,11 @@ +import { AkairoHandlerOptions, TaskHandler } from 'discord-akairo'; +import { BushClient } from './BushClient'; + +export type BushTaskHandlerOptions = AkairoHandlerOptions; + +export class BushTaskHandler extends TaskHandler { + public constructor(client: BushClient, options: BushTaskHandlerOptions) { + super(client, options); + } + declare client: BushClient; +} diff --git a/src/lib/extensions/discord.js/BushCategoryChannel.ts b/src/lib/extensions/discord.js/BushCategoryChannel.ts new file mode 100644 index 0000000..c4bc3ca --- /dev/null +++ b/src/lib/extensions/discord.js/BushCategoryChannel.ts @@ -0,0 +1,16 @@ +import { CategoryChannel, Collection, Snowflake } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushGuildChannel } from './BushGuildChannel'; +import { BushGuildMember } from './BushGuildMember'; + +export class BushCategoryChannel extends CategoryChannel { + public declare readonly client: BushClient; + public declare readonly children: Collection; + public declare guild: BushGuild; + public declare readonly members: Collection; + public declare readonly parent: CategoryChannel | null; + constructor(guild: BushGuild, data?: unknown) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushDMChannel.ts b/src/lib/extensions/discord.js/BushDMChannel.ts new file mode 100644 index 0000000..475f224 --- /dev/null +++ b/src/lib/extensions/discord.js/BushDMChannel.ts @@ -0,0 +1,14 @@ +import { DMChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushMessageManager } from './BushMessageManager'; +import { BushUser } from './BushUser'; + +export class BushDMChannel extends DMChannel { + public declare readonly client: BushClient; + public declare messages: BushMessageManager; + public declare recipient: BushUser; + + constructor(client: BushClient, data?: unknown) { + super(client, data); + } +} diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts new file mode 100644 index 0000000..95e07f9 --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuild.ts @@ -0,0 +1,20 @@ +import { Guild } from 'discord.js'; +import { Guild as GuildDB, GuildModel } from '../../models/Guild'; +import { BushClient } from '../discord-akairo/BushClient'; + +export class BushGuild extends Guild { + public declare readonly client: BushClient; + public constructor(client: BushClient, data: unknown) { + super(client, data); + } + + public async getSetting(setting: K): Promise { + return ((await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id })).get(setting); + } + + public async setSetting(setting: K, value: GuildDB[K]): Promise { + const row = (await GuildDB.findByPk(this.id)) ?? GuildDB.build({ id: this.id }); + row[setting] = value; + return await row.save(); + } +} diff --git a/src/lib/extensions/discord.js/BushGuildChannel.ts b/src/lib/extensions/discord.js/BushGuildChannel.ts new file mode 100644 index 0000000..75b8a5f --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuildChannel.ts @@ -0,0 +1,11 @@ +import { GuildChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; + +export class BushGuildChannel extends GuildChannel { + public declare readonly client: BushClient; + public declare guild: BushGuild; + constructor(guild: BushGuild, data?: unknown) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushGuildEmoji.ts b/src/lib/extensions/discord.js/BushGuildEmoji.ts new file mode 100644 index 0000000..8c97ada --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuildEmoji.ts @@ -0,0 +1,15 @@ +import { GuildEmoji } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushGuildEmojiRoleManager } from './BushGuildEmojiRoleManager'; +import { BushUser } from './BushUser'; + +export class BushGuildEmoji extends GuildEmoji { + public declare readonly client: BushClient; + public declare guild: BushGuild; + public declare author: BushUser | null; + public declare readonly roles: BushGuildEmojiRoleManager; + constructor(client: BushClient, data: unknown, guild: BushGuild) { + super(client, data, guild); + } +} diff --git a/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts b/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts new file mode 100644 index 0000000..86c2492 --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuildEmojiRoleManager.ts @@ -0,0 +1,13 @@ +import { Collection, GuildEmojiRoleManager, Snowflake } from 'discord.js'; +import { BushGuild } from './BushGuild'; +import { BushGuildEmoji } from './BushGuildEmoji'; +import { BushRole } from './BushRole'; + +export class BushGuildEmojiRoleManager extends GuildEmojiRoleManager { + public declare emoji: BushGuildEmoji; + public declare guild: BushGuild; + public declare cache: Collection; + constructor(emoji: BushGuildEmoji) { + super(emoji); + } +} diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts new file mode 100644 index 0000000..6bcb9b8 --- /dev/null +++ b/src/lib/extensions/discord.js/BushGuildMember.ts @@ -0,0 +1,13 @@ +import { GuildMember } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushUser } from './BushUser'; + +export class BushGuildMember extends GuildMember { + public declare readonly client: BushClient; + public declare guild: BushGuild; + public declare BushUser: BushUser; + public constructor(client: BushClient, data: unknown, guild: BushGuild) { + super(client, data, guild); + } +} diff --git a/src/lib/extensions/discord.js/BushMessage.ts b/src/lib/extensions/discord.js/BushMessage.ts new file mode 100644 index 0000000..e4380f7 --- /dev/null +++ b/src/lib/extensions/discord.js/BushMessage.ts @@ -0,0 +1,26 @@ +import { Message } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushCommandUtil } from '../discord-akairo/BushCommandUtil'; +import { BushDMChannel } from './BushDMChannel'; +import { BushGuild } from './BushGuild'; +import { BushGuildMember } from './BushGuildMember'; +import { BushNewsChannel } from './BushNewsChannel'; +import { BushTextChannel } from './BushTextChannel'; +import { BushThreadChannel } from './BushThreadChannel'; +import { BushUser } from './BushUser'; + +export class BushMessage extends Message { + public declare readonly client: BushClient; + public declare util: BushCommandUtil; + public declare readonly guild: BushGuild; + public declare readonly member: BushGuildMember; + public declare author: BushUser; + public declare channel: BushTextChannel | BushDMChannel | BushNewsChannel | BushThreadChannel; + public constructor( + client: BushClient, + data: unknown, + channel: BushTextChannel | BushDMChannel | BushNewsChannel | BushThreadChannel + ) { + super(client, data, channel); + } +} diff --git a/src/lib/extensions/discord.js/BushMessageManager.ts b/src/lib/extensions/discord.js/BushMessageManager.ts new file mode 100644 index 0000000..c9256a9 --- /dev/null +++ b/src/lib/extensions/discord.js/BushMessageManager.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Collection, MessageManager, Snowflake } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushDMChannel } from './BushDMChannel'; +import { BushMessage } from './BushMessage'; +import { BushTextChannel } from './BushTextChannel'; + +export class BushMessageManager extends MessageManager { + public declare readonly client: BushClient; + public declare cache: Collection; + constructor(channel: BushTextChannel | BushDMChannel, iterable?: Iterable) { + super(channel, iterable); + } +} diff --git a/src/lib/extensions/discord.js/BushNewsChannel.ts b/src/lib/extensions/discord.js/BushNewsChannel.ts new file mode 100644 index 0000000..77b7a9d --- /dev/null +++ b/src/lib/extensions/discord.js/BushNewsChannel.ts @@ -0,0 +1,16 @@ +import { NewsChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushMessageManager } from './BushMessageManager'; +import { BushThreadManager } from './BushThreadManager'; + +export class BushNewsChannel extends NewsChannel { + public declare readonly client: BushClient; + public declare guild: BushGuild; + public declare messages: BushMessageManager; + public declare threads: BushThreadManager; + // eslint-disable-next-line @typescript-eslint/ban-types + constructor(guild: BushGuild, data?: object) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushRole.ts b/src/lib/extensions/discord.js/BushRole.ts new file mode 100644 index 0000000..ce8e9dc --- /dev/null +++ b/src/lib/extensions/discord.js/BushRole.ts @@ -0,0 +1,13 @@ +import { Collection, Role, Snowflake } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushGuildMember } from './BushGuildMember'; + +export class BushRole extends Role { + public declare readonly client: BushClient; + public guild: BushGuild; + public readonly members: Collection; + constructor(client: BushClient, data: unknown, guild: BushGuild) { + super(client, data, guild); + } +} diff --git a/src/lib/extensions/discord.js/BushStoreChannel.ts b/src/lib/extensions/discord.js/BushStoreChannel.ts new file mode 100644 index 0000000..1a9b855 --- /dev/null +++ b/src/lib/extensions/discord.js/BushStoreChannel.ts @@ -0,0 +1,16 @@ +import { Collection, Snowflake, StoreChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushCategoryChannel } from './BushCategoryChannel'; +import { BushGuild } from './BushGuild'; +import { BushGuildMember } from './BushGuildMember'; + +export class BushStoreChannel extends StoreChannel { + public declare readonly client: BushClient; + public declare guild: BushGuild; + public declare readonly members: Collection; + public declare readonly parent: BushCategoryChannel | null; + + constructor(guild: BushGuild, data?: unknown) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushTextChannel.ts b/src/lib/extensions/discord.js/BushTextChannel.ts new file mode 100644 index 0000000..b58aa7b --- /dev/null +++ b/src/lib/extensions/discord.js/BushTextChannel.ts @@ -0,0 +1,13 @@ +import { TextChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushMessageManager } from './BushMessageManager'; + +export class BushTextChannel extends TextChannel { + public declare readonly client: BushClient; + public declare guild: BushGuild; + public declare messages: BushMessageManager; + constructor(guild: BushGuild, data?: unknown) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushThreadChannel.ts b/src/lib/extensions/discord.js/BushThreadChannel.ts new file mode 100644 index 0000000..10fc65e --- /dev/null +++ b/src/lib/extensions/discord.js/BushThreadChannel.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import { Collection, Snowflake, ThreadChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushGuildMember } from './BushGuildMember'; +import { BushMessageManager } from './BushMessageManager'; +import { BushNewsChannel } from './BushNewsChannel'; +import { BushTextChannel } from './BushTextChannel'; +import { BushThreadMemberManager } from './BushThreadMemberManager'; + +export class BushThreadChannel extends ThreadChannel { + public declare guild: BushGuild; + public declare messages: BushMessageManager; + public declare members: BushThreadMemberManager; + + public declare readonly client: BushClient; + public declare readonly guildMembers: Collection; + + public declare readonly parent: BushTextChannel | BushNewsChannel | null; + constructor(guild: BushGuild, data?: object) { + super(guild, data); + } +} diff --git a/src/lib/extensions/discord.js/BushThreadManager.ts b/src/lib/extensions/discord.js/BushThreadManager.ts new file mode 100644 index 0000000..408ac7f --- /dev/null +++ b/src/lib/extensions/discord.js/BushThreadManager.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { ThreadManager } from 'discord.js'; +import { BushNewsChannel } from './BushNewsChannel'; +import { BushTextChannel } from './BushTextChannel'; + +export class BushThreadManager extends ThreadManager { + public declare channel: BushTextChannel | BushNewsChannel; + constructor(channel: BushTextChannel | BushNewsChannel, iterable?: Iterable) { + super(channel, iterable); + } +} diff --git a/src/lib/extensions/discord.js/BushThreadMember.ts b/src/lib/extensions/discord.js/BushThreadMember.ts new file mode 100644 index 0000000..16da663 --- /dev/null +++ b/src/lib/extensions/discord.js/BushThreadMember.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import { ThreadMember } from 'discord.js'; +import { BushGuildMember } from './BushGuildMember'; +import { BushThreadChannel } from './BushThreadChannel'; +import { BushUser } from './BushUser'; + +export class BushThreadMember extends ThreadMember { + public declare readonly guildMember: BushGuildMember | null; + public declare readonly user: BushUser | null; + public declare thread: BushThreadChannel; + constructor(thread: BushThreadChannel, data?: object) { + super(thread, data); + } +} diff --git a/src/lib/extensions/discord.js/BushThreadMemberManager.ts b/src/lib/extensions/discord.js/BushThreadMemberManager.ts new file mode 100644 index 0000000..7c7bb6d --- /dev/null +++ b/src/lib/extensions/discord.js/BushThreadMemberManager.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-empty-interface */ +import { Snowflake, ThreadMemberManager, UserResolvable } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuildMember } from './BushGuildMember'; +import { BushMessage } from './BushMessage'; +import { BushThreadChannel } from './BushThreadChannel'; +import { BushThreadMember } from './BushThreadMember'; +import { BushUser } from './BushUser'; + +export type BushThreadMemberResolvable = BushThreadMember | UserResolvable; +export type BushUserResolvable = BushUser | Snowflake | BushMessage | BushGuildMember | BushThreadMember; + +export interface BushThreadMemberManager extends ThreadMemberManager {} + +export class BushThreadMemberManager extends ThreadMemberManager { + public declare thread: BushThreadChannel; + public declare readonly client: BushClient; + + constructor(thread: BushThreadChannel, iterable?: Iterable) { + super(thread, iterable); + } +} diff --git a/src/lib/extensions/discord.js/BushUser.ts b/src/lib/extensions/discord.js/BushUser.ts new file mode 100644 index 0000000..53a6be3 --- /dev/null +++ b/src/lib/extensions/discord.js/BushUser.ts @@ -0,0 +1,19 @@ +import { User } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushDMChannel } from './BushDMChannel'; + +export class BushUser extends User { + public declare readonly client: BushClient; + public declare readonly dmChannel: BushDMChannel | null; + public constructor(client: BushClient, data: unknown) { + super(client, data); + } + + public isOwner(): boolean { + return this.client.isOwner(this); + } + + public isSuperUser(): boolean { + return this.client.isSuperUser(this); + } +} diff --git a/src/lib/extensions/discord.js/BushVoiceChannel.ts b/src/lib/extensions/discord.js/BushVoiceChannel.ts new file mode 100644 index 0000000..7510b69 --- /dev/null +++ b/src/lib/extensions/discord.js/BushVoiceChannel.ts @@ -0,0 +1,12 @@ +import { Collection, Snowflake, VoiceChannel } from 'discord.js'; +import { BushClient } from '../discord-akairo/BushClient'; +import { BushGuild } from './BushGuild'; +import { BushGuildMember } from './BushGuildMember'; + +export class BushVoiceChannel extends VoiceChannel { + public declare readonly client: BushClient; + public declare readonly members: Collection; + constructor(guild: BushGuild, data?: unknown) { + super(guild, data); + } +} diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 480cc60..303335b 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -1,6 +1,6 @@ import { Snowflake } from 'discord.js'; import { DataTypes, Optional, Sequelize } from 'sequelize'; -import { BushClient } from '../extensions/BushClient'; +import { BushClient } from '../extensions/discord-akairo/BushClient'; import { BaseModel } from './BaseModel'; export interface GuildModel { diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts index f14a05b..7293c41 100644 --- a/src/lib/utils/BushLogger.ts +++ b/src/lib/utils/BushLogger.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; import { MessageEmbed } from 'discord.js'; import { inspect } from 'util'; -import { BushClient, BushSendMessageType } from '../extensions/BushClient'; +import { BushClient, BushSendMessageType } from '../extensions/discord-akairo/BushClient'; export class BushLogger { private client: BushClient; diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts index 1a51527..c739152 100644 --- a/src/listeners/client/ready.ts +++ b/src/listeners/client/ready.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; export default class ReadyListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index 816005d..342e025 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class CommandBlockedListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index 85ff11f..3cb5046 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -1,8 +1,8 @@ import { stripIndents } from 'common-tags'; import { Command } from 'discord-akairo'; import { MessageEmbed } from 'discord.js'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class CommandErrorListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/commandMissingPermissions.ts b/src/listeners/commands/commandMissingPermissions.ts index d695d25..e3420ae 100644 --- a/src/listeners/commands/commandMissingPermissions.ts +++ b/src/listeners/commands/commandMissingPermissions.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushMessage } from '../../lib/extensions/BushMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; export default class CommandMissingPermissionsListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts index 9266fc7..6cfd239 100644 --- a/src/listeners/commands/commandStarted.ts +++ b/src/listeners/commands/commandStarted.ts @@ -1,6 +1,6 @@ import { Message } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; export default class CommandStartedListener extends BushListener { constructor() { diff --git a/src/listeners/commands/slashBlocked.ts b/src/listeners/commands/slashBlocked.ts index 761bef8..04180f7 100644 --- a/src/listeners/commands/slashBlocked.ts +++ b/src/listeners/commands/slashBlocked.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; export default class SlashBlockedListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/slashCommandError.ts b/src/listeners/commands/slashCommandError.ts index da00eb4..ea48f34 100644 --- a/src/listeners/commands/slashCommandError.ts +++ b/src/listeners/commands/slashCommandError.ts @@ -1,8 +1,8 @@ import { stripIndents } from 'common-tags'; import { MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; export default class SlashCommandErrorListener extends BushListener { constructor() { diff --git a/src/listeners/commands/slashMissingPermissions.ts b/src/listeners/commands/slashMissingPermissions.ts index 1f3599f..d8f32cf 100644 --- a/src/listeners/commands/slashMissingPermissions.ts +++ b/src/listeners/commands/slashMissingPermissions.ts @@ -1,6 +1,6 @@ import { Command } from 'discord-akairo'; import { CommandInteraction } from 'discord.js'; -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; export default class SlashMissingPermissionsListener extends BushListener { public constructor() { diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts index 534d89d..028d962 100644 --- a/src/listeners/commands/slashStarted.ts +++ b/src/listeners/commands/slashStarted.ts @@ -1,6 +1,6 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushListener } from '../../lib/extensions/BushListener'; -import { BushSlashMessage } from '../../lib/extensions/BushSlashMessage'; +import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; +import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; export default class SlashStartedListener extends BushListener { constructor() { diff --git a/src/listeners/guild/syncUnban.ts b/src/listeners/guild/syncUnban.ts index 81a08f8..25529ea 100644 --- a/src/listeners/guild/syncUnban.ts +++ b/src/listeners/guild/syncUnban.ts @@ -1,5 +1,5 @@ -import { User, Guild } from 'discord.js'; -import { BushListener } from '../../lib/extensions/BushListener'; +import { Guild, User } from 'discord.js'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; import { Ban } from '../../lib/models'; export default class SyncUnbanListener extends BushListener { diff --git a/src/listeners/message/level.ts b/src/listeners/message/level.ts index 9f413e5..ea6a491 100644 --- a/src/listeners/message/level.ts +++ b/src/listeners/message/level.ts @@ -1,5 +1,5 @@ import { Message } from 'discord.js'; -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; import { Level } from '../../lib/models'; export default class LevelListener extends BushListener { diff --git a/src/listeners/other/consoleListener.ts b/src/listeners/other/consoleListener.ts index d1e318f..98f44e2 100644 --- a/src/listeners/other/consoleListener.ts +++ b/src/listeners/other/consoleListener.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; export default class ConsoleListener extends BushListener { public constructor() { diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts index 143659a..2fcfdc9 100644 --- a/src/listeners/other/promiseRejection.ts +++ b/src/listeners/other/promiseRejection.ts @@ -1,4 +1,4 @@ -import { BushListener } from '../../lib/extensions/BushListener'; +import { BushListener } from '../../lib/extensions/discord-akairo/BushListener'; export default class PromiseRejectionListener extends BushListener { constructor() { diff --git a/src/tasks/unban.ts b/src/tasks/unban.ts index 6e06db8..b6d96b8 100644 --- a/src/tasks/unban.ts +++ b/src/tasks/unban.ts @@ -1,6 +1,6 @@ import { DiscordAPIError } from 'discord.js'; import { Op } from 'sequelize'; -import { BushTask } from '../lib/extensions/BushTask'; +import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; import { Ban } from '../lib/models'; export default class UnbanTask extends BushTask { diff --git a/src/tasks/unmute.ts b/src/tasks/unmute.ts index 2dfa2ab..6513345 100644 --- a/src/tasks/unmute.ts +++ b/src/tasks/unmute.ts @@ -1,6 +1,6 @@ import { DiscordAPIError } from 'discord.js'; import { Op } from 'sequelize'; -import { BushTask } from '../lib/extensions/BushTask'; +import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; import { Guild } from '../lib/models'; import { Mute } from '../lib/models/Mute'; diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index 3f213f2..2f1d2d1 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -1,5 +1,5 @@ -import { BushClient } from '../lib/extensions/BushClient'; -import { BushTask } from '../lib/extensions/BushTask'; +import { BushClient } from '../lib/extensions/discord-akairo/BushClient'; +import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; import { Global } from '../lib/models'; import * as config from './../config/options'; -- cgit