From 3c56bbcf795725b65192409b3211d92c097f8c82 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 3 Mar 2022 23:45:16 -0500 Subject: refactor: preemptively switch addField to addFields --- src/commands/config/config.ts | 2 +- src/commands/dev/eval.ts | 10 ++-- src/commands/dev/javascript.ts | 8 +-- src/commands/dev/sh.ts | 10 ++-- src/commands/dev/test.ts | 2 +- src/commands/info/botInfo.ts | 30 +++++------ src/commands/info/color.ts | 8 +-- src/commands/info/guildInfo.ts | 6 +-- src/commands/info/help.ts | 10 ++-- src/commands/info/ping.ts | 8 +-- src/commands/info/snowflake.ts | 12 ++--- src/commands/info/userInfo.ts | 12 ++--- src/commands/moulberry-bush/report.ts | 6 +-- src/commands/moulberry-bush/rule.ts | 4 +- src/commands/moulberry-bush/serverStatus.ts | 4 +- src/commands/utilities/calculator.ts | 6 +-- src/commands/utilities/decode.ts | 6 +-- src/commands/utilities/highlight-show.ts | 4 +- src/commands/utilities/poll.ts | 80 +++++++++++++++++++++++++++++ src/commands/utilities/price.ts | 12 ++--- src/commands/utilities/suicide.ts | 4 +- src/commands/utilities/wolframAlpha.ts | 8 +-- 22 files changed, 166 insertions(+), 86 deletions(-) create mode 100644 src/commands/utilities/poll.ts (limited to 'src/commands') diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 6cb493d..88e83ec 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -369,7 +369,7 @@ export default class ConfigCommand extends BushCommand { message.util.isSlash ? _.snakeCase(setting) : setting } ${guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set'} " to set this setting.` }); - settingsEmbed.addField({ + settingsEmbed.addFields({ name: 'value', value: (await generateCurrentValue(guildSettingsObj[setting].type)) || '[No Value Set]' }); diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index a6221c9..8742246 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -254,8 +254,8 @@ export default class EvalCommand extends BushCommand { embed.setTimestamp(); - if (inputTS) embed.addField({ name: ':inbox_tray: Input (typescript)', value: inputTS }); - embed.addField({ name: `:inbox_tray: Input${inputTS ? ' (transpiled javascript)' : ''}`, value: inputJS }); + if (inputTS) embed.addFields({ name: ':inbox_tray: Input (typescript)', value: inputTS }); + embed.addFields({ name: `:inbox_tray: Input${inputTS ? ' (transpiled javascript)' : ''}`, value: inputJS }); const output = await this.codeblock(rawResult, 'js', { depth: selDepth ?? 0, @@ -270,10 +270,10 @@ export default class EvalCommand extends BushCommand { embed .setTitle(`${emojis[err ? 'errorFull' : 'successFull']} ${err ? 'Uns' : 'S'}uccessfully Evaluated Expression`) .setColor(colors[err ? 'error' : 'success']) - .addField({ name: `:outbox_tray: ${err ? 'Error' : 'Output'}`, value: output }); + .addFields({ name: `:outbox_tray: ${err ? 'Error' : 'Output'}`, value: output }); - if (!err && methods) embed.addField({ name: ':wrench: Methods', value: methods }); - if (!err && proto) embed.addField({ name: ':gear: Proto', value: proto }); + if (!err && methods) embed.addFields({ name: ':wrench: Methods', value: methods }); + if (!err && proto) embed.addFields({ name: ':gear: Proto', value: proto }); if (!silent || message.util.isSlashMessage(message)) { await message.util.reply({ content: null, embeds: [embed] }); diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index 3ede3e2..b0ba0c4 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -67,12 +67,12 @@ export default class JavascriptCommand extends BushCommand { }); embed.setTitle(`${util.emojis.successFull} Successfully Evaluated Expression`).setColor(util.colors.success); - embed.addField({ name: '📥 Input', value: input }); - embed.addField({ name: '📤 Output', value: output }); + embed.addFields({ name: '📥 Input', value: input }); + embed.addFields({ name: '📤 Output', value: output }); } catch (e) { embed.setTitle(`${util.emojis.errorFull} Unable to Evaluate Expression`).setColor(util.colors.error); - embed.addField({ name: '📥 Input', value: input }); - embed.addField({ name: '📤 Error', value: await util.inspectCleanRedactCodeblock(e, 'js') }); + embed.addFields({ name: '📥 Input', value: input }); + embed.addFields({ name: '📤 Error', value: await util.inspectCleanRedactCodeblock(e, 'js') }); } embed.setTimestamp().setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL() ?? undefined }); diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index 7d29df7..7134b6b 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -50,8 +50,8 @@ export default class ShCommand extends BushCommand { .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL() ?? undefined }) .setTimestamp() .setTitle('Shell Command') - .addField({ name: '📥 Input', value: await util.codeblock(input, 1024, 'sh', true) }) - .addField({ name: 'Running', value: util.emojis.loading }); + .addFields({ name: '📥 Input', value: await util.codeblock(input, 1024, 'sh', true) }) + .addFields({ name: 'Running', value: util.emojis.loading }); await message.util.reply({ embeds: [embed] }); @@ -72,15 +72,15 @@ export default class ShCommand extends BushCommand { .setColor(util.colors.success) .spliceFields(1, 1); - if (stdout) embed.addField({ name: '📤 stdout', value: await util.codeblock(stdout, 1024, 'json', true) }); - if (stderr) embed.addField({ name: '📤 stderr', value: await util.codeblock(stderr, 1024, 'json', true) }); + if (stdout) embed.addFields({ name: '📤 stdout', value: await util.codeblock(stdout, 1024, 'json', true) }); + if (stderr) embed.addFields({ name: '📤 stderr', value: await util.codeblock(stderr, 1024, 'json', true) }); } catch (e) { embed .setTitle(`${util.emojis.errorFull} An error occurred while executing.`) .setColor(util.colors.error) .spliceFields(1, 1); - embed.addField({ name: '📤 Output', value: await util.codeblock(e?.stack, 1024, 'js', true) }); + embed.addFields({ name: '📤 Output', value: await util.codeblock(e?.stack, 1024, 'js', true) }); } await message.util.edit({ embeds: [embed] }); } diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index 8c76ded..cca40a6 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -63,7 +63,7 @@ export default class TestCommand extends BushCommand { return await message.util.reply({ content: 'buttons', components: [ButtonRow] }); } else if (['embed', 'button embed'].includes(args?.feature?.toLowerCase())) { const embed = new Embed() - .addField({ name: 'Field Name', value: 'Field Content' }) + .addFields({ name: 'Field Name', value: 'Field Content' }) .setAuthor({ name: 'Author', iconURL: 'https://www.w3schools.com/w3css/img_snowtops.jpg', url: 'https://google.com/' }) .setColor(message.member?.displayColor ?? util.colors.default) .setDescription('Description') diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index d23f5b1..4d914e4 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -41,8 +41,8 @@ export default class BotInfoCommand extends BushCommand { if (repoUrl.includes('.git')) repoUrl = repoUrl.substring(0, repoUrl.length - 4); const embed = new Embed() .setTitle('Bot Info:') - .addField({ name: '**Uptime**', value: util.humanizeDuration(client.uptime!, 2), inline: true }) - .addField({ + .addFields({ name: '**Uptime**', value: util.humanizeDuration(client.uptime!, 2), inline: true }) + .addFields({ name: '**Memory Usage**', value: `System: ${prettyBytes(os.totalmem() - os.freemem(), { binary: true })}/${prettyBytes(os.totalmem(), { binary: true @@ -52,23 +52,23 @@ export default class BotInfoCommand extends BushCommand { )}`, inline: true }) - .addField({ name: '**CPU Usage**', value: `${client.stats.cpu}%`, inline: true }) - .addField({ name: '**Platform**', value: Platform[process.platform], inline: true }) - .addField({ name: '**Commands Used**', value: `${client.stats.commandsUsed.toLocaleString()}`, inline: true }) - .addField({ name: '**Servers**', value: client.guilds.cache.size.toLocaleString(), inline: true }) - .addField({ name: '**Users**', value: client.users.cache.size.toLocaleString(), inline: true }) - .addField({ name: '**Discord.js Version**', value: discordJSVersion, inline: true }) - .addField({ name: '**Node.js Version**', value: process.version.slice(1), inline: true }) - .addField({ name: '**Commands**', value: client.commandHandler.modules.size.toLocaleString(), inline: true }) - .addField({ name: '**Listeners**', value: client.listenerHandler.modules.size.toLocaleString(), inline: true }) - .addField({ name: '**Inhibitors**', value: client.inhibitorHandler.modules.size.toLocaleString(), inline: true }) - .addField({ name: '**Tasks**', value: client.taskHandler.modules.size.toLocaleString(), inline: true }) - .addField({ + .addFields({ name: '**CPU Usage**', value: `${client.stats.cpu}%`, inline: true }) + .addFields({ name: '**Platform**', value: Platform[process.platform], inline: true }) + .addFields({ name: '**Commands Used**', value: `${client.stats.commandsUsed.toLocaleString()}`, inline: true }) + .addFields({ name: '**Servers**', value: client.guilds.cache.size.toLocaleString(), inline: true }) + .addFields({ name: '**Users**', value: client.users.cache.size.toLocaleString(), inline: true }) + .addFields({ name: '**Discord.js Version**', value: discordJSVersion, inline: true }) + .addFields({ name: '**Node.js Version**', value: process.version.slice(1), inline: true }) + .addFields({ name: '**Commands**', value: client.commandHandler.modules.size.toLocaleString(), inline: true }) + .addFields({ name: '**Listeners**', value: client.listenerHandler.modules.size.toLocaleString(), inline: true }) + .addFields({ name: '**Inhibitors**', value: client.inhibitorHandler.modules.size.toLocaleString(), inline: true }) + .addFields({ name: '**Tasks**', value: client.taskHandler.modules.size.toLocaleString(), inline: true }) + .addFields({ name: '**Current Commit**', value: `[${currentCommit.substring(0, 7)}](${repoUrl}/commit/${currentCommit})`, inline: true }) - .addField({ name: '**Developers**', value: developers, inline: true }) + .addFields({ name: '**Developers**', value: developers, inline: true }) .setTimestamp() .setColor(util.colors.default); await message.util.reply({ embeds: [embed] }); diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index 6aad1fe..49e827d 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -76,10 +76,10 @@ export default class ColorCommand extends BushCommand { } const embed = new Embed() - .addField({ name: '» Hexadecimal', value: color.toHexString() }) - .addField({ name: '» Decimal', value: `${parseInt(color.toHex(), 16)}` }) - .addField({ name: '» HSL', value: this.removePrefixAndParenthesis(color.toHslString()) }) - .addField({ name: '» RGB', value: this.removePrefixAndParenthesis(color.toRgbString()) }) + .addFields({ name: '» Hexadecimal', value: color.toHexString() }) + .addFields({ name: '» Decimal', value: `${parseInt(color.toHex(), 16)}` }) + .addFields({ name: '» HSL', value: this.removePrefixAndParenthesis(color.toHslString()) }) + .addFields({ name: '» RGB', value: this.removePrefixAndParenthesis(color.toRgbString()) }) .setColor(parseInt(color.toHex(), 16)); return await message.util.reply({ embeds: [embed] }); diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index ed8a973..7f82e92 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -155,7 +155,7 @@ export default class GuildInfoCommand extends BushCommand { ); } - embed.addField({ name: '» About', value: guildAbout.join('\n') }); + embed.addFields({ name: '» About', value: guildAbout.join('\n') }); } private generateStatsField(embed: Embed, guild: Guild | GuildPreview) { @@ -191,7 +191,7 @@ export default class GuildInfoCommand extends BushCommand { `**Stickers:** ${guild.stickers.cache.size?.toLocaleString() ?? 0} / ${StickerTierMap[guild.premiumTier]}` ); - embed.addField({ name: '» Stats', value: guildStats.join('\n') }); + embed.addFields({ name: '» Stats', value: guildStats.join('\n') }); } private generateSecurityField(embed: Embed, guild: Guild | GuildPreview) { @@ -206,7 +206,7 @@ export default class GuildInfoCommand extends BushCommand { `**2FA Required:** ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}` ); - embed.addField({ name: '» Security', value: guildSecurity.join('\n') }); + embed.addFields({ name: '» Security', value: guildSecurity.join('\n') }); } } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 15c447a..04abd18 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -87,7 +87,7 @@ export default class HelpCommand extends BushCommand { .replace(/'(S)/g, (letter) => letter.toLowerCase()); const categoryCommands = categoryFilter.filter((cmd) => cmd.aliases.length > 0).map((cmd) => `\`${cmd.aliases[0]}\``); if (categoryCommands.length > 0) { - embed.addField({ name: `${categoryNice}`, value: `${categoryCommands.join(' ')}` }); + embed.addFields({ name: `${categoryNice}`, value: `${categoryCommands.join(' ')}` }); } } return await message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined }); @@ -98,18 +98,18 @@ export default class HelpCommand extends BushCommand { .setTitle(`${command.id} Command`) .setDescription(`${command.description ?? '*This command does not have a description.*'}`); if (command.usage?.length) { - embed.addField({ + embed.addFields({ name: `» Usage${command.usage.length > 1 ? 's' : ''}`, value: command.usage.map((u) => `\`${u}\``).join('\n') }); } if (command.examples?.length) { - embed.addField({ + embed.addFields({ name: `» Example${command.examples.length > 1 ? 's' : ''}`, value: command.examples.map((u) => `\`${u}\``).join('\n') }); } - if (command.aliases?.length > 1) embed.addField({ name: '» Aliases', value: `\`${command.aliases.join('` `')}\`` }); + if (command.aliases?.length > 1) embed.addFields({ name: '» Aliases', value: `\`${command.aliases.join('` `')}\`` }); if ( command.ownerOnly || command.superUserOnly || @@ -132,7 +132,7 @@ export default class HelpCommand extends BushCommand { .map((g) => util.format.inlineCode(client.guilds.cache.find((g1) => g1.id === g)?.name ?? 'Unknown')) .join(' ')}` ); - if (restrictions.length) embed.addField({ name: '» Restrictions', value: restrictions.join('\n') }); + if (restrictions.length) embed.addFields({ name: '» Restrictions', value: restrictions.join('\n') }); } const params = { embeds: [embed], components: row.components.length ? [row] : undefined }; diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index c767361..1b5e45a 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -22,8 +22,8 @@ export default class PingCommand extends BushCommand { const apiLatency = `${'```'}\n ${Math.round(message.client.ws.ping)}ms ${'```'}`; const embed = new Embed() .setTitle('Pong! 🏓') - .addField({ name: 'Bot Latency', value: botLatency, inline: true }) - .addField({ name: 'API Latency', value: apiLatency, inline: true }) + .addFields({ name: 'Bot Latency', value: botLatency, inline: true }) + .addFields({ name: 'API Latency', value: apiLatency, inline: true }) .setFooter({ text: message.author.username, iconURL: message.author.displayAvatarURL() }) .setColor(util.colors.default) .setTimestamp(); @@ -41,8 +41,8 @@ export default class PingCommand extends BushCommand { const apiLatency = `${'```'}\n ${Math.round(client.ws.ping)}ms ${'```'}`; const embed = new Embed() .setTitle('Pong! 🏓') - .addField({ name: 'Bot Latency', value: botLatency, inline: true }) - .addField({ name: 'API Latency', value: apiLatency, inline: true }) + .addFields({ name: 'Bot Latency', value: botLatency, inline: true }) + .addFields({ name: 'API Latency', value: apiLatency, inline: true }) .setFooter({ text: message.interaction.user.username, iconURL: message.interaction.user.displayAvatarURL() diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts index 3295960..c64a286 100644 --- a/src/commands/info/snowflake.ts +++ b/src/commands/info/snowflake.ts @@ -61,7 +61,7 @@ export default class SnowflakeCommand extends BushCommand { ); snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(channel.name)} \`[Channel]\``); } - snowflakeEmbed.addField({ name: '» Channel Info', value: channelInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» Channel Info', value: channelInfo.join('\n') }); } // Guild @@ -75,7 +75,7 @@ export default class SnowflakeCommand extends BushCommand { `**Members:** ${guild.memberCount?.toLocaleString()}` ]; if (guild.icon) snowflakeEmbed.setThumbnail(guild.iconURL({ size: 2048 })!); - snowflakeEmbed.addField({ name: '» Server Info', value: guildInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» Server Info', value: guildInfo.join('\n') }); snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(guild.name)} \`[Server]\``); } @@ -85,7 +85,7 @@ export default class SnowflakeCommand extends BushCommand { const user: User = (client.users.cache.get(snowflake) ?? fetchedUser)!; const userInfo = [`**Name:** <@${user.id}> (${util.discord.escapeMarkdown(user.tag)})`]; if (user.avatar) snowflakeEmbed.setThumbnail(user.avatarURL({ size: 2048 })!); - snowflakeEmbed.addField({ name: '» User Info', value: userInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» User Info', value: userInfo.join('\n') }); snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(user.tag)} \`[User]\``); } @@ -97,7 +97,7 @@ export default class SnowflakeCommand extends BushCommand { `**Animated:** ${emoji.animated}` ]; if (emoji.url) snowflakeEmbed.setThumbnail(emoji.url); - snowflakeEmbed.addField({ name: '» Emoji Info', value: emojiInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» Emoji Info', value: emojiInfo.join('\n') }); snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(emoji.name ?? '¯\\_(ツ)_/¯')} \`[Emoji]\``); } @@ -113,7 +113,7 @@ export default class SnowflakeCommand extends BushCommand { `**Hex Color:** ${role.hexColor}` ]; if (role.color) snowflakeEmbed.setColor(role.color); - snowflakeEmbed.addField({ name: '» Role Info', value: roleInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» Role Info', value: roleInfo.join('\n') }); snowflakeEmbed.setTitle(`:snowflake: ${util.discord.escapeMarkdown(role.name)} \`[Role]\``); } @@ -126,7 +126,7 @@ export default class SnowflakeCommand extends BushCommand { `**Process ID:** ${deconstructedSnowflake.processId}`, `**Increment:** ${deconstructedSnowflake.increment}` ]; - snowflakeEmbed.addField({ name: '» Snowflake Info', value: snowflakeInfo.join('\n') }); + snowflakeEmbed.addFields({ name: '» Snowflake Info', value: snowflakeInfo.join('\n') }); return await message.util.reply({ embeds: [snowflakeEmbed] }); } diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 0ff8611..a09d8ca 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -132,7 +132,7 @@ export default class UserInfoCommand extends BushCommand { if (pronouns && typeof pronouns === 'string' && pronouns !== 'Unspecified') generalInfo.push(`**Pronouns:** ${pronouns}`); - embed.addField({ name: '» General Info', value: generalInfo.join('\n') }); + embed.addFields({ name: '» General Info', value: generalInfo.join('\n') }); } private static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined) { @@ -156,7 +156,7 @@ export default class UserInfoCommand extends BushCommand { ) serverUserInfo.push(`**General Deletions:** ⅓`); if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`); - if (serverUserInfo.length) embed.addField({ name: '» Server Info', value: serverUserInfo.join('\n') }); + if (serverUserInfo.length) embed.addFields({ name: '» Server Info', value: serverUserInfo.join('\n') }); } private static generatePresenceField(embed: Embed, member?: BushGuildMember | undefined) { @@ -184,7 +184,7 @@ export default class UserInfoCommand extends BushCommand { if (activitiesNames.length) presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`); if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${util.discord.escapeMarkdown(customStatus)}`); - embed.addField({ name: '» Presence', value: presenceInfo.join('\n') }); + embed.addFields({ name: '» Presence', value: presenceInfo.join('\n') }); enum statusEmojis { online = '787550449435803658', @@ -207,7 +207,7 @@ export default class UserInfoCommand extends BushCommand { .filter((role) => role.name !== '@everyone') .sort((role1, role2) => role2.position - role1.position) .map((role) => `${role}`); - embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); + embed.addFields({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); } private static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined) { @@ -225,7 +225,7 @@ export default class UserInfoCommand extends BushCommand { }); } - if (perms.length) embed.addField({ name: '» Important Perms', value: perms.join(' ') }); + if (perms.length) embed.addFields({ name: '» Important Perms', value: perms.join(' ') }); } private static async generateBotField(embed: Embed, user: BushUser) { @@ -275,6 +275,6 @@ export default class UserInfoCommand extends BushCommand { ); } - if (botInfo.length) embed.addField({ name: '» Bot Info', value: botInfo.join('\n') }); + if (botInfo.length) embed.addFields({ name: '» Bot Info', value: botInfo.join('\n') }); } } diff --git a/src/commands/moulberry-bush/report.ts b/src/commands/moulberry-bush/report.ts index fc78a7b..ed25df4 100644 --- a/src/commands/moulberry-bush/report.ts +++ b/src/commands/moulberry-bush/report.ts @@ -71,7 +71,7 @@ export default class ReportCommand extends BushCommand { .setTitle('New Report') .setColor(util.colors.red) .setDescription(evidence) - .addField({ + .addFields({ name: 'Reporter', value: [ `**Name:**${message.author.tag} <@${message.author.id}>`, @@ -81,7 +81,7 @@ export default class ReportCommand extends BushCommand { ].join('\n'), inline: true }) - .addField({ + .addFields({ name: 'Reported User', value: [ `**Name:**${member.user.tag} <@${member.user.id}>`, @@ -96,7 +96,7 @@ export default class ReportCommand extends BushCommand { if (fileName.endsWith('.png') || fileName.endsWith('.jpg') || fileName.endsWith('.gif') || fileName.endsWith('.webp')) { reportEmbed.setImage(message.attachments.first()!.url); } else { - reportEmbed.addField({ name: 'Attachment', value: message.attachments.first()!.url }); + reportEmbed.addFields({ name: 'Attachment', value: message.attachments.first()!.url }); } } await reportChannel.send({ embeds: [reportEmbed] }).then(async (ReportMessage) => { diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index 5eb2b98..913a4b6 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -108,10 +108,10 @@ export default class RuleCommand extends BushCommand { } if (rule) { if (rules[rule - 1]?.title && rules[rule - 1]?.description) - rulesEmbed.addField({ name: rules[rule - 1].title, value: rules[rule - 1].description }); + rulesEmbed.addFields({ name: rules[rule - 1].title, value: rules[rule - 1].description }); } else { for (let i = 0; i < rules.length; i++) { - if (rules[i]?.title && rules[i]?.description) rulesEmbed.addField({ name: rules[i].title, value: rules[i].description }); + if (rules[i]?.title && rules[i]?.description) rulesEmbed.addFields({ name: rules[i].title, value: rules[i].description }); } } await message.util.send({ diff --git a/src/commands/moulberry-bush/serverStatus.ts b/src/commands/moulberry-bush/serverStatus.ts index 35240f9..703dfc4 100644 --- a/src/commands/moulberry-bush/serverStatus.ts +++ b/src/commands/moulberry-bush/serverStatus.ts @@ -38,7 +38,7 @@ export default class ServerStatusCommand extends BushCommand { await message.util.edit({ embeds: [ msgEmbed - .addField({ name: 'Status', value: 'The server is online, all features related to prices will likely work.' }) + .addFields({ name: 'Status', value: 'The server is online, all features related to prices will likely work.' }) .setColor(util.colors.success) ] }); @@ -46,7 +46,7 @@ export default class ServerStatusCommand extends BushCommand { await message.util.edit({ embeds: [ msgEmbed - .addField({ + .addFields({ name: 'Status', value: "It appears Moulberry's server is offline, this means that everything related to prices will likely not work." diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index 7492fc5..75dc63f 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -31,7 +31,7 @@ export default class CalculatorCommand extends BushCommand { } public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }) { - const decodedEmbed = new Embed().addField({ + const decodedEmbed = new Embed().addFields({ name: '📥 Input', value: await util.inspectCleanRedactCodeblock(args.expression, 'mma') }); @@ -40,12 +40,12 @@ export default class CalculatorCommand extends BushCommand { decodedEmbed .setTitle(`${util.emojis.successFull} Successfully Calculated Expression`) .setColor(util.colors.success) - .addField({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString(), 'mma') }); + .addFields({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString(), 'mma') }); } catch (error) { decodedEmbed .setTitle(`${util.emojis.errorFull} Unable to Calculate Expression`) .setColor(util.colors.error) - .addField({ name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }); + .addFields({ name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }); } return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts index 00420da..1d64145 100644 --- a/src/commands/utilities/decode.ts +++ b/src/commands/utilities/decode.ts @@ -55,14 +55,14 @@ export default class DecodeCommand extends BushCommand { const encodeOrDecode = util.capitalizeFirstLetter(message?.util?.parsed?.alias ?? 'decoded'); const decodedEmbed = new Embed() .setTitle(`${encodeOrDecode} Information`) - .addField({ name: '📥 Input', value: await util.inspectCleanRedactCodeblock(data) }); + .addFields({ name: '📥 Input', value: await util.inspectCleanRedactCodeblock(data) }); try { const decoded = Buffer.from(data, from).toString(to); decodedEmbed .setColor(util.colors.success) - .addField({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(decoded) }); + .addFields({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(decoded) }); } catch (error) { - decodedEmbed.setColor(util.colors.error).addField({ + decodedEmbed.setColor(util.colors.error).addFields({ name: `📤 Error ${encodeOrDecode.slice(1)}ing`, value: await util.inspectCleanRedactCodeblock(error?.stack ?? error) }); diff --git a/src/commands/utilities/highlight-show.ts b/src/commands/utilities/highlight-show.ts index c3c6723..7058675 100644 --- a/src/commands/utilities/highlight-show.ts +++ b/src/commands/utilities/highlight-show.ts @@ -39,7 +39,7 @@ export default class HighlightShowCommand extends BushCommand { .setColor(util.colors.default); if (highlight.blacklistedChannels.length) - embed.addField({ + embed.addFields({ name: 'Ignored Channels', value: highlight.blacklistedChannels .map((c) => `<#${c}>`) @@ -48,7 +48,7 @@ export default class HighlightShowCommand extends BushCommand { inline: true }); if (highlight.blacklistedUsers.length) - embed.addField({ + embed.addFields({ name: 'Ignored Users', value: highlight.blacklistedUsers .map((u) => `<@!${u}>`) diff --git a/src/commands/utilities/poll.ts b/src/commands/utilities/poll.ts new file mode 100644 index 0000000..e53eb51 --- /dev/null +++ b/src/commands/utilities/poll.ts @@ -0,0 +1,80 @@ +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType, ComponentType } from 'discord.js'; + +export default class PollCommand extends BushCommand { + public constructor() { + super('poll', { + aliases: ['poll', 'quick-poll'], + category: 'utilities', + description: 'Allows you to create a poll that other users can vote on. Separate options with "," or "|".', + usage: ['poll options'], + examples: ['poll 1 2'], + args: [ + { + id: 'question', + description: 'The question to be answered by a poll.', + type: 'string', + prompt: 'What question would you like to ask?', + retry: '{error} Choose a question.', + slashType: ApplicationCommandOptionType.String, + only: 'slash' + }, + { + id: 'options', + description: 'The options to include in the poll. Separate options with "," or "|".', + type: 'string', + prompt: 'What options you want to include in the poll? Separate options with "," or "|".', + retry: '{error} Choose options for the poll. Separate options with "," or "|".', + slashType: ApplicationCommandOptionType.String + } + ], + slash: true, + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: [] + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, args: { question?: string; options: ArgType<'string'> }) { + const { question, options } = this.parseArgs(message, args); + if (!question || !options.length) return; + + if (question.length > 256) return await message.util.reply(`${util.emojis.error} Question must be 256 characters or less.`); + if (options.length > 10) return await message.util.reply(`${util.emojis.error} You can only have upto 10 options.`); + + return message.util.send({ + embeds: [ + { + author: { name: `asked by: ${message.author.tag}`, icon_url: message.author.displayAvatarURL() || undefined }, + title: question + } + ], + components: [ + { + type: ComponentType.ActionRow, + components: [] + } + ] + }); + } + + private parseArgs( + message: BushMessage | BushSlashMessage, + args: { question?: string; options: ArgType<'string'> } + ): { question: string; options: string[] } { + const split = args.options.split(/[,|]/).filter((s) => s.trim().length > 0); + if (message.util.isSlash) { + if (split.length < 2) { + void message.util.reply(`${util.emojis.error} You must provide at least two options.`); + return { question: '', options: [] }; + } + return { question: args.question!, options: split }; + } else { + if (split.length < 3) { + void message.util.reply(`${util.emojis.error} You must provide a question and at least two options.`); + return { question: '', options: [] }; + } + + return { question: split[0], options: split.slice(1) }; + } + } +} diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index b0a7428..2af6a76 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -89,14 +89,14 @@ export default class PriceCommand extends BushCommand { const bazaarPriceEmbed = new Embed() .setColor(errors?.length ? util.colors.warn : util.colors.success) .setTitle(`Bazaar Information for ${util.format.input(parsedItem)}`) - .addField({ name: 'Sell Price', value: addBazaarInformation('sellPrice', 2, true) }) - .addField({ name: 'Buy Price', value: addBazaarInformation('buyPrice', 2, true) }) - .addField({ + .addFields({ name: 'Sell Price', value: addBazaarInformation('sellPrice', 2, true) }) + .addFields({ name: 'Buy Price', value: addBazaarInformation('buyPrice', 2, true) }) + .addFields({ name: 'Margin', value: (+addBazaarInformation('buyPrice', 2, false) - +addBazaarInformation('sellPrice', 2, false)).toLocaleString() }) - .addField({ name: 'Current Sell Orders', value: addBazaarInformation('sellOrders', 0, true) }) - .addField({ name: 'Current Buy Orders', value: addBazaarInformation('buyOrders', 0, true) }); + .addFields({ name: 'Current Sell Orders', value: addBazaarInformation('sellOrders', 0, true) }) + .addFields({ name: 'Current Buy Orders', value: addBazaarInformation('buyOrders', 0, true) }); return await message.util.reply({ embeds: [bazaarPriceEmbed] }); } @@ -138,7 +138,7 @@ export default class PriceCommand extends BushCommand { } function addPrice(name: string, price: number | undefined) { if (price) - priceEmbed.addField({ + priceEmbed.addFields({ name: name, value: price.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }); diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index 693896d..be6730b 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -26,7 +26,7 @@ export default class SuicideCommand extends BushCommand { iconURL: 'https://media.discordapp.net/attachments/770256340639416320/854689949193076737/Medical_31-60_974.jpg?width=523&height=523' }) - .addField({ + .addFields({ name: '**National Suicide Prevention Hotline (U.S.):**', value: [ '**Call:** 1-800-273-8255, available 24/7 for emotional support', @@ -36,7 +36,7 @@ export default class SuicideCommand extends BushCommand { '**Outside the U.S:** Find a supportive resource on [this Wikipedia list of worldwide crisis hotlines](https://en.wikipedia.org/wiki/List_of_suicide_crisis_lines)' ].join('\n') }) - .addField({ + .addFields({ name: '**More Support**', value: [ 'For Substance Abuse Support, Eating Disorder Support & Child Abuse and Domestic Violence:', diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts index f8e5c22..948aec6 100644 --- a/src/commands/utilities/wolframAlpha.ts +++ b/src/commands/utilities/wolframAlpha.ts @@ -45,7 +45,7 @@ export default class WolframAlphaCommand extends BushCommand { args.image && void message.util.reply({ content: `${util.emojis.loading} Loading...`, embeds: [] }); const waApi = WolframAlphaAPI(client.config.credentials.wolframAlphaAppId); - const decodedEmbed = new Embed().addField({ + const decodedEmbed = new Embed().addFields({ name: '📥 Input', value: await util.inspectCleanRedactCodeblock(args.expression) }); @@ -58,15 +58,15 @@ export default class WolframAlphaCommand extends BushCommand { if (args.image) { decodedEmbed.setImage(await util.uploadImageToImgur(calculated.split(',')[1])); - decodedEmbed.addField({ name: '📤 Output', value: '​' }); + decodedEmbed.addFields({ name: '📤 Output', value: '​' }); } else { - decodedEmbed.addField({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString()) }); + decodedEmbed.addFields({ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString()) }); } } catch (error) { decodedEmbed .setTitle(`${util.emojis.errorFull} Unable to Query Expression`) .setColor(util.colors.error) - .addField({ name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }); + .addFields({ name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }); } sendOptions.embeds = [decodedEmbed]; -- cgit