@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
@@ -0,0 +1,218 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/core
4
+ * @Version 1.6.0-rc.1
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/9 17:33:05
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 messages_exports = {};
31
+ __export(messages_exports, {
32
+ MessageList: () => MessageList,
33
+ MessageSingle: () => MessageSingle,
34
+ Messages: () => Messages,
35
+ default: () => messages_default
36
+ });
37
+ module.exports = __toCommonJS(messages_exports);
38
+ class MessageSingle extends String {
39
+ /**
40
+ * Message data.
41
+ *
42
+ * @readonly
43
+ */
44
+ data;
45
+ /**
46
+ * Create a single message
47
+ *
48
+ * @param type - Message type
49
+ * @param data - Message data
50
+ */
51
+ constructor(type, data) {
52
+ super(Messages.stringify(type, data, false));
53
+ this.data = { type, ...data };
54
+ }
55
+ /**
56
+ * Convert message to string.
57
+ *
58
+ * @param isStrict - Whether to strictly convert message, strict convert will ignore the elements else text
59
+ * @returns Message string
60
+ */
61
+ toString(isStrict = true) {
62
+ return Messages.stringify(this.data.type, this.data, isStrict);
63
+ }
64
+ /**
65
+ * Check whether the message is text.
66
+ *
67
+ * @returns Whether the message is text
68
+ */
69
+ isText() {
70
+ return this.data.type === "text";
71
+ }
72
+ }
73
+ class MessageListOrigin extends Array {
74
+ /**
75
+ * Create a message list.
76
+ *
77
+ * @param messages - Message list
78
+ */
79
+ constructor(...messages) {
80
+ const handleMessage = [];
81
+ for (const value of messages) {
82
+ if (typeof value === "string") handleMessage.push(Messages.text(value));
83
+ else handleMessage.push(...value instanceof MessageListOrigin ? [...value] : [value]);
84
+ }
85
+ super(...handleMessage);
86
+ Object.setPrototypeOf(this, MessageList.prototype);
87
+ }
88
+ /**
89
+ * Convert message list to string.
90
+ *
91
+ * @param isStrict - Whether to strictly convert message, strict convert will ignore the elements else text
92
+ * @returns Message string
93
+ */
94
+ toString(isStrict = true) {
95
+ return Array.from(this).map((value) => value.toString(isStrict)).join("");
96
+ }
97
+ /**
98
+ * Check whether the message list is pure.
99
+ *
100
+ * @param keys - Message type list
101
+ *
102
+ * @returns Whether the message list is pure
103
+ */
104
+ isPure(...keys) {
105
+ return this.every((value) => keys.includes(value.data.type));
106
+ }
107
+ /**
108
+ * Check whether the message list is text.
109
+ *
110
+ * @returns Whether the message list is text
111
+ */
112
+ isText() {
113
+ return this.isPure("text");
114
+ }
115
+ /**
116
+ * Pick message list.
117
+ *
118
+ * @param keys - Message type list
119
+ * @returns Message list
120
+ */
121
+ pick(...keys) {
122
+ return Messages(
123
+ ...this.filter((value) => keys.includes(value.data.type))
124
+ );
125
+ }
126
+ /**
127
+ * Omit message list.
128
+ *
129
+ * @param keys - Message type list
130
+ * @returns Message list
131
+ */
132
+ omit(...keys) {
133
+ return Messages(
134
+ ...this.filter((value) => !keys.includes(value.data.type))
135
+ );
136
+ }
137
+ }
138
+ const MessageList = new Proxy(MessageListOrigin, {
139
+ construct: (target, argArray, newTarget) => new Proxy(Reflect.construct(target, argArray, newTarget), {
140
+ get: (target2, prop, receiver) => {
141
+ if (prop in target2) return Reflect.get(target2, prop, receiver);
142
+ const func = String.prototype[target2];
143
+ if (func instanceof Function) func.bind(void 0);
144
+ return void 0;
145
+ }
146
+ })
147
+ });
148
+ function Messages(...messages) {
149
+ return new MessageList(...messages);
150
+ }
151
+ ((Messages2) => {
152
+ function text(text2) {
153
+ return new MessageSingle("text", { text: text2 });
154
+ }
155
+ Messages2.text = text;
156
+ function mention(userId) {
157
+ return new MessageSingle("mention", { userId });
158
+ }
159
+ Messages2.mention = mention;
160
+ function mentionAll() {
161
+ return new MessageSingle("mentionAll", {});
162
+ }
163
+ Messages2.mentionAll = mentionAll;
164
+ function image(content) {
165
+ return new MessageSingle("image", { content });
166
+ }
167
+ Messages2.image = image;
168
+ function voice(content) {
169
+ return new MessageSingle("voice", { content });
170
+ }
171
+ Messages2.voice = voice;
172
+ function audio(content) {
173
+ return new MessageSingle("audio", { content });
174
+ }
175
+ Messages2.audio = audio;
176
+ function video(content) {
177
+ return new MessageSingle("video", { content });
178
+ }
179
+ Messages2.video = video;
180
+ function file(content) {
181
+ return new MessageSingle("file", { content });
182
+ }
183
+ Messages2.file = file;
184
+ function location(latitude, longitude, title, content) {
185
+ return new MessageSingle("location", { latitude, longitude, title, content });
186
+ }
187
+ Messages2.location = location;
188
+ function reply(messageId) {
189
+ return new MessageSingle("reply", { messageId });
190
+ }
191
+ Messages2.reply = reply;
192
+ function stringify(type, data, isStrict = true) {
193
+ if (isStrict) {
194
+ if (type === "text") return data.text;
195
+ return "";
196
+ }
197
+ switch (type) {
198
+ case "text":
199
+ return data.text;
200
+ case "mention":
201
+ return `@${data.userId}`;
202
+ case "mentionAll":
203
+ return "@all";
204
+ case "location":
205
+ return "[Location]";
206
+ default:
207
+ return `[${type.charAt(0).toUpperCase()}${type.slice(1)}]`;
208
+ }
209
+ }
210
+ Messages2.stringify = stringify;
211
+ })(Messages || (Messages = {}));
212
+ var messages_default = Messages;
213
+ // Annotate the CommonJS export names for ESM import in node:
214
+ 0 && (module.exports = {
215
+ MessageList,
216
+ MessageSingle,
217
+ Messages
218
+ });
@@ -0,0 +1,177 @@
1
+ import { type EventDataApiBase, type Message, MessageScope, type MessageQuick, type CommandResult, type EventDataPrivateMsg, type EventDataGroupMsg, type EventDataChannelMsg } from '../types';
2
+ import type { Adapter } from './adapter';
3
+ import { formatFactory } from '../utils/factory';
4
+ import { CommandError } from '../utils/error';
5
+ import type { Api } from './api';
6
+ import type { Elements } from './elements';
7
+ import type { I18n } from '@kotori-bot/i18n';
8
+ declare class SessionOrigin<T extends EventDataApiBase = EventDataApiBase> implements EventDataApiBase {
9
+ /**
10
+ * Api instance of current session.
11
+ *
12
+ * @readonly
13
+ */
14
+ readonly api: Api;
15
+ /**
16
+ * Elements instance of current session.
17
+ *
18
+ * @readonly
19
+ */
20
+ readonly el: Elements;
21
+ /**
22
+ * I18n instance of current session.
23
+ *
24
+ * @readonly
25
+ */
26
+ readonly i18n: I18n;
27
+ /**
28
+ * Session unique id, generated base on `type`. `userId`, `groupId`, `guildId`, `channelId`.
29
+ *
30
+ * @readonly
31
+ */
32
+ readonly id: string;
33
+ /**
34
+ * Send message to current session.
35
+ *
36
+ * @param message - Message to send
37
+ * @returns Message id and sent time
38
+ */
39
+ send(message: Message): Promise<import("../types").SendMessageResponse>;
40
+ /**
41
+ * Format message template with data.
42
+ *
43
+ * @param template - Message template
44
+ * @param data - Data to format
45
+ * @returns Formatted message
46
+ */
47
+ readonly format: ReturnType<typeof formatFactory>;
48
+ /**
49
+ * Send message to current session, it's packed base on `session.send()`, `session.i18n` and `session.format()`.
50
+ *
51
+ * @param message - Message to send
52
+ * @returns Message id and sent time
53
+ *
54
+ * @async
55
+ */
56
+ quick(message: MessageQuick): Promise<void>;
57
+ /**
58
+ * Get message from current session.
59
+ *
60
+ * @param message - Message to get
61
+ * @returns Message id and sent time
62
+ */
63
+ json(message: unknown): Promise<string | import("../types").SendMessageResponse>;
64
+ /**
65
+ * Prompt message to current session.
66
+ *
67
+ * @param message - Message to prompt
68
+ * @returns Message from current session
69
+ *
70
+ * @async
71
+ */
72
+ prompt(message?: Message): Promise<Message>;
73
+ /**
74
+ * Confirm message to current session.
75
+ *
76
+ * @param options - Options to confirm
77
+ * @returns Message from current session
78
+ *
79
+ * @async
80
+ */
81
+ confirm(options?: {
82
+ message: Message;
83
+ sure: Message;
84
+ }): Promise<boolean>;
85
+ /**
86
+ * Create a command error.
87
+ *
88
+ * @param type - Error type
89
+ * @param data - Error data
90
+ * @returns Command error
91
+ */
92
+ error<K extends keyof CommandResult>(type: K, data?: CommandResult[K]): CommandError;
93
+ readonly t: I18n['t'];
94
+ /**
95
+ * Session type
96
+ *
97
+ * @readonly
98
+ */
99
+ readonly type: EventDataApiBase['type'];
100
+ /**
101
+ * Session time, milliseconds timestamp.
102
+ *
103
+ * @readonly
104
+ */
105
+ readonly time: number;
106
+ /**
107
+ * Session related user id if exists.
108
+ *
109
+ * @readonly
110
+ */
111
+ readonly userId?: string;
112
+ /**
113
+ * Session related operator id if exists.
114
+ *
115
+ * @readonly
116
+ */
117
+ readonly operatorId?: string;
118
+ /**
119
+ * Session related message id if exists.
120
+ *
121
+ * @readonly
122
+ */
123
+ readonly messageId?: string;
124
+ /**
125
+ * Session related group id if exists.
126
+ *
127
+ * @readonly
128
+ */
129
+ readonly groupId?: string;
130
+ /**
131
+ * Session related channel id if exists.
132
+ *
133
+ * @readonly
134
+ */
135
+ readonly channelId?: string;
136
+ /**
137
+ * Session related guild id if exists.
138
+ *
139
+ * @readonly
140
+ */
141
+ readonly guildId?: string;
142
+ /**
143
+ * Session related meta data if exists, it is customized by the specific adapter.
144
+ *
145
+ * @readonly
146
+ */
147
+ readonly meta?: EventDataApiBase['meta'];
148
+ /**
149
+ * Create a session instance.
150
+ *
151
+ * @param data - Session data
152
+ * @param adapter - Adapter instance
153
+ *
154
+ * @constructor
155
+ */
156
+ constructor(data: T, adapter: Adapter);
157
+ }
158
+ /**
159
+ * Session instance.
160
+ *
161
+ * @class Session
162
+ * @extends {SessionOrigin}
163
+ * @template T
164
+ */
165
+ export type Session<T extends EventDataApiBase = EventDataApiBase> = SessionOrigin<T> & T;
166
+ export type SessionMsg = Session<EventDataPrivateMsg | EventDataGroupMsg | EventDataChannelMsg>;
167
+ export type SessionMsgPrivate = Session<EventDataPrivateMsg>;
168
+ export type SessionMsgGroup = Session<EventDataGroupMsg>;
169
+ export type SessionMsgChannel = Session<EventDataChannelMsg>;
170
+ /**
171
+ * Session event.
172
+ *
173
+ * @class
174
+ * @template T - Session event data type
175
+ */
176
+ export declare const Session: new <T extends EventDataApiBase<MessageScope> = EventDataApiBase<MessageScope>>(data: T, bot: Adapter) => Session<T>;
177
+ export {};
@@ -0,0 +1,275 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/core
4
+ * @Version 1.6.0-rc.1
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/9 17:33:05
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 session_exports = {};
31
+ __export(session_exports, {
32
+ Session: () => Session
33
+ });
34
+ module.exports = __toCommonJS(session_exports);
35
+ var import_types = require("../types");
36
+ var import_factory = require("../utils/factory");
37
+ var import_error = require("../utils/error");
38
+ var import_global = require("../global");
39
+ var import_messages = require("./messages");
40
+ class SessionOrigin {
41
+ /**
42
+ * Api instance of current session.
43
+ *
44
+ * @readonly
45
+ */
46
+ api;
47
+ /**
48
+ * Elements instance of current session.
49
+ *
50
+ * @readonly
51
+ */
52
+ el;
53
+ /**
54
+ * I18n instance of current session.
55
+ *
56
+ * @readonly
57
+ */
58
+ i18n;
59
+ /**
60
+ * Session unique id, generated base on `type`. `userId`, `groupId`, `guildId`, `channelId`.
61
+ *
62
+ * @readonly
63
+ */
64
+ id;
65
+ /**
66
+ * Send message to current session.
67
+ *
68
+ * @param message - Message to send
69
+ * @returns Message id and sent time
70
+ */
71
+ async send(message) {
72
+ if (this.type === import_types.MessageScope.GROUP) {
73
+ return await this.api.sendGroupMsg(message, this.groupId, this.meta);
74
+ }
75
+ if (this.type === import_types.MessageScope.CHANNEL) {
76
+ return await this.api.sendChannelMsg(message, this.guildId, this.channelId, this.meta);
77
+ }
78
+ if (this.type === import_types.MessageScope.PRIVATE) {
79
+ return await this.api.sendPrivateMsg(message, this.userId, this.meta);
80
+ }
81
+ return { messageId: "", time: 0 };
82
+ }
83
+ /**
84
+ * Format message template with data.
85
+ *
86
+ * @param template - Message template
87
+ * @param data - Data to format
88
+ * @returns Formatted message
89
+ */
90
+ format;
91
+ /**
92
+ * Send message to current session, it's packed base on `session.send()`, `session.i18n` and `session.format()`.
93
+ *
94
+ * @param message - Message to send
95
+ * @returns Message id and sent time
96
+ *
97
+ * @async
98
+ */
99
+ async quick(message) {
100
+ const msg = await message;
101
+ if (!msg || msg instanceof import_error.CommandError) return;
102
+ if (msg instanceof import_messages.MessageList && (msg.toString() === "" || msg.pick("text").length === 0)) {
103
+ this.send(msg);
104
+ return;
105
+ }
106
+ if (Array.isArray(msg) && !(msg instanceof import_messages.MessageList) && msg.length === 2) {
107
+ this.send(this.format(msg[0], msg[1]));
108
+ return;
109
+ }
110
+ this.send(typeof msg === "string" ? this.i18n.locale(msg) : msg);
111
+ }
112
+ /**
113
+ * Get message from current session.
114
+ *
115
+ * @param message - Message to get
116
+ * @returns Message id and sent time
117
+ */
118
+ async json(message) {
119
+ if (typeof message === "string") return this.send(message);
120
+ if (message && typeof message === "object") {
121
+ const result = JSON.stringify(message, void 0, 2);
122
+ if (result === "{}") return this.send(String(message));
123
+ return result;
124
+ }
125
+ if (typeof message === "function") {
126
+ return `[${message.toString().slice(0, 5) === "class" ? "class" : "Function"} ${message.name || "(anonymous)"}]`;
127
+ }
128
+ return this.send(String(message));
129
+ }
130
+ /**
131
+ * Prompt message to current session.
132
+ *
133
+ * @param message - Message to prompt
134
+ * @returns Message from current session
135
+ *
136
+ * @async
137
+ */
138
+ prompt(message) {
139
+ return new Promise((resolve) => {
140
+ this.api.adapter.ctx[import_global.Symbols.promise].set(this.id, [
141
+ ...this.api.adapter.ctx[import_global.Symbols.promise].get(this.id) ?? [],
142
+ resolve
143
+ ]);
144
+ this.quick(message ?? "corei18n.template.prompt").then(() => {
145
+ });
146
+ }).finally(() => this.api.adapter.ctx[import_global.Symbols.promise].delete(this.id));
147
+ }
148
+ /**
149
+ * Confirm message to current session.
150
+ *
151
+ * @param options - Options to confirm
152
+ * @returns Message from current session
153
+ *
154
+ * @async
155
+ */
156
+ confirm(options) {
157
+ return new Promise((resolve) => {
158
+ this.api.adapter.ctx[import_global.Symbols.promise].set(this.id, [
159
+ ...this.api.adapter.ctx[import_global.Symbols.promise].get(this.id) ?? [],
160
+ (message) => resolve(message === (options?.sure ?? "corei18n.template.confirm.sure"))
161
+ ]);
162
+ this.quick(options?.message ?? "corei18n.template.confirm").then(() => {
163
+ });
164
+ }).finally(() => this.api.adapter.ctx[import_global.Symbols.promise].delete(this.id));
165
+ }
166
+ /**
167
+ * Create a command error.
168
+ *
169
+ * @param type - Error type
170
+ * @param data - Error data
171
+ * @returns Command error
172
+ */
173
+ error(type, data) {
174
+ return new import_error.CommandError(Object.assign(data ?? {}, { type }));
175
+ }
176
+ t;
177
+ /**
178
+ * Session type
179
+ *
180
+ * @readonly
181
+ */
182
+ type;
183
+ /**
184
+ * Session time, milliseconds timestamp.
185
+ *
186
+ * @readonly
187
+ */
188
+ time;
189
+ /**
190
+ * Session related user id if exists.
191
+ *
192
+ * @readonly
193
+ */
194
+ userId;
195
+ /**
196
+ * Session related operator id if exists.
197
+ *
198
+ * @readonly
199
+ */
200
+ operatorId;
201
+ /**
202
+ * Session related message id if exists.
203
+ *
204
+ * @readonly
205
+ */
206
+ messageId;
207
+ /**
208
+ * Session related group id if exists.
209
+ *
210
+ * @readonly
211
+ */
212
+ groupId;
213
+ /**
214
+ * Session related channel id if exists.
215
+ *
216
+ * @readonly
217
+ */
218
+ channelId;
219
+ /**
220
+ * Session related guild id if exists.
221
+ *
222
+ * @readonly
223
+ */
224
+ guildId;
225
+ /**
226
+ * Session related meta data if exists, it is customized by the specific adapter.
227
+ *
228
+ * @readonly
229
+ */
230
+ meta;
231
+ /**
232
+ * Create a session instance.
233
+ *
234
+ * @param data - Session data
235
+ * @param adapter - Adapter instance
236
+ *
237
+ * @constructor
238
+ */
239
+ constructor(data, adapter) {
240
+ this.api = adapter.api;
241
+ this.el = adapter.elements;
242
+ this.i18n = adapter.ctx.i18n.extends(adapter.config.lang);
243
+ this.type = data.type;
244
+ this.userId = data.userId;
245
+ this.groupId = data.groupId;
246
+ this.operatorId = data.operatorId;
247
+ this.time = data.time;
248
+ this.meta = data.meta;
249
+ switch (this.type) {
250
+ case import_types.MessageScope.PRIVATE:
251
+ this.id = `${import_types.MessageScope.PRIVATE}|${this.userId}`;
252
+ break;
253
+ case import_types.MessageScope.GROUP:
254
+ this.id = `${import_types.MessageScope.GROUP}|${this.groupId}|${this.userId}`;
255
+ break;
256
+ case import_types.MessageScope.CHANNEL:
257
+ this.id = `${import_types.MessageScope.CHANNEL}|${this.channelId}|${this.guildId}|${this.userId}`;
258
+ break;
259
+ }
260
+ this.format = (0, import_factory.formatFactory)(this.i18n);
261
+ this.t = this.i18n.t.bind(this.i18n);
262
+ }
263
+ }
264
+ const Session = new Proxy(SessionOrigin, {
265
+ construct: (target, args, newTarget) => new Proxy(Reflect.construct(target, args, newTarget), {
266
+ get: (target2, prop, receiver) => {
267
+ const result = Reflect.get(target2, prop, receiver);
268
+ return result === void 0 ? args[0][prop] : result;
269
+ }
270
+ })
271
+ });
272
+ // Annotate the CommonJS export names for ESM import in node:
273
+ 0 && (module.exports = {
274
+ Session
275
+ });
@@ -0,0 +1,7 @@
1
+ import Decorators from './utils';
2
+ export * from './plugin';
3
+ export * from './utils';
4
+ export declare function plugins(plugin: string | string[] | {
5
+ name: string;
6
+ }): Decorators;
7
+ export default plugins;