@globalart/nestcord 1.3.11 → 1.3.12

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.
@@ -18,4 +18,5 @@ export declare class NestCordStatReporterService implements OnModuleInit {
18
18
  private reportStats;
19
19
  private calculateServerCount;
20
20
  private logStats;
21
+ private logErrors;
21
22
  }
@@ -30,6 +30,7 @@ const schedule_1 = require("@nestjs/schedule");
30
30
  const cron_1 = require("cron");
31
31
  const axios_1 = require("@nestjs/axios");
32
32
  const text_utils_1 = require("@globalart/text-utils");
33
+ const rxjs_1 = require("rxjs");
33
34
  let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCordStatReporterService {
34
35
  constructor(client, shard, options, schedulerRegistry, httpService) {
35
36
  this.client = client;
@@ -63,23 +64,26 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
63
64
  }
64
65
  reportStats(service) {
65
66
  return __awaiter(this, void 0, void 0, function* () {
66
- var _a, _b;
67
- yield ((_a = this.client.application) === null || _a === void 0 ? void 0 : _a.fetch());
68
- const serverCount = yield this.calculateServerCount();
69
- const shardCount = ((_b = this.shard) === null || _b === void 0 ? void 0 : _b.count) || 1;
70
- const bodyData = (0, text_utils_1.replacePlaceholdersInObject)(service.bodyData, { serverCount, shardCount });
71
- const headerData = service.headerData || {};
72
- this.httpService
73
- .request({
74
- method: service.method || 'POST',
75
- url: service.url,
76
- data: bodyData,
77
- headers: headerData,
78
- })
79
- .subscribe({
80
- next: () => this.logStats(service.name, serverCount, shardCount),
81
- error: (err) => this.logger.error(`Error reporting stats for ${service.name}`, err),
82
- });
67
+ var _a;
68
+ try {
69
+ const [_, serverCount, shardCount] = yield Promise.all([
70
+ this.client.application.fetch(),
71
+ this.calculateServerCount(),
72
+ Promise.resolve(((_a = this.shard) === null || _a === void 0 ? void 0 : _a.count) || 1),
73
+ ]);
74
+ const bodyData = (0, text_utils_1.replacePlaceholdersInObject)(service.bodyData, { serverCount, shardCount });
75
+ const headerData = service.headerData || {};
76
+ yield (0, rxjs_1.lastValueFrom)(this.httpService.request({
77
+ method: service.method || 'POST',
78
+ url: service.url,
79
+ data: bodyData,
80
+ headers: headerData,
81
+ }));
82
+ this.logStats(service.name, serverCount, shardCount);
83
+ }
84
+ catch (err) {
85
+ this.logErrors(service.name, err);
86
+ }
83
87
  });
84
88
  }
85
89
  calculateServerCount() {
@@ -98,6 +102,12 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
98
102
  this.logger.log(`Reporting stats for ${serviceName}, servers: ${serverCount}, shards: ${shardCount}`);
99
103
  }
100
104
  }
105
+ logErrors(serviceName, error) {
106
+ var _a;
107
+ if ((_a = this.options.log) !== null && _a !== void 0 ? _a : true) {
108
+ this.logger.error(`Error reporting stats for ${serviceName}`, error);
109
+ }
110
+ }
101
111
  };
102
112
  exports.NestCordStatReporterService = NestCordStatReporterService;
103
113
  exports.NestCordStatReporterService = NestCordStatReporterService = NestCordStatReporterService_1 = __decorate([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@globalart/nestcord",
3
3
  "description": "A module for creating Discord bots using NestJS, based on Discord.js",
4
- "version": "1.3.11",
4
+ "version": "1.3.12",
5
5
  "private": false,
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc -p tsconfig.build.json",