2023-10-07 22:46:02 -07:00
|
|
|
/**
|
|
|
|
* sync.ts
|
2023-10-08 13:48:41 -07:00
|
|
|
* Syncs message reactions in chat with the database.
|
|
|
|
* The bot will do the same thing automatically upon startup, but this is just in the form of a standalone script.
|
2023-10-07 22:46:02 -07:00
|
|
|
*/
|
|
|
|
|
2023-10-08 13:48:41 -07:00
|
|
|
import { Client, Events, GatewayIntentBits, IntentsBitField, Partials } from 'discord.js';
|
2023-10-08 19:20:00 -07:00
|
|
|
import { logInfo } from '../logging';
|
|
|
|
import { db, openDb, reactionEmojis, sync } from './util';
|
2023-10-07 22:46:02 -07:00
|
|
|
|
|
|
|
const client = new Client({
|
|
|
|
intents: [GatewayIntentBits.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages],
|
|
|
|
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
|
|
|
});
|
|
|
|
|
|
|
|
client.once(Events.ClientReady, async () => {
|
2023-10-08 19:10:47 -07:00
|
|
|
logInfo('[bot] Ready.');
|
2023-10-07 22:46:02 -07:00
|
|
|
for (let i = 0; i < reactionEmojis.length; ++i)
|
2023-10-08 19:10:47 -07:00
|
|
|
logInfo(`[bot] config: reaction_${i + 1} = ${reactionEmojis[i]}`);
|
2023-10-07 22:46:02 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
async function startup() {
|
2023-10-08 19:10:47 -07:00
|
|
|
logInfo("[db] Opening...");
|
2023-10-07 22:46:02 -07:00
|
|
|
await openDb();
|
2023-10-08 19:10:47 -07:00
|
|
|
logInfo("[db] Migrating...");
|
2023-10-07 22:46:02 -07:00
|
|
|
await db.migrate();
|
2023-10-08 19:10:47 -07:00
|
|
|
logInfo("[db] Ready.");
|
|
|
|
logInfo("[bot] Logging in...");
|
2023-10-07 22:46:02 -07:00
|
|
|
await client.login(process.env.TOKEN);
|
2023-10-08 13:48:41 -07:00
|
|
|
await sync(client.guilds);
|
2023-10-07 22:46:02 -07:00
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
startup();
|