diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 21:42:06 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-27 21:42:06 -0500 |
commit | b5ada8dca12013bfc730a50f4e8808d61bce23ba (patch) | |
tree | 721f5c0f3068a7f98b30e257b3d58b2713f2f9bf /src/lib | |
parent | 973bbebfd0a47b0b36d19fccf6a882e971beaaa5 (diff) | |
download | tanzanite-b5ada8dca12013bfc730a50f4e8808d61bce23ba.tar.gz tanzanite-b5ada8dca12013bfc730a50f4e8808d61bce23ba.tar.bz2 tanzanite-b5ada8dca12013bfc730a50f4e8808d61bce23ba.zip |
fix(FeaturesCommand): properly hide disabled features
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/common/AutoMod.ts | 29 | ||||
-rw-r--r-- | src/lib/common/ButtonPaginator.ts | 55 | ||||
-rw-r--r-- | src/lib/common/ConfirmationPrompt.ts | 4 | ||||
-rw-r--r-- | src/lib/common/DeleteButton.ts | 11 | ||||
-rw-r--r-- | src/lib/common/util/Moderation.ts | 11 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 34 | ||||
-rw-r--r-- | src/lib/models/instance/Guild.ts | 83 |
7 files changed, 101 insertions, 126 deletions
diff --git a/src/lib/common/AutoMod.ts b/src/lib/common/AutoMod.ts index d043ef0..93d2f8f 100644 --- a/src/lib/common/AutoMod.ts +++ b/src/lib/common/AutoMod.ts @@ -162,17 +162,15 @@ export class AutoMod { .setColor(color) .setTimestamp() ], - components: - Severity.TEMP_MUTE >= 2 - ? [ - new ActionRow().addComponents( - new ButtonComponent() - .setStyle(ButtonStyle.Danger) - .setLabel('Ban User') - .setCustomId(`automod;ban;${this.message.author.id};everyone mention and scam phrase`) - ) - ] - : undefined + components: [ + new ActionRow().addComponents( + new ButtonComponent({ + style: ButtonStyle.Danger, + label: 'Ban User', + customId: `automod;ban;${this.message.author.id};everyone mention and scam phrase` + }) + ) + ] }); } } @@ -334,10 +332,11 @@ export class AutoMod { highestOffence.severity >= 2 ? [ new ActionRow().addComponents( - new ButtonComponent() - .setStyle(ButtonStyle.Danger) - .setLabel('Ban User') - .setCustomId(`automod;ban;${this.message.author.id};${highestOffence.reason}`) + new ButtonComponent({ + style: ButtonStyle.Danger, + label: 'Ban User', + customId: `automod;ban;${this.message.author.id};${highestOffence.reason}` + }) ) ] : undefined diff --git a/src/lib/common/ButtonPaginator.ts b/src/lib/common/ButtonPaginator.ts index a289855..15c07fa 100644 --- a/src/lib/common/ButtonPaginator.ts +++ b/src/lib/common/ButtonPaginator.ts @@ -172,31 +172,36 @@ export class ButtonPaginator { */ protected getPaginationRow(disableAll = false): ActionRow<ActionRowComponent> { return new ActionRow().addComponents( - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate_beginning') - .setEmoji(PaginateEmojis.BEGINNING) - .setDisabled(disableAll || this.curPage === 0), - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate_back') - .setEmoji(PaginateEmojis.BACK) - .setDisabled(disableAll || this.curPage === 0), - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate_stop') - .setEmoji(PaginateEmojis.STOP) - .setDisabled(disableAll), - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate_next') - .setEmoji(PaginateEmojis.FORWARD) - .setDisabled(disableAll || this.curPage === this.embeds.length - 1), - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate_end') - .setEmoji(PaginateEmojis.END) - .setDisabled(disableAll || this.curPage === this.embeds.length - 1) + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate_beginning', + emoji: PaginateEmojis.BEGINNING, + disabled: disableAll || this.curPage === 0 + }), + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate_back', + emoji: PaginateEmojis.BACK, + disabled: disableAll || this.curPage === 0 + }), + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate_stop', + emoji: PaginateEmojis.STOP, + disabled: disableAll + }), + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate_next', + emoji: PaginateEmojis.FORWARD, + disabled: disableAll || this.curPage === this.numPages - 1 + }), + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate_end', + emoji: PaginateEmojis.END, + disabled: disableAll || this.curPage === this.numPages - 1 + }) ); } diff --git a/src/lib/common/ConfirmationPrompt.ts b/src/lib/common/ConfirmationPrompt.ts index b775640..4ff00ce 100644 --- a/src/lib/common/ConfirmationPrompt.ts +++ b/src/lib/common/ConfirmationPrompt.ts @@ -30,8 +30,8 @@ export class ConfirmationPrompt { protected async send(): Promise<boolean> { this.messageOptions.components = [ new ActionRow().addComponents( - new ButtonComponent().setStyle(ButtonStyle.Success).setCustomId('confirmationPrompt_confirm').setLabel('Yes'), - new ButtonComponent().setStyle(ButtonStyle.Danger).setCustomId('confirmationPrompt_cancel').setLabel('No') + new ButtonComponent({ style: ButtonStyle.Success, customId: 'confirmationPrompt_confirm', label: 'Yes' }), + new ButtonComponent({ style: ButtonStyle.Danger, customId: 'confirmationPrompt_cancel', label: 'No' }) ) ]; diff --git a/src/lib/common/DeleteButton.ts b/src/lib/common/DeleteButton.ts index cf3b416..0a9fd79 100644 --- a/src/lib/common/DeleteButton.ts +++ b/src/lib/common/DeleteButton.ts @@ -67,11 +67,12 @@ export class DeleteButton { protected updateComponents(edit = false, disable = false): void { this.messageOptions.components = [ new ActionRow().addComponents( - new ButtonComponent() - .setStyle(ButtonStyle.Primary) - .setCustomId('paginate__stop') - .setEmoji(PaginateEmojis.STOP) - .setDisabled(disable) + new ButtonComponent({ + style: ButtonStyle.Primary, + customId: 'paginate__stop', + emoji: PaginateEmojis.STOP, + disabled: disable + }) ) ]; if (edit) { diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index 365dbd5..afe220c 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -11,7 +11,7 @@ import { type ModLogType } from '#lib'; import assert from 'assert'; -import { ActionRow, ButtonComponent, ButtonStyle, ComponentType, Embed, PermissionFlagsBits, type Snowflake } from 'discord.js'; +import { ActionRow, ButtonComponent, ButtonStyle, Embed, PermissionFlagsBits, type Snowflake } from 'discord.js'; enum punishMap { 'warned' = 'warn', @@ -289,13 +289,12 @@ export class Moderation { new ActionRow({ components: [ new ButtonComponent({ - custom_id: `appeal;${this.punishmentToPresentTense(options.punishment)};${ - options.guild.id - };${client.users.resolveId(options.user)};${options.modlog}`, + customId: `appeal;${this.punishmentToPresentTense(options.punishment)};${options.guild.id};${client.users.resolveId( + options.user + )};${options.modlog}`, style: ButtonStyle.Primary, - type: ComponentType.Button, label: 'Appeal' - }) + }).toJSON() ] }) ]; diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index fa6dc53..1a748ed 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -10,7 +10,7 @@ import { roleWithDuration, snowflake } from '#args'; -import { +import type { BushBaseGuildEmojiManager, BushChannelManager, BushClientEvents, @@ -23,6 +23,7 @@ import { import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'; import * as Sentry from '@sentry/node'; import { AkairoClient, ContextMenuCommandHandler, version as akairoVersion } from 'discord-akairo'; +import { GatewayIntentBits } from 'discord-api-types/v9'; import { ActivityType, Options, @@ -42,7 +43,6 @@ import { } from 'discord.js'; import EventEmitter from 'events'; import { google } from 'googleapis'; -import snakeCase from 'lodash.snakecase'; import path from 'path'; import readline from 'readline'; import type { Options as SequelizeOptions, Sequelize as SequelizeType } from 'sequelize'; @@ -213,9 +213,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re allowedMentions: AllowedMentions.users(), // No everyone or role mentions by default makeCache: Options.cacheWithLimits({}), failIfNotExists: false, - rest: { api: 'https://canary.discord.com/api' }, - // todo: remove this when https://github.com/discordjs/discord.js/pull/7497 is merged - jsonTransformer + rest: { api: 'https://canary.discord.com/api' } }); patch(this); @@ -527,29 +525,3 @@ export interface BushStats { */ commandsUsed: bigint; } - -// exported as const enum from discord-api-types -enum GatewayIntentBits { - Guilds = 1, - GuildMembers = 2, - GuildBans = 4, - GuildEmojisAndStickers = 8, - GuildIntegrations = 16, - GuildWebhooks = 32, - GuildInvites = 64, - GuildVoiceStates = 128, - GuildPresences = 256, - GuildMessages = 512, - GuildMessageReactions = 1024, - GuildMessageTyping = 2048, - DirectMessages = 4096, - DirectMessageReactions = 8192, - DirectMessageTyping = 16384, - GuildScheduledEvents = 65536 -} - -function jsonTransformer(obj: any): any { - if (typeof obj !== 'object' || !obj) return obj; - if (Array.isArray(obj)) return obj.map(jsonTransformer); - return Object.fromEntries(Object.entries(obj).map(([key, value]) => [snakeCase(key), jsonTransformer(value)])); -} diff --git a/src/lib/models/instance/Guild.ts b/src/lib/models/instance/Guild.ts index 7fe7ac1..5fb507a 100644 --- a/src/lib/models/instance/Guild.ts +++ b/src/lib/models/instance/Guild.ts @@ -311,77 +311,81 @@ interface GuildFeature { name: string; description: string; default: boolean; - notConfigurable?: boolean; + hidden: boolean; } -const asGuildFeature = <T>(gf: { [K in keyof T]: GuildFeature }) => gf; + +type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; + +const asGuildFeature = <T>(gf: { [K in keyof T]: PartialBy<GuildFeature, 'hidden' | 'default'> }): { + [K in keyof T]: GuildFeature; +} => { + for (const key in gf) { + gf[key].hidden ??= false; + gf[key].default ??= false; + } + return gf as { [K in keyof T]: GuildFeature }; +}; export const guildFeaturesObj = asGuildFeature({ automod: { name: 'Automod', - description: 'Deletes offensive content as well as phishing links.', - default: false + description: 'Deletes offensive content as well as phishing links.' }, excludeDefaultAutomod: { name: 'Exclude Default Automod', - description: 'Opt out of using the default automod options.', - default: false + description: 'Opt out of using the default automod options.' }, excludeAutomodScamLinks: { name: 'Exclude Automod Scam Links', - description: 'Opt out of having automod delete scam links.', - default: false + description: 'Opt out of having automod delete scam links.' }, delScamMentions: { name: 'Delete Scam Mentions', - description: 'Deletes messages with @everyone and @here mentions that have common scam phrases.', - default: false + description: 'Deletes messages with @everyone and @here mentions that have common scam phrases.' + }, + blacklistedFile: { + name: 'Blacklisted File', + description: 'Automatically deletes malicious files.' }, autoPublish: { name: 'Auto Publish', - description: 'Publishes messages in configured announcement channels.', - default: false + description: 'Publishes messages in configured announcement channels.' }, // todo implement a better auto thread system autoThread: { name: 'Auto Thread', description: 'Creates a new thread for messages in configured channels.', - default: false, - notConfigurable: true + hidden: true }, - blacklistedFile: { - name: 'Blacklisted File', - description: 'Automatically deletes malicious files.', - default: false + perspectiveApi: { + name: 'Perspective API', + description: 'Use the Perspective API to detect toxicity.', + hidden: true }, boosterMessageReact: { name: 'Booster Message React', - description: 'Reacts to booster messages with the boost emoji.', - default: false + description: 'Reacts to booster messages with the boost emoji.' }, leveling: { name: 'Leveling', - description: "Tracks users' messages and assigns them xp.", - default: false + description: "Tracks users' messages and assigns them xp." + }, + sendLevelUpMessages: { + name: 'Send Level Up Messages', + description: 'Send a message when a user levels up.', + default: true }, stickyRoles: { name: 'Sticky Roles', - description: 'Restores past roles to a user when they rejoin.', - default: false + description: 'Restores past roles to a user when they rejoin.' }, reporting: { name: 'Reporting', - description: 'Allow users to make reports.', - default: false + description: 'Allow users to make reports.' }, modsCanPunishMods: { name: 'Mods Can Punish Mods', - description: 'Allow moderators to punish other moderators.', - default: false - }, - sendLevelUpMessages: { - name: 'Send Level Up Messages', - description: 'Send a message when a user levels up.', - default: true + description: 'Allow moderators to punish other moderators.' }, logManualPunishments: { name: 'Log Manual Punishments', @@ -391,14 +395,7 @@ export const guildFeaturesObj = asGuildFeature({ punishmentAppeals: { name: 'Punishment Appeals', description: 'Allow users to appeal their punishments and send the appeal to the configured channel.', - default: false, - notConfigurable: true - }, - perspectiveApi: { - name: 'Perspective API', - description: 'Use the Perspective API to detect toxicity.', - default: false, - notConfigurable: true + hidden: true }, highlight: { name: 'Highlight', @@ -437,4 +434,6 @@ export const guildLogsArr = Object.keys(guildLogsObj).filter( type LogChannelDB = { [x in keyof typeof guildLogsObj]?: Snowflake }; export type GuildFeatures = keyof typeof guildFeaturesObj; -export const guildFeaturesArr: GuildFeatures[] = Object.keys(guildFeaturesObj) as GuildFeatures[]; +export const guildFeaturesArr: GuildFeatures[] = Object.keys(guildFeaturesObj).filter( + (f) => !guildFeaturesObj[f as keyof typeof guildFeaturesObj].hidden +) as GuildFeatures[]; |