silvanus/main.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-01-18 00:35:24 +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;
const statusChannelId = process.env.statusChannelId;
// Discord.JS
2023-01-24 01:50:14 +00:00
const { Client, GatewayIntentBits, Partials, ActivityType } = require('discord.js');
2023-01-18 00:35:24 +00:00
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
2023-01-18 01:27:04 +00:00
GatewayIntentBits.MessageContent
2023-01-18 00:35:24 +00:00
],
partials: [
Partials.Channel,
2023-01-18 01:27:04 +00:00
Partials.Message
2023-01-18 00:35:24 +00:00
],
});
// Various imports
2023-01-19 17:44:49 +00:00
const fn = require('./modules/functions.js');
const strings = require('./data/strings.json');
2023-02-01 03:30:20 +00:00
const dbfn = require('./modules/dbfn.js');
2023-01-18 00:35:24 +00:00
const isDev = process.env.isDev;
client.once('ready', () => {
fn.collections.slashCommands(client);
console.log('Ready!');
2023-01-24 01:50:14 +00:00
client.user.setActivity({ name: strings.activity.name, type: ActivityType.Watching });
2023-01-28 05:30:57 +00:00
fn.checkReady(client);
2023-01-27 02:31:02 +00:00
if (isDev == 'false') {
client.channels.fetch(statusChannelId).then(channel => {
2023-01-27 23:14:01 +00:00
channel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`);
});
2023-01-27 02:31:02 +00:00
}
2023-01-18 00:35:24 +00:00
});
// slash-commands
client.on('interactionCreate', async interaction => {
if (interaction.isCommand()) {
// if (isDev) {
// console.log(interaction);
// }
2023-01-18 00:35:24 +00:00
const { commandName } = 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);
2023-01-18 00:35:24 +00:00
}
}
2023-01-19 01:10:05 +00:00
if (interaction.isButton() && interaction.component.customId == 'refresh') {
2023-02-01 03:30:20 +00:00
// console.log(JSON.stringify(interaction));
2023-01-31 00:28:12 +00:00
await fn.refresh(interaction).catch(err => {
2023-01-31 22:23:26 +00:00
interaction.channel.send(fn.builders.errorEmbed(err));
2023-01-30 06:12:26 +00:00
});
2023-01-27 23:14:01 +00:00
} else if (interaction.isButton() && interaction.component.customId == 'resetping') {
2023-01-31 00:28:12 +00:00
await fn.resetPing(interaction);
await fn.refresh(interaction).catch(err => {
2023-02-01 03:30:20 +00:00
interaction.channel.send(fn.builders.errorEmbed(err));
2023-01-31 00:28:12 +00:00
});
} else if (interaction.isButton() && interaction.component.customId == 'deleteping') {
if (interaction.message.deletable) {
2023-02-01 03:30:20 +00:00
await dbfn.setRemindedStatus(interaction.guildId, 0);
await dbfn.getGuildInfo(interaction.guildId).then(async res => {
const guildInfo = res.data;
await fn.refreshComparisonMessage(interaction.client, guildInfo);
});
2023-01-31 00:28:12 +00:00
await interaction.message.delete().catch(err => {
console.error(err);
});
}
2023-01-18 00:35:24 +00:00
}
});
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
2023-01-18 00:35:24 +00:00
client.login(token);