@globalart/nestcord 2.5.0-0 → 2.5.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,8 @@ export declare class ShardingListenersModule implements OnModuleInit {
|
|
|
6
6
|
private readonly metadataScanner;
|
|
7
7
|
private readonly reflector;
|
|
8
8
|
private readonly shardingManager;
|
|
9
|
+
private readonly logger;
|
|
9
10
|
constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector, shardingManager: ShardingManager);
|
|
10
11
|
onModuleInit(): void;
|
|
12
|
+
private registerBaseShardEvents;
|
|
11
13
|
}
|
|
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var ShardingListenersModule_1;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.ShardingListenersModule = void 0;
|
|
13
14
|
const common_1 = require("@nestjs/common");
|
|
@@ -15,15 +16,17 @@ const core_1 = require("@nestjs/core");
|
|
|
15
16
|
const discord_js_1 = require("discord.js");
|
|
16
17
|
const decorators_1 = require("./decorators");
|
|
17
18
|
const enums_1 = require("./enums");
|
|
18
|
-
let ShardingListenersModule = class ShardingListenersModule {
|
|
19
|
+
let ShardingListenersModule = ShardingListenersModule_1 = class ShardingListenersModule {
|
|
19
20
|
constructor(discoveryService, metadataScanner, reflector, shardingManager) {
|
|
20
21
|
this.discoveryService = discoveryService;
|
|
21
22
|
this.metadataScanner = metadataScanner;
|
|
22
23
|
this.reflector = reflector;
|
|
23
24
|
this.shardingManager = shardingManager;
|
|
25
|
+
this.logger = new common_1.Logger(ShardingListenersModule_1.name);
|
|
24
26
|
}
|
|
25
27
|
onModuleInit() {
|
|
26
28
|
var _a;
|
|
29
|
+
this.registerBaseShardEvents();
|
|
27
30
|
const groupedListeners = new Map();
|
|
28
31
|
const wrappers = this.discoveryService.getProviders().filter((wrapper) => {
|
|
29
32
|
const { instance } = wrapper;
|
|
@@ -44,38 +47,44 @@ let ShardingListenersModule = class ShardingListenersModule {
|
|
|
44
47
|
groupedListeners.set(key, listeners);
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (host === enums_1.ShardingHostType.ShardingManager) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* register listeners with a dynamic event name without bypassing type safety —
|
|
53
|
-
* EventEmitter.on(event: string) is the correct untyped surface for this.
|
|
54
|
-
*/
|
|
55
|
-
this.shardingManager.on(event, (...args) => {
|
|
56
|
-
for (const listener of listeners) {
|
|
57
|
-
listener.run(args);
|
|
58
|
-
}
|
|
50
|
+
const allListeners = [...groupedListeners.values()].flat();
|
|
51
|
+
for (const listener of allListeners) {
|
|
52
|
+
if (listener.host === enums_1.ShardingHostType.ShardingManager) {
|
|
53
|
+
this.shardingManager[listener.type](listener.event, (...args) => {
|
|
54
|
+
listener.run(...args);
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
shard.on(event, (...args) => {
|
|
68
|
-
for (const listener of listeners) {
|
|
69
|
-
listener.run(args);
|
|
70
|
-
}
|
|
57
|
+
}
|
|
58
|
+
this.shardingManager.on('shardCreate', (shard) => {
|
|
59
|
+
for (const listener of allListeners) {
|
|
60
|
+
if (listener.host === enums_1.ShardingHostType.Shard) {
|
|
61
|
+
shard[listener.type](listener.event, (...args) => {
|
|
62
|
+
listener.run(shard, ...args);
|
|
71
63
|
});
|
|
72
|
-
}
|
|
64
|
+
}
|
|
73
65
|
}
|
|
74
|
-
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
registerBaseShardEvents() {
|
|
69
|
+
this.shardingManager.on('shardCreate', (shard) => {
|
|
70
|
+
shard.on('spawn', () => {
|
|
71
|
+
this.logger.log(`Shard: [${shard.id}] spawned`);
|
|
72
|
+
});
|
|
73
|
+
shard.on('ready', () => {
|
|
74
|
+
this.logger.log(`Shard: [${shard.id}] is ready`);
|
|
75
|
+
});
|
|
76
|
+
shard.on('death', () => {
|
|
77
|
+
this.logger.error(`Shard: [${shard.id}] is dead`);
|
|
78
|
+
});
|
|
79
|
+
shard.on('error', (err) => {
|
|
80
|
+
this.logger.error(`Error in shard: [${shard.id}]`, err);
|
|
81
|
+
shard.respawn();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
75
84
|
}
|
|
76
85
|
};
|
|
77
86
|
exports.ShardingListenersModule = ShardingListenersModule;
|
|
78
|
-
exports.ShardingListenersModule = ShardingListenersModule = __decorate([
|
|
87
|
+
exports.ShardingListenersModule = ShardingListenersModule = ShardingListenersModule_1 = __decorate([
|
|
79
88
|
(0, common_1.Module)({
|
|
80
89
|
imports: [core_1.DiscoveryModule],
|
|
81
90
|
}),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ShardingManager } from 'discord.js';
|
|
3
3
|
import { NestCordShardingConfigurableModule } from './nestcord-sharding.module-definition';
|
|
4
4
|
import { NestCordShardingModuleOptions } from './nestcord-sharding-options.interface';
|
|
5
|
-
export declare class NestCordShardingModule extends NestCordShardingConfigurableModule implements
|
|
5
|
+
export declare class NestCordShardingModule extends NestCordShardingConfigurableModule implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
6
6
|
private readonly shardingManager;
|
|
7
7
|
private readonly options;
|
|
8
8
|
private readonly logger;
|
|
9
9
|
constructor(shardingManager: ShardingManager, options: NestCordShardingModuleOptions);
|
|
10
|
-
|
|
10
|
+
onApplicationBootstrap(): Promise<void>;
|
|
11
11
|
onApplicationShutdown(): void;
|
|
12
12
|
}
|
|
@@ -37,7 +37,7 @@ let NestCordShardingModule = NestCordShardingModule_1 = class NestCordShardingMo
|
|
|
37
37
|
this.options = options;
|
|
38
38
|
this.logger = new common_1.Logger(NestCordShardingModule_1.name);
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
onApplicationBootstrap() {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
if (this.options.autoSpawn === false) {
|
|
43
43
|
return;
|
package/package.json
CHANGED