@kotori-bot/core 1.5.1 → 1.6.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 (79) hide show
  1. package/README.md +10 -4
  2. package/lib/app/config.d.ts +32 -0
  3. package/lib/app/config.js +65 -0
  4. package/lib/app/core.d.ts +138 -0
  5. package/lib/{components → app}/core.js +24 -10
  6. package/lib/app/index.d.ts +1 -0
  7. package/lib/{service → app}/index.js +7 -13
  8. package/lib/{components → app}/message.d.ts +11 -10
  9. package/lib/app/message.js +253 -0
  10. package/lib/components/adapter.d.ts +122 -0
  11. package/lib/components/adapter.js +75 -0
  12. package/lib/components/api.d.ts +417 -0
  13. package/lib/components/api.js +546 -0
  14. package/lib/components/cache.d.ts +37 -0
  15. package/lib/{service → components}/cache.js +27 -6
  16. package/lib/components/command.d.ts +153 -0
  17. package/lib/{utils → components}/command.js +154 -48
  18. package/lib/components/elements.d.ts +144 -0
  19. package/lib/components/elements.js +179 -0
  20. package/lib/components/filter.d.ts +22 -0
  21. package/lib/components/filter.js +130 -0
  22. package/lib/components/index.d.ts +8 -2
  23. package/lib/components/index.js +19 -7
  24. package/lib/components/messages.d.ts +186 -0
  25. package/lib/components/messages.js +218 -0
  26. package/lib/components/session.d.ts +177 -0
  27. package/lib/components/session.js +275 -0
  28. package/lib/decorators/index.d.ts +7 -0
  29. package/lib/{components/config.js → decorators/index.js} +23 -39
  30. package/lib/decorators/plugin.d.ts +7 -0
  31. package/lib/{utils/commandError.js → decorators/plugin.js} +16 -16
  32. package/lib/decorators/utils.d.ts +59 -0
  33. package/lib/decorators/utils.js +189 -0
  34. package/lib/global/constants.d.ts +1 -8
  35. package/lib/global/constants.js +6 -25
  36. package/lib/global/index.js +3 -3
  37. package/lib/global/symbols.d.ts +13 -8
  38. package/lib/global/symbols.js +18 -12
  39. package/lib/index.d.ts +4 -4
  40. package/lib/index.js +10 -11
  41. package/lib/types/adapter.d.ts +1 -1
  42. package/lib/types/adapter.js +3 -3
  43. package/lib/types/api.d.ts +72 -0
  44. package/lib/{utils/jsxFactory.js → types/api.js} +5 -5
  45. package/lib/types/command.d.ts +78 -0
  46. package/lib/types/command.js +50 -0
  47. package/lib/types/config.d.ts +4 -6
  48. package/lib/types/config.js +3 -3
  49. package/lib/types/filter.d.ts +51 -0
  50. package/lib/types/filter.js +87 -0
  51. package/lib/types/index.d.ts +4 -0
  52. package/lib/types/index.js +12 -4
  53. package/lib/types/message.d.ts +128 -193
  54. package/lib/types/message.js +12 -31
  55. package/lib/types/session.d.ts +349 -0
  56. package/lib/types/session.js +27 -0
  57. package/lib/utils/container.d.ts +6 -6
  58. package/lib/utils/container.js +12 -16
  59. package/lib/utils/error.d.ts +46 -22
  60. package/lib/utils/error.js +38 -21
  61. package/lib/utils/factory.d.ts +10 -16
  62. package/lib/utils/factory.js +41 -101
  63. package/lib/utils/internal.d.ts +46 -0
  64. package/lib/utils/internal.js +102 -0
  65. package/package.json +10 -7
  66. package/lib/components/config.d.ts +0 -16
  67. package/lib/components/core.d.ts +0 -34
  68. package/lib/components/message.js +0 -195
  69. package/lib/service/adapter.d.ts +0 -41
  70. package/lib/service/adapter.js +0 -131
  71. package/lib/service/api.d.ts +0 -32
  72. package/lib/service/api.js +0 -80
  73. package/lib/service/cache.d.ts +0 -13
  74. package/lib/service/elements.d.ts +0 -12
  75. package/lib/service/elements.js +0 -73
  76. package/lib/service/index.d.ts +0 -4
  77. package/lib/utils/command.d.ts +0 -51
  78. package/lib/utils/commandError.d.ts +0 -7
  79. package/lib/utils/jsxFactory.d.ts +0 -6
