diff --git a/.github/workflows/host.yml b/.github/workflows/host.yml index 3d8425a51..d8b485b20 100644 --- a/.github/workflows/host.yml +++ b/.github/workflows/host.yml @@ -13,7 +13,7 @@ concurrency: cancel-in-progress: true jobs: - build: + host: name: Host runs-on: ubuntu-latest diff --git a/package.json b/package.json index 7917faa69..0446f638f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sklld-bot", - "version": "1.0.0", + "version": "0.6.0", "description": "", "main": "index.js", "type": "module", diff --git a/src/behaviors/interactionCreate.ts b/src/behaviors/interactionCreate.ts index 4e3a512cb..fbb68304a 100644 --- a/src/behaviors/interactionCreate.ts +++ b/src/behaviors/interactionCreate.ts @@ -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(); -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}`)) diff --git a/src/commands/debug.ts b/src/commands/debug.ts new file mode 100644 index 000000000..9b98d4b31 --- /dev/null +++ b/src/commands/debug.ts @@ -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; diff --git a/src/commands/help.ts b/src/commands/help.ts new file mode 100644 index 000000000..15c8ec4a7 --- /dev/null +++ b/src/commands/help.ts @@ -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; diff --git a/src/commands/inactive.ts b/src/commands/inactive.ts index 70e3864bf..ba58200b1 100644 --- a/src/commands/inactive.ts +++ b/src/commands/inactive.ts @@ -11,7 +11,7 @@ const DEFAULT_THRESHOLD = 7; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/tanks.ts b/src/commands/tanks.ts index 1334c7552..8d7fef6d4 100644 --- a/src/commands/tanks.ts +++ b/src/commands/tanks.ts @@ -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; diff --git a/src/index.ts b/src/index.ts index 183e7eba1..cb55cea83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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({ diff --git a/src/utilities/getBlitzAccount.ts b/src/utilities/getBlitzAccount.ts index d74f26195..a686eb0b2 100644 --- a/src/utilities/getBlitzAccount.ts +++ b/src/utilities/getBlitzAccount.ts @@ -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.`); } } diff --git a/src/utilities/getBlitzStarsAccount.ts b/src/utilities/getBlitzStarsAccount.ts index ab34b236a..ad05ec001 100644 --- a/src/utilities/getBlitzStarsAccount.ts +++ b/src/utilities/getBlitzStarsAccount.ts @@ -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}`) diff --git a/src/utilities/getClan.ts b/src/utilities/getClan.ts index af1600600..36f3ecd65 100644 --- a/src/utilities/getClan.ts +++ b/src/utilities/getClan.ts @@ -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.`); } }