12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import Sentry from '@sentry/node';
- import bancho from './bancho.js';
- import commands from './commands.js';
- import db from './database.js';
- import {init as init_discord_interactions} from './discord_interactions.js';
- import {init as init_discord_updates} from './discord_updates.js';
- import {listen as website_listen} from './website.js';
- import Config from './util/config.js';
- import {capture_sentry_exception} from './util/helpers.js';
- import {init_the_ones} from './elo_cache.js';
- import {auto_rejoin_lobbies} from './supervisor.js';
- async function init_discord() {
- let discord_client = null;
- try {
- discord_client = await init_discord_interactions();
- await init_discord_updates(discord_client);
- } catch (err) {
- console.error('Failed to login to Discord:', err.message);
- process.exit();
- }
- }
- async function main() {
- console.log('Starting...');
- if (Config.ENABLE_SENTRY) {
- Sentry.init({
- dsn: Config.sentry_dsn,
- });
- }
- init_the_ones();
- bancho.on('pm', (msg) => {
- for (const cmd of commands) {
- const match = cmd.regex.exec(msg.message);
- if (match) {
- if (!cmd.modes.includes('pm')) {
- bancho.privmsg(msg.from, 'You should send that command in #multiplayer.');
- return;
- }
- cmd.handler(msg, match, null).catch(capture_sentry_exception);
- return;
- }
- }
- });
- if (Config.CONNECT_TO_DISCORD) {
- init_discord();
- }
- if (Config.HOST_WEBSITE) {
- website_listen();
- }
- if (Config.CONNECT_TO_BANCHO) {
- bancho.on('disconnect', () => {
- db.close();
- process.exit();
- });
- await bancho.connect();
- await auto_rejoin_lobbies();
- }
- console.log('All ready and fired up!');
- }
- main();
|