From 30a9ece95c895606f66e0336cf1fef49dec83db7 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 1 Oct 2026 21:26:05 -0400 Subject: [PATCH] Restructure how sendAlert works and add ability to add text to it for pings eg --- dot-commands/request.js | 2 +- functions.js | 10 ++++++++-- main.js | 30 +++++++++++++++--------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/dot-commands/request.js b/dot-commands/request.js index 41ce37f..b679d9e 100644 --- a/dot-commands/request.js +++ b/dot-commands/request.js @@ -23,7 +23,7 @@ module.exports = { message.reply({ embeds: [ replyEmbed ]}); const errorEmbed = fn.embeds.error(`An error has occurred in command ${this.name}:\n${err}`); - fn.sendAlert(errorEmbed, message.client); + fn.sendAlert(message.client, [errorEmbed]); } }, }; \ No newline at end of file diff --git a/functions.js b/functions.js index 3ea1706..a23f6fc 100644 --- a/functions.js +++ b/functions.js @@ -921,13 +921,19 @@ const functions = { const errorId = digits.join(""); return errorId; }, - async sendAlert(embed, client) { + async sendAlert(client, embeds, text) { const statusChannel = await client.channels.fetch(statusChannelId) .catch(err => { console.error(err); }); - await statusChannel.send({ embeds: [ embed ] }) + const messageOptions = { + embeds: embeds + }; + + if (text) messageOptions.content = text; + + await statusChannel.send(messageOptions) .catch(err => { console.error(err); }); diff --git a/main.js b/main.js index 7503b56..8825eda 100644 --- a/main.js +++ b/main.js @@ -4,14 +4,13 @@ const dotenv = require('dotenv'); dotenv.config(); const token = process.env.TOKEN; -const statusChannelId = process.env.statusChannelId; const ownerId = process.env.ownerId; // Dump the env vars to log in dev environment: -if (process.env.isDev === "true") console.log(JSON.stringify(process.env)); +if (process.env.isDev === 'true') console.log(JSON.stringify(process.env)); // Discord.JS -const { Client, Intents } = require('discord.js'); +const { Client } = require('discord.js'); const client = new Client({ intents: [ 'GUILDS', @@ -25,13 +24,10 @@ const client = new Client({ 'MESSAGE', ], }); -const { MessageActionRow, MessageButton } = require('discord.js'); // Various imports const fn = require('./functions.js'); -const config = require('./config.json'); -const strings = require('./strings.json'); -const { GifData, CommandData } = require('./CustomModules/NodBot.js'); +const { CommandData } = require('./CustomModules/NodBot.js'); const ButtonHandlers = require('./CustomModules/ButtonHandlers.js'); const InteractionStorage = require('./CustomModules/InteractionStorage.js'); const appVersion = require('./package.json').version; @@ -57,10 +53,12 @@ client.once('ready', async () => { // console.log(JSON.stringify(icaoArray)); // statusChannel = await client.channels.fetch(statusChannelId).catch(e => console.error(e)); // await statusChannel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`).catch(e => console.error(e)); - const readyTimestamp = new Date().toISOString(); - const readyMessage = readyTimestamp + ' -- <@' + ownerId + '>\nStartup Sequence Complete'; + const readyTimestamp = Math.floor(Date.now() / 1000); + const timestampDiscordString = ''; + const readyMessage = 'Startup Sequence Complete at ' + timestampDiscordString; + const readyMsgContent = '<@' + ownerId + '>'; const readyMsgEmbed = fn.embeds.text({ command: 'Boot', content: readyMessage, author: appVersion }); - await fn.sendAlert(readyMsgEmbed, client); + await fn.sendAlert(client, [readyMsgEmbed], readyMsgContent); // Check for banned servers fn.checkBannedServers(client, statusChannel); }); @@ -79,7 +77,8 @@ client.on('interactionCreate', async interaction => { if (client.slashCommands.has(commandName)) { client.slashCommands.get(commandName).execute(interaction); - } else { + } + else { interaction.reply('Sorry, I don\'t have access to that command.'); console.error('Slash command attempted to run but not found: ' + commandName); } @@ -98,16 +97,18 @@ client.on('interactionCreate', async interaction => { const searchString = interaction.options.getFocused(); const choices = fn.weed.strain.lookup(searchString, interaction.client); await interaction.respond( + // eslint-disable-next-line comma-dangle choices.map(choice => ({ name: choice, value: choice })) ); break; - case "edit": - //TODO + case 'edit': + // TODO switch (interaction.options.getSubcommand()) { case 'gif': const gifQuery = interaction.options.getFocused(); const gifChoices = fn.search.gifs(gifQuery, interaction.client); await interaction.respond( + // eslint-disable-next-line comma-dangle gifChoices.map(choice => ({ name: choice, value: choice })) ); break; @@ -115,15 +116,14 @@ client.on('interactionCreate', async interaction => { const pastaQuery = interaction.options.getFocused(); const pastaChoices = fn.search.pastas(pastaQuery, interaction.client); await interaction.respond( + // eslint-disable-next-line comma-dangle pastaChoices.map(choice => ({ name: choice, value: choice })) ); break; - default: break; } break; - default: break; }