@kotori-bot/core 1.6.4 → 1.7.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.
Files changed (46) hide show
  1. package/LICENSE.md +166 -0
  2. package/lib/app/common.js +8 -10
  3. package/lib/app/config.d.ts +1 -1
  4. package/lib/app/config.js +9 -11
  5. package/lib/app/core.d.ts +0 -5
  6. package/lib/app/core.js +9 -14
  7. package/lib/app/index.d.ts +3 -1
  8. package/lib/app/index.js +26 -12
  9. package/lib/app/message.js +16 -18
  10. package/lib/components/adapter.js +8 -10
  11. package/lib/components/api.d.ts +10 -6
  12. package/lib/components/api.js +18 -16
  13. package/lib/components/cache.js +8 -10
  14. package/lib/components/command.js +8 -10
  15. package/lib/components/elements.js +8 -10
  16. package/lib/components/filter.js +8 -10
  17. package/lib/components/index.js +8 -10
  18. package/lib/components/messages.js +8 -10
  19. package/lib/components/session.d.ts +1 -1
  20. package/lib/components/session.js +27 -17
  21. package/lib/decorators/index.js +8 -10
  22. package/lib/decorators/plugin.js +8 -10
  23. package/lib/decorators/utils.js +14 -12
  24. package/lib/global/constants.js +8 -10
  25. package/lib/global/index.js +8 -10
  26. package/lib/global/symbols.js +8 -10
  27. package/lib/index.d.ts +1 -0
  28. package/lib/index.js +10 -10
  29. package/lib/types/adapter.js +8 -10
  30. package/lib/types/api.js +8 -10
  31. package/lib/types/command.js +8 -10
  32. package/lib/types/config.js +8 -10
  33. package/lib/types/events.js +8 -10
  34. package/lib/types/filter.js +8 -10
  35. package/lib/types/index.js +8 -10
  36. package/lib/types/message.js +8 -10
  37. package/lib/types/session.js +8 -10
  38. package/lib/utils/container.js +8 -10
  39. package/lib/utils/error.js +8 -10
  40. package/lib/utils/factory.d.ts +2 -2
  41. package/lib/utils/factory.js +10 -11
  42. package/lib/utils/internal.js +8 -10
  43. package/lib/utils/jsx.d.ts +57 -0
  44. package/lib/utils/jsx.js +97 -0
  45. package/package.json +6 -5
  46. package/LICENSE +0 -674
@@ -1,4 +1,4 @@
1
- import type { I18n } from '@kotori-bot/i18n';
1
+ import { I18n } from '@kotori-bot/i18n';
2
2
  import type { CommandArgType, Message, MessageMapping } from '../types';
3
3
  import { MessageList } from '../components';
4
4
  /**
@@ -6,7 +6,7 @@ import { MessageList } from '../components';
6
6
  * @param i18n - i18n instance
7
7
  * @returns - format function
8
8
  */
