alemonjs 2.1.44 → 2.1.46

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.
@@ -130,6 +130,95 @@ const useMessage = (event) => {
130
130
  return sendRaw(params.length > 0 ? params : []);
131
131
  }
132
132
  return sendRaw(resolveFormat(params), params?.replyId ?? event.MessageId);
133
+ },
134
+ async delete(params) {
135
+ const targetId = params?.messageId || event.MessageId;
136
+ if (!targetId) {
137
+ return createResult(ResultCode.FailParams, 'Missing MessageId', null);
138
+ }
139
+ try {
140
+ const results = await sendAction({
141
+ action: 'message.delete',
142
+ payload: { MessageId: targetId, ChannelId: event.ChannelId, event }
143
+ });
144
+ const result = results.find(item => item.code === ResultCode.Ok);
145
+ return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
146
+ }
147
+ catch {
148
+ return createResult(ResultCode.Fail, 'Failed to delete message', null);
149
+ }
150
+ },
151
+ async edit(params) {
152
+ const targetId = params.messageId || event.MessageId;
153
+ const channelId = event.ChannelId;
154
+ if (!targetId || !channelId) {
155
+ return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
156
+ }
157
+ try {
158
+ const val = params.format instanceof Format ? params.format.value : params.format;
159
+ const results = await sendAction({
160
+ action: 'message.edit',
161
+ payload: { ChannelId: channelId, MessageId: targetId, params: { format: val }, event }
162
+ });
163
+ const result = results.find(item => item.code === ResultCode.Ok);
164
+ return result || createResult(ResultCode.Warn, 'Edit not supported or failed', null);
165
+ }
166
+ catch {
167
+ return createResult(ResultCode.Fail, 'Failed to edit message', null);
168
+ }
169
+ },
170
+ async pin(params) {
171
+ const targetId = params?.messageId || event.MessageId;
172
+ const channelId = event.ChannelId;
173
+ if (!targetId || !channelId) {
174
+ return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
175
+ }
176
+ try {
177
+ const results = await sendAction({
178
+ action: 'message.pin',
179
+ payload: { ChannelId: channelId, MessageId: targetId }
180
+ });
181
+ const result = results.find(item => item.code === ResultCode.Ok);
182
+ return result || createResult(ResultCode.Warn, 'Pin not supported or failed', null);
183
+ }
184
+ catch {
185
+ return createResult(ResultCode.Fail, 'Failed to pin message', null);
186
+ }
187
+ },
188
+ async unpin(params) {
189
+ const targetId = params?.messageId || event.MessageId;
190
+ const channelId = event.ChannelId;
191
+ if (!targetId || !channelId) {
192
+ return createResult(ResultCode.FailParams, 'Missing MessageId or ChannelId', null);
193
+ }
194
+ try {
195
+ const results = await sendAction({
196
+ action: 'message.unpin',
197
+ payload: { ChannelId: channelId, MessageId: targetId }
198
+ });
199
+ const result = results.find(item => item.code === ResultCode.Ok);
200
+ return result || createResult(ResultCode.Warn, 'Unpin not supported or failed', null);
201
+ }
202
+ catch {
203
+ return createResult(ResultCode.Fail, 'Failed to unpin message', null);
204
+ }
205
+ },
206
+ async get(params) {
207
+ const targetId = params?.messageId || event.MessageId;
208
+ if (!targetId) {
209
+ return createResult(ResultCode.FailParams, 'Missing MessageId', null);
210
+ }
211
+ try {
212
+ const results = await sendAction({
213
+ action: 'message.get',
214
+ payload: { MessageId: targetId }
215
+ });
216
+ const result = results.find(item => item.code === ResultCode.Ok);
217
+ return result || createResult(ResultCode.Warn, 'Get message not supported or failed', null);
218
+ }
219
+ catch {
220
+ return createResult(ResultCode.Fail, 'Failed to get message', null);
221
+ }
133
222
  }
134
223
  };
135
224
  return [lightweight];
@@ -143,21 +232,22 @@ const useMember = (event) => {
143
232
  });
144
233
  throw new Error('Invalid event: event must be an object');
145
234
  }
