-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use discord sharding, improve error handling in intervals
- Loading branch information
1 parent
998f3b0
commit 8033c39
Showing
11 changed files
with
192 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logger from './bot/Logger.js'; | ||
import {ShardingManager} from 'discord.js'; | ||
import config from './bot/Config.js'; | ||
import database from './bot/Database.js'; | ||
import commandManager from './commands/CommandManager.js'; | ||
|
||
try { | ||
await logger.debug('Loading settings'); | ||
await config.load(); | ||
await logger.info('Connecting to database'); | ||
await database.connect(); | ||
await logger.info('Creating database tables'); | ||
await database.createTables(); | ||
await database.runMigrations(); | ||
await logger.notice('Registering slash commands'); | ||
await commandManager.registerGlobalCommands(); | ||
|
||
await logger.info('Spawning shards'); | ||
const manager = new ShardingManager( import.meta.dirname + '/shard.js', { | ||
token: config.data.authToken, | ||
totalShards: 2, | ||
}); | ||
|
||
manager.on('shardCreate', async shard => { | ||
shard.args = [shard.id, manager.totalShards]; | ||
await logger.notice(`Launched shard ${shard.id}`); | ||
|
||
|
||
shard.on("ready", () => { | ||
logger.info(`Shard ${shard.id} connected to Discord's Gateway.`); | ||
}); | ||
}); | ||
await manager.spawn(); | ||
} catch (error) { | ||
try { | ||
await logger.critical('Shard Manager crashed', error); | ||
} catch (e) { | ||
console.error('Failed to send fatal error to monitoring', e); | ||
} | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.