aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-12-26 17:16:32 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-12-26 17:16:32 -0500
commitfc390ffc300334c396d9d06b0feaf8fbc6ed2814 (patch)
treea6282a74cf99033291ac7bc9de123ae273d528d2 /src
parent062435590980b87f5b054418ed88604e26358ae9 (diff)
downloadtanzanite-fc390ffc300334c396d9d06b0feaf8fbc6ed2814.tar.gz
tanzanite-fc390ffc300334c396d9d06b0feaf8fbc6ed2814.tar.bz2
tanzanite-fc390ffc300334c396d9d06b0feaf8fbc6ed2814.zip
documentation, bug fixes etc
Diffstat (limited to 'src')
-rw-r--r--src/bot.ts6
-rw-r--r--src/commands/config/blacklist.ts105
-rw-r--r--src/commands/config/config.ts2
-rw-r--r--src/commands/config/disable.ts23
-rw-r--r--src/commands/config/log.ts7
-rw-r--r--src/commands/info/snowflake.ts5
-rw-r--r--src/commands/info/userInfo.ts34
-rw-r--r--src/commands/moderation/role.ts2
-rw-r--r--src/commands/utilities/suicide.ts6
-rw-r--r--src/context-menu-commands/user/userInfo.ts26
-rw-r--r--src/inhibitors/blacklist/userGlobalBlacklist.ts3
-rw-r--r--src/lib/common/AutoMod.ts1
-rw-r--r--src/lib/common/ButtonPaginator.ts3
-rw-r--r--src/lib/common/DeleteButton.ts3
-rw-r--r--src/lib/common/Moderation.ts166
-rw-r--r--src/lib/common/util/Arg.ts56
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts195
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts102
-rw-r--r--src/lib/extensions/discord-akairo/BushCommand.ts188
-rw-r--r--src/lib/extensions/discord-akairo/BushInhibitor.ts7
-rw-r--r--src/lib/extensions/discord-akairo/BushSlashMessage.ts2
-rw-r--r--src/lib/extensions/discord.js/BushActivity.ts3
-rw-r--r--src/lib/extensions/discord.js/BushApplicationCommand.ts3
-rw-r--r--src/lib/extensions/discord.js/BushApplicationCommandManager.d.ts101
-rw-r--r--src/lib/extensions/discord.js/BushApplicationCommandPermissionsManager.d.ts123
-rw-r--r--src/lib/extensions/discord.js/BushBaseGuildEmojiManager.d.ts8
-rw-r--r--src/lib/extensions/discord.js/BushBaseGuildTextChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushBaseGuildVoiceChannel.d.ts13
-rw-r--r--src/lib/extensions/discord.js/BushButtonInteraction.ts7
-rw-r--r--src/lib/extensions/discord.js/BushCategoryChannel.ts7
-rw-r--r--src/lib/extensions/discord.js/BushChannel.d.ts14
-rw-r--r--src/lib/extensions/discord.js/BushChannelManager.d.ts20
-rw-r--r--src/lib/extensions/discord.js/BushClientEvents.d.ts29
-rw-r--r--src/lib/extensions/discord.js/BushClientUser.d.ts78
-rw-r--r--src/lib/extensions/discord.js/BushCommandInteraction.ts31
-rw-r--r--src/lib/extensions/discord.js/BushDMChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushEmoji.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts109
-rw-r--r--src/lib/extensions/discord.js/BushGuildApplicationCommandManager.d.ts89
-rw-r--r--src/lib/extensions/discord.js/BushGuildBan.d.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuildChannel.ts9
-rw-r--r--src/lib/extensions/discord.js/BushGuildEmoji.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuildEmojiRoleManager.d.ts36
-rw-r--r--src/lib/extensions/discord.js/BushGuildManager.d.ts16
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts289
-rw-r--r--src/lib/extensions/discord.js/BushGuildMemberManager.d.ts131
-rw-r--r--src/lib/extensions/discord.js/BushMessage.ts10
-rw-r--r--src/lib/extensions/discord.js/BushMessageManager.d.ts84
-rw-r--r--src/lib/extensions/discord.js/BushMessageReaction.ts3
-rw-r--r--src/lib/extensions/discord.js/BushNewsChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushPresence.ts3
-rw-r--r--src/lib/extensions/discord.js/BushReactionEmoji.ts5
-rw-r--r--src/lib/extensions/discord.js/BushRole.ts3
-rw-r--r--src/lib/extensions/discord.js/BushSelectMenuInteraction.ts7
-rw-r--r--src/lib/extensions/discord.js/BushStageChannel.ts5
-rw-r--r--src/lib/extensions/discord.js/BushStageInstance.ts3
-rw-r--r--src/lib/extensions/discord.js/BushStoreChannel.ts4
-rw-r--r--src/lib/extensions/discord.js/BushTextChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushThreadChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushThreadManager.d.ts57
-rw-r--r--src/lib/extensions/discord.js/BushThreadMember.ts3
-rw-r--r--src/lib/extensions/discord.js/BushThreadMemberManager.d.ts31
-rw-r--r--src/lib/extensions/discord.js/BushUser.ts9
-rw-r--r--src/lib/extensions/discord.js/BushUserManager.d.ts59
-rw-r--r--src/lib/extensions/discord.js/BushVoiceChannel.ts3
-rw-r--r--src/lib/extensions/discord.js/BushVoiceState.ts9
-rw-r--r--src/lib/extensions/global.d.ts7
-rw-r--r--src/lib/utils/BushCache.ts4
-rw-r--r--src/lib/utils/BushConstants.ts4
-rw-r--r--src/lib/utils/BushLogger.ts118
-rw-r--r--src/listeners/client/dcjsDebug.ts15
-rw-r--r--src/listeners/client/dcjsError.ts15
-rw-r--r--src/listeners/client/dcjsWarn.ts15
-rw-r--r--src/listeners/commands/commandError.ts8
-rw-r--r--src/listeners/commands/commandStarted.ts7
-rw-r--r--src/listeners/message/autoThread.ts9
-rw-r--r--src/listeners/other/warning.ts2
77 files changed, 2084 insertions, 500 deletions
diff --git a/src/bot.ts b/src/bot.ts
index bbef018..473ee27 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -6,5 +6,7 @@ import { Sentry } from './lib/common/Sentry.js';
import { BushClient } from './lib/index.js';
new Sentry(dirname(fileURLToPath(import.meta.url)) || process.cwd());
-BushClient.init();
-void new BushClient(config).start();
+BushClient.extendStructures();
+const client = new BushClient(config);
+await client.init();
+if (!process.argv.includes('dry')) await client.start();
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts
index da4ad18..a6e6a3d 100644
--- a/src/commands/config/blacklist.ts
+++ b/src/commands/config/blacklist.ts
@@ -1,6 +1,5 @@
-import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib';
-import { GuildTextBasedChannels } from 'discord-akairo';
-import { User } from 'discord.js';
+import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
+import { GuildTextBasedChannel, User } from 'discord.js';
export default class BlacklistCommand extends BushCommand {
public constructor() {
@@ -52,10 +51,10 @@ export default class BlacklistCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- args: { action: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannels | User | string; global: boolean }
+ args: { action?: 'blacklist' | 'unblacklist'; target: GuildTextBasedChannel | User | string; global: boolean }
) {
let action: 'blacklist' | 'unblacklist' | 'toggle' =
- args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist') ?? 'toggle';
+ args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist' | undefined) ?? 'toggle';
const global = args.global && message.author.isOwner();
const target =
typeof args.target === 'string'
@@ -64,65 +63,43 @@ export default class BlacklistCommand extends BushCommand {
if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`);
const targetID = target.id;
- if (global) {
- if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') {
- const globalDB =
- (await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment }));
- const blacklistedUsers = globalDB.blacklistedUsers;
- const blacklistedChannels = globalDB.blacklistedChannels;
- action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist';
- }
- const success = await util
- .insertOrRemoveFromGlobal(
- action === 'blacklist' ? 'add' : 'remove',
- target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels',
- targetID
- )
- .catch(() => false);
- if (!success)
- return await message.util.reply({
- content: `${util.emojis.error} There was an error globally ${action}ing ${util.format.input(
- target instanceof User ? target.tag : target.name
- )}.`,
- allowedMentions: AllowedMentions.none()
- });
- else
- return await message.util.reply({
- content: `${util.emojis.success} Successfully ${action}ed ${util.format.input(
- target instanceof User ? target.tag : target.name
- )} globally.`,
- allowedMentions: AllowedMentions.none()
- });
- // guild disable
- } else {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`);
- const blacklistedChannels = (await message.guild.getSetting('blacklistedChannels')) ?? [];
- const blacklistedUsers = (await message.guild.getSetting('blacklistedUsers')) ?? [];
- if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') {
- action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist';
- }
- const newValue = util.addOrRemoveFromArray(
- action === 'blacklist' ? 'add' : 'remove',
- target instanceof User ? blacklistedUsers : blacklistedChannels,
- targetID
- );
- const success = await message.guild
- .setSetting(target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels', newValue, message.member!)
- .catch(() => false);
- if (!success)
- return await message.util.reply({
- content: `${util.emojis.error} There was an error ${action}ing ${util.format.input(
- target instanceof User ? target.tag : target.name
- )}.`,
- allowedMentions: AllowedMentions.none()
- });
- else
- return await message.util.reply({
- content: `${util.emojis.success} Successfully ${action}ed ${util.format.input(
- target instanceof User ? target.tag : target.name
- )}.`,
- allowedMentions: AllowedMentions.none()
- });
+ if (!message.guild && global)
+ return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`);
+ const blacklistedUsers = global
+ ? util.getGlobal('blacklistedUsers')
+ : (await message.guild!.getSetting('blacklistedChannels')) ?? [];
+ const blacklistedChannels = global
+ ? util.getGlobal('blacklistedChannels')
+ : (await message.guild!.getSetting('blacklistedUsers')) ?? [];
+ if (action === 'toggle') {
+ action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist';
}
+ const newValue = util.addOrRemoveFromArray(
+ action === 'blacklist' ? 'add' : 'remove',
+ target instanceof User ? blacklistedUsers : blacklistedChannels,
+ targetID
+ );
+
+ const key = target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels';
+
+ const success = await (global
+ ? util.setGlobal(key, newValue)
+ : message.guild!.setSetting(key, newValue, message.member!)
+ ).catch(() => false);
+
+ if (!success)
+ return await message.util.reply({
+ content: `${util.emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${util.format.input(
+ target instanceof User ? target.tag : target.name
+ )}.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ else
+ return await message.util.reply({
+ content: `${util.emojis.success} Successfully ${action}ed ${util.format.input(
+ target instanceof User ? target.tag : target.name
+ )}${global ? ' globally' : ''}.`,
+ allowedMentions: AllowedMentions.none()
+ });
}
}
diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts
index 6af5895..b88147d 100644
--- a/src/commands/config/config.ts
+++ b/src/commands/config/config.ts
@@ -97,7 +97,7 @@ export default class SettingsCommand extends BushCommand {
});
}
- override *args(message: BushMessage): Generator<ArgumentOptions | Flag> {
+ public override *args(message: BushMessage): Generator<ArgumentOptions | Flag> {
const optional = message.util.parsed!.alias === 'settings';
const setting = yield {
id: 'setting',
diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts
index a30652a..44c28d3 100644
--- a/src/commands/config/disable.ts
+++ b/src/commands/config/disable.ts
@@ -1,6 +1,8 @@
-import { AllowedMentions, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib';
+import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
export default class DisableCommand extends BushCommand {
+ private static blacklistedCommands = ['eval', 'disable'];
+
public constructor() {
super('disable', {
aliases: ['disable', 'enable'],
@@ -45,20 +47,23 @@ export default class DisableCommand extends BushCommand {
});
}
- blacklistedCommands = ['eval', 'disable'];
-
public override async exec(
message: BushMessage | BushSlashMessage,
- args: { action: 'enable' | 'disable'; command: BushCommand | string; global: boolean }
+ args: { action?: 'enable' | 'disable'; command: BushCommand | string; global: boolean }
) {
let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle';
const global = args.global && message.author.isOwner();
- const commandID = (args.command as BushCommand).id;
+ const commandID =
+ args.command instanceof BushCommand
+ ? args.command.id
+ : (await util.arg.cast(util.arg.union('commandAlias', 'command'), message, args.command))?.id;
+
+ if (!commandID) return await message.util.reply(`${util.emojis.error} Invalid command.`);
+
+ if (DisableCommand.blacklistedCommands.includes(commandID))
+ return message.util.send(`${util.emojis.error} the ${commandID} command cannot be disabled.`);
- const disabledCommands = global
- ? ((await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment })))
- .disabledCommands
- : await message.guild!.getSetting('disabledCommands');
+ const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild!.getSetting('disabledCommands');
if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID);
diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts
index 6121ad7..52cb8f5 100644
--- a/src/commands/config/log.ts
+++ b/src/commands/config/log.ts
@@ -22,11 +22,12 @@ export default class LogCommand extends BushCommand {
},
{
id: 'channel',
- description: 'The channel to have logs of the seleted type to be sent in.',
+ description: 'The channel to have logs of the selected type to be sent in.',
type: 'channel',
prompt: 'What channel would you like these logs to be sent in?',
slashType: 'CHANNEL',
- channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD']
+ channelTypes: ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_NEWS_THREAD', 'GUILD_PUBLIC_THREAD', 'GUILD_PRIVATE_THREAD'],
+ only: 'slash'
}
],
channel: 'guild',
@@ -35,7 +36,7 @@ export default class LogCommand extends BushCommand {
});
}
- override *args(): IterableIterator<ArgumentOptions | Flag> {
+ public override *args(): IterableIterator<ArgumentOptions | Flag> {
const log_type = yield {
id: 'log_type',
type: guildLogsArr,
diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts
index bd0924f..f2ffaa8 100644
--- a/src/commands/info/snowflake.ts
+++ b/src/commands/info/snowflake.ts
@@ -4,7 +4,6 @@ import {
SnowflakeUtil,
VoiceChannel,
type CategoryChannel,
- type Channel,
type DeconstructedSnowflake,
type DMChannel,
type Guild,
@@ -46,9 +45,9 @@ export default class SnowflakeCommand extends BushCommand {
// Channel
if (client.channels.cache.has(snowflake)) {
- const channel: Channel = client.channels.cache.get(snowflake)!;
+ const channel = client.channels.cache.get(snowflake)!;
const channelInfo = [`**Type:** ${channel.type}`];
- if ((['DM', 'GROUP_DM'] as const).includes(channel.type)) {
+ if (['DM', 'GROUP_DM'].includes(channel.type)) {
const _channel = channel as DMChannel;
channelInfo.push(`**Recipient:** ${util.discord.escapeMarkdown(_channel.recipient.tag)} (${_channel.recipient.id})`);
snowflakeEmbed.setTitle(
diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts
index 2d7fcfb..c62be93 100644
--- a/src/commands/info/userInfo.ts
+++ b/src/commands/info/userInfo.ts
@@ -1,4 +1,11 @@
-import { BushCommand, type BushMessage, type BushSlashMessage, type BushUser } from '#lib';
+import {
+ BushCommand,
+ BushGuild,
+ BushGuildMember,
+ type BushMessage,
+ type BushSlashMessage,
+ type BushUser
+} from '#lib';
import { MessageEmbed, type Snowflake } from 'discord.js';
// TODO: Add bot information
@@ -37,11 +44,17 @@ export default class UserInfoCommand extends BushCommand {
: await client.users.fetch(`${args.user}`).catch(() => undefined);
if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`);
const member = message.guild ? message.guild.members.cache.get(user.id) : undefined;
+ await user.fetch(true); // gets banner info and accent color
+
+ const userEmbed = await UserInfoCommand.makeUserInfoEmbed(user, member, message.guild);
+
+ return await message.util.reply({ embeds: [userEmbed] });
+ }
+
+ public static async makeUserInfoEmbed(user: BushUser, member?: BushGuildMember, guild?: BushGuild | null) {
const emojis = [];
const superUsers = client.cache.global.superUsers;
- await user.fetch(true); // gets banner info and accent color
-
const userEmbed: MessageEmbed = new MessageEmbed()
.setTitle(util.discord.escapeMarkdown(user.tag))
.setThumbnail(user.displayAvatarURL({ size: 2048, format: 'png', dynamic: true }))
@@ -69,7 +82,7 @@ export default class UserInfoCommand extends BushCommand {
emojis.push(client.consts.mappings.otherEmojis.NITRO);
}
- if (message.guild?.ownerId == user.id) emojis.push(client.consts.mappings.otherEmojis.OWNER);
+ if (guild?.ownerId == user.id) emojis.push(client.consts.mappings.otherEmojis.OWNER);
else if (member?.permissions.has('ADMINISTRATOR')) emojis.push(client.consts.mappings.otherEmojis.ADMIN);
if (member?.premiumSinceTimestamp) emojis.push(client.consts.mappings.otherEmojis.BOOSTER);
@@ -92,16 +105,14 @@ export default class UserInfoCommand extends BushCommand {
// Server User Info
const serverUserInfo = [];
if (joinedAt)
- serverUserInfo.push(
- `**${message.guild!.ownerId == user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)`
- );
+ serverUserInfo.push(`**${guild!.ownerId == user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)`);
if (premiumSince) serverUserInfo.push(`**Boosting Since:** ${premiumSince} (${premiumSinceDelta} ago)`);
if (member?.displayHexColor) serverUserInfo.push(`**Display Color:** ${member.displayHexColor}`);
- if (user.id == '322862723090219008' && message.guild?.id == client.consts.mappings.guilds.bush)
+ if (user.id == '322862723090219008' && guild?.id == client.consts.mappings.guilds.bush)
serverUserInfo.push(`**General Deletions:** 1⅓`);
if (
(['384620942577369088', '496409778822709251'] as const).includes(user.id) &&
- message.guild?.id == client.consts.mappings.guilds.bush
+ guild?.id == client.consts.mappings.guilds.bush
)
serverUserInfo.push(`**General Deletions:** ⅓`);
if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`);
@@ -154,7 +165,7 @@ export default class UserInfoCommand extends BushCommand {
// Important Perms
const perms = [];
- if (member?.permissions.has('ADMINISTRATOR') || message.guild?.ownerId == user.id) {
+ if (member?.permissions.has('ADMINISTRATOR') || guild?.ownerId == user.id) {
perms.push('`Administrator`');
} else if (member?.permissions.toArray(false).length) {
member.permissions.toArray(false).forEach((permission)