-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: Introduce new sharding system (#149)
* add: base for /blacklist command (#101) This commit will add the base for /blacklist command with raw string and not translated. Also this commit is not tested * merge: latest update from main branch (#146) * improve: logging system interface * add: host option to bind into 0.0.0.0 ip address * add: host option to config file * add: spanish lang to ByteBlaze * add: blacklist cmmand; merge: all filter command This commit fill merge all filter command to 1 file to optimize and reduce code. Also this command introduce brand new command named blacklist to block user/guild rom using bot * remove: file command due to lavalink restriction * fix: 24/7 rejoin bug (#137) * add: MAX Length for a song command (user wide, some command maynot work, #86) * add: rewritten sharding system * fix: sometimes bot leave server suddenly
- Loading branch information
Showing
22 changed files
with
170 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Manager } from '../manager.js' | ||
import { ConfigDataService } from '../services/ConfigDataService.js' | ||
import { ClusterManager } from './core.js' | ||
|
||
export function bootBot(clusterManager?: ClusterManager) { | ||
const configData = new ConfigDataService().data | ||
const byteblaze = new Manager( | ||
configData, | ||
configData.utilities.MESSAGE_CONTENT.enable, | ||
clusterManager | ||
) | ||
|
||
// Anti crash handling | ||
process | ||
.on('unhandledRejection', (error) => byteblaze.logger.unhandled('AntiCrash', error)) | ||
.on('uncaughtException', (error) => byteblaze.logger.unhandled('AntiCrash', error)) | ||
.on('uncaughtExceptionMonitor', (error) => byteblaze.logger.unhandled('AntiCrash', error)) | ||
.on('exit', () => | ||
byteblaze.logger.info('ClientManager', `Successfully Powered Off ByteBlaze, Good Bye!`) | ||
) | ||
.on('SIGINT', () => { | ||
byteblaze.logger.info('ClientManager', `Powering Down ByteBlaze...`) | ||
process.exit(0) | ||
}) | ||
|
||
byteblaze.start() | ||
} |
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,63 @@ | ||
import cluster from 'node:cluster' | ||
import process from 'node:process' | ||
import { config } from 'dotenv' | ||
import { bootBot } from './bot.js' | ||
config() | ||
|
||
export interface ClusterManagerOptions { | ||
shardsPerClusters: number | ||
totalClusters: number | ||
} | ||
|
||
export class ClusterManager { | ||
public readonly clusterShardList: Record<string, number[]> = {} | ||
public readonly totalShards: number = 0 | ||
constructor(public readonly options: ClusterManagerOptions) { | ||
this.totalShards = this.options.totalClusters * this.options.shardsPerClusters | ||
const shardArrayID = this.arrayRange(0, this.totalShards - 1, 1) | ||
this.arrayChunk<number>(shardArrayID, this.options.shardsPerClusters).map((value, index) => { | ||
this.clusterShardList[String(index + 1)] = value | ||
}) | ||
} | ||
|
||
public async start() { | ||
if (cluster.isPrimary) { | ||
this.log('INFO', `Primary process ${process.pid} is running`) | ||
for (let i = 0; i < this.options.totalClusters; i++) { | ||
cluster.fork() | ||
} | ||
|
||
cluster.on('exit', (worker) => { | ||
this.log('WARN', `worker ${worker.process.pid} / ${worker.id} died`) | ||
}) | ||
} else { | ||
bootBot(this) | ||
|
||
this.log('INFO', `Worker ${process.pid} / ${cluster.worker.id} started`) | ||
} | ||
} | ||
|
||
public getShard(clusterId: number) { | ||
return this.clusterShardList[String(clusterId)] | ||
} | ||
|
||
protected arrayRange(start: number, stop: number, step: number) { | ||
return Array.from({ length: (stop - start) / step + 1 }, (_, index) => start + index * step) | ||
} | ||
|
||
protected arrayChunk<D = unknown>(array: D[], chunkSize: number): D[][] { | ||
return [].concat.apply( | ||
[], | ||
array.map(function (_, i) { | ||
return i % chunkSize ? [] : [array.slice(i, i + chunkSize)] | ||
}) | ||
) | ||
} | ||
|
||
protected log(level: string, msg: string, pad: number = 9) { | ||
const date = new Date(Date.now()).toISOString() | ||
const prettyLevel = level.toUpperCase().padEnd(pad) | ||
const prettyClass = 'ClusterManager'.padEnd(28) | ||
console.log(`${date} - ${prettyLevel} - ${prettyClass} - ${msg}`) | ||
} | ||
} |
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,10 @@ | ||
import { ConfigDataService } from '../services/ConfigDataService.js' | ||
import { ClusterManager } from './core.js' | ||
|
||
const configData = new ConfigDataService().data | ||
|
||
configData.utilities.SHARDING_SYSTEM | ||
|
||
const manager = new ClusterManager(configData.utilities.SHARDING_SYSTEM) | ||
|
||
manager.start() |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export type MaxLength = number | ||
export type MaxLength = number |
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
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.