146
- const information = async (params) => {
235
+ const getGuildId = (guildId) => guildId || event.GuildId;
236
+ const info = async (params) => {
147
237
  try {
148
238
  const results = await sendAction({
149
239
  action: 'member.info',
150
240
  payload: {
151
241
  event,
152
242
  params: {
153
- userId: params?.userId
243
+ userId: params.userId,
244
+ guildId: getGuildId(params.guildId)
154
245
  }
155
246
  }
156
247
  });
157
248
  const result = results.find(item => item.code === ResultCode.Ok);
158
249
  if (result) {
159
- const data = result?.data ?? null;
160
- return createResult(ResultCode.Ok, 'Successfully retrieved member information', data);
250
+ return createResult(ResultCode.Ok, 'Successfully retrieved member information', result.data ?? null);
161
251
  }
162
252
  return createResult(ResultCode.Warn, 'No member information found', null);
163
253
  }
@@ -165,8 +255,171 @@ const useMember = (event) => {
165
255
  return createResult(ResultCode.Fail, 'Failed to get member information', null);
166
256
  }
167
257
  };
258
+ const list = async (params) => {
259
+ const guildId = getGuildId(params?.guildId);
260
+ if (!guildId) {
261
+ return createResult(ResultCode.FailParams, 'Missing GuildId', { Items: [] });
262
+ }
263
+ try {
264
+ const results = await sendAction({
265
+ action: 'member.list',
266
+ payload: { GuildId: guildId, params: params?.pagination }
267
+ });
268
+ const result = results.find(item => item.code === ResultCode.Ok);
269
+ if (result) {
270
+ return createResult(ResultCode.Ok, 'Successfully retrieved member list', result.data ?? { Items: [] });
271
+ }
272
+ return createResult(ResultCode.Warn, 'No member list found', { Items: [] });
273
+ }
274
+ catch {
275
+ return createResult(ResultCode.Fail, 'Failed to get member list', { Items: [] });
276
+ }
277
+ };
278
+ const kick = async (params) => {
279
+ const gid = getGuildId(params.guildId);
280
+ if (!gid || !params.userId) {
281
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
282
+ }
283
+ try {
284
+ const results = await sendAction({
285
+ action: 'member.kick',
286
+ payload: { GuildId: gid, UserId: params.userId }
287
+ });
288
+ const result = results.find(item => item.code === ResultCode.Ok);
289
+ return result || createResult(ResultCode.Warn, 'Kick not supported or failed', null);
290
+ }
291
+ catch {
292
+ return createResult(ResultCode.Fail, 'Failed to kick member', null);
293
+ }
294
+ };
295
+ const ban = async (params) => {
296
+ const gid = getGuildId(params.guildId);
297
+ if (!gid || !params.userId) {
298
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
299
+ }
300
+ try {
301
+ const results = await sendAction({
302
+ action: 'member.ban',
303
+ payload: { GuildId: gid, UserId: params.userId, params: { reason: params.reason, duration: params.duration } }
304
+ });
305
+ const result = results.find(item => item.code === ResultCode.Ok);
306
+ return result || createResult(ResultCode.Warn, 'Ban not supported or failed', null);
307
+ }
308
+ catch {
309
+ return createResult(ResultCode.Fail, 'Failed to ban member', null);
310
+ }
311
+ };
312
+ const unban = async (params) => {
313
+ const gid = getGuildId(params.guildId);
314
+ if (!gid || !params.userId) {
315
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
316
+ }
317
+ try {
318
+ const results = await sendAction({
319
+ action: 'member.unban',
320
+ payload: { GuildId: gid, UserId: params.userId }
321
+ });
322
+ const result = results.find(item => item.code === ResultCode.Ok);
323
+ return result || createResult(ResultCode.Warn, 'Unban not supported or failed', null);
324
+ }
325
+ catch {
326
+ return createResult(ResultCode.Fail, 'Failed to unban member', null);
327
+ }
328
+ };
329
+ const information = (params) => info(params);
330
+ const search = async (params) => {
331
+ const gid = getGuildId(params.guildId);
332
+ if (!gid || !params.keyword) {
333
+ return createResult(ResultCode.FailParams, 'Missing GuildId or keyword', null);
334
+ }
335
+ try {
336
+ const results = await sendAction({
337
+ action: 'member.search',
338
+ payload: { GuildId: gid, params: { keyword: params.keyword, limit: params.limit } }
339
+ });
340
+ const result = results.find(item => item.code === ResultCode.Ok);
341
+ return result || createResult(ResultCode.Warn, 'Member search not supported or failed', null);
342
+ }
343
+ catch {
344
+ return createResult(ResultCode.Fail, 'Failed to search members', null);
345
+ }
346
+ };
168
347
  const member = {
169
- information
348
+ info,
349
+ information,
350
+ list,
351
+ kick,
352
+ ban,
353
+ unban,
354
+ search,
355
+ async mute(params) {
356
+ const gid = getGuildId(params.guildId);
357
+ if (!gid || !params.userId) {
358
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
359
+ }
360
+ try {
361
+ const results = await sendAction({
362
+ action: 'member.mute',
363
+ payload: { GuildId: gid, UserId: params.userId, params: { duration: params.duration } }
364
+ });
365
+ const result = results.find(item => item.code === ResultCode.Ok);
366
+ return result || createResult(ResultCode.Warn, 'Mute not supported or failed', null);
367
+ }
368
+ catch {
369
+ return createResult(ResultCode.Fail, 'Failed to mute member', null);
370
+ }
371
+ },
372
+ async admin(params) {
373
+ const gid = getGuildId(params.guildId);
374
+ if (!gid || !params.userId) {
375
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
376
+ }
377
+ try {
378
+ const results = await sendAction({
379
+ action: 'member.admin',
380
+ payload: { GuildId: gid, UserId: params.userId, params: { enable: params.enable } }
381
+ });
382
+ const result = results.find(item => item.code === ResultCode.Ok);
383
+ return result || createResult(ResultCode.Warn, 'Admin set not supported or failed', null);
384
+ }
385
+ catch {
386
+ return createResult(ResultCode.Fail, 'Failed to set admin', null);
387
+ }
388
+ },
389
+ async card(params) {
390
+ const gid = getGuildId(params.guildId);
391
+ if (!gid || !params.userId) {
392
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
393
+ }
394
+ try {
395
+ const results = await sendAction({
396
+ action: 'member.card',
397
+ payload: { GuildId: gid, UserId: params.userId, params: { card: params.card } }
398
+ });
399
+ const result = results.find(item => item.code === ResultCode.Ok);
400
+ return result || createResult(ResultCode.Warn, 'Card set not supported or failed', null);
401
+ }
402
+ catch {
403
+ return createResult(ResultCode.Fail, 'Failed to set member card', null);
404
+ }
405
+ },
406
+ async title(params) {
407
+ const gid = getGuildId(params.guildId);
408
+ if (!gid || !params.userId) {
409
+ return createResult(ResultCode.FailParams, 'Missing GuildId or UserId', null);
410
+ }
411
+ try {
412
+ const results = await sendAction({
413
+ action: 'member.title',
414
+ payload: { GuildId: gid, UserId: params.userId, params: { title: params.title, duration: params.duration ?? -1 } }
415
+ });
416
+ const result = results.find(item => item.code === ResultCode.Ok);
417
+ return result || createResult(ResultCode.Warn, 'Title set not supported or failed', null);
418
+ }
419
+ catch {
420
+ return createResult(ResultCode.Fail, 'Failed to set member title', null);
421
+ }
422
+ }
170
423
  };
171
424
  return [member];
172
425
  };