@@ -1,131 +0,0 @@
1
-
2
- /**
3
- * @Package @kotori-bot/core
4
- * @Version 1.5.0
5
- * @Author Hotaru <biyuehuya@gmail.com>
6
- * @Copyright 2024 Hotaru. All rights reserved.
7
- * @License GPL-3.0
8
- * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 11:22:22
10
- */
11
-
12
- "use strict";
13
- var __create = Object.create;
14
- var __defProp = Object.defineProperty;
15
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
16
- var __getOwnPropNames = Object.getOwnPropertyNames;
17
- var __getProtoOf = Object.getPrototypeOf;
18
- var __hasOwnProp = Object.prototype.hasOwnProperty;
19
- var __export = (target, all) => {
20
- for (var name in all)
21
- __defProp(target, name, { get: all[name], enumerable: true });
22
- };
23
- var __copyProps = (to, from, except, desc) => {
24
- if (from && typeof from === "object" || typeof from === "function") {
25
- for (let key of __getOwnPropNames(from))
26
- if (!__hasOwnProp.call(to, key) && key !== except)
27
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
- }
29
- return to;
30
- };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
- // If the importer is in node compatibility mode or this is not an ESM
33
- // file that has been converted to a CommonJS file using a Babel-
34
- // compatible transform (i.e. "__esModule" has not been set), then set
35
- // "default" to the CommonJS "module.exports" for node compatibility.
36
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
- mod
38
- ));
39
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
- var adapter_exports = {};
41
- __export(adapter_exports, {
42
- Adapter: () => Adapter,
43
- default: () => adapter_default
44
- });
45
- module.exports = __toCommonJS(adapter_exports);
46
- var import_types = require("../types");
47
- var import_elements = __toESM(require("./elements"));
48
- var import_factory = require("../utils/factory");
49
- var import_commandError = __toESM(require("../utils/commandError"));
50
- var import_global = require("../global");
51
- function setProxy(api, ctx) {
52
- const proxy = Object.create(api);
53
- proxy.sendPrivateMsg = new Proxy(api.sendPrivateMsg, {
54
- apply(_, __, argArray) {
55
- const [message, targetId] = argArray;
56
- const cancel = (0, import_factory.cancelFactory)();
57
- ctx.emit("before_send", { api, message, messageType: import_types.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
58
- if (cancel.value) return;
59
- api.sendPrivateMsg(message, targetId, argArray[2]);
60
- }
61
- });
62
- proxy.sendGroupMsg = new Proxy(api.sendGroupMsg, {
63
- apply(_, __, argArray) {
64
- const [message, targetId] = argArray;
65
- const cancel = (0, import_factory.cancelFactory)();
66
- ctx.emit("before_send", { api, message, messageType: import_types.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
67
- if (cancel.value) return;
68
- api.sendGroupMsg(message, targetId, argArray[2]);
69
- }
70
- });
71
- return proxy;
72
- }
73
- function error(type, data) {
74
- return new import_commandError.default(Object.assign(data ?? {}, { type }));
75
- }
76
- class Adapter {
77
- constructor(ctx, config, identity, Api, el = new import_elements.default()) {
78
- this.ctx = ctx;
79
- this.config = config;
80
- this.identity = identity;
81
- this.platform = config.extends;
82
- this.api = setProxy(new Api(this), this.ctx);
83
- this.elements = el;
84
- if (!this.ctx[import_global.Symbols.bot].get(this.platform)) this.ctx[import_global.Symbols.bot].set(this.platform, /* @__PURE__ */ new Set());
85
- this.ctx[import_global.Symbols.bot].get(this.platform).add(this.api);
86
- }
87
- online() {
88
- if (this.status.value !== "offline") return;
89
- this.status.value = "online";
90
- this.ctx.emit("status", { adapter: this, status: "online" });
91
- }
92
- offline() {
93
- if (this.status.value !== "online") return;
94
- this.status.value = "offline";
95
- this.status.offlineTimes += 1;
96
- this.ctx.emit("status", { adapter: this, status: "offline" });
97
- }
98
- session(type, data) {
99
- const i18n = this.ctx.i18n.extends(this.config.lang);
100
- const send = (0, import_factory.sendMessageFactory)(this, type, data);
101
- const format = (0, import_factory.formatFactory)(i18n);
102
- const quick = (0, import_factory.quickFactory)(send, i18n);
103
- const prompt = (0, import_factory.promptFactory)(quick, this, data);
104
- const confirm = (0, import_factory.confirmFactory)(quick, this, data);
105
- const { api, elements: el } = this;
106
- this.ctx.emit(
107
- type,
108
- ...[{ ...data, api, el, send, i18n, format, quick, prompt, confirm, error }]
109
- );
110
- }
111
- ctx;
112
- config;
113
- identity;
114
- platform;
115
- api;
116
- elements;
117
- status = {
118
- value: "offline",
119
- createTime: /* @__PURE__ */ new Date(),
120
- lastMsgTime: null,
121
- receivedMsg: 0,
122
- sentMsg: 0,
123
- offlineTimes: 0
124
- };
125
- selfId = -1;
126
- }
127
- var adapter_default = Adapter;
128
- // Annotate the CommonJS export names for ESM import in node:
129
- 0 && (module.exports = {
130
- Adapter
131
- });
@@ -1,32 +0,0 @@
1
- import type Adapter from './adapter';
2
- import type { EventDataTargetId, MessageRaw } from '../types';
3
- interface ApiImpl {
4
- readonly adapter: Adapter<this>;
5
- sendPrivateMsg(message: MessageRaw, userId: EventDataTargetId): void;
6
- sendGroupMsg(message: MessageRaw, groupId: EventDataTargetId): void;
7
- deleteMsg(messageId: EventDataTargetId): void;
8
- setGroupName(groupId: EventDataTargetId, groupName: string): void;
9
- setGroupAvatar(groupId: EventDataTargetId, image: string): void;
10
- setGroupAdmin(groupId: EventDataTargetId, userId: EventDataTargetId, enable: boolean): void;
11
- setGroupCard(groupId: EventDataTargetId, userId: EventDataTargetId, card: string): void;
12
- setGroupBan(groupId: EventDataTargetId, userId?: EventDataTargetId, time?: number): void;
13
- sendGroupNotice(groupId: EventDataTargetId, content: string, image?: string): void;
14
- setGroupKick(groupId: EventDataTargetId, userId: EventDataTargetId): void;
15
- setGroupLeave(groupId: EventDataTargetId): void;
16
- }
17
- export declare abstract class Api implements ApiImpl {
18
- readonly adapter: Adapter<this>;
19
- constructor(adapter: Adapter);
20
- sendPrivateMsg(message: MessageRaw, userId: EventDataTargetId, ...extra: unknown[]): void;
21
- sendGroupMsg(message: MessageRaw, groupId: EventDataTargetId, ...extra: unknown[]): void;
22
- deleteMsg(messageId: EventDataTargetId, ...extra: unknown[]): void;
23
- setGroupName(groupId: EventDataTargetId, groupName: string, ...extra: unknown[]): void;
24
- setGroupAvatar(groupId: EventDataTargetId, image: string, ...extra: unknown[]): void;
25
- setGroupAdmin(groupId: EventDataTargetId, userId: EventDataTargetId, enable: boolean, ...extra: unknown[]): void;
26
- setGroupCard(groupId: EventDataTargetId, userId: EventDataTargetId, card: string, ...extra: unknown[]): void;
27
- setGroupBan(groupId: EventDataTargetId, userId?: EventDataTargetId, time?: number, ...extra: unknown[]): void;
28
- sendGroupNotice(groupId: EventDataTargetId, content: string, image?: string, ...extra: unknown[]): void;
29
- setGroupKick(groupId: EventDataTargetId, userId: EventDataTargetId, ...extra: unknown[]): void;
30
- setGroupLeave(groupId: EventDataTargetId, ...extra: unknown[]): void;
31
- }
32
- export default Api;
@@ -1,80 +0,0 @@
1
-
2
- /**
3
- * @Package @kotori-bot/core
4
- * @Version 1.5.0
5
- * @Author Hotaru <biyuehuya@gmail.com>
6
- * @Copyright 2024 Hotaru. All rights reserved.
7
- * @License GPL-3.0
8
- * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 11:22:22
10
- */
11
-
12
- "use strict";
13
- var __defProp = Object.defineProperty;
14
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
- var __getOwnPropNames = Object.getOwnPropertyNames;
16
- var __hasOwnProp = Object.prototype.hasOwnProperty;
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var api_exports = {};
31
- __export(api_exports, {
32
- Api: () => Api,
33
- default: () => api_default
34
- });
35
- module.exports = __toCommonJS(api_exports);
36
- var import_tools = require("@kotori-bot/tools");
37
- class Api {
38
- adapter;
39
- constructor(adapter) {
40
- this.adapter = adapter;
41
- }
42
- sendPrivateMsg(message, userId, ...extra) {
43
- (0, import_tools.none)(this, message, userId, extra);
44
- }
45
- sendGroupMsg(message, groupId, ...extra) {
46
- (0, import_tools.none)(this, message, groupId, extra, extra);
47
- }
48
- deleteMsg(messageId, ...extra) {
49
- (0, import_tools.none)(this, messageId, extra);
50
- }
51
- setGroupName(groupId, groupName, ...extra) {
52
- (0, import_tools.none)(this, groupId, groupName, extra);
53
- }
54
- setGroupAvatar(groupId, image, ...extra) {
55
- (0, import_tools.none)(this, groupId, image, extra);
56
- }
57
- setGroupAdmin(groupId, userId, enable, ...extra) {
58
- (0, import_tools.none)(this, groupId, userId, enable, extra);
59
- }
60
- setGroupCard(groupId, userId, card, ...extra) {
61
- (0, import_tools.none)(this, groupId, userId, card, extra);
62
- }
63
- setGroupBan(groupId, userId, time, ...extra) {
64
- (0, import_tools.none)(this, groupId, userId, time, extra);
65
- }
66
- sendGroupNotice(groupId, content, image, ...extra) {
67
- (0, import_tools.none)(this, groupId, content, image, extra);
68
- }
69
- setGroupKick(groupId, userId, ...extra) {
70
- (0, import_tools.none)(this, groupId, userId, extra);
71
- }
72
- setGroupLeave(groupId, ...extra) {
73
- (0, import_tools.none)(this, groupId, groupId, extra);
74
- }
75
- }
76
- var api_default = Api;
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- Api
80
- });
@@ -1,13 +0,0 @@
1
- import { Service } from 'fluoro';
2
- type CacheKey = string | symbol;
3
- type CacheValue = string | number | object;
4
- export declare class Cache extends Service {
5
- private cache?;
6
- constructor(ctx: ConstructorParameters<typeof Service>[0]);
7
- start(): void;
8
- stop(): void;
9
- getContainer(): Map<CacheKey, CacheValue>;
10
- get<T = CacheValue>(prop: CacheKey): T;
11
- set(prop: CacheKey, value: CacheValue): void;
12
- }
13
- export default Cache;
@@ -1,12 +0,0 @@
1
- import type { EventDataTargetId } from '../types';
2
- export declare class Elements {
3
- private default;
4
- at(target: EventDataTargetId, ...extra: unknown[]): string;
5
- image(url: string, ...extra: unknown[]): string;
6
- voice(url: string, ...extra: unknown[]): string;
7
- video(url: string, ...extra: unknown[]): string;
8
- face(id: number | string, ...extra: unknown[]): string;
9
- file(data: unknown, ...extra: unknown[]): string;
10
- supports(): (keyof Elements)[];
11
- }
12
- export default Elements;
@@ -1,73 +0,0 @@
1
-
2
- /**
3
- * @Package @kotori-bot/core
4
- * @Version 1.5.0
5
- * @Author Hotaru <biyuehuya@gmail.com>
6
- * @Copyright 2024 Hotaru. All rights reserved.
7
- * @License GPL-3.0
8
- * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 11:22:22
10
- */
11
-
12
- "use strict";
13
- var __defProp = Object.defineProperty;
14
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
- var __getOwnPropNames = Object.getOwnPropertyNames;
16
- var __hasOwnProp = Object.prototype.hasOwnProperty;
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var elements_exports = {};
31
- __export(elements_exports, {
32
- Elements: () => Elements,
33
- default: () => elements_default
34
- });
35
- module.exports = __toCommonJS(elements_exports);
36
- var import_tools = require("@kotori-bot/tools");
37
- class Elements {
38
- default(...args) {
39
- (0, import_tools.none)(this, args);
40
- return "";
41
- }
42
- at(target, ...extra) {
43
- return this.default(target, extra);
44
- }
45
- image(url, ...extra) {
46
- return this.default(url, extra);
47
- }
48
- voice(url, ...extra) {
49
- return this.default(url, extra);
50
- }
51
- video(url, ...extra) {
52
- return this.default(url, extra);
53
- }
54
- face(id, ...extra) {
55
- return this.default(id, extra);
56
- }
57
- file(data, ...extra) {
58
- return this.default(data, extra);
59
- }
60
- supports() {
61
- const supports = [];
62
- const keys = ["at", "image", "voice", "video", "face", "file"];
63
- keys.forEach((key) => {
64
- if (this[key] !== new Elements()[key]) supports.push(key);
65
- });
66
- return supports;
67
- }
68
- }
69
- var elements_default = Elements;
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- Elements
73
- });
@@ -1,4 +0,0 @@
1
- export * from './adapter';
2
- export * from './api';
3
- export * from './elements';
4
- export * from './cache';
@@ -1,51 +0,0 @@
1
- import { CommandAccess, type CommandAction, type CommandArgType, type CommandArgTypeSign, type CommandConfig, ArgsOrigin, OptsOrigin } from '../types';
2
- import { CommandError } from './commandError';
3
- interface CommandArg {
4
- name: string;
5
- type: CommandArgTypeSign;
6
- optional: boolean;
7
- default?: CommandArgType;
8
- rest: boolean;
9
- }
10
- interface CommandOption {
11
- name: string;
12
- type: CommandArgTypeSign;
13
- realname: string;
14
- description?: string;
15
- }
16
- interface CommandData<Args = ArgsOrigin, Opts = OptsOrigin> {
17
- root: string;
18
- alias: string[];
19
- args: CommandArg[];
20
- options: CommandOption[];
21
- scope: CommandConfig['scope'];
22
- access: CommandAccess;
23
- help?: string;
24
- action?: CommandAction<Args, Opts>;
25
- description?: string;
26
- }
27
- type GetSignType<T extends string> = T extends `${string}number${string}` ? number : T extends `${string}boolean${string}` ? boolean : string;
28
- type GetArgCtn<Template extends string> = Template extends `${string}:${infer Suffix}` ? Suffix extends `${infer T}=${string}` ? GetSignType<T> : GetSignType<Suffix> : Template extends `${infer T}=${string}` ? GetSignType<T> : string;
29
- type ParseArgs<Template extends string> = string extends Template ? ArgsOrigin : Template extends `${string} ${`<${infer Ctn}>`}${infer Rest}` ? Ctn extends `...${infer Ctn2}` ? [...GetSignType<Ctn2>[]] : [GetArgCtn<Ctn>, ...ParseArgs<Rest>] : Template extends `${string} [${infer Ctn}]${infer Rest}` ? Ctn extends `${infer Ctn2}=${string}` ? Ctn2 extends `...${infer Ctn3}` ? [...GetSignType<Ctn3>[]] : [GetArgCtn<Ctn2>, ...ParseArgs<Rest>] : Ctn extends `...${infer Ctn2}` ? [...GetSignType<Ctn2>[]] : [GetArgCtn<Ctn>?, ...ParseArgs<Rest>] : [];
30
- type ParseOpts<Template extends string> = string extends Template ? {} : Template extends `${infer K}:${infer V}` ? GetSignType<V> extends Boolean ? {
31
- [C in K]: GetSignType<V>;
32
- } : {
33
- [C in K]?: GetSignType<V>;
34
- } : {};
35
- export declare class Command<Template extends string = string, Opts extends OptsOrigin = OptsOrigin> {
36
- static run(input: string, data: CommandData): CommandError | {
37
- args: ArgsOrigin;
38
- options: OptsOrigin;
39
- };
40
- private template;
41
- readonly meta: CommandData<ParseArgs<Template>, Opts>;
42
- constructor(template: Template, config?: CommandConfig);
43
- private parse;
44
- alias(alias: string | string[]): this;
45
- scope(scope: CommandConfig['scope']): this;
46
- access(access: CommandAccess): this;
47
- option<TemplateOpt extends string>(name: string, template: TemplateOpt): Command<Template, Opts & ParseOpts<TemplateOpt>>;
48
- action(callback: CommandAction<ParseArgs<Template>, Opts>): this;
49
- help(text: string): this;
50
- }
51
- export default Command;
@@ -1,7 +0,0 @@
1
- import { CommandResultExtra } from '../types';
2
- import { KotoriError } from './error';
3
- export declare class CommandError extends KotoriError {
4
- readonly value: CommandResultExtra[keyof CommandResultExtra];
5
- constructor(value: CommandResultExtra[keyof CommandResultExtra]);
6
- }
7
- export default CommandError;
@@ -1,6 +0,0 @@
1
- export declare namespace JSX {
2
- interface IntrinsicElements {
3
- render: unknown;
4
- }
5
- }
6
- export default JSX;