diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c5bada9..18c438a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,7 +10,7 @@ jobs: steps: - name: checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Executing remote command uses: appleboy/ssh-action@master diff --git a/package.json b/package.json index b87dbd1..8c10a22 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,8 @@ "build": "tsc", "watch": "tsc -w", "start": "node dist/index.js", + "start:prod": "NODE_ENV=production node dist/index.js", + "start:test": "NODE_ENV=test node dist/index.js", "dev": "run-s build start", "watch:start": "tsc-watch --onSuccess \"node ./dist/index.js\"", "format": "prettier --write \"src/**/*.ts\"", diff --git a/src/commands/General/uptime.ts b/src/commands/General/uptime.ts new file mode 100644 index 0000000..58b4881 --- /dev/null +++ b/src/commands/General/uptime.ts @@ -0,0 +1,54 @@ +import { ApplyOptions } from '@sapphire/decorators'; +import { Command } from '@sapphire/framework'; +import { codeBlock } from '@sapphire/utilities'; +import { EmbedBuilder } from 'discord.js'; + +@ApplyOptions({ + description: 'Check the bot uptime!' +}) +export class UserCommand extends Command { + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand((builder) => + builder // + .setName(this.name) + .setDescription(this.description) + ); + } + + public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) { + const { client } = this.container + + let totalSeconds = (client.uptime || -1) / 1000 + let days = Math.floor(totalSeconds / 86400) + totalSeconds %= 86400 + let hours = Math.floor(totalSeconds / 3600) + totalSeconds %= 3600 + let minutes = Math.floor(totalSeconds / 60) + let seconds = Math.floor(totalSeconds % 60) + let uptime = `${days}d${hours}h${minutes}m${seconds}s` + + const embed = new EmbedBuilder().setColor('Random').addFields([ + { + name: `Online`, + value: codeBlock(uptime), + inline: false, + }, + { + name: `API Latency`, + value: codeBlock(Math.round(client.ws.ping) + 'ms'), + inline: true, + }, + { + name: `Client Latency`, + value: codeBlock( + Math.round(Date.now() - interaction.createdTimestamp) + 'ms' + ), + inline: true, + }, + ]) + + return interaction.reply({ + embeds: [embed], + }) + } +} diff --git a/src/lib/HootClient.ts b/src/lib/HootClient.ts index 8a3637a..20c5d39 100644 --- a/src/lib/HootClient.ts +++ b/src/lib/HootClient.ts @@ -2,6 +2,8 @@ import { ApplicationCommandRegistries, SapphireClient, container } from '@sapphi import { ClientOptions } from 'discord.js'; import { DisTube, DisTubeOptions } from 'distube'; +const dev = process.env.NODE_ENV !== 'production'; + export class HootClient extends SapphireClient { distube: DisTube; @@ -17,7 +19,7 @@ export class HootClient extends SapphireClient { this.distube = distube; container.distube = distube; - ApplicationCommandRegistries.setDefaultGuildIds(process.env.NODE_ENV === 'development' ? [process.env.DEV_GUILD_ID] : null); + dev && ApplicationCommandRegistries.setDefaultGuildIds([process.env.DEV_GUILD_ID]); ApplicationCommandRegistries.registries.forEach((r) => r.registerChatInputCommand((b) => b.setDMPermission(false))); }