@@ -179,7 +432,104 @@ const useChannel = (event) => {
179
432
  });
180
433
  throw new Error('Invalid event: event must be an object');
181
434
  }
182
- const channel = {};
435
+ const info = async (params) => {
436
+ const cid = params?.channelId || event.ChannelId;
437
+ if (!cid) {
438
+ return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
439
+ }
440
+ try {
441
+ const results = await sendAction({
442
+ action: 'channel.info',
443
+ payload: { ChannelId: cid }
444
+ });
445
+ const result = results.find(item => item.code === ResultCode.Ok);
446
+ if (result) {
447
+ return createResult(ResultCode.Ok, 'Successfully retrieved channel info', result.data ?? null);
448
+ }
449
+ return createResult(ResultCode.Warn, 'No channel info found', null);
450
+ }
451
+ catch {
452
+ return createResult(ResultCode.Fail, 'Failed to get channel info', null);
453
+ }
454
+ };
455
+ const list = async (params) => {
456
+ const gid = params?.guildId || event.GuildId;
457
+ if (!gid) {
458
+ return createResult(ResultCode.FailParams, 'Missing GuildId', []);
459
+ }
460
+ try {
461
+ const results = await sendAction({
462
+ action: 'channel.list',
463
+ payload: { GuildId: gid }
464
+ });
465
+ const result = results.find(item => item.code === ResultCode.Ok);
466
+ if (result) {
467
+ return createResult(ResultCode.Ok, 'Successfully retrieved channel list', result.data ?? []);
468
+ }
469
+ return createResult(ResultCode.Warn, 'No channel list found', []);
470
+ }
471
+ catch {
472
+ return createResult(ResultCode.Fail, 'Failed to get channel list', []);
473
+ }
474
+ };
475
+ const create = async (params) => {
476
+ const gid = params.guildId || event.GuildId;
477
+ if (!gid) {
478
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
479
+ }
480
+ try {
481
+ const results = await sendAction({
482
+ action: 'channel.create',
483
+ payload: { GuildId: gid, params: { name: params.name, type: params.type, parentId: params.parentId } }
484
+ });
485
+ const result = results.find(item => item.code === ResultCode.Ok);
486
+ return result
487
+ ? createResult(ResultCode.Ok, 'Channel created', result.data ?? null)
488
+ : createResult(ResultCode.Warn, 'Create not supported or failed', null);
489
+ }
490
+ catch {
491
+ return createResult(ResultCode.Fail, 'Failed to create channel', null);
492
+ }
493
+ };
494
+ const update = async (params) => {
495
+ if (!params.channelId) {
496
+ return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
497
+ }
498
+ try {
499
+ const results = await sendAction({
500
+ action: 'channel.update',
501
+ payload: { ChannelId: params.channelId, params: { name: params.name, topic: params.topic, position: params.position } }
502
+ });
503
+ const result = results.find(item => item.code === ResultCode.Ok);
504
+ return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
505
+ }
506
+ catch {
507
+ return createResult(ResultCode.Fail, 'Failed to update channel', null);
508
+ }
509
+ };
510
+ const remove = async (params) => {
511
+ if (!params.channelId) {
512
+ return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
513
+ }
514
+ try {
515
+ const results = await sendAction({
516
+ action: 'channel.delete',
517
+ payload: { ChannelId: params.channelId }
518
+ });
519
+ const result = results.find(item => item.code === ResultCode.Ok);
520
+ return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
521
+ }
522
+ catch {
523
+ return createResult(ResultCode.Fail, 'Failed to delete channel', null);
524
+ }
525
+ };
526
+ const channel = {
527
+ info,
528
+ list,
529
+ create,
530
+ update,
531
+ delete: remove
532
+ };
183
533
  return [channel];
