feat: /debug and /help

This commit is contained in:
TresAbhi committed 2023-04-26 14:23:42 +00:00
1 parent 91260aed2a
commit c37b90caac
11 files changed
+110 -10

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ concurrency:
cancel-in-progress: true
jobs:
build:
host:
name: Host
runs-on: ubuntu-latest
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sklld-bot",
"version": "1.0.0",
"version": "0.6.0",
"description": "",
"main": "index.js",
"type": "module",
+4 -2
View File
@@ -25,8 +25,10 @@ export interface CommandRegistry {
export const rest = new REST().setToken(process.env.DISCORD_TOKEN!);
const commandFolders = readdirSync('src/commands/');
const commandCollection = new Collection<string, CommandRegistry>();
const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`))
+45
View File
@@ -0,0 +1,45 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import packageJSON from '../../package.json' assert { type: 'json' };
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { executionStart } from '../index.js';
import getClientId from '../utilities/getClientId.js';
import { tankopedia } from '../utilities/tankopedia.js';
export default {
inProduction: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
.setName('debug')
.setDescription('Debug information about the bot'),
async execute(interaction) {
const currentTime = new Date().getTime();
const uptime = currentTime - executionStart;
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle('Skilled Bot information')
.setColor(SKILLED_COLOR)
.setDescription(
`**Version**: ${packageJSON.version}\n**Uptime**: ${Math.floor(
uptime / 1000 / 60 / 60 / 24,
)}d ${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor(
(uptime / 1000 / 60) % 60,
)}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor(
uptime % 1000,
)}ms\n**Tankopedia**: ${
tankopedia ? 'cached' : 'not cached'
}\n**Client ID**: ${getClientId()}\n**Tag**: ${
interaction.client.user.tag
}`,
),
],
});
console.log("Displaying bot's debug information");
},
} satisfies CommandRegistry;
+41
View File
@@ -0,0 +1,41 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import discord from '../../discord.json' assert { type: 'json' };
import {
CommandRegistry,
guildCommands,
publicCommands,
} from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
export default {
inProduction: false,
inDevelopment: true,
inPublic: true,
command: new SlashCommandBuilder()
.setName('help')
.setDescription('All the help you need about the bot'),
async execute(interaction) {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle('Skilled Bot help')
.setColor(SKILLED_COLOR)
.setDescription(
`**About**\nSkilled Bot provides many useful commands that automate many mundane tasks and provide statistics in just the right may.\Made by TresAbhi from the Skilled [SKLLD] clan.\nGitHub: https://github.com/sklld/bot\nSkilled: ADD THE LINK HERE I FORGOT\n\n**Commands**\n${(interaction.guildId ===
discord.guild_id
? [...guildCommands, ...publicCommands]
: publicCommands
)
.map((command) => `**/${command.name}**: ${command.description}`)
.join(
'\n',
)})}\n\n*I am a new bot; I may make mistakes and go offline from time to time.*`,
),
],
});
console.log('Displaying help information');
},
} satisfies CommandRegistry;
+1 -1
View File
@@ -11,7 +11,7 @@ const DEFAULT_THRESHOLD = 7;
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+5 -1
View File
@@ -57,7 +57,7 @@ export default {
(tankData) => tankopedia.data[tankData.tank_id],
).filter((tank) => tank.tier === tier);
interaction.reply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle(
@@ -80,6 +80,10 @@ export default {
.setColor(SKILLED_COLOR),
],
});
console.log(
`Displaying ${account.nickname}'s owned tanks in tier ${tier}`,
);
});
},
} satisfies CommandRegistry;
+2
View File
@@ -5,6 +5,8 @@ import interactionCreate from './behaviors/interactionCreate.js';
import ready from './behaviors/ready.js';
import tokenRequirements from './utilities/tokenRequirements.js';
export const executionStart = new Date().getTime();
tokenRequirements();
const client = new Client({
+3 -1
View File
@@ -27,7 +27,7 @@ export default async function getBlitzAccount(
callback(players.data[0]);
} else {
// no exact match
interaction.reply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
@@ -49,5 +49,7 @@ export default async function getBlitzAccount(
),
],
});
console.log(`Account not found for ${name} in ${serverName} server.`);
}
}
+4 -2
View File
@@ -13,8 +13,8 @@ export default async function getBlitzStarsAccount(
name: string,
callback: (account: PlayerStatistics) => void,
) {
function notTracked() {
interaction.reply({
async function notTracked() {
await interaction.reply({
embeds: [
new EmbedBuilder()
.setTitle('No data to display')
@@ -22,6 +22,8 @@ export default async function getBlitzStarsAccount(
.setColor(NEGATIVE_COLOR),
],
});
console.log(`${name} is not tracked by BlitzStars.`);
}
fetch(`https://www.blitzstars.com/api/top/player/${accountId}`)
+3 -1
View File
@@ -28,7 +28,7 @@ export default async function getClan(
callback(clans.data[0]);
} else {
// no exact match
interaction.reply({
await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
@@ -48,5 +48,7 @@ export default async function getClan(
),
],
});
console.log(`Clan not found for ${name} in ${serverName} server.`);
}
}