-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (60 loc) · 1.91 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const fs = require('fs');
const { Sequelize, Op, INTEGER } = require('sequelize');
const { CronJob } = require('cron');
const { DateTime } = require('luxon');
const { Client, Collection, Intents } = require('discord.js');
const { guildId, token } = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const sequelize = new Sequelize('database', 'user', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
const Reminders = sequelize.define('reminders', {
username: Sequelize.STRING,
reminder: Sequelize.TEXT,
date: Sequelize.STRING,
channelId: Sequelize.STRING,
});
client.db = Reminders;
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
const checkReminder = new CronJob('0 0 * * *', async () => {
const date = DateTime.now().toISODate();
const currentReminders = await client.db.findAll({
where: {
date: {
[Op.lte]: date
}
}
});
if (currentReminders.length == 0) return;
for (const currentReminder of currentReminders) {
const guild = await client.guilds.fetch(guildId);
const channel = guild.channels.cache.get(currentReminder.channelId);
channel.send(`From: ${currentReminder.username}\nReminder: ${currentReminder.reminder}`);
}
await client.db.destroy({
where: {
date: {
[Op.lte]: date
}
}
});
});
client.login(token);
checkReminder.start();