184
534
  };
185
535
  const useSend = (event) => {
@@ -228,6 +578,303 @@ const useClient = (event, _ApiClass) => {
228
578
  });
229
579
  return [client];
230
580
  };
581
+ const useGuild = (event) => {
582
+ if (!event || typeof event !== 'object') {
583
+ logger.error({
584
+ code: ResultCode.FailParams,
585
+ message: 'Invalid event: event must be an object',
586
+ data: null
587
+ });
588
+ throw new Error('Invalid event: event must be an object');
589
+ }
590
+ const info = async (params) => {
591
+ const gid = params?.guildId || event.GuildId;
592
+ if (!gid) {
593
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
594
+ }
595
+ try {
596
+ const results = await sendAction({
597
+ action: 'guild.info',
598
+ payload: { GuildId: gid }
599
+ });
600
+ const result = results.find(item => item.code === ResultCode.Ok);
601
+ if (result) {
602
+ return createResult(ResultCode.Ok, 'Successfully retrieved guild info', result.data ?? null);
603
+ }
604
+ return createResult(ResultCode.Warn, 'No guild info found', null);
605
+ }
606
+ catch {
607
+ return createResult(ResultCode.Fail, 'Failed to get guild info', null);
608
+ }
609
+ };
610
+ const list = async () => {
611
+ try {
612
+ const results = await sendAction({
613
+ action: 'guild.list',
614
+ payload: {}
615
+ });
616
+ const result = results.find(item => item.code === ResultCode.Ok);
617
+ if (result) {
618
+ return createResult(ResultCode.Ok, 'Successfully retrieved guild list', result.data ?? []);
619
+ }
620
+ return createResult(ResultCode.Warn, 'No guild list found', []);
621
+ }
622
+ catch {
623
+ return createResult(ResultCode.Fail, 'Failed to get guild list', []);
624
+ }
625
+ };
626
+ const guild = {
627
+ info,
628
+ list,
629
+ async update(params) {
630
+ const gid = params.guildId || event.GuildId;
631
+ if (!gid) {
632
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
633
+ }
634
+ try {
635
+ const results = await sendAction({
636
+ action: 'guild.update',
637
+ payload: { GuildId: gid, params: { name: params.name } }
638
+ });
639
+ const result = results.find(item => item.code === ResultCode.Ok);
640
+ return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
641
+ }
642
+ catch {
643
+ return createResult(ResultCode.Fail, 'Failed to update guild', null);
644
+ }
645
+ },
646
+ async leave(params) {
647
+ const gid = params?.guildId || event.GuildId;
648
+ if (!gid) {
649
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
650
+ }
651
+ try {
652
+ const results = await sendAction({
653
+ action: 'guild.leave',
654
+ payload: { GuildId: gid, params: { isDismiss: params?.isDismiss } }
655
+ });
656
+ const result = results.find(item => item.code === ResultCode.Ok);
657
+ return result || createResult(ResultCode.Warn, 'Leave not supported or failed', null);
658
+ }
659
+ catch {
660
+ return createResult(ResultCode.Fail, 'Failed to leave guild', null);
661
+ }
662
+ },
663
+ async mute(params) {
664
+ const gid = params.guildId || event.GuildId;
665
+ if (!gid) {
666
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
667
+ }
668
+ try {
669
+ const results = await sendAction({
670
+ action: 'guild.mute',
671
+ payload: { GuildId: gid, params: { enable: params.enable } }
672
+ });
673
+ const result = results.find(item => item.code === ResultCode.Ok);
674
+ return result || createResult(ResultCode.Warn, 'Mute not supported or failed', null);
675
+ }
676
+ catch {
677
+ return createResult(ResultCode.Fail, 'Failed to mute guild', null);
678
+ }
679
+ }
680
+ };
681
+ return [guild];
682
+ };
683
+ const useRole = (event) => {
684
+ if (!event || typeof event !== 'object') {
685
+ logger.error({
686
+ code: ResultCode.FailParams,
687
+ message: 'Invalid event: event must be an object',
688
+ data: null
689
+ });
690
+ throw new Error('Invalid event: event must be an object');
691
+ }
692
+ const getGuildId = (guildId) => guildId || event.GuildId;
693
+ const list = async (params) => {
694
+ const gid = getGuildId(params?.guildId);
695
+ if (!gid) {
696
+ return createResult(ResultCode.FailParams, 'Missing GuildId', []);
697
+ }
698
+ try {
699
+ const results = await sendAction({
700
+ action: 'role.list',
701
+ payload: { GuildId: gid }
702
+ });
703
+ const result = results.find(item => item.code === ResultCode.Ok);
704
+ if (result) {
705
+ return createResult(ResultCode.Ok, 'Successfully retrieved role list', result.data ?? []);
706
+ }
707
+ return createResult(ResultCode.Warn, 'No role list found', []);
708
+ }
709
+ catch {
710
+ return createResult(ResultCode.Fail, 'Failed to get role list', []);
711
+ }
712
+ };
713
+ const create = async (params) => {
714
+ const gid = getGuildId(params.guildId);
715
+ if (!gid) {
716
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
717
+ }
718
+ try {
719
+ const results = await sendAction({
720
+ action: 'role.create',
721
+ payload: { GuildId: gid, params: { name: params.name, color: params.color, permissions: params.permissions } }
722
+ });
723
+ const result = results.find(item => item.code === ResultCode.Ok);
724
+ return result ? createResult(ResultCode.Ok, 'Role created', result.data ?? null) : createResult(ResultCode.Warn, 'Create not supported or failed', null);
725
+ }
726
+ catch {
727
+ return createResult(ResultCode.Fail, 'Failed to create role', null);
728
+ }
729
+ };
730
+ const update = async (params) => {
731
+ const gid = getGuildId(params.guildId);
732
+ if (!gid || !params.roleId) {
733
+ return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
734
+ }
735
+ try {
736
+ const results = await sendAction({
737
+ action: 'role.update',
738
+ payload: { GuildId: gid, RoleId: params.roleId, params: { name: params.name, color: params.color, permissions: params.permissions } }
739
+ });
740
+ const result = results.find(item => item.code === ResultCode.Ok);
741
+ return result || createResult(ResultCode.Warn, 'Update not supported or failed', null);
742
+ }
743
+ catch {
744
+ return createResult(ResultCode.Fail, 'Failed to update role', null);
745
+ }
746
+ };
747
+ const remove = async (params) => {
748
+ const gid = getGuildId(params.guildId);
749
+ if (!gid || !params.roleId) {
750
+ return createResult(ResultCode.FailParams, 'Missing GuildId or RoleId', null);
751
+ }
752
+ try {
753
+ const results = await sendAction({
754
+ action: 'role.delete',
755
+ payload: { GuildId: gid, RoleId: params.roleId }
756
+ });
757
+ const result = results.find(item => item.code === ResultCode.Ok);
758
+ return result || createResult(ResultCode.Warn, 'Delete not supported or failed', null);
759
+ }
760
+ catch {
761
+ return createResult(ResultCode.Fail, 'Failed to delete role', null);
762
+ }
763
+ };
764
+ const assign = async (params) => {
765
+ const gid = getGuildId(params.guildId);
766
+ if (!gid || !params.userId || !params.roleId) {
767
+ return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
768
+ }
769
+ try {
770
+ const results = await sendAction({
771
+ action: 'role.assign',
772
+ payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
773
+ });
774
+ const result = results.find(item => item.code === ResultCode.Ok);
775
+ return result || createResult(ResultCode.Warn, 'Assign not supported or failed', null);
776
+ }
777
+ catch {
778
+ return createResult(ResultCode.Fail, 'Failed to assign role', null);
779
+ }
780
+ };
781
+ const revoke = async (params) => {
782
+ const gid = getGuildId(params.guildId);
783
+ if (!gid || !params.userId || !params.roleId) {
784
+ return createResult(ResultCode.FailParams, 'Missing GuildId, UserId or RoleId', null);
785
+ }
786
+ try {
787
+ const results = await sendAction({
788
+ action: 'role.remove',
789
+ payload: { GuildId: gid, UserId: params.userId, RoleId: params.roleId }
790
+ });
791
+ const result = results.find(item => item.code === ResultCode.Ok);
792
+ return result || createResult(ResultCode.Warn, 'Remove not supported or failed', null);
793
+ }
794
+ catch {
795
+ return createResult(ResultCode.Fail, 'Failed to remove role', null);
796
+ }
797
+ };
798
+ const role = {
799
+ list,
800
+ create,
801
+ update,
802
+ delete: remove,
803
+ assign,
804
+ remove: revoke
805
+ };
806
+ return [role];
807
+ };
808
+ const useReaction = (event) => {
809
+ if (!event || typeof event !== 'object') {
810
+ logger.error({
811
+ code: ResultCode.FailParams,
812
+ message: 'Invalid event: event must be an object',
813
+ data: null
814
+ });
815
+ throw new Error('Invalid event: event must be an object');
816
+ }
817
+ const add = async (params) => {
818
+ const mid = params.messageId || event.MessageId;
819
+ const cid = event.ChannelId;
820
+ if (!mid || !cid || !params.emojiId) {
821
+ return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
822
+ }
823
+ try {
824
+ const results = await sendAction({
825
+ action: 'reaction.add',
826
+ payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
827
+ });
828
+ const result = results.find(item => item.code === ResultCode.Ok);
829
+ return result || createResult(ResultCode.Warn, 'Reaction add not supported or failed', null);
830
+ }
831
+ catch {
832
+ return createResult(ResultCode.Fail, 'Failed to add reaction', null);
833
+ }
834
+ };
835
+ const remove = async (params) => {
836
+ const mid = params.messageId || event.MessageId;
837
+ const cid = event.ChannelId;
838
+ if (!mid || !cid || !params.emojiId) {
839
+ return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
840
+ }
841
+ try {
842
+ const results = await sendAction({
843
+ action: 'reaction.remove',
844
+ payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId }
845
+ });
846
+ const result = results.find(item => item.code === ResultCode.Ok);
847
+ return result || createResult(ResultCode.Warn, 'Reaction remove not supported or failed', null);
848
+ }
849
+ catch {
850
+ return createResult(ResultCode.Fail, 'Failed to remove reaction', null);
851
+ }
852
+ };
853
+ const list = async (params) => {
854
+ const mid = params.messageId || event.MessageId;
855
+ const cid = event.ChannelId;
856
+ if (!mid || !cid || !params.emojiId) {
857
+ return createResult(ResultCode.FailParams, 'Missing ChannelId, MessageId or EmojiId', null);
858
+ }
859
+ try {
860
+ const results = await sendAction({
861
+ action: 'reaction.list',
862
+ payload: { ChannelId: cid, MessageId: mid, EmojiId: params.emojiId, params: { limit: params.limit } }
863
+ });
864
+ const result = results.find(item => item.code === ResultCode.Ok);
865
+ return result || createResult(ResultCode.Warn, 'Reaction list not supported or failed', null);
866
+ }
867
+ catch {
868
+ return createResult(ResultCode.Fail, 'Failed to list reactions', null);
869
+ }
870
+ };
871
+ const reaction = {
872
+ add,
873
+ remove,
874
+ list
875
+ };
876
+ return [reaction];
877
+ };
231
878
  const useMe = () => {
232
879
  const info = async () => {
233
880
  try {
@@ -254,13 +901,12 @@ const useMe = () => {
254
901
  });
255
902
  const result = results.find(item => item.code === ResultCode.Ok);
256
903
  if (result) {
257
- const data = result?.data ?? null;
258
- return createResult(ResultCode.Ok, 'Successfully retrieved bot information', data);
904
+ return createResult(ResultCode.Ok, 'Successfully retrieved guild list', result.data ?? []);
259
905
  }
260
- return createResult(ResultCode.Warn, 'No bot information found', null);
906
+ return createResult(ResultCode.Warn, 'No guild list found', []);
261
907
  }
262
908
  catch {
263
- return createResult(ResultCode.Fail, 'Failed to get bot information', null);
909
+ return createResult(ResultCode.Fail, 'Failed to get guild list', []);
264
910
  }
265
911
  };
