2021-09-22 17:15:31 +00:00
|
|
|
/* eslint-disable no-case-declarations */
|
|
|
|
/* eslint-disable indent */
|
|
|
|
// dotenv for handling environment variables
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
const token = process.env.TOKEN;
|
2022-05-28 21:08:41 +00:00
|
|
|
const statusChannelId = process.env.statusChannelId;
|
2021-09-22 17:15:31 +00:00
|
|
|
|
|
|
|
// Discord.JS
|
|
|
|
const { Client, Intents } = require('discord.js');
|
|
|
|
const client = new Client({
|
|
|
|
intents: [
|
|
|
|
'GUILDS',
|
|
|
|
'GUILD_MESSAGES',
|
|
|
|
'GUILD_MESSAGE_REACTIONS',
|
|
|
|
'DIRECT_MESSAGES',
|
|
|
|
'DIRECT_MESSAGE_REACTIONS',
|
|
|
|
],
|
|
|
|
partials: [
|
|
|
|
'CHANNEL',
|
|
|
|
'MESSAGE',
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const { MessageActionRow, MessageButton } = require('discord.js');
|
|
|
|
|
|
|
|
// Various imports
|
|
|
|
const fn = require('./functions.js');
|
|
|
|
const config = require('./config.json');
|
|
|
|
const strings = require('./strings.json');
|
2024-09-25 19:35:01 +00:00
|
|
|
const { GifData, CommandData } = require('./CustomModules/NodBot.js');
|
2024-09-26 03:22:22 +00:00
|
|
|
const ButtonHandlers = require('./CustomModules/ButtonHandlers.js');
|
|
|
|
const InteractionStorage = require('./CustomModules/InteractionStorage.js');
|
2022-05-28 21:08:41 +00:00
|
|
|
const isDev = process.env.isDev;
|
2021-09-22 17:15:31 +00:00
|
|
|
|
2024-06-21 22:35:12 +00:00
|
|
|
client.once('ready', async () => {
|
2024-09-26 03:22:22 +00:00
|
|
|
fn.collections.interactionStorage(client);
|
2021-09-22 17:15:31 +00:00
|
|
|
fn.collections.slashCommands(client);
|
|
|
|
fn.collections.dotCommands(client);
|
|
|
|
fn.collections.setvalidCommands(client);
|
2023-12-14 15:43:40 +00:00
|
|
|
fn.collections.roaches(client);
|
2024-06-21 22:35:12 +00:00
|
|
|
await fn.download.gifs(client);
|
|
|
|
await fn.download.pastas(client);
|
|
|
|
await fn.download.joints(client);
|
|
|
|
await fn.download.requests(client);
|
|
|
|
await fn.download.strains(client);
|
|
|
|
await fn.download.medicalAdvice(client);
|
2021-09-22 17:15:31 +00:00
|
|
|
console.log('Ready!');
|
2024-06-22 13:17:24 +00:00
|
|
|
await fn.avWx.metar.getAllICAOs();
|
2024-06-22 13:42:02 +00:00
|
|
|
await fn.avWx.datis.getAllICAOs();
|
2024-06-21 22:35:12 +00:00
|
|
|
// console.log(JSON.stringify(icaoArray));
|
2022-05-28 21:08:41 +00:00
|
|
|
client.channels.fetch(statusChannelId).then(channel => {
|
2022-12-02 20:35:23 +00:00
|
|
|
channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`);
|
2021-09-22 17:15:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// slash-commands
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
|
|
if (interaction.isCommand()) {
|
2022-05-28 21:08:41 +00:00
|
|
|
if (isDev) {
|
2024-09-26 12:09:09 +00:00
|
|
|
console.log('Interaction ID: ' + interaction.id);
|
2021-09-22 17:15:31 +00:00
|
|
|
}
|
|
|
|
const { commandName } = interaction;
|
|
|
|
|
2024-09-26 12:09:09 +00:00
|
|
|
if (!client.iStorage.has(interaction.id)) {
|
|
|
|
new InteractionStorage(interaction.id, interaction);
|
2024-09-26 03:22:22 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 17:15:31 +00:00
|
|
|
if (client.slashCommands.has(commandName)) {
|
|
|
|
client.slashCommands.get(commandName).execute(interaction);
|
|
|
|
} else {
|
|
|
|
interaction.reply('Sorry, I don\'t have access to that command.');
|
|
|
|
console.error('Slash command attempted to run but not found: ' + commandName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interaction.isButton()) {
|
2024-09-26 12:09:09 +00:00
|
|
|
if (isDev) console.log('Origin Interaction ID: ' + interaction.message.interaction.id);
|
|
|
|
if (isDev) console.log('Button ID: ' + interaction.component.customId);
|
2024-09-26 23:30:41 +00:00
|
|
|
ButtonHandlers.baseEvent(interaction);
|
2021-09-22 17:15:31 +00:00
|
|
|
}
|
2023-01-08 01:00:15 +00:00
|
|
|
|
|
|
|
// Handle autocomplete requests
|
|
|
|
if (interaction.isAutocomplete()) {
|
2023-08-08 17:25:07 +00:00
|
|
|
switch (interaction.commandName) {
|
|
|
|
case 'strain':
|
|
|
|
const searchString = interaction.options.getFocused();
|
|
|
|
const choices = fn.weed.strain.lookup(searchString, interaction.client);
|
|
|
|
await interaction.respond(
|
|
|
|
choices.map(choice => ({ name: choice, value: choice }))
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
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(
|
|
|
|
gifChoices.map(choice => ({ name: choice, value: choice }))
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'pasta':
|
|
|
|
const pastaQuery = interaction.options.getFocused();
|
|
|
|
const pastaChoices = fn.search.pastas(pastaQuery, interaction.client);
|
|
|
|
await interaction.respond(
|
|
|
|
pastaChoices.map(choice => ({ name: choice, value: choice }))
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2023-01-08 01:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-22 17:15:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// dot-commands
|
|
|
|
client.on('messageCreate', message => {
|
|
|
|
// Some basic checking to prevent running unnecessary code
|
|
|
|
if (message.author.bot) return;
|
|
|
|
|
2024-06-21 19:02:22 +00:00
|
|
|
// Automatic Responses, will respond if any message contains the keyword(s), excluding self-messages
|
2021-09-22 21:14:14 +00:00
|
|
|
const lowerContent = message.content.toLowerCase();
|
2024-06-21 19:02:22 +00:00
|
|
|
const autoresponses = fn.autoresponses.checkForAll(lowerContent);
|
|
|
|
autoresponses.forEach(e => {
|
|
|
|
fn.autoresponses.send(message, e);
|
|
|
|
});
|
2021-09-22 17:15:31 +00:00
|
|
|
|
2022-05-28 21:08:41 +00:00
|
|
|
// Break the message down into its components and analyze it
|
2024-09-25 19:35:01 +00:00
|
|
|
const commandData = new CommandData(message).validate(message.client.dotCommands);
|
2022-06-09 22:31:34 +00:00
|
|
|
console.log(commandData);
|
2021-09-24 00:08:29 +00:00
|
|
|
|
2021-09-22 17:15:31 +00:00
|
|
|
if (commandData.isValid && commandData.isCommand) {
|
|
|
|
try {
|
|
|
|
client.dotCommands.get(commandData.command).execute(message, commandData);
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
message.reply('There was an error trying to execute that command.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
client.login(token);
|