From 0c5841111c37bb00e164b29c513b6df458fda01a Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 22 Jul 2022 14:34:35 +0300 Subject: [PATCH] misc fixes --- src/structure/DiscordClient.js | 10 +++--- .../components/commands/information/Guild.js | 22 +++++------- src/structure/components/infractions/Prune.js | 3 +- .../components/observers/CommandHandler.js | 4 +-- .../components/settings/logging/Messages.js | 2 +- .../settings/moderation/InviteFilter.js | 5 ++- .../settings/moderation/LinkFilter.js | 4 +-- .../components/settings/utility/Autorole.js | 2 +- src/structure/interfaces/FilterSetting.js | 34 +++++++++---------- src/structure/interfaces/Infraction.js | 2 +- .../interfaces/commands/SettingsCommand.js | 11 +++--- 11 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/structure/DiscordClient.js b/src/structure/DiscordClient.js index f95be3b..a1ff2ac 100644 --- a/src/structure/DiscordClient.js +++ b/src/structure/DiscordClient.js @@ -1,4 +1,4 @@ -const { Client, Collection, DataResolver } = require('discord.js'); +const { Client, Collection, DataResolver, ActivityType } = require('discord.js'); const chalk = require('chalk'); const { inspect } = require('util'); @@ -69,8 +69,6 @@ class DiscordClient extends Client { this.emit('rateLimit', ...args); }); - this.ws.on('onmessage', (data) => console.log(data)); - // this.once('ready', () => { // this._setActivity(); @@ -206,16 +204,16 @@ class DiscordClient extends Client { const result = await this.shard.broadcastEval((client) => client.guilds.cache.size).catch(() => null); if (!result) return; const guildCount = result.reduce((p, v) => p+v, 0); - this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' }); + this.user.setActivity(`${guildCount} servers`, { type: ActivityType.Watching }); }, 1: async () => { const result = await this.shard.broadcastEval((client) => client.users.cache.size).catch(() => null); if (!result) return; const userCount = result.reduce((p, v) => p+v, 0); - this.user.setActivity(`${userCount} users`, { type: 'LISTENING' }); + this.user.setActivity(`${userCount} users`, { type: ActivityType.Listening }); }, 2: async () => { - this.user.setActivity("for /help", { type: 'LISTENING' }); + this.user.setActivity("for /help", { type: ActivityType.Listening }); } }; diff --git a/src/structure/components/commands/information/Guild.js b/src/structure/components/commands/information/Guild.js index c3e0a9c..d82b642 100644 --- a/src/structure/components/commands/information/Guild.js +++ b/src/structure/components/commands/information/Guild.js @@ -1,10 +1,6 @@ -const { EmbedBuilder } = require("discord.js"); +const { EmbedBuilder, ChannelType } = require("discord.js"); const { SlashCommand } = require("../../../interfaces"); -const Tiers = { - NONE: 0 -}; - class GuildCommand extends SlashCommand { constructor(client) { @@ -38,13 +34,13 @@ class GuildCommand extends SlashCommand { for (const channel of guild.channels.cache.values()) { - if (channel.type === 'GUILD_VOICE') vc++; - if (channel.type === 'GUILD_TEXT') tc++; - if (channel.type === 'GUILD_CATEGORY') cat++; - if (channel.type === 'GUILD_NEWS') news++; - if (channel.type === 'GUILD_NEWS_THREAD') newsThread++; - if (channel.type === 'GUILD_PUBLIC_THREAD') publicThread++; - if (channel.type === 'GUILD_PRIVATE_THREAD') privateThread++; + if (channel.type === ChannelType.GuildVoice) vc++; + if (channel.type === ChannelType.GuildText) tc++; + if (channel.type === ChannelType.GuildCategory) cat++; + if (channel.type === ChannelType.GuildNews) news++; + if (channel.type === ChannelType.GuildNewsThread) newsThread++; + if (channel.type === ChannelType.GuildPublicThread) publicThread++; + if (channel.type === ChannelType.GuildPrivateThread) privateThread++; totalChannels++; } @@ -91,7 +87,7 @@ class GuildCommand extends SlashCommand { roleCount: guild.roles.cache.size, emojiCount: guild.emojis.cache.filter((e) => !e.animated).size, gifEmojiCount: guild.emojis.cache.filter((e) => e.animated).size, - emojiTotal: 50 + 50 * Tiers[guild.premiumTier] + emojiTotal: 50 + 50 * guild.premiumTier }), inline: true } diff --git a/src/structure/components/infractions/Prune.js b/src/structure/components/infractions/Prune.js index de9f9ab..8340413 100644 --- a/src/structure/components/infractions/Prune.js +++ b/src/structure/components/infractions/Prune.js @@ -1,5 +1,6 @@ const { Infraction } = require('../../interfaces/'); const { Collection } = require('@discordjs/collection'); +const { MessageType } = require('discord.js'); const Arguments = ['users', 'bots', 'humans', 'contains', 'startswith', 'endswith', 'emojis', 'reactions', 'text', 'invites', 'links', 'emojis', 'reactions', 'images', 'attachments']; @@ -43,7 +44,7 @@ class PruneInfraction extends Infraction { const hasOld = messages.some((m) => m.createdTimestamp >= Date.now() + 1209600000); //I hope Node.js can handle these large of numbers.. e_e (2 weeks) const hasUndeletable = messages.some((m) => m.deletable); - messages = messages.filter((m) => m.deletable && m.type !== 'APPLICATION_COMMAND'); + messages = messages.filter((m) => m.deletable && m.type !== MessageType.ChatInputCommand); if (messages.size === 0) return this._fail('C_PRUNE_NOTDELETABLE'); const filtered = await this.filterMessages(messages); diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 02eaf67..ad24b19 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -1,4 +1,4 @@ -const { EmbedBuilder, Message, ChannelType, ComponentType } = require('discord.js'); +const { EmbedBuilder, Message, ChannelType, ComponentType, ButtonStyle } = require('discord.js'); const { Util } = require('../../../utilities'); const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers'); const { Observer, CommandError } = require('../../interfaces/'); @@ -482,7 +482,7 @@ class CommandHandler extends Observer { { label: 'Support', type: ComponentType.Button, - style: 'LINK', + style: ButtonStyle.Link, url: this.client._options.discord.invite } ] diff --git a/src/structure/components/settings/logging/Messages.js b/src/structure/components/settings/logging/Messages.js index b18300b..12125c6 100644 --- a/src/structure/components/settings/logging/Messages.js +++ b/src/structure/components/settings/logging/Messages.js @@ -124,7 +124,7 @@ class MessageLog extends Setting { if (!values.length) return { error: true, index: 'RESOLVE_FAIL', params: { type: list === 'bypass' ? 'roles' : 'channels' } }; const { modified } = this[method](setting[list], values.map((o) => o.id)); if(modified.length) { - index = `SETTING_SUCCESS_${list.toUpperCase()}`; + index = `SETTING_SUCCESS_${method.toUpperCase()}`; langParams.updated = list; langParams.modified = modified.map((o) => o.name).join('__, __'); } diff --git a/src/structure/components/settings/moderation/InviteFilter.js b/src/structure/components/settings/moderation/InviteFilter.js index c73c036..ac31e9a 100644 --- a/src/structure/components/settings/moderation/InviteFilter.js +++ b/src/structure/components/settings/moderation/InviteFilter.js @@ -116,7 +116,10 @@ class InviteFilterSetting extends FilterSetting { return { id: word }; }); // TODO Figure out guild ID validation here - if (!params.length && ![silent, enabled].some((o) => o !== undefined)) return { error: true, index: 'RESOLVE_FAIL', params: { type: list === 'bypass' ? 'roles' : 'channels' } }; + if (!params.length && ![silent, enabled].some((o) => o !== undefined)) + // eslint-disable-next-line no-nested-ternary + return { error: true, index: 'RESOLVE_FAIL', params: { type: ['bypass', 'ignore'].includes(list) ? list === 'bypass' ? 'roles' : 'channels' : 'guilds' } }; + const { modified } = this[method](setting[list], params.map((o) => o.id)); if (modified.length) { index = `SETTING_SUCCESS_${method.toUpperCase()}`; diff --git a/src/structure/components/settings/moderation/LinkFilter.js b/src/structure/components/settings/moderation/LinkFilter.js index 176980d..52b42b9 100644 --- a/src/structure/components/settings/moderation/LinkFilter.js +++ b/src/structure/components/settings/moderation/LinkFilter.js @@ -143,8 +143,8 @@ class LinkFilterSetting extends FilterSetting { const { modified } = this[method](setting[list], params.map((o) => o.id || o)); if (modified.length) { index = `SETTING_SUCCESS_${method.toUpperCase()}`; - langParams.list = list; - langParams.modified = modified.filter((o) => modified.includes(o.id || o)).map((o) => o.name || o).join('__, __'); + langParams.updated = list; + langParams.modified = params.filter((o) => modified.includes(o.id || o)).map((o) => o.name || o).join('__, __'); } } diff --git a/src/structure/components/settings/utility/Autorole.js b/src/structure/components/settings/utility/Autorole.js index 97fd318..124dca7 100644 --- a/src/structure/components/settings/utility/Autorole.js +++ b/src/structure/components/settings/utility/Autorole.js @@ -87,7 +87,7 @@ class Autorole extends Setting { }, { name: 'GENERAL_ROLES', - value: setting.roles.map((role) => `<@&${role}>`).join(' ') + value: setting.roles.map((role) => `<@&${role}>`).join(' ') || '**N/A**' } ]; } diff --git a/src/structure/interfaces/FilterSetting.js b/src/structure/interfaces/FilterSetting.js index 8af0c62..50ec5bf 100644 --- a/src/structure/interfaces/FilterSetting.js +++ b/src/structure/interfaces/FilterSetting.js @@ -9,7 +9,7 @@ class FilterSetting extends Setting { async _action(interaction, method, actions, { _wordWatcher } = {}) { if (!['add', 'remove', 'edit', 'list', 'reset'].includes(method)) - return { error: true, message: interaction.format('ERR_INVALID_METHOD', { method }) }; + return { error: true, content: interaction.format('ERR_INVALID_METHOD', { method }) }; this.client.logger.debug(`_action method:${method}`); let result = null, @@ -17,7 +17,7 @@ class FilterSetting extends Setting { if (method === 'add') { if (actions.length >= 5 && _wordWatcher) return { error: true, - message: interaction.format('SETTING_WORDWATCHER_ACTION_LIMIT') + content: interaction.format('SETTING_WORDWATCHER_ACTION_LIMIT') }; result = await this._createAction(interaction, actions, { _wordWatcher }); index = 'SETTING_FILTER_ACTION_ADD'; @@ -76,7 +76,7 @@ class FilterSetting extends Setting { || !validInfractions.includes(infType)) && !['del', 'delete'].includes(action)) return { error: true, - message: interaction.format('SETTING_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') }) + content: interaction.format('SETTING_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') }) }; if (!infType && ['del', 'delete'].includes(action)) infType = 'DELETE'; actionObject.type = infType; @@ -192,7 +192,7 @@ class FilterSetting extends Setting { async _removeAction(interaction, actions) { - if (!actions.length) return { error: true, message: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') }; + if (!actions.length) return { error: true, content: interaction.format('SETTING_FILTER_ACTION_REMOVE_NO_ACTIONS') }; const embed = this._createActionEmbed(interaction, actions); const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_REMOVE_START', time: 60, embed }); @@ -200,12 +200,12 @@ class FilterSetting extends Setting { if (['cancel', 'abort', 'exit'].includes(content)) return { error: true, - message: interaction.format('ERR_CANCEL') + content: interaction.format('ERR_CANCEL') }; const index = parseInt(content); - if (isNaN(index)) return { error: true, message: interaction.format('ERR_NAN') }; - if (index < 0 || index > actions.length - 1) return { error: true, message: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') }; + if (isNaN(index)) return { error: true, content: interaction.format('ERR_NAN') }; + if (index < 0 || index > actions.length - 1) return { error: true, content: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') }; return actions.splice(index, 1)[0]; @@ -218,8 +218,8 @@ class FilterSetting extends Setting { if (content.error) return content; const index = parseInt(content); - if (isNaN(index)) return { error: true, message: interaction.format('ERR_NAN') }; - if (index < 0 || index > actions.length - 1) return { error: true, message: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') }; + if (isNaN(index)) return { error: true, content: interaction.format('ERR_NAN') }; + if (index < 0 || index > actions.length - 1) return { error: true, content: interaction.format('ERR_INDEX_OUT_OF_BOUNDS') }; const action = actions[index]; @@ -234,7 +234,7 @@ class FilterSetting extends Setting { if (!properties.includes(prop)) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_BADPROP') }; if (prop === 'trigger') return this._editTrigger(interaction, actions, action); @@ -254,7 +254,7 @@ class FilterSetting extends Setting { if (!interaction.guild._settings.modpoints?.enabled) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') }; const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_EXPIRATION', time: 60 }); @@ -277,7 +277,7 @@ class FilterSetting extends Setting { const bool = resolver.resolveBoolean(content); if (bool === null) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_BOOL_INVALID') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_BOOL_INVALID') }; action[prop] = bool; @@ -289,7 +289,7 @@ class FilterSetting extends Setting { if (!interaction.guild._settings.modpoints?.enabled) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_DISABLED') }; const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_POINTS', time: 60 }); @@ -298,7 +298,7 @@ class FilterSetting extends Setting { const reg = /(\d{1,3})\s?(points?|pts?|p)?/iu; if (!reg.test(content)) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_FAIL') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_POINTS_FAIL') }; const match = content.match(reg); @@ -324,7 +324,7 @@ class FilterSetting extends Setting { if (!validInfractions.includes(content.toUpperCase())) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_INVALID_TYPE') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_INVALID_TYPE') }; action.type = content.toUpperCase(); @@ -339,7 +339,7 @@ class FilterSetting extends Setting { if (!['MUTE', 'BAN'].includes(action.type)) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.type }) + content: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR', { action: action.type }) }; const content = await this._prompt(interaction, { index: 'SETTING_FILTER_ACTION_EDIT_DURATION', time: 120 }); @@ -351,7 +351,7 @@ class FilterSetting extends Setting { const time = resolver.resolveTime(content); if (!time) return { error: true, - message: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR2') + content: interaction.format('SETTING_FILTER_ACTION_EDIT_DURATION_ERR2') }; action.duration = time; } diff --git a/src/structure/interfaces/Infraction.js b/src/structure/interfaces/Infraction.js index 0f72f65..d118bab 100644 --- a/src/structure/interfaces/Infraction.js +++ b/src/structure/interfaces/Infraction.js @@ -442,7 +442,7 @@ class Infraction { async unresolve(staff, reason) { this.changes.push({ - type: 'RESOLVE', + type: 'UNRESOLVE', staff: staff.id, timestamp: Date.now(), reason diff --git a/src/structure/interfaces/commands/SettingsCommand.js b/src/structure/interfaces/commands/SettingsCommand.js index a9aa091..64b034d 100644 --- a/src/structure/interfaces/commands/SettingsCommand.js +++ b/src/structure/interfaces/commands/SettingsCommand.js @@ -171,15 +171,16 @@ class SettingsCommand extends SlashCommand { const embed = setting.usageEmbed(guild, null, this.subcommand(subcommand.name)); const dataFields = await setting.fields(guild); // eslint-disable-next-line no-return-assign - dataFields.forEach((field) => { + dataFields.forEach((field, index) => { + if (!field.name.length) this.client.logger.warn(`${setting.name} is missing name for a field, index: ${index}`, { broadcast: true }); + if (!field.value.length) this.client.logger.warn(`${setting.name} is missing value for a field, index: ${index}`, { broadcast: true }); if(field.name.length > 1) field.name = guild.format(field.name); }); - embed.addFields(dataFields); + try { + embed.addFields(...dataFields); + }catch(err) { /* */ } await invoker.reply({ embeds: [embed] }); - // .catch((error) => { - // this.client.logger.error(`${error.stack || error}\nError context: ${JSON.stringify(embed)}`); - // }); }