@kotori-bot/core 1.4.0 → 1.4.1

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.
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Config = void 0;
7
7
  const tsukiko_1 = __importDefault(require("tsukiko"));
8
- const path_1 = require("path");
8
+ const node_path_1 = require("node:path");
9
9
  const tools_1 = require("@kotori-bot/tools");
10
10
  const global_1 = require("../global");
11
11
  const packageInfoSchema = tsukiko_1.default.Object({
@@ -22,7 +22,7 @@ class Config {
22
22
  constructor(config = global_1.DEFAULT_CORE_CONFIG) {
23
23
  this.config = config;
24
24
  /* load package.json */
25
- const info = (0, tools_1.loadConfig)((0, path_1.join)(__dirname, '../../package.json'));
25
+ const info = (0, tools_1.loadConfig)((0, node_path_1.join)(__dirname, '../../package.json'));
26
26
  if (!info || Object.values(info).length === 0) {
27
27
  process.stderr.write(`Cannot find kotori-bot package.json\n`);
28
28
  process.exit();
@@ -6,7 +6,7 @@ export declare const CUSTOM_PREFIX = "kotori-plugin-custom-";
6
6
  export declare const DEFAULT_PORT = 720;
7
7
  export declare const DEFAULT_CORE_CONFIG: {
8
8
  global: {
9
- lang: "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
9
+ lang: "common" | "en_US" | "en_GB" | "en_AU" | "zh_CN" | "zh_HK" | "zh_TW" | "zh_SG" | "es_ES" | "es_MX" | "ar_EG" | "ar_AE" | "ru_RU" | "fr_FR" | "fr_CA" | "de_DE" | "de_CH" | "it_IT" | "it_CH" | "hi_IN" | "pt_BR" | "pt_PT" | "tr_TR" | "ja_JP" | "id_ID" | "uk_UA" | "vi_VN" | "th_TH" | "sv_SE" | "nb_NO" | "da_DK" | "fi_FI" | "he_IL" | "sk_SK" | "bg_BG" | "lt_LT" | "sl_SI" | "sr_RS" | "mk_MK" | "sq_AL" | "et_EE" | "mt_MT";
10
10
  'command-prefix': string;
11
11
  port: number;
12
12
  };
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './utils/command';
5
5
  export * from './utils/error';
6
6
  export * from './utils/commandError';
7
7
  export * from './utils/container';
8
+ export * from './utils/factory';
8
9
  export * from './global';
9
10
  export * from './types';
10
11
  export * from '@kotori-bot/tools';
package/lib/index.js CHANGED
@@ -28,6 +28,7 @@ __exportStar(require("./utils/command"), exports);
28
28
  __exportStar(require("./utils/error"), exports);
29
29
  __exportStar(require("./utils/commandError"), exports);
30
30
  __exportStar(require("./utils/container"), exports);
31
+ __exportStar(require("./utils/factory"), exports);
31
32
  __exportStar(require("./global"), exports);
32
33
  __exportStar(require("./types"), exports);
33
34
  __exportStar(require("@kotori-bot/tools"), exports);
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Adapter = void 0;
7
- const tools_1 = require("@kotori-bot/tools");
8
7
  const types_1 = require("../types");
9
8
  const elements_1 = __importDefault(require("./elements"));
10
9
  const factory_1 = require("../utils/factory");
@@ -44,24 +43,6 @@ function sendMessageFactory(adapter, type, data) {
44
43
  adapter.api.sendPrivateMsg(message, data.userId, data.extra);
45
44
  };
46
45
  }
47
- function formatFactory(i18n) {
48
- return (template, data) => {
49
- const params = data;
50
- if (Array.isArray(params)) {
51
- let str = i18n.locale(template);
52
- params.forEach((value, index) => {
53
- str = str.replaceAll(`{${index}}`, i18n.locale(typeof value === 'string' ? value : String(value)));
54
- });
55
- return str;
56
- }
57
- Object.keys(params).forEach((key) => {
58
- if (typeof params[key] !== 'string')
59
- params[key] = String(params[key]);
60
- params[key] = i18n.locale(params[key]);
61
- });
62
- return (0, tools_1.stringTemp)(i18n.locale(template), params);
63
- };
64
- }
65
46
  function quickFactory(send, i18n) {
66
47
  return async (message) => {
67
48
  const msg = await message;
@@ -71,7 +52,7 @@ function quickFactory(send, i18n) {
71
52
  send(i18n.locale(msg));
72
53
  return;
73
54
  }
74
- send(formatFactory(i18n)(...msg));
55
+ send((0, factory_1.formatFactory)(i18n)(...msg));
75
56
  };
76
57
  }
77
58
  function isSameSender(adapter, data, session) {
@@ -138,7 +119,7 @@ class Adapter {
138
119
  session(type, data) {
139
120
  const i18n = this.ctx.i18n.extends(this.config.lang);
140
121
  const send = sendMessageFactory(this, type, data);
141
- const format = formatFactory(i18n);
122
+ const format = (0, factory_1.formatFactory)(i18n);
142
123
  const quick = quickFactory(send, i18n);
143
124
  const prompt = promptFactory(quick, this, data);
144
125
  const confirm = confirmFactory(quick, this, data);
@@ -1,7 +1,10 @@
1
+ import I18n from '@kotori-bot/i18n/src/common';
1
2
  import type { Context } from 'fluoro';
3
+ import { CommandArgType } from '..';
2
4
  export declare function disposeFactory(ctx: Context, dispose: () => void): void;
3
5
  export declare function cancelFactory(): {
4
6
  get(): () => void;
5
7
  fn(): void;
6
8
  value: boolean;
7
9
  };
10
+ export declare function formatFactory(i18n: I18n): (template: string, data: Record<string, unknown> | CommandArgType[]) => string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cancelFactory = exports.disposeFactory = void 0;
3
+ exports.formatFactory = exports.cancelFactory = exports.disposeFactory = void 0;
4
+ const __1 = require("..");
4
5
  function disposeFactory(ctx, dispose) {
5
6
  ctx.once('dispose_module', (data) => {
6
7
  if ((typeof data.instance === 'object' ? data.instance.name : data.instance) !== ctx.identity) {
@@ -23,3 +24,22 @@ function cancelFactory() {
23
24
  };
24
25
  }
25
26
  exports.cancelFactory = cancelFactory;
27
+ function formatFactory(i18n) {
28
+ return (template, data) => {
29
+ const params = data;
30
+ if (Array.isArray(params)) {
31
+ let str = i18n.locale(template);
32
+ params.forEach((value, index) => {
33
+ str = str.replaceAll(`{${index}}`, i18n.locale(typeof value === 'string' ? value : String(value)));
34
+ });
35
+ return str;
36
+ }
37
+ Object.keys(params).forEach((key) => {
38
+ if (typeof params[key] !== 'string')
39
+ params[key] = String(params[key]);
40
+ params[key] = i18n.locale(params[key]);
41
+ });
42
+ return (0, __1.stringTemp)(i18n.locale(template), params);
43
+ };
44
+ }
45
+ exports.formatFactory = formatFactory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kotori-bot/core",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Kotori Core",
5
5
  "main": "lib/index.js",
6
6
  "license": "GPL-3.0",
@@ -27,9 +27,9 @@
27
27
  "@types/minimist": "^1.2.5",
28
28
  "minimist": "^1.2.8",
29
29
  "tsukiko": "^1.2.1",
30
- "@kotori-bot/i18n": "^1.2.1",
31
- "@kotori-bot/tools": "^1.3.0",
32
- "fluoro": "^1.0.0"
30
+ "@kotori-bot/i18n": "^1.3.0",
31
+ "@kotori-bot/tools": "^1.3.1",
32
+ "fluoro": "^1.0.1"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc --build"