@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,241 +1,176 @@
1
- import Tsu, { TsuError } from 'tsukiko';
2
- import type I18n from '@kotori-bot/i18n';
3
- import type { Context, EventsList } from 'fluoro';
4
- import type CommandError from '../utils/commandError';
5
- import type { Api, Elements } from '../service';
6
- import { Command } from '../utils/command';
1
+ import type { Context } from 'fluoro';
2
+ import type { CommandError } from '../utils/error';
3
+ import type { Api, Command, MessageList, MessageSingle, SessionMsg } from '../components';
4
+ import type { CommandAction, CommandArgType } from './command';
7
5
  declare module 'fluoro' {
8
6
  interface EventsMapping {
9
- midwares(data: EventDataMidwares): void;
10
- before_parse(data: EventDataBeforeParse): void;
11
- parse(data: EventDataParse): void;
12
7
  before_command(data: EventDataBeforeCommand): void;
8
+ /**
9
+ * Event after command running.
10
+ *
11
+ * @param data - Event data
12
+ */
13
13
  command(data: EventDataCommand): void;
14
+ /**
15
+ * Event before regexp.
16
+ *
17
+ * @param data - Event data
18
+ */
19
+ before_regexp(data: EventDataBeforeRegexp): void;
20
+ /**
21
+ * Event after regexp.
22
+ *
23
+ * @param data - Event data
24
+ */
14
25
  regexp(data: EventDataRegexp): void;
26
+ /**
27
+ * Event before message send.
28
+ *
29
+ * @param data - Event data
30
+ */
15
31
  before_send(data: EventDataBeforeSend): void;
32
+ /**
33
+ * Event after message send.
34
+ *
35
+ * @param data - Event data
36
+ */
16
37
  send(data: EventDataSend): void;
17
- on_message(session: EventDataPrivateMsg | EventDataGroupMsg): void;
18
- on_recall(session: EventDataPrivateRecall | EventDataGroupRecall): void;
19
- on_request(session: EventDataPrivateRequest | EventDataGroupRequest): void;
20
- on_private_add(session: EventDataPrivateAdd): void;
21
- on_group_increase(session: EventDataGroupIncrease): void;
22
- on_group_decrease(session: EventDataGroupDecrease): void;
23
- on_group_admin(session: EventDataGroupAdmin): void;
24
- on_group_ban(session: EventDataGroupBan): void;
25
38
  }
26
39
  }