266
912
  const threads = async () => {
@@ -305,5 +951,260 @@ const useMe = () => {
305
951
  };
306
952
  return [control];
307
953
  };
954
+ const useRequest = () => {
955
+ const friend = async (params) => {
956
+ if (!params.flag) {
957
+ return createResult(ResultCode.FailParams, 'Missing flag', null);
958
+ }
959
+ try {
960
+ const results = await sendAction({
961
+ action: 'request.friend',
962
+ payload: { params: { flag: params.flag, approve: params.approve, remark: params.remark } }
963
+ });
964
+ const result = results.find(item => item.code === ResultCode.Ok);
965
+ return result || createResult(ResultCode.Warn, 'Friend request handling not supported or failed', null);
966
+ }
967
+ catch {
968
+ return createResult(ResultCode.Fail, 'Failed to handle friend request', null);
969
+ }
970
+ };
971
+ const guild = async (params) => {
972
+ if (!params.flag || !params.subType) {
973
+ return createResult(ResultCode.FailParams, 'Missing flag or subType', null);
974
+ }
975
+ try {
976
+ const results = await sendAction({
977
+ action: 'request.guild',
978
+ payload: { params: { flag: params.flag, subType: params.subType, approve: params.approve, reason: params.reason } }
979
+ });
980
+ const result = results.find(item => item.code === ResultCode.Ok);
981
+ return result || createResult(ResultCode.Warn, 'Guild request handling not supported or failed', null);
982
+ }
983
+ catch {
984
+ return createResult(ResultCode.Fail, 'Failed to handle guild request', null);
985
+ }
986
+ };
987
+ const request = {
988
+ friend,
989
+ guild
990
+ };
991
+ return [request];
992
+ };
993
+ const useUser = () => {
994
+ const info = async (params) => {
995
+ if (!params.userId) {
996
+ return createResult(ResultCode.FailParams, 'Missing UserId', null);
997
+ }
998
+ try {
999
+ const results = await sendAction({
1000
+ action: 'user.info',
1001
+ payload: { UserId: params.userId }
1002
+ });
1003
+ const result = results.find(item => item.code === ResultCode.Ok);
1004
+ if (result) {
1005
+ return createResult(ResultCode.Ok, 'Successfully retrieved user info', result.data ?? null);
1006
+ }
1007
+ return createResult(ResultCode.Warn, 'No user info found', null);
1008
+ }
1009
+ catch {
1010
+ return createResult(ResultCode.Fail, 'Failed to get user info', null);
1011
+ }
1012
+ };
1013
+ const user = {
1014
+ info
1015
+ };
1016
+ return [user];
1017
+ };
1018
+ const useMedia = (event) => {
1019
+ if (!event || typeof event !== 'object') {
1020
+ logger.error({
1021
+ code: ResultCode.FailParams,
1022
+ message: 'Invalid event: event must be an object',
1023
+ data: null
1024
+ });
1025
+ throw new Error('Invalid event: event must be an object');
1026
+ }
1027
+ const upload = async (params) => {
1028
+ try {
1029
+ const results = await sendAction({
1030
+ action: 'media.upload',
1031
+ payload: { params }
1032
+ });
1033
+ const result = results.find(item => item.code === ResultCode.Ok);
1034
+ return result || createResult(ResultCode.Warn, 'Media upload not supported or failed', null);
1035
+ }
1036
+ catch {
1037
+ return createResult(ResultCode.Fail, 'Failed to upload media', null);
1038
+ }
1039
+ };
1040
+ const sendChannel = async (params) => {
1041
+ const cid = params.channelId || event.ChannelId;
1042
+ if (!cid) {
1043
+ return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
1044
+ }
1045
+ try {
1046
+ const results = await sendAction({
1047
+ action: 'media.send.channel',
1048
+ payload: { ChannelId: cid, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
1049
+ });
1050
+ const result = results.find(item => item.code === ResultCode.Ok);
1051
+ return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
1052
+ }
1053
+ catch {
1054
+ return createResult(ResultCode.Fail, 'Failed to send media to channel', null);
1055
+ }
1056
+ };
1057
+ const sendUser = async (params) => {
1058
+ if (!params.userId) {
1059
+ return createResult(ResultCode.FailParams, 'Missing UserId', null);
1060
+ }
1061
+ try {
1062
+ const results = await sendAction({
1063
+ action: 'media.send.user',
1064
+ payload: { UserId: params.userId, params: { type: params.type, url: params.url, data: params.data, name: params.name } }
1065
+ });
1066
+ const result = results.find(item => item.code === ResultCode.Ok);
1067
+ return result || createResult(ResultCode.Warn, 'Media send not supported or failed', null);
1068
+ }
1069
+ catch {
1070
+ return createResult(ResultCode.Fail, 'Failed to send media to user', null);
1071
+ }
1072
+ };
1073
+ const media = {
1074
+ upload,
1075
+ sendChannel,
1076
+ sendUser
1077
+ };
1078
+ return [media];
1079
+ };
1080
+ const useHistory = (event) => {
1081
+ if (!event || typeof event !== 'object') {
1082
+ logger.error({
1083
+ code: ResultCode.FailParams,
1084
+ message: 'Invalid event: event must be an object',
1085
+ data: null
1086
+ });
1087
+ throw new Error('Invalid event: event must be an object');
1088
+ }
1089
+ const list = async (params) => {
1090
+ const cid = params?.channelId || event.ChannelId;
1091
+ if (!cid) {
1092
+ return createResult(ResultCode.FailParams, 'Missing ChannelId', null);
1093
+ }
1094
+ try {
1095
+ const results = await sendAction({
1096
+ action: 'history.list',
1097
+ payload: { ChannelId: cid, params: { limit: params?.limit, before: params?.before, after: params?.after } }
1098
+ });
1099
+ const result = results.find(item => item.code === ResultCode.Ok);
1100
+ return result || createResult(ResultCode.Warn, 'History list not supported or failed', null);
1101
+ }
1102
+ catch {
1103
+ return createResult(ResultCode.Fail, 'Failed to get message history', null);
1104
+ }
1105
+ };
1106
+ const history = {
1107
+ list
1108
+ };
1109
+ return [history];
1110
+ };
1111
+ const usePermission = (event) => {
1112
+ if (!event || typeof event !== 'object') {
1113
+ logger.error({
1114
+ code: ResultCode.FailParams,
1115
+ message: 'Invalid event: event must be an object',
1116
+ data: null
1117
+ });
1118
+ throw new Error('Invalid event: event must be an object');
1119
+ }
1120
+ const get = async (params) => {
1121
+ const cid = params.channelId || event.ChannelId;
1122
+ if (!cid || !params.userId) {
1123
+ return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
1124
+ }
1125
+ try {
1126
+ const results = await sendAction({
1127
+ action: 'permission.get',
1128
+ payload: { ChannelId: cid, UserId: params.userId }
1129
+ });
1130
+ const result = results.find(item => item.code === ResultCode.Ok);
1131
+ return result || createResult(ResultCode.Warn, 'Permission get not supported or failed', null);
1132
+ }
1133
+ catch {
1134
+ return createResult(ResultCode.Fail, 'Failed to get permission', null);
1135
+ }
1136
+ };
1137
+ const set = async (params) => {
1138
+ const cid = params.channelId || event.ChannelId;
1139
+ if (!cid || !params.userId) {
1140
+ return createResult(ResultCode.FailParams, 'Missing ChannelId or UserId', null);
1141
+ }
1142
+ try {
1143
+ const results = await sendAction({
1144
+ action: 'permission.set',
1145
+ payload: { ChannelId: cid, UserId: params.userId, params: { allow: params.allow, deny: params.deny } }
1146
+ });
1147
+ const result = results.find(item => item.code === ResultCode.Ok);
1148
+ return result || createResult(ResultCode.Warn, 'Permission set not supported or failed', null);
1149
+ }
1150
+ catch {
1151
+ return createResult(ResultCode.Fail, 'Failed to set permission', null);
1152
+ }
1153
+ };
1154
+ const permission = {
1155
+ get,
1156
+ set
1157
+ };
1158
+ return [permission];
1159
+ };
1160
+ const useAnnounce = (event) => {
1161
+ if (!event || typeof event !== 'object') {
1162
+ logger.error({
1163
+ code: ResultCode.FailParams,
1164
+ message: 'Invalid event: event must be an object',
1165
+ data: null
1166
+ });
1167
+ throw new Error('Invalid event: event must be an object');
1168
+ }
1169
+ const set = async (params) => {
1170
+ const gid = params.guildId || event.GuildId;
1171
+ if (!gid || !params.messageId) {
1172
+ return createResult(ResultCode.FailParams, 'Missing GuildId or MessageId', null);
1173
+ }
1174
+ try {
1175
+ const results = await sendAction({
1176
+ action: 'channel.announce',
1177
+ payload: { GuildId: gid, params: { messageId: params.messageId, channelId: params.channelId } }
1178
+ });
1179
+ const result = results.find(item => item.code === ResultCode.Ok);
1180
+ return result || createResult(ResultCode.Warn, 'Announce set not supported or failed', null);
1181
+ }
1182
+ catch {
1183
+ return createResult(ResultCode.Fail, 'Failed to set announcement', null);
1184
+ }
1185
+ };
1186
+ const remove = async (params) => {
1187
+ const gid = params?.guildId || event.GuildId;
1188
+ if (!gid) {
1189
+ return createResult(ResultCode.FailParams, 'Missing GuildId', null);
1190
+ }
1191
+ try {
1192
+ const results = await sendAction({
1193
+ action: 'channel.announce',
1194
+ payload: { GuildId: gid, params: { messageId: params?.messageId || 'all', remove: true } }
1195
+ });
1196
+ const result = results.find(item => item.code === ResultCode.Ok);
1197
+ return result || createResult(ResultCode.Warn, 'Announce remove not supported or failed', null);
1198
+ }
1199
+ catch {
1200
+ return createResult(ResultCode.Fail, 'Failed to remove announcement', null);
1201
+ }
1202
+ };
1203
+ const announce = {
1204
+ set,
1205
+ remove
1206
+ };
1207
+ return [announce];
1208
+ };
308
1209
 
309
- export { createSelects, onSelects, unChildren, useChannel, useClient, useMe, useMember, useMention, useMessage, useSend, useSends };
1210
+ export { createSelects, onSelects, unChildren, useAnnounce, useChannel, useClient, useGuild, useHistory, useMe, useMedia, useMember, useMention, useMessage, usePermission, useReaction, useRequest, useRole, useSend, useSends, useUser };