alemonjs 2.1.40 → 2.1.41

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.
@@ -1,6 +1,6 @@
1
1
  import { DataEnums, EventKeys, Events, User } from '../types';
2
2
  import { Result } from '../core/utils';
3
- import { BT, Format, MD } from './message-format';
3
+ import { Format } from './message-format';
4
4
  type Options = {
5
5
  UserId?: string;
6
6
  UserKey?: string;
@@ -17,33 +17,23 @@ export declare const useMention: <T extends EventKeys>(event: Events[T]) => [{
17
17
  }>;
18
18
  }];
19
19
  export declare const useMessage: <T extends EventKeys>(event: Events[T]) => readonly [{
20
- readonly currentFormat: any;
21
- addText(val: string, options?: {
22
- style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
23
- }): any;
24
- addLink(val: string, options?: {
25
- style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
26
- }): any;
27
- addImage(val: string | Buffer<ArrayBufferLike>): any;
28
- addImageFile(val: string): any;
29
- addImageURL(val: string): any;
30
- addMention(UserId?: string, options?: {
31
- belong?: "user" | "guild" | "channel" | "everyone";
32
- payload?: User | import("..").Guild | import("..").Channel | "everyone";
33
- }): any;
34
- addButtonGroup(...args: Parameters<typeof BT.group>): any;
35
- addMarkdown(...args: Parameters<typeof MD>): any;
36
- addFormat(val: DataEnums[]): any;
37
- clear(): any;
38
20
  send(params?: {
39
21
  format: Format | DataEnums[];
40
- } | DataEnums[]): Promise<Result[]>;
22
+ } | DataEnums[], param2?: {
23
+ replyId?: string;
24
+ }): Promise<Result[]>;
25
+ }];
26
+ export declare const useMember: <T extends EventKeys>(event: Events[T]) => readonly [{
27
+ information: (params: {
28
+ userId: string;
29
+ }) => Promise<Result<any>>;
41
30
  }];
42
- export declare const useMember: <T extends EventKeys>(event: Events[T]) => readonly [{}];
43
31
  export declare const useChannel: <T extends EventKeys>(event: Events[T]) => readonly [{}];
44
32
  export declare const useSend: <T extends EventKeys>(event: Events[T]) => (...val: DataEnums[]) => Promise<Result[]>;
45
33
  export declare const useSends: <T extends EventKeys>(event: Events[T]) => readonly [(params?: DataEnums[] | {
46
34
  format: Format | DataEnums[];
35
+ }, param2?: {
36
+ replyId?: string;
47
37
  }) => Promise<Result[]>];
48
38
  export declare const unChildren: (name?: string) => void;
49
39
  export declare const onSelects: <T extends EventKeys[] | EventKeys>(values: T) => T;
