From 7d02cf9b8d2d4b587aa6695591747b38c197d9e4 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 12:27:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20ping=20module=20to=20utility?= =?UTF-8?q?=20command=20#338?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/utility/index.ts | 5 +- src/plugins/commands/utility/modules/index.ts | 2 + .../commands/utility/modules/ping/index.ts | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/plugins/commands/utility/modules/ping/index.ts diff --git a/src/plugins/commands/utility/index.ts b/src/plugins/commands/utility/index.ts index c9a5ce9..43da584 100644 --- a/src/plugins/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -10,7 +10,8 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.about.builder) .addSubcommand(modules.stats.builder) - .addSubcommand(modules.avatar.builder); + .addSubcommand(modules.avatar.builder) + .addSubcommand(modules.ping.builder); export const execute = async (interaction: CommandInteraction) => { switch (interaction.options.getSubcommand()) { @@ -20,6 +21,8 @@ export const execute = async (interaction: CommandInteraction) => { return modules.stats.execute(interaction); case "avatar": return modules.avatar.execute(interaction); + case "ping": + return modules.ping.execute(interaction); default: throw new Error( `Unknown subcommand: ${interaction.options.getSubcommand()}` diff --git a/src/plugins/commands/utility/modules/index.ts b/src/plugins/commands/utility/modules/index.ts index 29a60e0..33fa0f5 100644 --- a/src/plugins/commands/utility/modules/index.ts +++ b/src/plugins/commands/utility/modules/index.ts @@ -1,9 +1,11 @@ import avatar from "./avatar"; import about from "./about"; import stats from "./stats"; +import ping from "./ping"; export default { avatar, about, stats, + ping, }; diff --git a/src/plugins/commands/utility/modules/ping/index.ts b/src/plugins/commands/utility/modules/ping/index.ts new file mode 100644 index 0000000..666529b --- /dev/null +++ b/src/plugins/commands/utility/modules/ping/index.ts @@ -0,0 +1,51 @@ +// Dependencies +import { + CommandInteraction, + MessageActionRow, + MessageButton, +} from "discord.js"; + +// Configurations +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; + +import { hosterName, hosterUrl } from "../../../../../config/other"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + metadata: { guildOnly: false, ephemeral: false }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command.setName("ping").setDescription("Ping this bot"); + }, + execute: async (interaction: CommandInteraction) => { + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const interactionEmbed = { + title: "[:tools:] Ping", + fields: [ + { + name: "📦 Deliver Latency", + value: `${Math.abs(Date.now() - interaction.createdTimestamp)} ms`, + inline: true, + }, + { + name: "🤖 API Latency", + value: `${Math.round(interaction.client.ws.ping)} ms`, + inline: true, + }, + ], + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + await interaction.editReply({ + embeds: [interactionEmbed], + }); + }, +};