27
- export declare const enum CommandAccess {
40
+ /** User access */
41
+ export declare enum UserAccess {
42
+ /** Normal member */
28
43
  MEMBER = 0,
44
+ /** Manager (group owner and group mangers) */
29
45
  MANGER = 1,
46
+ /** Admin (master of bot instance) */
30
47
  ADMIN = 2
31
48
  }
32
- export type ArgsOrigin = CommandArgType[];
33
- export type OptsOrigin = Record<string, CommandArgType>;
34
- export type CommandAction<Args = ArgsOrigin, Opts = OptsOrigin> = (data: {
35
- args: Args;
36
- options: Opts;
37
- }, session: SessionData) => MessageQuick;
38
- export type CommandArgType = string | number | boolean;
39
- export declare const commandArgTypeSignSchema: import("tsukiko").UnionParser<[import("tsukiko").UnionParser<[import("tsukiko").LiteralParser<"string">, import("tsukiko").LiteralParser<"number">]>, import("tsukiko").LiteralParser<"boolean">]>;
40
- export type CommandArgTypeSign = Tsu.infer<typeof commandArgTypeSignSchema>;
41
- export interface CommandConfig {
42
- alias?: string[];
43
- scope?: MessageScope | 'all';
44
- access?: CommandAccess;
45
- help?: string;
46
- action?: CommandAction;
47
- }
48
- interface CommandParseResult {
49
- option_error: {
50
- expected: CommandArgTypeSign;
51
- reality: CommandArgTypeSign;
52
- target: string;
49
+ /** Message scope (session type) */
50
+ export declare enum MessageScope {
51
+ /** Private message */
52
+ PRIVATE = 0,
53
+ /** Group message */
54
+ GROUP = 1,
55
+ /** Channel message */
56
+ CHANNEL = 2
57
+ }
58
+ export interface MessageMapping {
59
+ text: {
60
+ text: string;
53
61
  };
54
- arg_error: {
55
- expected: CommandArgTypeSign;
56
- reality: CommandArgTypeSign;
57
- index: number;
62
+ mention: {
63
+ userId: string;
58
64
  };
59
- arg_many: {
60
- expected: number;
61
- reality: number;
65
+ mentionAll: {};
66
+ image: {
67
+ content: string;
62
68
  };
63
- arg_few: CommandParseResult['arg_many'];
64
- syntax: {
65
- index: number;
66
- char: string;
69
+ voice: {
70
+ content: string;
67
71
  };
68
- unknown: {
69
- input: string;
72
+ audio: {
73
+ content: string;
70
74
  };
71
- }
72
- export interface CommandResult extends CommandParseResult {
73
- error: {
74
- error: unknown;
75
+ video: {
76
+ content: string;
75
77
  };
76
- data_error: {
77
- target: string | number;
78
+ file: {
79
+ content: string;
78
80
  };
79
- res_error: {
80
- error: TsuError;
81
+ location: {
82
+ latitude: number;
83
+ longitude: number;
84
+ title: string;
85
+ content: string;
81
86
  };
82
- num_error: null;
83
- no_access_manger: null;
84
- no_access_admin: null;
85
- disable: null;
86
- exists: {
87
- target: string;
87
+ reply: {
88
+ messageId: string;
88
89
  };
89
- no_exists: CommandResult['exists'];
90
90
  }
91
- type CommandResultNoArgs = 'num_error' | 'no_access_manger' | 'no_access_admin' | 'disable';
92
- export type CommandResultExtra = {
93
- [K in keyof CommandResult]: {
94
- type: K;
95
- } & (K extends CommandResultNoArgs ? object : CommandResult[K]);
96
- };
97
- export type SessionData = EventsList['on_message'];
98
- export declare enum MessageScope {
99
- PRIVATE = 0,
100
- GROUP = 1
101
- }
102
- export type MessageRaw = string;
103
- export type MessageQuickReal = [string, (CommandArgType | undefined)[] | Record<string, CommandArgType | undefined>] | MessageRaw | CommandError | void;
91
+ export type Message<T extends keyof MessageMapping = keyof MessageMapping> = MessageSingle<T | 'text'> | MessageList<T | 'text'> | string;
92
+ export type MessageQuickReal = [string, (Message | CommandArgType | undefined)[] | Record<string, CommandArgType | undefined>] | Message | void;
104
93
  export type MessageQuick = MessageQuickReal | Promise<MessageQuickReal>;
105
- export type MidwareCallback = (next: () => void, session: SessionData) => MessageQuick;
106
- export type RegexpCallback = (match: RegExpMatchArray, session: SessionData) => MessageQuick;
94
+ export type MidwareCallback = (next: () => void | Promise<void>, session: SessionMsg) => MessageQuick;
95
+ export type RegexpCallback = (match: RegExpMatchArray, session: SessionMsg) => MessageQuick;
107
96
  export type TaskCallback = (ctx: Context) => void;
108
- export type EventApiType = {
109
- [K in keyof EventsList]: EventsList[K] extends EventDataApiBase ? EventsList[K] : never;
97
+ export type TaskOptions = string | {
98
+ cron: string;
99
+ start?: boolean;
100
+ timeZone?: string;
110
101
  };
111
- export declare const eventDataTargetIdSchema: import("tsukiko").UnionParser<[import("tsukiko").NumberParser, import("tsukiko").StringParser]>;
112
- export type EventDataTargetId = Tsu.infer<typeof eventDataTargetIdSchema>;
113
- interface EventDataMidwares {
114
- isPass: boolean;
115
- session: SessionData;
116
- }
117
- interface EventDataBeforeParse {
118
- session: SessionData;
119
- raw: string;
120
- }
121
- interface EventDataParse {
122
- session: SessionData;
102
+ /** Event data before command running */
103
+ interface EventDataBeforeCommand {
104
+ /** Session instance */
105
+ session: SessionMsg;
106
+ /** Target command instance */
123
107
  command: Command;
108
+ /** Raw text message */
124
109
  raw: string;
110
+ /** Parsed result, command error or command data (args and options) */
125
111
  result: CommandError | Parameters<CommandAction>[0];
112
+ /** Cancel the command running */
126
113
  cancel(): void;
127
114
  }
128
- interface EventDataBeforeCommand {
129
- session: SessionData;
130
- raw: string;
131
- cancel(): void;
132
- }
115
+ /** Event data after command running */
133
116
  interface EventDataCommand {
134
- session: SessionData;
117
+ /** Session instance */
118
+ session: SessionMsg;
119
+ /** Raw text message */
135
120
  raw: string;
121
+ /** Target command instance */
136
122
  command: Command;
137
- result: EventDataParse['result'] | MessageQuick;
123
+ /** Command running result, running error or back message */
124
+ result: EventDataBeforeCommand['result'] | MessageQuick;
125
+ }
126
+ /** Event data before regexp running */
127
+ interface EventDataBeforeRegexp {
128
+ /** Session instance */
129
+ session: SessionMsg;
130
+ /** Raw text message */
131
+ raw: string;
132
+ /** Target regexp instance */
133
+ regexp: RegExp;
134
+ /** Cancel the regexp running */
135
+ cancel(): void;
138
136
  }
137
+ /** Event data after regexp running */
139
138
  interface EventDataRegexp {
140
- session: SessionData;
139
+ /** Session instance */
140
+ session: SessionMsg;
141
+ /** Raw text message */
141
142
  raw: string;
143
+ /** Target regexp instance */
142
144
  regexp: RegExp;
145
+ /** Match result */
143
146
  result: RegExpMatchArray;
144
147
  }
148
+ /** Event data before message sending */
145
149
  interface EventDataBeforeSend {
150
+ /** Api instance */
146
151
  api: Api;
147
- message: MessageRaw;
148
- messageType: MessageScope;
149
- targetId: EventDataTargetId;
152
+ /** Message to send */
153
+ message: Message;
154
+ /** Target user or group or channel */
155
+ target: {
156
+ type: MessageScope.PRIVATE;
157
+ userId: string;
158
+ } | {
159
+ type: MessageScope.GROUP;
160
+ groupId: string;
161
+ } | {
162
+ type: MessageScope.CHANNEL;
163
+ channelId: string;
164
+ guildId: string;
165
+ };
166
+ /** Cancel the message sending */
150
167
  cancel(): void;
151
168
  }
169
+ /** Event data after message sending */
152
170
  interface EventDataSend {
171
+ /** Api instance */
153
172
  api: Api;
154
- messageId: EventDataTargetId;
155
- }
156
- interface SessionDataSender {
157
- nickname: string;
158
- sex: 'male' | 'female' | 'unknown';
159
- age: number;
160
- }
161
- export interface EventDataApiBase {
162
- type?: MessageScope;
163
- api: Api;
164
- el: Elements;
165
- userId: EventDataTargetId;
166
- groupId?: EventDataTargetId;
167
- operatorId?: EventDataTargetId;
168
- i18n: I18n;
169
- send(message: MessageRaw): void;
170
- format(template: string, data: Record<string, CommandArgType | undefined> | (CommandArgType | undefined)[]): string;
171
- quick(message: MessageQuick): void;
172
- prompt(message?: MessageRaw): Promise<MessageRaw>;
173
- confirm(options?: {
174
- message: MessageRaw;
175
- sure: MessageRaw;
176
- }): Promise<boolean>;
177
- error<T extends Exclude<keyof CommandResult, CommandResultNoArgs>>(type: T, data: CommandResult[T] extends object ? CommandResult[T] : never): CommandError;
178
- error<T extends CommandResultNoArgs>(type: T): CommandError;
179
- extra?: unknown;
180
- }
181
- interface EventDataPrivateMsg extends EventDataApiBase {
182
- type: MessageScope.PRIVATE;
183
- messageId: EventDataTargetId;
184
- message: MessageRaw;
185
- sender: SessionDataSender;
186
- }
187
- interface EventDataGroupMsg extends EventDataApiBase {
188
- type: MessageScope.GROUP;
189
- messageId: EventDataTargetId;
190
- message: MessageRaw;
191
- sender: SessionDataSender & {
192
- level: string;
193
- role: 'owner' | 'admin' | 'member';
194
- title: string;
195
- };
196
- groupId: EventDataTargetId;
197
- }
198
- interface EventDataPrivateRecall extends EventDataApiBase {
199
- type: MessageScope.PRIVATE;
200
- messageId: EventDataTargetId;
201
- }
202
- interface EventDataGroupRecall extends EventDataApiBase {
203
- messageId: EventDataTargetId;
204
- operatorId: EventDataTargetId;
205
- groupId: EventDataTargetId;
206
- }
207
- interface EventDataPrivateRequest extends EventDataApiBase {
208
- type: MessageScope.PRIVATE;
209
- userId: EventDataTargetId;
210
- }
211
- interface EventDataGroupRequest extends EventDataApiBase {
212
- type: MessageScope.GROUP;
213
- userId: EventDataTargetId;
214
- operatorId: EventDataTargetId;
215
- groupId: EventDataTargetId;
216
- }
217
- interface EventDataPrivateAdd extends EventDataApiBase {
218
- userId: EventDataTargetId;
219
- }
220
- interface EventDataGroupIncrease extends EventDataApiBase {
221
- userId: EventDataTargetId;
222
- operatorId: EventDataTargetId;
223
- groupId: EventDataTargetId;
224
- }
225
- interface EventDataGroupDecrease extends EventDataApiBase {
226
- userId: EventDataTargetId;
227
- operatorId: EventDataTargetId;
228
- groupId: EventDataTargetId;
229
- }
230
- interface EventDataGroupAdmin extends EventDataApiBase {
231
- userId: EventDataTargetId;
232
- operation: 'set' | 'unset';
233
- groupId: EventDataTargetId;
234
- }
235
- interface EventDataGroupBan extends EventDataApiBase {
236
- userId: EventDataTargetId | 0;
237
- operatorId: EventDataTargetId;
238
- time: number | -1;
239
- groupId: EventDataTargetId;
173
+ /** Message id */
174
+ messageId: string;
240
175
  }
241
176
  export {};
@@ -1,20 +1,18 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/core
4
- * @Version 1.5.0
5
- * @Author Hotaru <biyuehuya@gmail.com>
4
+ * @Version 1.6.0-rc.1
5
+ * @Author Arimura Sena <me@hotaru.icu>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/7 11:22:22
9
+ * @Date 2024/8/9 17:33:05
10
10
  */
11
11
 
12
12
  "use strict";
13
- var __create = Object.create;
14
13
  var __defProp = Object.defineProperty;
15
14
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
16
15
  var __getOwnPropNames = Object.getOwnPropertyNames;
17
- var __getProtoOf = Object.getPrototypeOf;
18
16
  var __hasOwnProp = Object.prototype.hasOwnProperty;
19
17
  var __export = (target, all) => {
20
18
  for (var name in all)
@@ -28,44 +26,27 @@ var __copyProps = (to, from, except, desc) => {
28
26
  }
29
27
  return to;
30
28
  };
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
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
30
  var message_exports = {};
41
31
  __export(message_exports, {
42
- CommandAccess: () => CommandAccess,
43
32
  MessageScope: () => MessageScope,
44
- commandArgTypeSignSchema: () => commandArgTypeSignSchema,
45
- eventDataTargetIdSchema: () => eventDataTargetIdSchema
33
+ UserAccess: () => UserAccess
46
34
  });
47
35
  module.exports = __toCommonJS(message_exports);
48
- var import_tsukiko = __toESM(require("tsukiko"));
49
- var CommandAccess = /* @__PURE__ */ ((CommandAccess2) => {
50
- CommandAccess2[CommandAccess2["MEMBER"] = 0] = "MEMBER";
51
- CommandAccess2[CommandAccess2["MANGER"] = 1] = "MANGER";
52
- CommandAccess2[CommandAccess2["ADMIN"] = 2] = "ADMIN";
53
- return CommandAccess2;
54
- })(CommandAccess || {});
55
- const commandArgTypeSignSchema = import_tsukiko.default.Union([
56
- import_tsukiko.default.Union([import_tsukiko.default.Literal("string"), import_tsukiko.default.Literal("number")]),
57
- import_tsukiko.default.Literal("boolean")
58
- ]);
36
+ var UserAccess = /* @__PURE__ */ ((UserAccess2) => {
37
+ UserAccess2[UserAccess2["MEMBER"] = 0] = "MEMBER";
38
+ UserAccess2[UserAccess2["MANGER"] = 1] = "MANGER";
39
+ UserAccess2[UserAccess2["ADMIN"] = 2] = "ADMIN";
40
+ return UserAccess2;
41
+ })(UserAccess || {});
59
42
  var MessageScope = /* @__PURE__ */ ((MessageScope2) => {
60
43
  MessageScope2[MessageScope2["PRIVATE"] = 0] = "PRIVATE";
61
44
  MessageScope2[MessageScope2["GROUP"] = 1] = "GROUP";
45
+ MessageScope2[MessageScope2["CHANNEL"] = 2] = "CHANNEL";
62
46
  return MessageScope2;
63
47
  })(MessageScope || {});
64
- const eventDataTargetIdSchema = import_tsukiko.default.Union([import_tsukiko.default.Number(), import_tsukiko.default.String()]);
65
48
  // Annotate the CommonJS export names for ESM import in node:
66
49
  0 && (module.exports = {
67
- CommandAccess,
68
50
  MessageScope,
69
- commandArgTypeSignSchema,
70
- eventDataTargetIdSchema
51
+ UserAccess
71
52
  });