@@ -51,5 +41,8 @@ export declare const createSelects: <T extends EventKeys[] | EventKeys>(values:
51
41
  export declare const useClient: <T extends object>(event: any, _ApiClass: new (...args: any[]) => T) => readonly [T];
52
42
  export declare const useMe: () => readonly [{
53
43
  info: () => Promise<Result<User | null>>;
44
+ guilds: () => Promise<Result<User | null>>;
45
+ threads: () => Promise<Result<User | null>>;
46
+ friends: () => Promise<Result<User | null>>;
54
47
  }];
55
48
  export {};
@@ -4,7 +4,6 @@ import { createResult } from '../core/utils.js';
4
4
  import { sendAction } from '../cbp/processor/actions.js';
5
5
  import { sendAPI } from '../cbp/processor/api.js';
6
6
  import { Format } from './message-format.js';
7
- import { MessageControllerImpl } from './message-controller.js';
8
7
 
9
8
  const useMention = (event) => {
10
9
  if (!event || typeof event !== 'object') {
@@ -109,7 +108,7 @@ const useMessage = (event) => {
109
108
  }
110
109
  return params.format;
111
110
  };
112
- const sendRaw = async (val) => {
111
+ const sendRaw = async (val, replyId) => {
113
112
  if (!val || val.length === 0) {
114
113
  return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
115
114
  }
@@ -118,61 +117,19 @@ const useMessage = (event) => {
118
117
  payload: {
119
118
  event,
120
119
  params: {
121
- format: val
120
+ format: val,
121
+ replyId
122
122
  }
123
123
  }
124
124
  });
125
125
  return Array.isArray(result) ? result : [result];
126
126
  };
127
- let _ctrl = null;
128
- const getCtrl = () => {
129
- if (!_ctrl) {
130
- _ctrl = new MessageControllerImpl(sendRaw, resolveFormat);
131
- }
132
- return _ctrl;
133
- };
134
127
  const lightweight = {
135
- get currentFormat() {
136
- return getCtrl().currentFormat;
137
- },
138
- addText(...args) {
139
- return getCtrl().addText(...args);
140
- },
141
- addLink(...args) {
142
- return getCtrl().addLink(...args);
143
- },
144
- addImage(...args) {
145
- return getCtrl().addImage(...args);
146
- },
147
- addImageFile(...args) {
148
- return getCtrl().addImageFile(...args);
149
- },
150
- addImageURL(...args) {
151
- return getCtrl().addImageURL(...args);
152
- },
153
- addMention(...args) {
154
- return getCtrl().addMention(...args);
155
- },
156
- addButtonGroup(...args) {
157
- return getCtrl().addButtonGroup(...args);
158
- },
159
- addMarkdown(...args) {
160
- return getCtrl().addMarkdown(...args);
161
- },
162
- addFormat(val) {
163
- return getCtrl().addFormat(val);
164
- },
165
- clear() {
166
- return getCtrl().clear();
167
- },
168
- send(params) {
169
- if (!params) {
170
- return _ctrl ? sendRaw(_ctrl.currentFormat) : sendRaw([]);
171
- }
128
+ send(params, param2) {
172
129
  if (Array.isArray(params)) {
173
- return sendRaw(params.length > 0 ? params : _ctrl ? _ctrl.currentFormat : []);
130
+ return sendRaw(params.length > 0 ? params : [], param2?.replyId ?? event.MessageId);
174
131
  }
175
- return sendRaw(resolveFormat(params));
132
+ return sendRaw(resolveFormat(params), param2?.replyId ?? event.MessageId);
176
133
  }
177
134
  };
178
135
  return [lightweight];
@@ -186,7 +143,31 @@ const useMember = (event) => {
186
143
  });
187
144
  throw new Error('Invalid event: event must be an object');
188
145
  }
189
- const member = {};
146
+ const information = async (params) => {
147
+ try {
148
+ const results = await sendAction({
149
+ action: 'member.info',
150
+ payload: {
151
+ event,
152
+ params: {
153
+ userId: params?.userId
154
+ }
155
+ }
156
+ });
157
+ const result = results.find(item => item.code === ResultCode.Ok);
158
+ if (result) {
159
+ const data = result?.data ?? null;
160
+ return createResult(ResultCode.Ok, 'Successfully retrieved member information', data);
161
+ }
162
+ return createResult(ResultCode.Warn, 'No member information found', null);
163
+ }
164
+ catch {
165
+ return createResult(ResultCode.Fail, 'Failed to get member information', null);
166
+ }
167
+ };
168
+ const member = {
169
+ information
170
+ };
190
171
  return [member];
191
172
  };
192
173
  const useChannel = (event) => {
@@ -230,6 +211,9 @@ const createSelects = onSelects;
230
211
  const useClient = (event, _ApiClass) => {
231
212
  const client = new Proxy({}, {
232
213
  get(_target, prop) {
214
+ if (typeof prop === 'symbol') {
215
+ return undefined;
216
+ }
233
217
  return (...args) => {
234
218
  return sendAPI({
235
219
  action: 'client.api',
@@ -262,8 +246,62 @@ const useMe = () => {
262
246
  return createResult(ResultCode.Fail, 'Failed to get bot information', null);
263
247
  }
264
248
  };
249
+ const guilds = async () => {
250
+ try {
251
+ const results = await sendAction({
252
+ action: 'me.guilds',
253
+ payload: {}
254
+ });
255
+ const result = results.find(item => item.code === ResultCode.Ok);
256
+ if (result) {
257
+ const data = result?.data ?? null;
258
+ return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
259
+ }
260
+ return createResult(ResultCode.Warn, 'No bot information found', null);
261
+ }
262
+ catch {
263
+ return createResult(ResultCode.Fail, 'Failed to get bot information', null);
264
+ }
265
+ };
266
+ const threads = async () => {
267
+ try {
268
+ const results = await sendAction({
269
+ action: 'me.threads',
270
+ payload: {}
271
+ });
272
+ const result = results.find(item => item.code === ResultCode.Ok);
273
+ if (result) {
274
+ const data = result?.data ?? null;
275
+ return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
276
+ }
277
+ return createResult(ResultCode.Warn, 'No bot information found', null);
278
+ }
279
+ catch {
280
+ return createResult(ResultCode.Fail, 'Failed to get bot information', null);
281
+ }
282
+ };
283
+ const friends = async () => {
284
+ try {
285
+ const results = await sendAction({
286
+ action: 'me.friends',
287
+ payload: {}
288
+ });
289
+ const result = results.find(item => item.code === ResultCode.Ok);
290
+ if (result) {
291
+ const data = result?.data ?? null;
292
+ return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
293
+ }
294
+ return createResult(ResultCode.Warn, 'No bot information found', null);
295
+ }
296
+ catch {
297
+ return createResult(ResultCode.Fail, 'Failed to get bot information', null);
298
+ }
299
+ };
265
300
  const control = {
266
- info
301
+ info,
302
+ guilds,
303
+ threads,
304
+ friends
267
305
  };
268
306
  return [control];
269
307
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.40",
3
+ "version": "2.1.41",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",