@alemonjs/kook 2.1.4 → 2.1.6
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.
- package/LICENSE +21 -0
- package/dist/assets/index.js +3 -3
- package/lib/config.d.ts +1 -1
- package/lib/config.js +6 -3
- package/lib/core/config.js +3 -1
- package/lib/format.js +55 -65
- package/lib/index.js +274 -1
- package/lib/sdk/api.d.ts +78 -0
- package/lib/sdk/api.js +153 -0
- package/lib/sdk/wss.js +0 -1
- package/package.json +4 -3
package/lib/config.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export type Options = {
|
|
|
6
6
|
hideUnsupported?: boolean | number;
|
|
7
7
|
};
|
|
8
8
|
export declare const getKOOKConfig: () => Options;
|
|
9
|
-
export declare const getMaster: (UserId: string) => readonly [
|
|
9
|
+
export declare const getMaster: (UserId: string) => readonly [any, string];
|
package/lib/config.js
CHANGED
|
@@ -6,14 +6,17 @@ const getKOOKConfig = () => {
|
|
|
6
6
|
return value[platform] || {};
|
|
7
7
|
};
|
|
8
8
|
const getMaster = (UserId) => {
|
|
9
|
+
const values = getConfigValue() || {};
|
|
10
|
+
const mainMasterKey = values.master_key || [];
|
|
11
|
+
const mainMasterId = values.master_id || [];
|
|
9
12
|
const config = getKOOKConfig();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
13
|
+
const masterKey = config.master_key || [];
|
|
14
|
+
const masterId = config.master_id || [];
|
|
12
15
|
const UserKey = useUserHashKey({
|
|
13
16
|
Platform: platform,
|
|
14
17
|
UserId: UserId
|
|
15
18
|
});
|
|
16
|
-
const is =
|
|
19
|
+
const is = mainMasterKey.includes(UserKey) || mainMasterId.includes(UserId) || masterKey.includes(UserKey) || masterId.includes(UserId);
|
|
17
20
|
return [is, UserKey];
|
|
18
21
|
};
|
|
19
22
|
|
package/lib/core/config.js
CHANGED
package/lib/format.js
CHANGED
|
@@ -1,79 +1,69 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const v = item.value;
|
|
22
|
-
if (Number(hideUnsupported) >= 3)
|
|
23
|
-
return '';
|
|
24
|
-
return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
|
|
25
|
-
}
|
|
26
|
-
case 'MD.image':
|
|
27
|
-
return hideUnsupported ? '' : '[图片]';
|
|
28
|
-
case 'MD.list':
|
|
29
|
-
return (item.value
|
|
30
|
-
.map(li => {
|
|
31
|
-
if (typeof li.value === 'object') {
|
|
32
|
-
return `${li.value.index}. ${li.value.text ?? ''}`;
|
|
33
|
-
}
|
|
34
|
-
return `- ${li.value}`;
|
|
35
|
-
})
|
|
36
|
-
.join('\n') + '\n');
|
|
37
|
-
case 'MD.blockquote':
|
|
38
|
-
return `> ${item.value}\n`;
|
|
39
|
-
case 'MD.divider':
|
|
40
|
-
return hideUnsupported ? '' : '---\n';
|
|
41
|
-
case 'MD.newline':
|
|
42
|
-
return '\n';
|
|
43
|
-
case 'MD.code': {
|
|
44
|
-
const lang = item?.options?.language || '';
|
|
45
|
-
return `\`\`\`${lang}\n${item.value}\n\`\`\`\n`;
|
|
46
|
-
}
|
|
47
|
-
case 'MD.mention':
|
|
48
|
-
if (item.value === 'everyone') {
|
|
49
|
-
return '(met)all(met)';
|
|
50
|
-
}
|
|
51
|
-
return `(met)${item.value ?? ''}(met)`;
|
|
52
|
-
case 'MD.content':
|
|
53
|
-
return item.value;
|
|
54
|
-
case 'MD.button':
|
|
55
|
-
if (Number(hideUnsupported) >= 3)
|
|
56
|
-
return '';
|
|
57
|
-
if (Number(hideUnsupported) >= 2) {
|
|
58
|
-
return item.options?.data || String(item.value);
|
|
59
|
-
}
|
|
60
|
-
return hideUnsupported ? String(item.value) : `[${item.value}]`;
|
|
61
|
-
default:
|
|
62
|
-
return String(item?.value ?? '');
|
|
1
|
+
const mardownMap = {
|
|
2
|
+
'MD.text': (item) => item.value,
|
|
3
|
+
'MD.title': (item) => `**${item.value}**\n`,
|
|
4
|
+
'MD.subtitle': (item) => `**${item.value}**\n`,
|
|
5
|
+
'MD.bold': (item) => `**${item.value}**`,
|
|
6
|
+
'MD.italic': (item) => `*${item.value}*`,
|
|
7
|
+
'MD.italicStar': (item) => `*${item.value}*`,
|
|
8
|
+
'MD.strikethrough': (item) => `~~${item.value}~~`,
|
|
9
|
+
'MD.link': (item, hideUnsupported) => {
|
|
10
|
+
const v = item.value;
|
|
11
|
+
if (Number(hideUnsupported) >= 3) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
return Number(hideUnsupported) >= 2 ? v.url : `[${v.text}](${v.url})`;
|
|
15
|
+
},
|
|
16
|
+
'MD.image': (_, hideUnsupported) => (hideUnsupported ? '' : '[图片]'),
|
|
17
|
+
'MD.list': (item) => item.value
|
|
18
|
+
.map((li) => {
|
|
19
|
+
if (typeof li.value === 'object') {
|
|
20
|
+
return `${li.value.index}. ${li.value.text ?? ''}`;
|
|
63
21
|
}
|
|
22
|
+
return `- ${li.value}`;
|
|
64
23
|
})
|
|
65
|
-
.join('')
|
|
24
|
+
.join('\n') + '\n',
|
|
25
|
+
'MD.blockquote': (item) => `> ${item.value}\n`,
|
|
26
|
+
'MD.divider': (_, hideUnsupported) => (hideUnsupported ? '' : '\n---\n'),
|
|
27
|
+
'MD.newline': () => '\n',
|
|
28
|
+
'MD.code': (item) => {
|
|
29
|
+
const lang = item?.options?.language || '';
|
|
30
|
+
return `\`\`\`${lang}\n${item.value}\n\`\`\`\n`;
|
|
31
|
+
},
|
|
32
|
+
'MD.mention': (item) => {
|
|
33
|
+
if (item.value === 'everyone') {
|
|
34
|
+
return '(met)all(met)';
|
|
35
|
+
}
|
|
36
|
+
return '';
|
|
37
|
+
},
|
|
38
|
+
'MD.content': (item) => item.value,
|
|
39
|
+
'MD.button': (item, hideUnsupported) => {
|
|
40
|
+
if (Number(hideUnsupported) >= 3) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
if (Number(hideUnsupported) >= 2) {
|
|
44
|
+
return item.options?.data || String(item.value);
|
|
45
|
+
}
|
|
46
|
+
return hideUnsupported ? String(item.value) : `[${item.value}]`;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const markdownToKMarkdown = (items, hideUnsupported) => {
|
|
50
|
+
if (Number(hideUnsupported) >= 4) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
return items.map(item => (mardownMap[item.type] ? mardownMap[item.type](item, hideUnsupported) : '')).join('');
|
|
66
54
|
};
|
|
67
55
|
const markdownRawToKMarkdown = (raw, hideUnsupported) => {
|
|
68
|
-
if (Number(hideUnsupported) >= 4)
|
|
56
|
+
if (Number(hideUnsupported) >= 4) {
|
|
69
57
|
return '';
|
|
58
|
+
}
|
|
70
59
|
let text = raw;
|
|
71
60
|
text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
|
|
72
61
|
return text;
|
|
73
62
|
};
|
|
74
63
|
const dataEnumToKMarkdown = (item, hideUnsupported) => {
|
|
75
|
-
if (Number(hideUnsupported) >= 4)
|
|
64
|
+
if (Number(hideUnsupported) >= 4) {
|
|
76
65
|
return '';
|
|
66
|
+
}
|
|
77
67
|
switch (item.type) {
|
|
78
68
|
case 'Markdown':
|
|
79
69
|
return markdownToKMarkdown(item.value, hideUnsupported);
|
package/lib/index.js
CHANGED
|
@@ -380,7 +380,10 @@ const main = () => {
|
|
|
380
380
|
.filter(Boolean)
|
|
381
381
|
.join('')
|
|
382
382
|
: '';
|
|
383
|
-
return [nativeText, fallbackText]
|
|
383
|
+
return [nativeText, fallbackText]
|
|
384
|
+
.filter(Boolean)
|
|
385
|
+
.join('')
|
|
386
|
+
.replace(/^[^\S\n\r]+|[^\S\n\r]+$/g, '');
|
|
384
387
|
};
|
|
385
388
|
const resolveImageBuffer = async (val) => {
|
|
386
389
|
const images = val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
@@ -607,6 +610,276 @@ const main = () => {
|
|
|
607
610
|
const res = await api.use.mention(event);
|
|
608
611
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
609
612
|
}
|
|
613
|
+
else if (data.action === 'me.info') {
|
|
614
|
+
const res = await client
|
|
615
|
+
.userMe()
|
|
616
|
+
.then(r => {
|
|
617
|
+
const d = r?.data ?? r;
|
|
618
|
+
const [isMaster, UserKey] = getMaster(String(d?.id));
|
|
619
|
+
return createResult(ResultCode.Ok, data.action, {
|
|
620
|
+
UserId: String(d?.id),
|
|
621
|
+
UserName: d?.username,
|
|
622
|
+
UserAvatar: d?.avatar ?? '',
|
|
623
|
+
IsBot: true,
|
|
624
|
+
IsMaster: isMaster,
|
|
625
|
+
UserKey
|
|
626
|
+
});
|
|
627
|
+
})
|
|
628
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
629
|
+
consume([res]);
|
|
630
|
+
}
|
|
631
|
+
else if (data.action === 'message.delete') {
|
|
632
|
+
const messageId = data.payload.MessageId;
|
|
633
|
+
const res = await client
|
|
634
|
+
.messageDelete(messageId)
|
|
635
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
636
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
637
|
+
consume([res]);
|
|
638
|
+
}
|
|
639
|
+
else if (data.action === 'message.edit') {
|
|
640
|
+
const messageId = data.payload.MessageId;
|
|
641
|
+
const format = data.payload.params?.format;
|
|
642
|
+
const content = format?.map(i => i.value).join('') ?? '';
|
|
643
|
+
const res = await client
|
|
644
|
+
.messageUpdate({ msg_id: messageId, content })
|
|
645
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
646
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
647
|
+
consume([res]);
|
|
648
|
+
}
|
|
649
|
+
else if (data.action === 'reaction.add') {
|
|
650
|
+
const res = await client
|
|
651
|
+
.messageAddReaction({ msg_id: data.payload.MessageId, emoji: data.payload.EmojiId })
|
|
652
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
653
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
654
|
+
consume([res]);
|
|
655
|
+
}
|
|
656
|
+
else if (data.action === 'reaction.remove') {
|
|
657
|
+
const res = await client
|
|
658
|
+
.messageDeleteReaction({ msg_id: data.payload.MessageId, emoji: data.payload.EmojiId, user_id: '' })
|
|
659
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
660
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
661
|
+
consume([res]);
|
|
662
|
+
}
|
|
663
|
+
else if (data.action === 'member.info') {
|
|
664
|
+
const guildId = data.payload.params?.guildId ?? data.payload.GuildId;
|
|
665
|
+
const userId = data.payload.params?.userId ?? data.payload.UserId;
|
|
666
|
+
const res = await client
|
|
667
|
+
.userView(guildId, userId)
|
|
668
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
669
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
670
|
+
consume([res]);
|
|
671
|
+
}
|
|
672
|
+
else if (data.action === 'member.list') {
|
|
673
|
+
const guildId = data.payload.GuildId;
|
|
674
|
+
const res = await client
|
|
675
|
+
.guildUserList(guildId)
|
|
676
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
677
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
678
|
+
consume([res]);
|
|
679
|
+
}
|
|
680
|
+
else if (data.action === 'member.kick') {
|
|
681
|
+
const res = await client
|
|
682
|
+
.guildKickout(data.payload.GuildId, data.payload.UserId)
|
|
683
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
684
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
685
|
+
consume([res]);
|
|
686
|
+
}
|
|
687
|
+
else if (data.action === 'member.ban') {
|
|
688
|
+
const res = await client
|
|
689
|
+
.blacklistCreate({ guild_id: data.payload.GuildId, target_id: data.payload.UserId, remark: data.payload.params?.reason })
|
|
690
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
691
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
692
|
+
consume([res]);
|
|
693
|
+
}
|
|
694
|
+
else if (data.action === 'member.unban') {
|
|
695
|
+
const res = await client
|
|
696
|
+
.blacklistDelete({ guild_id: data.payload.GuildId, target_id: data.payload.UserId })
|
|
697
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
698
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
699
|
+
consume([res]);
|
|
700
|
+
}
|
|
701
|
+
else if (data.action === 'member.mute') {
|
|
702
|
+
const duration = data.payload.params?.duration ?? 0;
|
|
703
|
+
if (duration > 0) {
|
|
704
|
+
const res = await client
|
|
705
|
+
.guildMuteCreate(data.payload.GuildId, data.payload.UserId, 1)
|
|
706
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
707
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
708
|
+
consume([res]);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
const res = await client
|
|
712
|
+
.guildMuteDelete(data.payload.GuildId, data.payload.UserId, 1)
|
|
713
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
714
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
715
|
+
consume([res]);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
else if (data.action === 'member.card') {
|
|
719
|
+
const res = await client
|
|
720
|
+
.guildNickname(data.payload.GuildId, data.payload.params?.card ?? '', data.payload.UserId)
|
|
721
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
722
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
723
|
+
consume([res]);
|
|
724
|
+
}
|
|
725
|
+
else if (data.action === 'guild.info') {
|
|
726
|
+
const res = await client
|
|
727
|
+
.guildView(data.payload.GuildId)
|
|
728
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
729
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
730
|
+
consume([res]);
|
|
731
|
+
}
|
|
732
|
+
else if (data.action === 'guild.list') {
|
|
733
|
+
const res = await client
|
|
734
|
+
.guildList()
|
|
735
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
736
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
737
|
+
consume([res]);
|
|
738
|
+
}
|
|
739
|
+
else if (data.action === 'me.guilds') {
|
|
740
|
+
const res = await client
|
|
741
|
+
.guildList()
|
|
742
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
743
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
744
|
+
consume([res]);
|
|
745
|
+
}
|
|
746
|
+
else if (data.action === 'channel.info') {
|
|
747
|
+
const res = await client
|
|
748
|
+
.channelView(data.payload.ChannelId)
|
|
749
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
750
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
751
|
+
consume([res]);
|
|
752
|
+
}
|
|
753
|
+
else if (data.action === 'channel.list') {
|
|
754
|
+
const res = await client
|
|
755
|
+
.channelList(data.payload.GuildId)
|
|
756
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
757
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
758
|
+
consume([res]);
|
|
759
|
+
}
|
|
760
|
+
else if (data.action === 'channel.create') {
|
|
761
|
+
const params = data.payload.params;
|
|
762
|
+
const res = await client
|
|
763
|
+
.channelCreate({ guild_id: data.payload.GuildId, name: params.name, type: params.type ? Number(params.type) : 1, parent_id: params.parentId })
|
|
764
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
765
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
766
|
+
consume([res]);
|
|
767
|
+
}
|
|
768
|
+
else if (data.action === 'channel.update') {
|
|
769
|
+
const params = data.payload.params;
|
|
770
|
+
const res = await client
|
|
771
|
+
.channelUpdate({ channel_id: data.payload.ChannelId, name: params.name, topic: params.topic })
|
|
772
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
773
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
774
|
+
consume([res]);
|
|
775
|
+
}
|
|
776
|
+
else if (data.action === 'channel.delete') {
|
|
777
|
+
const res = await client
|
|
778
|
+
.channelDelete(data.payload.ChannelId)
|
|
779
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
780
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
781
|
+
consume([res]);
|
|
782
|
+
}
|
|
783
|
+
else if (data.action === 'role.list') {
|
|
784
|
+
const res = await client
|
|
785
|
+
.guildRoleList(data.payload.GuildId)
|
|
786
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
787
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
788
|
+
consume([res]);
|
|
789
|
+
}
|
|
790
|
+
else if (data.action === 'role.create') {
|
|
791
|
+
const params = data.payload.params;
|
|
792
|
+
const res = await client
|
|
793
|
+
.guildRoleCreate({ guild_id: data.payload.GuildId, name: params.name })
|
|
794
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
795
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
796
|
+
consume([res]);
|
|
797
|
+
}
|
|
798
|
+
else if (data.action === 'role.update') {
|
|
799
|
+
const params = data.payload.params;
|
|
800
|
+
const res = await client
|
|
801
|
+
.guildRoleUpdate({ guild_id: data.payload.GuildId, role_id: Number(data.payload.RoleId), name: params.name, color: params.color })
|
|
802
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
803
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
804
|
+
consume([res]);
|
|
805
|
+
}
|
|
806
|
+
else if (data.action === 'role.delete') {
|
|
807
|
+
const res = await client
|
|
808
|
+
.guildRoleDelete({ guild_id: data.payload.GuildId, role_id: Number(data.payload.RoleId) })
|
|
809
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
810
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
811
|
+
consume([res]);
|
|
812
|
+
}
|
|
813
|
+
else if (data.action === 'role.assign') {
|
|
814
|
+
const res = await client
|
|
815
|
+
.guildRoleGrant({ guild_id: data.payload.GuildId, user_id: data.payload.UserId, role_id: Number(data.payload.RoleId) })
|
|
816
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
817
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
818
|
+
consume([res]);
|
|
819
|
+
}
|
|
820
|
+
else if (data.action === 'role.remove') {
|
|
821
|
+
const res = await client
|
|
822
|
+
.guildRoleRevoke({ guild_id: data.payload.GuildId, user_id: data.payload.UserId, role_id: Number(data.payload.RoleId) })
|
|
823
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
824
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
825
|
+
consume([res]);
|
|
826
|
+
}
|
|
827
|
+
else if (data.action === 'message.get') {
|
|
828
|
+
const res = await client
|
|
829
|
+
.messageView(data.payload.MessageId)
|
|
830
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
831
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
832
|
+
consume([res]);
|
|
833
|
+
}
|
|
834
|
+
else if (data.action === 'guild.leave') {
|
|
835
|
+
const res = await client
|
|
836
|
+
.guildLeave(data.payload.GuildId)
|
|
837
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
838
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
839
|
+
consume([res]);
|
|
840
|
+
}
|
|
841
|
+
else if (data.action === 'user.info') {
|
|
842
|
+
const res = await client
|
|
843
|
+
.userView(data.payload.GuildId ?? '', data.payload.UserId)
|
|
844
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
845
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
846
|
+
consume([res]);
|
|
847
|
+
}
|
|
848
|
+
else if (data.action === 'media.upload') {
|
|
849
|
+
const params = data.payload.params;
|
|
850
|
+
const fileData = params?.url ?? params?.data;
|
|
851
|
+
if (!fileData) {
|
|
852
|
+
consume([createResult(ResultCode.FailParams, 'Missing url or data', null)]);
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
const res = await client
|
|
856
|
+
.postImage(fileData, params?.name)
|
|
857
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
858
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
859
|
+
consume([res]);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
else if (data.action === 'history.list') {
|
|
863
|
+
const res = await client
|
|
864
|
+
.messageList(data.payload.ChannelId, { page_size: data.payload.params?.limit })
|
|
865
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
866
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
867
|
+
consume([res]);
|
|
868
|
+
}
|
|
869
|
+
else if (data.action === 'reaction.list') {
|
|
870
|
+
const res = await client
|
|
871
|
+
.messageReactionList({ msg_id: data.payload.MessageId, emoji: data.payload.EmojiId })
|
|
872
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
873
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
874
|
+
consume([res]);
|
|
875
|
+
}
|
|
876
|
+
else if (data.action === 'member.search') {
|
|
877
|
+
const res = await client
|
|
878
|
+
.guildUserList(data.payload.GuildId, { search: data.payload.params?.keyword, page_size: data.payload.params?.limit })
|
|
879
|
+
.then(r => createResult(ResultCode.Ok, data.action, r?.data ?? r))
|
|
880
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
881
|
+
consume([res]);
|
|
882
|
+
}
|
|
610
883
|
else {
|
|
611
884
|
consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
|
|
612
885
|
}
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -79,6 +79,12 @@ export declare class KOOKAPI {
|
|
|
79
79
|
message: string;
|
|
80
80
|
data: any[];
|
|
81
81
|
}>;
|
|
82
|
+
messageList(target_id: string, params?: {
|
|
83
|
+
msg_id?: string;
|
|
84
|
+
pin?: number;
|
|
85
|
+
flag?: string;
|
|
86
|
+
page_size?: number;
|
|
87
|
+
}): Promise<any>;
|
|
82
88
|
messageAddReaction(data: {
|
|
83
89
|
msg_id: string;
|
|
84
90
|
emoji: string;
|
|
@@ -157,4 +163,76 @@ export declare class KOOKAPI {
|
|
|
157
163
|
message: string;
|
|
158
164
|
data: any;
|
|
159
165
|
}>;
|
|
166
|
+
guildList(): Promise<any>;
|
|
167
|
+
guildView(guild_id: string): Promise<any>;
|
|
168
|
+
guildUserList(guild_id: string, params?: {
|
|
169
|
+
channel_id?: string;
|
|
170
|
+
search?: string;
|
|
171
|
+
role_id?: number;
|
|
172
|
+
mobile_verified?: number;
|
|
173
|
+
active_time?: number;
|
|
174
|
+
joined_at?: number;
|
|
175
|
+
page?: number;
|
|
176
|
+
page_size?: number;
|
|
177
|
+
}): Promise<any>;
|
|
178
|
+
guildLeave(guild_id: string): Promise<any>;
|
|
179
|
+
guildNickname(guild_id: string, nickname: string, user_id?: string): Promise<any>;
|
|
180
|
+
guildMuteCreate(guild_id: string, user_id: string, type: 1 | 2): Promise<any>;
|
|
181
|
+
guildMuteDelete(guild_id: string, user_id: string, type: 1 | 2): Promise<any>;
|
|
182
|
+
messageView(msg_id: string): Promise<any>;
|
|
183
|
+
channelList(guild_id: string): Promise<any>;
|
|
184
|
+
channelView(channel_id: string): Promise<any>;
|
|
185
|
+
channelCreate(data: {
|
|
186
|
+
guild_id: string;
|
|
187
|
+
name: string;
|
|
188
|
+
type?: number;
|
|
189
|
+
parent_id?: string;
|
|
190
|
+
limit_amount?: number;
|
|
191
|
+
voice_quality?: string;
|
|
192
|
+
}): Promise<any>;
|
|
193
|
+
channelUpdate(data: {
|
|
194
|
+
channel_id: string;
|
|
195
|
+
name?: string;
|
|
196
|
+
topic?: string;
|
|
197
|
+
slow_mode?: number;
|
|
198
|
+
}): Promise<any>;
|
|
199
|
+
channelDelete(channel_id: string): Promise<any>;
|
|
200
|
+
guildRoleList(guild_id: string): Promise<any>;
|
|
201
|
+
guildRoleCreate(data: {
|
|
202
|
+
guild_id: string;
|
|
203
|
+
name?: string;
|
|
204
|
+
}): Promise<any>;
|
|
205
|
+
guildRoleUpdate(data: {
|
|
206
|
+
guild_id: string;
|
|
207
|
+
role_id: number;
|
|
208
|
+
name?: string;
|
|
209
|
+
color?: number;
|
|
210
|
+
hoist?: 0 | 1;
|
|
211
|
+
mentionable?: 0 | 1;
|
|
212
|
+
permissions?: number;
|
|
213
|
+
}): Promise<any>;
|
|
214
|
+
guildRoleDelete(data: {
|
|
215
|
+
guild_id: string;
|
|
216
|
+
role_id: number;
|
|
217
|
+
}): Promise<any>;
|
|
218
|
+
guildRoleGrant(data: {
|
|
219
|
+
guild_id: string;
|
|
220
|
+
user_id: string;
|
|
221
|
+
role_id: number;
|
|
222
|
+
}): Promise<any>;
|
|
223
|
+
guildRoleRevoke(data: {
|
|
224
|
+
guild_id: string;
|
|
225
|
+
user_id: string;
|
|
226
|
+
role_id: number;
|
|
227
|
+
}): Promise<any>;
|
|
228
|
+
blacklistCreate(data: {
|
|
229
|
+
guild_id: string;
|
|
230
|
+
target_id: string;
|
|
231
|
+
remark?: string;
|
|
232
|
+
del_msg_days?: number;
|
|
233
|
+
}): Promise<any>;
|
|
234
|
+
blacklistDelete(data: {
|
|
235
|
+
guild_id: string;
|
|
236
|
+
target_id: string;
|
|
237
|
+
}): Promise<any>;
|
|
160
238
|
}
|