@globalart/nestcord 1.3.11 → 1.4.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2003 GlobalArt Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -2,4 +2,5 @@ export declare abstract class BaseLocalizationAdapter<Options = unknown> {
2
2
  protected readonly options?: Options;
3
3
  constructor(options?: Options);
4
4
  abstract getTranslation(key: string, locale: string, ...args: unknown[]): string;
5
+ abstract translate(key: string, ...args: unknown[]): string;
5
6
  }
@@ -5,6 +5,7 @@ interface DefaultLocalizationAdapterOptions {
5
5
  }
6
6
  export declare class DefaultLocalizationAdapter extends BaseLocalizationAdapter<DefaultLocalizationAdapterOptions> {
7
7
  getTranslation(key: string, locale: string, placeholders?: Record<string, string>): string;
8
+ translate(key: string, placeholders?: Record<string, string>): string;
8
9
  private getTranslations;
9
10
  private getFallbackTranslation;
10
11
  }
@@ -3,11 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultLocalizationAdapter = void 0;
4
4
  const text_utils_1 = require("@globalart/text-utils");
5
5
  const base_localization_adapter_1 = require("./base-localization.adapter");
6
+ const interceptors_1 = require("../interceptors");
6
7
  class DefaultLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
7
8
  getTranslation(key, locale, placeholders) {
8
9
  const translation = this.getTranslations(locale)[key] || this.getFallbackTranslation(key);
9
10
  return placeholders ? (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders) : translation;
10
11
  }
12
+ translate(key, placeholders) {
13
+ const currentTranslationFn = interceptors_1.LocalizationInterceptor.getCurrentTranslationFn();
14
+ return currentTranslationFn
15
+ ? currentTranslationFn(key, placeholders)
16
+ : this.getTranslation(key, this.options.fallbackLocale, placeholders);
17
+ }
11
18
  getTranslations(locale) {
12
19
  var _a, _b;
13
20
  return ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale]) || {};
@@ -8,6 +8,7 @@ interface NestedLocalizationAdapterOptions {
8
8
  }
9
9
  export declare class NestedLocalizationAdapter extends BaseLocalizationAdapter<NestedLocalizationAdapterOptions> {
10
10
  getTranslation(key: string, locale: string, placeholders?: Record<string, string>): string;
11
+ translate(key: string, placeholders?: Record<string, string>): string;
11
12
  private getTranslations;
12
13
  private findTranslation;
13
14
  private getFallbackTranslation;
@@ -3,12 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestedLocalizationAdapter = void 0;
4
4
  const text_utils_1 = require("@globalart/text-utils");
5
5
  const base_localization_adapter_1 = require("./base-localization.adapter");
6
+ const interceptors_1 = require("../interceptors");
6
7
  class NestedLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
7
8
  getTranslation(key, locale, placeholders) {
8
9
  const translations = this.getTranslations(locale);
9
10
  const translation = this.findTranslation(translations, key) || this.getFallbackTranslation(key);
10
11
  return (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders);
11
12
  }
13
+ translate(key, placeholders) {
14
+ const currentTranslationFn = interceptors_1.LocalizationInterceptor.getCurrentTranslationFn();
15
+ return currentTranslationFn
16
+ ? currentTranslationFn(key, placeholders)
17
+ : this.getTranslation(key, this.options.fallbackLocale, placeholders);
18
+ }
12
19
  getTranslations(locale) {
13
20
  var _a, _b;
14
21
  return ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.locales) === null || _b === void 0 ? void 0 : _b[locale]) || {};
@@ -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.4.0",
5
5
  "private": false,
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc -p tsconfig.build.json",
@@ -11,7 +11,8 @@
11
11
  "publish:dev": "npm publish --access public --tag dev",
12
12
  "prepare": "husky ./.github/husky",
13
13
  "format": "prettier --write \"packages/**/*.ts\"",
14
- "lint": "eslint --ignore-path .gitignore packages/**/*.ts"
14
+ "lint": "eslint --ignore-path .gitignore packages/**/*.ts",
15
+ "upgrade": "npx npm-check-updates -u"
15
16
  },
16
17
  "lint-staged": {
17
18
  "*.ts": "npm run format"
@@ -60,7 +61,7 @@
60
61
  "@nestjs/common": "10.3.8",
61
62
  "@nestjs/core": "10.3.8",
62
63
  "@nestjs/platform-express": "^10.3.8",
63
- "@types/node": "20.12.13",
64
+ "@types/node": "20.13.0",
64
65
  "@typescript-eslint/eslint-plugin": "7.0.0",
65
66
  "@typescript-eslint/parser": "6.21.0",
66
67
  "discord-api-types": "0.37.86",