Skip to content

Commit

Permalink
Added info command
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Dec 30, 2023
1 parent 73df94a commit 66fcea6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/commands/info/info.ts
Original file line number Diff line number Diff line change
@@ -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")]});
}
};
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +46,7 @@ export function closeWebsockets() {

export async function wsConnect(): Promise<WebSocket> {
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");
Expand Down Expand Up @@ -82,6 +88,8 @@ export async function wsConnect(): Promise<WebSocket> {

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) {
Expand Down

0 comments on commit 66fcea6

Please sign in to comment.