@globalart/nestcord 1.3.10 → 1.3.11

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.
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultLocalizationAdapter = void 0;
4
+ const text_utils_1 = require("@globalart/text-utils");
4
5
  const base_localization_adapter_1 = require("./base-localization.adapter");
5
6
  class DefaultLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
6
7
  getTranslation(key, locale, placeholders) {
7
8
  const translation = this.getTranslations(locale)[key] || this.getFallbackTranslation(key);
8
- return placeholders
9
- ? translation.replace(/{{\s*([^}\s]+)\s*}}/g, (_, placeholder) => placeholders[placeholder] || '')
10
- : translation;
9
+ return placeholders ? (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders) : translation;
11
10
  }
12
11
  getTranslations(locale) {
13
12
  var _a, _b;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestedLocalizationAdapter = void 0;
4
+ const text_utils_1 = require("@globalart/text-utils");
4
5
  const base_localization_adapter_1 = require("./base-localization.adapter");
5
6
  class NestedLocalizationAdapter extends base_localization_adapter_1.BaseLocalizationAdapter {
6
7
  getTranslation(key, locale, placeholders) {
7
8
  const translations = this.getTranslations(locale);
8
9
  const translation = this.findTranslation(translations, key) || this.getFallbackTranslation(key);
9
- return translation.replace(/{{\s*([^}\s]+)\s*}}/g, (_, placeholder) => (placeholders === null || placeholders === void 0 ? void 0 : placeholders[placeholder]) || '');
10
+ return (0, text_utils_1.replacePlaceholdersInString)(translation, placeholders);
10
11
  }
11
12
  getTranslations(locale) {
12
13
  var _a, _b;
@@ -18,5 +18,4 @@ export declare class NestCordStatReporterService implements OnModuleInit {
18
18
  private reportStats;
19
19
  private calculateServerCount;
20
20
  private logStats;
21
- private replacePlaceholders;
22
21
  }
@@ -29,6 +29,7 @@ const nestcord_stat_reporter_module_definition_1 = require("./nestcord-stat-repo
29
29
  const schedule_1 = require("@nestjs/schedule");
30
30
  const cron_1 = require("cron");
31
31
  const axios_1 = require("@nestjs/axios");
32
+ const text_utils_1 = require("@globalart/text-utils");
32
33
  let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCordStatReporterService {
33
34
  constructor(client, shard, options, schedulerRegistry, httpService) {
34
35
  this.client = client;
@@ -47,7 +48,7 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
47
48
  }
48
49
  isFirstShard() {
49
50
  var _a, _b;
50
- return (((_b = (_a = this.shard) === null || _a === void 0 ? void 0 : _a.ids) === null || _b === void 0 ? void 0 : _b[0]) === 0) || !this.shard;
51
+ return ((_b = (_a = this.shard) === null || _a === void 0 ? void 0 : _a.ids) === null || _b === void 0 ? void 0 : _b[0]) === 0 || !this.shard;
51
52
  }
52
53
  isProduction() {
53
54
  return !this.options.development;
@@ -66,7 +67,7 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
66
67
  yield ((_a = this.client.application) === null || _a === void 0 ? void 0 : _a.fetch());
67
68
  const serverCount = yield this.calculateServerCount();
68
69
  const shardCount = ((_b = this.shard) === null || _b === void 0 ? void 0 : _b.count) || 1;
69
- const bodyData = this.replacePlaceholders(service.bodyData, { serverCount, shardCount });
70
+ const bodyData = (0, text_utils_1.replacePlaceholdersInObject)(service.bodyData, { serverCount, shardCount });
70
71
  const headerData = service.headerData || {};
71
72
  this.httpService
72
73
  .request({
@@ -85,8 +86,8 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
85
86
  return __awaiter(this, void 0, void 0, function* () {
86
87
  var _a;
87
88
  if (this.shard) {
88
- const shardGuildSizes = yield this.shard.fetchClientValues('guilds.cache.size');
89
- return shardGuildSizes.reduce((acc, size) => acc + size, 0) || ((_a = this.client.application) === null || _a === void 0 ? void 0 : _a.approximateGuildCount) || 0;
89
+ const shardGuildSizes = (yield this.shard.fetchClientValues('guilds.cache.size'));
90
+ return (shardGuildSizes.reduce((acc, size) => acc + size, 0) || ((_a = this.client.application) === null || _a === void 0 ? void 0 : _a.approximateGuildCount) || 0);
90
91
  }
91
92
  return this.client.guilds.cache.size;
92
93
  });
@@ -97,18 +98,6 @@ let NestCordStatReporterService = NestCordStatReporterService_1 = class NestCord
97
98
  this.logger.log(`Reporting stats for ${serviceName}, servers: ${serverCount}, shards: ${shardCount}`);
98
99
  }
99
100
  }
100
- replacePlaceholders(obj, replacements) {
101
- if (typeof obj === 'string') {
102
- const val = obj.replace(/{{(.*?)}}/g, (_, key) => { var _a; return (_a = replacements[key]) !== null && _a !== void 0 ? _a : _; });
103
- return !isNaN(parseFloat(val)) ? Number(val) : val;
104
- }
105
- if (obj && typeof obj === 'object') {
106
- Object.entries(obj).forEach(([key, value]) => {
107
- obj[key] = this.replacePlaceholders(value, replacements);
108
- });
109
- }
110
- return obj;
111
- }
112
101
  };
113
102
  exports.NestCordStatReporterService = NestCordStatReporterService;
114
103
  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.10",
4
+ "version": "1.3.11",
5
5
  "private": false,
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc -p tsconfig.build.json",
@@ -9,7 +9,7 @@
9
9
  "publish:npm": "release-it",
10
10
  "prepublish:dev": "npm run build",
11
11
  "publish:dev": "npm publish --access public --tag dev",
12
- "prepare": "husky install .github/husky",
12
+ "prepare": "husky ./.github/husky",
13
13
  "format": "prettier --write \"packages/**/*.ts\"",
14
14
  "lint": "eslint --ignore-path .gitignore packages/**/*.ts"
15
15
  },
@@ -45,6 +45,7 @@
45
45
  "url": "https://github.com/GlobalartInc/nestcord"
46
46
  },
47
47
  "dependencies": {
48
+ "@globalart/text-utils": "^1.0.1",
48
49
  "@nestjs/axios": "^3.0.2",
49
50
  "@nestjs/schedule": "^4.0.2",
50
51
  "axios": "^1.7.2",
@@ -59,7 +60,7 @@
59
60
  "@nestjs/common": "10.3.8",
60
61
  "@nestjs/core": "10.3.8",
61
62
  "@nestjs/platform-express": "^10.3.8",
62
- "@types/node": "20.12.12",
63
+ "@types/node": "20.12.13",
63
64
  "@typescript-eslint/eslint-plugin": "7.0.0",
64
65
  "@typescript-eslint/parser": "6.21.0",
65
66
  "discord-api-types": "0.37.86",