diff --git a/src/commands/info/info.ts b/src/commands/info/info.ts new file mode 100644 index 0000000..9d6c3eb --- /dev/null +++ b/src/commands/info/info.ts @@ -0,0 +1,35 @@ +// @command +import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder, time } from 'discord.js' +import { botInfo } from '@src/index'; +import { getSources } from '../alerts/functions'; +const Theme = loadYaml("bot/info.yml") + +// @command +// here cuz otherwise tsc removes it +export default { + data: new SlashCommandBuilder() + .setName('info') + .setDescription('Montre des informations à propos du bot'), + async execute(interaction) { + const desc = ` + **Events Helper** par <:ce:1184928871984926781> Communauté Events + + __WebSocket__ + Status de la connection au WebSocket: ${botInfo.websocket ? '✅' : '❌'} + Dernière connection: ${time(new Date())} + + __Sources__ + ${(await getSources()).map(src => `${src.emoji} - **${src.name}**\n`)} + __Autres__ + Version du bot: \`${process.env.npm_package_version? process.env.npm_package_version : '? Inconnu'}\` + Serveur du support: https://commu.events/discord + ` + + const embed = new EmbedBuilder() + .setTitle("Informations sur le bot") + .setColor(Theme.Color) + .setThumbnail("attachment://question_mark.png") + .setDescription(desc) + await interaction.reply({embeds: [embed], files: [new AttachmentBuilder("src/images/question_mark.png")]}); + } +}; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 45db9b1..4772ce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,11 @@ const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits let websockets: WebSocket[] = [] let isReconnecting; +export let botInfo = { + websocket: false, + lastConexion: 0 +} + export function closeWebsockets() { websockets.forEach(ws => { const url = ws.url @@ -41,6 +46,7 @@ export function closeWebsockets() { export async function wsConnect(): Promise { function wsError(error) { + botInfo.websocket = false if (isReconnecting) return isReconnecting = true logging(`WebSocket error, retrying to connect in 10 seconds.\n${error}: ${error.message}`, "error"); @@ -82,6 +88,8 @@ export async function wsConnect(): Promise { ws.on("open",()=> { logging(`WebSocket connection has been established. The bot is operational.`,"success") + botInfo.websocket = true + botInfo.lastConexion = Date.now() }) return ws } catch (error) {