Skip to content

Commit

Permalink
feat: Add GatewayEvent decorator for marking methods as event liste…
Browse files Browse the repository at this point in the history
…ners
  • Loading branch information
dev-737 committed May 6, 2024
1 parent 301d0f2 commit 73956fd
Show file tree
Hide file tree
Showing 27 changed files with 1,565 additions and 1,565 deletions.
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},

"eslint.validate": [
"javascript",
"typescript"
],
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "interchat",
"version": "3.20.7",
"description": "A growing Discord bot which provides inter-server chat!",
"main": "build/index.js",
"main": "build/cluster.js",
"license": "GPL-3.0-or-later",
"scripts": {
"start": "node .",
Expand Down
193 changes: 0 additions & 193 deletions src/InterChat.ts

This file was deleted.

63 changes: 63 additions & 0 deletions src/cluster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import db from './utils/Db.js';
import Scheduler from './services/SchedulerService.js';
import { startApi } from './api/index.js';
import { isDevBuild } from './utils/Constants.js';
import { VoteManager } from './managers/VoteManager.js';
import { ClusterManager } from 'discord-hybrid-sharding';
import syncBotlistStats from './scripts/tasks/syncBotlistStats.js';
import deleteExpiredInvites from './scripts/tasks/deleteExpiredInvites.js';
import updateBlacklists from './scripts/tasks/updateBlacklists.js';
import deleteOldMessages from './scripts/tasks/deleteOldMessages.js';
import 'dotenv/config';
import { getUsername, wait } from './utils/Utils.js';
import Logger from './utils/Logger.js';

const clusterManager = new ClusterManager('build/index.js', {
token: process.env.TOKEN,
shardsPerClusters: 2,
});

clusterManager.on('clusterCreate', async (cluster) => {
// if it is the last cluster
if (cluster.id === clusterManager.totalClusters - 1) {
const scheduler = new Scheduler();
// remove expired blacklists or set new timers for them
const serverQuery = { where: { hubs: { some: { expires: { isSet: true } } } } };
const userQuery = { where: { blacklistedFrom: { some: { expires: { isSet: true } } } } };
updateBlacklists(await db.blacklistedServers.findMany(serverQuery), scheduler)
.catch(Logger.error);

updateBlacklists(await db.userData.findMany(userQuery), scheduler)
.catch(Logger.error);

// code must be in production to run these tasks
if (isDevBuild) return;
// give time for shards to connect for these tasks
await wait(10_000);

// perform start up tasks
syncBotlistStats(clusterManager).catch(Logger.error);
deleteOldMessages().catch(Logger.error);
deleteExpiredInvites().catch(Logger.error);

scheduler.addRecurringTask('deleteExpiredInvites', 60 * 60 * 1_000, deleteExpiredInvites);
scheduler.addRecurringTask('deleteOldMessages', 60 * 60 * 12_000, deleteOldMessages);
scheduler.addRecurringTask('syncBotlistStats', 60 * 10_000, () =>
syncBotlistStats(clusterManager),
);
}
});

const voteManager = new VoteManager(clusterManager);
voteManager.on('vote', async (vote) => {
const username = (await getUsername(clusterManager, vote.user)) ?? undefined;
await voteManager.incrementUserVote(vote.user, username);
await voteManager.addVoterRole(vote.user);
await voteManager.announceVote(vote);
});

// spawn clusters and start the api that handles nsfw filter and votes
clusterManager.spawn({ timeout: -1 })
.then(() => startApi({ voteManager }))
.catch(Logger.error);

2 changes: 1 addition & 1 deletion src/commands/slash/Main/blacklist/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class UserBlacklist extends BlacklistCommand {
.setDescription(
t(
{ phrase: 'blacklist.server.success', locale: interaction.user.locale },
{ emoji: emojis.tick, server: server.name },
{ server: server.name, emoji: emojis.tick },
),
)
.setColor('Green')
Expand Down
2 changes: 1 addition & 1 deletion src/commands/slash/Main/blacklist/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class Server extends BlacklistCommand {
.setDescription(
t(
{ phrase: 'blacklist.user.success', locale: interaction.user.locale },
{ username: user.username },
{ username: user.username, emoji: emojis.tick },
),
)
.setColor('Green')
Expand Down
Loading

0 comments on commit 73956fd

Please sign in to comment.