jillo-bot/src/index.ts

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-06-08 02:57:15 +02:00
import * as Discord from 'discord.js';
import * as fs from 'fs';
const { token, disableDaytimeAnnouncements } = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
import * as path from 'path';
2022-07-19 21:39:34 +02:00
import { initializeCounter } from './lib/counter';
2023-03-22 11:59:06 +01:00
import { getNextAnnouncementTime, initializeAnnouncements, loadNext, loadSubscriptions, next, saveNext, subscriptions, timeAnnouncements } from './lib/subscriptions';
2022-06-08 01:28:20 +02:00
2023-03-22 11:59:06 +01:00
loadNext();
loadSubscriptions();
2022-06-08 01:28:20 +02:00
const bot = new Discord.Client({
2022-06-08 03:46:00 +02:00
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
2022-07-16 21:24:13 +02:00
Discord.Intents.FLAGS.GUILD_MEMBERS,
2023-05-04 00:17:15 +02:00
Discord.Intents.FLAGS.DIRECT_MESSAGES
2022-06-08 03:46:00 +02:00
],
2022-06-08 01:28:20 +02:00
});
2022-06-08 02:57:15 +02:00
bot.on('ready', async () => {
2023-04-19 21:08:26 +02:00
initializeCounter(false);
initializeCounter(true);
2022-07-19 21:39:34 +02:00
2023-03-22 11:59:06 +01:00
if (!disableDaytimeAnnouncements) {
initializeAnnouncements(bot);
}
2022-06-08 03:46:00 +02:00
bot.commands = new Discord.Collection();
const cmdFiles = fs.readdirSync(path.join(__dirname, './commands')).filter((file) => file.endsWith('.js'));
2022-06-08 01:28:20 +02:00
for (const file of cmdFiles) {
2022-06-08 02:57:15 +02:00
const cmd = (await import(`./commands/${file}`));
2022-06-08 01:28:20 +02:00
bot.commands.set(cmd.data.name, cmd);
2022-06-08 03:46:00 +02:00
if (cmd.onClientReady) cmd.onClientReady(bot);
2022-06-08 01:28:20 +02:00
}
2022-07-19 20:48:02 +02:00
console.log('jillo online');
2022-06-08 01:28:20 +02:00
});
bot.on('interactionCreate', async (interaction) => {
2022-06-08 03:46:00 +02:00
if (!interaction.isCommand()) return;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
try {
await command.execute(interaction, interaction.member);
} catch (error) {
interaction.reply({ content: '`ERROR`', ephemeral: true });
console.error(error);
}
2022-06-08 01:28:20 +02:00
});
2023-01-20 22:00:16 +01:00
bot.on('messageDelete', (msg) => {
console.log(`${msg.author?.username}#${msg.author?.discriminator} in #${msg.channel instanceof Discord.TextChannel ? msg.channel.name : '?'} at ${msg.createdAt.toISOString()}`);
console.log(`${msg.content}`);
});
2022-06-08 01:28:20 +02:00
bot.login(token);