Skylar Grant
3def31b0fb
All checks were successful
NodBot Production Dockerization / build (pull_request) Successful in 18s
149 lines
4.5 KiB
JavaScript
149 lines
4.5 KiB
JavaScript
/* eslint-disable no-case-declarations */
|
|
/* eslint-disable indent */
|
|
// dotenv for handling environment variables
|
|
const dotenv = require('dotenv');
|
|
dotenv.config();
|
|
const token = process.env.TOKEN;
|
|
const statusChannelId = process.env.statusChannelId;
|
|
|
|
// 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');
|
|
const { GifData, CommandData } = require('./CustomModules/NodBot.js');
|
|
const ButtonHandlers = require('./CustomModules/ButtonHandlers.js');
|
|
const InteractionStorage = require('./CustomModules/InteractionStorage.js');
|
|
const isDev = process.env.isDev;
|
|
|
|
client.once('ready', async () => {
|
|
fn.collections.interactionStorage(client);
|
|
fn.collections.slashCommands(client);
|
|
fn.collections.dotCommands(client);
|
|
fn.collections.setvalidCommands(client);
|
|
fn.collections.roaches(client);
|
|
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);
|
|
console.log('Ready!');
|
|
await fn.avWx.metar.getAllICAOs();
|
|
await fn.avWx.datis.getAllICAOs();
|
|
// console.log(JSON.stringify(icaoArray));
|
|
client.channels.fetch(statusChannelId).then(channel => {
|
|
channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`);
|
|
});
|
|
});
|
|
|
|
// slash-commands
|
|
client.on('interactionCreate', async interaction => {
|
|
if (interaction.isCommand()) {
|
|
if (isDev) {
|
|
console.log('Interaction ID: ' + interaction.id);
|
|
}
|
|
const { commandName } = interaction;
|
|
|
|
if (!client.iStorage.has(interaction.id)) {
|
|
new InteractionStorage(interaction.id, interaction);
|
|
}
|
|
|
|
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()) {
|
|
if (isDev) console.log('Origin Interaction ID: ' + interaction.message.interaction.id);
|
|
if (isDev) console.log('Button ID: ' + interaction.component.customId);
|
|
ButtonHandlers.baseEvent(interaction);
|
|
}
|
|
|
|
// Handle autocomplete requests
|
|
if (interaction.isAutocomplete()) {
|
|
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;
|
|
}
|
|
}
|
|
});
|
|
|
|
// dot-commands
|
|
client.on('messageCreate', message => {
|
|
// Some basic checking to prevent running unnecessary code
|
|
if (message.author.bot) return;
|
|
|
|
// Automatic Responses, will respond if any message contains the keyword(s), excluding self-messages
|
|
const lowerContent = message.content.toLowerCase();
|
|
const autoresponses = fn.autoresponses.checkForAll(lowerContent);
|
|
autoresponses.forEach(e => {
|
|
fn.autoresponses.send(message, e);
|
|
});
|
|
|
|
// Break the message down into its components and analyze it
|
|
const commandData = new CommandData(message).validate(message.client.dotCommands);
|
|
console.log(commandData);
|
|
|
|
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); |