Restructure how sendAlert works and add ability to add text to it for pings eg

This commit is contained in:
Skylar Grant 2026-10-01 21:26:05 -04:00
parent cb4f6fc5fd
commit 30a9ece95c
3 changed files with 24 additions and 18 deletions

View File

@ -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]);
}
},
};

View File

@ -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);
});

28
main.js
View File

@ -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 = '<t:' + readyTimestamp + ':f>';
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":
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;
}