9
- export declare function formatFactory(i18n: I18n): {
9
+ export declare function formatFactory(i18n?: I18n): {
10
10
  (template: string, data: Record<string, CommandArgType | undefined> | (CommandArgType | undefined)[]): string;
11
11
  <T extends keyof MessageMapping>(template: string, data: (Message<T> | CommandArgType | undefined)[]): MessageList<T | 'text'>;
12
12
  };
@@ -1,14 +1,12 @@
1
-
2
1
  /**
3
- * @Package @kotori-bot/core
4
- * @Version 1.6.3
5
- * @Author Arimura Sena <me@hotaru.icu>
6
- * @Copyright 2024 Hotaru. All rights reserved.
7
- * @License GPL-3.0
8
- * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/8/16 15:24:56
10
- */
11
-
2
+ * @Package @kotori-bot/core
3
+ * @Version 1.7.0
4
+ * @Author Arimura Sena <me@hotaru.icu>
5
+ * @Copyright 2024-2025 Hotaru. All rights reserved.
6
+ * @License BAN-ZHINESE-USING
7
+ * @Link https://github.com/kotorijs/kotori
8
+ * @Date 17:26:09
9
+ */
12
10
  "use strict";
13
11
  var __defProp = Object.defineProperty;
14
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -32,9 +30,10 @@ __export(factory_exports, {
32
30
  formatFactory: () => formatFactory
33
31
  });
34
32
  module.exports = __toCommonJS(factory_exports);
33
+ var import_i18n = require("@kotori-bot/i18n");
35
34
  var import_tools = require("@kotori-bot/tools");
36
35
  var import_components = require("../components");
37
- function formatFactory(i18n) {
36
+ function formatFactory(i18n = new import_i18n.I18n()) {
38
37
  function format(template, data) {
39
38
  if (!Array.isArray(data)) {
40
39
  for (const key of Object.keys(data)) {
@@ -1,14 +1,12 @@
1
-
2
1
  /**
3
- * @Package @kotori-bot/core
4
- * @Version 1.6.3
5
- * @Author Arimura Sena <me@hotaru.icu>
6
- * @Copyright 2024 Hotaru. All rights reserved.
7
- * @License GPL-3.0
8
- * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/8/16 15:24:56
10
- */
11
-
2
+ * @Package @kotori-bot/core
3
+ * @Version 1.7.0
4
+ * @Author Arimura Sena <me@hotaru.icu>
5
+ * @Copyright 2024-2025 Hotaru. All rights reserved.
6
+ * @License BAN-ZHINESE-USING
7
+ * @Link https://github.com/kotorijs/kotori
8
+ * @Date 17:26:09
9
+ */
12
10
  "use strict";
13
11
  var __defProp = Object.defineProperty;
14
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -0,0 +1,57 @@
1
+ declare global {
2
+ namespace JSX {
3
+ type Node = string | number | boolean | null | Element | Node[];
4
+ type Element = import('../components/messages').MessageList<keyof import('../types/message').MessageMapping> | import('../components/messages').MessageSingle<keyof import('../types/message').MessageMapping>;
5
+ interface ElementAttributesProperty {
6
+ props: any;
7
+ }
8
+ interface ElementChildrenAttribute {
9
+ children: unknown;
10
+ }
11
+ interface IntrinsicElements {
12
+ text: {
13
+ children: string;
14
+ };
15
+ br: never;
16
+ image: {
17
+ src: string;
18
+ };
19
+ reply: {
20
+ messageId: string;
21
+ };
22
+ mention: {
23
+ userId: string;
24
+ };
25
+ mentionAll: never;
26
+ video: {
27
+ src: string;
28
+ };
29
+ audio: {
30
+ src: string;
31
+ };
32
+ voice: {
33
+ src: string;
34
+ };
35
+ file: {
36
+ src: string;
37
+ };
38
+ location: {
39
+ latitude: number;
40
+ longitude: number;
41
+ title: string;
42
+ content: string;
43
+ };
44
+ seg: {
45
+ children: Node;
46
+ };
47
+ format: {
48
+ template: string;
49
+ children: Element[] | Element;
50
+ };
51
+ }
52
+ }
53
+ }
54
+ declare const Fragment: unique symbol;
55
+ export declare function hTs(type: string | typeof Fragment | ((props: Record<string, unknown>) => JSX.Element), props: Record<string, unknown>, ...children: any[]): JSX.Element;
56
+ export declare function hRes(type: string, props: Record<string, unknown>): JSX.Element;
57
+ export {};
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @Package @kotori-bot/core
3
+ * @Version 1.7.0
4
+ * @Author Arimura Sena <me@hotaru.icu>
5
+ * @Copyright 2024-2025 Hotaru. All rights reserved.
6
+ * @License BAN-ZHINESE-USING
7
+ * @Link https://github.com/kotorijs/kotori
8
+ * @Date 17:26:09
9
+ */
10
+ "use strict";
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var jsx_exports = {};
29
+ __export(jsx_exports, {
30
+ hRes: () => hRes,
31
+ hTs: () => hTs
32
+ });
33
+ module.exports = __toCommonJS(jsx_exports);
34
+ var import_factory = require("../utils/factory");
35
+ var import_messages = require("../components/messages");
36
+ const Fragment = Symbol("Fragment");
37
+ function hTs(type, props, ...children) {
38
+ if (type === Fragment) return hTs("list", props, ...children);
39
+ if (typeof type === "function") return type(Object.assign({}, props, { children }));
40
+ const flattenedChildren = children.flat(Number.MAX_SAFE_INTEGER).filter((child) => child != null && child !== false && child !== true);
41
+ switch (type) {
42
+ case "text":
43
+ return import_messages.Messages.text(flattenedChildren.map((child) => String(child)).join(""));
44
+ case "mention":
45
+ return import_messages.Messages.mention(props.userId);
46
+ case "mentionAll":
47
+ return import_messages.Messages.mentionAll();
48
+ case "reply":
49
+ return import_messages.Messages.reply(props.messageId);
50
+ case "image":
51
+ return import_messages.Messages.image(props.src);
52
+ case "audio":
53
+ return import_messages.Messages.audio(props.src);
54
+ case "video":
55
+ return import_messages.Messages.video(props.src);
56
+ case "file":
57
+ return import_messages.Messages.file(props.src);
58
+ case "location":
59
+ const locationProps = props;
60
+ return import_messages.Messages.location(
61
+ locationProps.latitude,
62
+ locationProps.longitude,
63
+ locationProps.title,
64
+ locationProps.content
65
+ );
66
+ case "seg":
67
+ return (0, import_messages.Messages)(
68
+ ...flattenedChildren.map(
69
+ (child) => child instanceof import_messages.MessageSingle || child instanceof import_messages.MessageList ? child : child && typeof child === "object" && "type" in child ? hTs(child.type, child.props, child.children) : String(child)
70
+ )
71
+ );
72
+ case "br":
73
+ return hTs("text", {}, "\n");
74
+ case "format":
75
+ return (0, import_factory.formatFactory)()(
76
+ props.template,
77
+ flattenedChildren
78
+ );
79
+ default:
80
+ throw new Error(`Unknown element type: ${type}`);
81
+ }
82
+ }
83
+ function hRes(type, props) {
84
+ return hTs(
85
+ type,
86
+ props,
87
+ ..."children" in props ? Array.isArray(props.children) ? props.children : [props.children] : []
88
+ );
89
+ }
90
+ ;
91
+ globalThis.kotoriHTs = hTs;
92
+ globalThis.kotoriHRes = hRes;
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ hRes,
96
+ hTs
97
+ });
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@kotori-bot/core",
3
- "version": "1.6.4",
3
+ "version": "1.7.0",
4
4
  "description": "Kotori Core",
5
5
  "main": "lib/index.js",
6
- "license": "GPL-3.0",
6
+ "license": "BAN-ZHINESE-USING",
7
7
  "author": "Arimura Sena <me@hotaru.icu>",
8
8
  "keywords": [
9
9
  "kotori",
@@ -25,12 +25,13 @@
25
25
  "homepage": "https://kotori.js.org",
26
26
  "dependencies": {
27
27
  "cron": "^3.1.7",
28
+ "fast-safe-stringify": "^2.1.1",
28
29
  "minimist": "^1.2.8",
29
30
  "reflect-metadata": "^0.2.2",
30
31
  "tsukiko": "^1.4.2",
31
- "@kotori-bot/i18n": "^1.3.2",
32
- "@kotori-bot/tools": "^1.5.1",
33
- "fluoro": "^1.1.1"
32
+ "@kotori-bot/i18n": "^1.3.3",
33
+ "@kotori-bot/tools": "^1.5.2",
34
+ "fluoro": "^1.1.2"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/minimist": "^1.2.5"