Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fieztazica committed May 12, 2024
2 parents 76a6d6c + ff30858 commit 546a4f9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down
54 changes: 54 additions & 0 deletions src/commands/General/uptime.ts
Original file line number Diff line number Diff line change
@@ -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<Command.Options>({
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],
})
}
}
4 changes: 3 additions & 1 deletion src/lib/HootClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)));
}
Expand Down

0 comments on commit 546a4f9

Please sign in to comment.