@alemonjs/qq-bot 2.1.32 → 2.1.33
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/README.md +1946 -35
- package/lib/hook.d.ts +2 -1
- package/lib/index.websoket.js +2 -2
- package/lib/message/group/GROUP_JOIN_REQUEST.d.ts +23 -0
- package/lib/message/group/GROUP_JOIN_REQUEST.js +1 -0
- package/lib/register.js +248 -44
- package/lib/sdk/api.d.ts +58 -3
- package/lib/sdk/api.js +138 -3
- package/lib/sdk/instance.js +2 -0
- package/lib/sdk/intents.d.ts +1 -1
- package/lib/sdk/intents.js +2 -0
- package/lib/sdk/message.group.d.ts +2 -0
- package/lib/sdk/typing.d.ts +123 -1
- package/lib/sends.d.ts +6 -2
- package/lib/sends.js +131 -73
- package/lib/upload.d.ts +21 -0
- package/lib/upload.js +60 -0
- package/package.json +4 -4
package/lib/hook.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { C2C_MSG_RECEIVE_TYPE } from './message/group/C2C_MSG_RECEIVE';
|
|
|
31
31
|
import { C2C_MSG_REJECT_TYPE } from './message/group/C2C_MSG_REJECT';
|
|
32
32
|
import { MESSAGE_AUDIT_PASS_TYPE } from './message/group/MESSAGE_AUDIT_PASS';
|
|
33
33
|
import { MESSAGE_AUDIT_REJECT_TYPE } from './message/group/MESSAGE_AUDIT_REJECT';
|
|
34
|
+
import { GROUP_JOIN_REQUEST_TYPE } from './message/group/GROUP_JOIN_REQUEST';
|
|
34
35
|
type MAP = {
|
|
35
36
|
'message.create': GROUP_AT_MESSAGE_CREATE_TYPE | GROUP_MESSAGE_CREATE_TYPE | AT_MESSAGE_CREATE_TYPE | MESSAGE_CREATE_TYPE;
|
|
36
37
|
'private.message.create': DIRECT_MESSAGE_CREATE_TYPE | C2C_MESSAGE_CREATE_TYPE;
|
|
@@ -52,7 +53,7 @@ type MAP = {
|
|
|
52
53
|
'member.ban': undefined;
|
|
53
54
|
'member.unban': undefined;
|
|
54
55
|
'member.update': GUILD_MEMBER_UPDATE_TYPE;
|
|
55
|
-
'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE | MESSAGE_AUDIT_PASS_TYPE | MESSAGE_AUDIT_REJECT_TYPE;
|
|
56
|
+
'notice.create': GROUP_MSG_RECEIVE_TYPE | GROUP_MSG_REJECT_TYPE | MESSAGE_AUDIT_PASS_TYPE | MESSAGE_AUDIT_REJECT_TYPE | GROUP_JOIN_REQUEST_TYPE;
|
|
56
57
|
'private.message.update': undefined;
|
|
57
58
|
'private.message.delete': DIRECT_MESSAGE_DELETE_TYPE;
|
|
58
59
|
'private.friend.add': FRIEND_ADD_TYPE;
|
package/lib/index.websoket.js
CHANGED
|
@@ -23,11 +23,11 @@ const start = () => {
|
|
|
23
23
|
'DIRECT_MESSAGE',
|
|
24
24
|
'FORUMS_EVENT'
|
|
25
25
|
];
|
|
26
|
-
const isGroupIntents = ['GROUP_AND_C2C_EVENT'];
|
|
26
|
+
const isGroupIntents = ['GROUP_AND_C2C_EVENT', 'GROUP_MEMBER_EVENT'];
|
|
27
27
|
const pubIntents = ['INTERACTION'];
|
|
28
28
|
const intents = [];
|
|
29
29
|
if (config?.is_private) {
|
|
30
|
-
intents.push(...isPrivateIntents, ...pubIntents);
|
|
30
|
+
intents.push(...isPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
intents.push(...notPrivateIntents, ...isGroupIntents, ...pubIntents);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type GROUP_JOIN_REQUEST_TYPE = {
|
|
2
|
+
group_openid: string;
|
|
3
|
+
join_request_id: string;
|
|
4
|
+
risk_tips?: string;
|
|
5
|
+
union_openid?: string;
|
|
6
|
+
member_openid: string;
|
|
7
|
+
username: string;
|
|
8
|
+
apply_at: string;
|
|
9
|
+
apply_source: string;
|
|
10
|
+
invited_by?: string;
|
|
11
|
+
bot: boolean;
|
|
12
|
+
verify_info?: {
|
|
13
|
+
method: string;
|
|
14
|
+
verify_message?: string;
|
|
15
|
+
review_qa_list?: {
|
|
16
|
+
question: string;
|
|
17
|
+
answer: string;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
auto_approved?: {
|
|
21
|
+
strategy_id: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/lib/register.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { cbpPlatform, FormatEvent, ResultCode,
|
|
1
|
+
import { cbpPlatform, FormatEvent, createResult, ResultCode, logger } from 'alemonjs';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { stat, readFile } from 'node:fs/promises';
|
|
4
4
|
import { basename } from 'node:path';
|
|
5
|
+
import { chunkedUpload } from './upload.js';
|
|
5
6
|
import { GROUP_AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, AT_MESSAGE_CREATE, MESSAGE_CREATE } from './sends.js';
|
|
6
7
|
import { getQQBotConfig, platform, getMaster, getIdentity } from './config.js';
|
|
7
8
|
|
|
@@ -229,6 +230,24 @@ const register = (client, options) => {
|
|
|
229
230
|
.addUser({ UserId: UserId, UserKey, UserName: event?.username ?? '', UserAvatar: createUserAvatarURL(UserId), IsMaster: isMaster, IsBot: false })
|
|
230
231
|
.add({ tag: 'GROUP_MEMBER_REMOVE' }).value);
|
|
231
232
|
});
|
|
233
|
+
client.on('GROUP_JOIN_REQUEST', event => {
|
|
234
|
+
const UserId = event.member_openid ?? '';
|
|
235
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
236
|
+
cbp.send(FormatEvent.create('notice.create')
|
|
237
|
+
.addPlatform({ Platform: platform, value: event, BotId: botId })
|
|
238
|
+
.addGuild({ GuildId: event.group_openid ?? '', SpaceId: `GROUP:${event.group_openid ?? ''}` })
|
|
239
|
+
.addChannel({ ChannelId: event.group_openid ?? '' })
|
|
240
|
+
.addUser({
|
|
241
|
+
UserId: UserId,
|
|
242
|
+
UserKey,
|
|
243
|
+
UserName: event?.username ?? '',
|
|
244
|
+
UserAvatar: createUserAvatarURL(UserId),
|
|
245
|
+
IsMaster: isMaster,
|
|
246
|
+
IsBot: event.bot ?? false
|
|
247
|
+
})
|
|
248
|
+
.addMessage({ MessageId: `group_join_request_${event.group_openid}_${event.join_request_id}` })
|
|
249
|
+
.add({ tag: 'GROUP_JOIN_REQUEST' }).value);
|
|
250
|
+
});
|
|
232
251
|
client.on('GROUP_AT_MESSAGE_CREATE', event => {
|
|
233
252
|
if (event?.author?.bot) {
|
|
234
253
|
return;
|
|
@@ -367,7 +386,13 @@ const register = (client, options) => {
|
|
|
367
386
|
.addOpen({ OpenId: `DIRECT:${event.guild_id}` })
|
|
368
387
|
.add({ tag: 'MESSAGE_CREATE' }).value);
|
|
369
388
|
});
|
|
370
|
-
client.on('INTERACTION_CREATE', event => {
|
|
389
|
+
client.on('INTERACTION_CREATE', async (event) => {
|
|
390
|
+
try {
|
|
391
|
+
await client.interactionResponse('group', event.id, 0);
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
createResult(ResultCode.Fail, 'interactionResponse failed', err?.response?.data ?? err?.message ?? err);
|
|
395
|
+
}
|
|
371
396
|
if (event.scene === 'group') {
|
|
372
397
|
const UserAvatar = createUserAvatarURL(event.group_member_openid);
|
|
373
398
|
const UserId = event.group_member_openid;
|
|
@@ -384,7 +409,7 @@ const register = (client, options) => {
|
|
|
384
409
|
IsMaster: isMaster,
|
|
385
410
|
IsBot: false
|
|
386
411
|
})
|
|
387
|
-
.addMessage({ MessageId:
|
|
412
|
+
.addMessage({ MessageId: event.id })
|
|
388
413
|
.addText({ MessageText: MessageText })
|
|
389
414
|
.addInteraction({
|
|
390
415
|
InteractionId: event.id,
|
|
@@ -681,19 +706,19 @@ const register = (client, options) => {
|
|
|
681
706
|
}
|
|
682
707
|
},
|
|
683
708
|
use: {
|
|
684
|
-
send: async (event, val) => {
|
|
709
|
+
send: async (event, val, options) => {
|
|
685
710
|
if (!val || val.length <= 0) {
|
|
686
711
|
return [];
|
|
687
712
|
}
|
|
688
713
|
const tag = event._tag;
|
|
689
714
|
if (tag === 'GROUP_AT_MESSAGE_CREATE') {
|
|
690
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
715
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
691
716
|
}
|
|
692
717
|
if (tag === 'GROUP_MESSAGE_CREATE') {
|
|
693
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
718
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
694
719
|
}
|
|
695
720
|
if (tag === 'C2C_MESSAGE_CREATE') {
|
|
696
|
-
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
721
|
+
return await C2C_MESSAGE_CREATE(client, event, val, options);
|
|
697
722
|
}
|
|
698
723
|
if (tag === 'DIRECT_MESSAGE_CREATE') {
|
|
699
724
|
return await DIRECT_MESSAGE_CREATE(client, event, val);
|
|
@@ -705,10 +730,10 @@ const register = (client, options) => {
|
|
|
705
730
|
return await MESSAGE_CREATE(client, event, val);
|
|
706
731
|
}
|
|
707
732
|
if (tag === 'INTERACTION_CREATE_GROUP') {
|
|
708
|
-
return await GROUP_AT_MESSAGE_CREATE(client, event, val);
|
|
733
|
+
return await GROUP_AT_MESSAGE_CREATE(client, event, val, options);
|
|
709
734
|
}
|
|
710
735
|
if (tag === 'INTERACTION_CREATE_C2C') {
|
|
711
|
-
return await C2C_MESSAGE_CREATE(client, event, val);
|
|
736
|
+
return await C2C_MESSAGE_CREATE(client, event, val, options);
|
|
712
737
|
}
|
|
713
738
|
if (tag === 'INTERACTION_CREATE_GUILD') {
|
|
714
739
|
return await AT_MESSAGE_CREATE(client, event, val);
|
|
@@ -740,6 +765,12 @@ const register = (client, options) => {
|
|
|
740
765
|
}
|
|
741
766
|
};
|
|
742
767
|
const onactions = async (data, consume) => {
|
|
768
|
+
const event = data.payload.event ?? {};
|
|
769
|
+
const getGroupOpenId = () => data.payload.ChannelId ?? data.payload.params?.groupOpenId ?? data.payload.GuildId ?? event.ChannelId ?? event.GuildId ?? '';
|
|
770
|
+
const getMemberOpenId = () => data.payload.params?.memberOpenId ?? data.payload.UserId ?? event.UserId ?? '';
|
|
771
|
+
const getGuildId = () => data.payload.GuildId ?? event.GuildId ?? '';
|
|
772
|
+
const getUserId = () => data.payload.UserId ?? event.UserId ?? '';
|
|
773
|
+
const getChannelId = () => data.payload.ChannelId ?? event.ChannelId ?? '';
|
|
743
774
|
try {
|
|
744
775
|
if (data.action === 'me.info') {
|
|
745
776
|
const res = await client.usersMe();
|
|
@@ -758,7 +789,8 @@ const register = (client, options) => {
|
|
|
758
789
|
else if (data.action === 'message.send') {
|
|
759
790
|
const event = data.payload.event;
|
|
760
791
|
const paramFormat = data.payload.params.format;
|
|
761
|
-
const
|
|
792
|
+
const options = data.payload.params?.forceVerifyImageResource !== undefined ? { forceVerifyImageResource: data.payload.params.forceVerifyImageResource } : undefined;
|
|
793
|
+
const res = await api.use.send(event, paramFormat, options);
|
|
762
794
|
consume(res);
|
|
763
795
|
}
|
|
764
796
|
else if (data.action === 'mention.get') {
|
|
@@ -819,45 +851,55 @@ const register = (client, options) => {
|
|
|
819
851
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
820
852
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
821
853
|
consume([res]);
|
|
854
|
+
consume([res]);
|
|
822
855
|
}
|
|
823
856
|
else if (data.action === 'message.pin') {
|
|
824
857
|
const res = await client
|
|
825
|
-
.channelsPinsPut(
|
|
858
|
+
.channelsPinsPut(getChannelId(), data.payload.MessageId)
|
|
826
859
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
827
860
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
828
861
|
consume([res]);
|
|
829
862
|
}
|
|
830
863
|
else if (data.action === 'message.unpin') {
|
|
831
864
|
const res = await client
|
|
832
|
-
.channelsPinsDelete(
|
|
865
|
+
.channelsPinsDelete(getChannelId(), data.payload.MessageId)
|
|
833
866
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
834
867
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
835
868
|
consume([res]);
|
|
836
869
|
}
|
|
837
870
|
else if (data.action === 'reaction.add') {
|
|
838
871
|
const res = await client
|
|
839
|
-
.channelsMessagesReactionsPut(
|
|
872
|
+
.channelsMessagesReactionsPut(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId)
|
|
840
873
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
841
874
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
842
875
|
consume([res]);
|
|
843
876
|
}
|
|
844
877
|
else if (data.action === 'reaction.remove') {
|
|
845
878
|
const res = await client
|
|
846
|
-
.channelsMessagesReactionsDelete(
|
|
879
|
+
.channelsMessagesReactionsDelete(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId)
|
|
847
880
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
848
881
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
849
882
|
consume([res]);
|
|
850
883
|
}
|
|
851
884
|
else if (data.action === 'message.get') {
|
|
852
885
|
const res = await client
|
|
853
|
-
.channelsMessagesById(
|
|
886
|
+
.channelsMessagesById(getChannelId(), data.payload.MessageId)
|
|
854
887
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
855
888
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
856
889
|
consume([res]);
|
|
857
890
|
}
|
|
891
|
+
else if (data.action === 'interaction.response') {
|
|
892
|
+
const interactionId = data.payload.interaction_id;
|
|
893
|
+
const code = data.payload.code ?? 0;
|
|
894
|
+
const res = await client
|
|
895
|
+
.interactionResponse('group', interactionId, code)
|
|
896
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
897
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
898
|
+
consume([res]);
|
|
899
|
+
}
|
|
858
900
|
else if (data.action === 'member.info') {
|
|
859
|
-
const guildId = data.payload.params?.guildId ??
|
|
860
|
-
const userId = data.payload.params?.userId ??
|
|
901
|
+
const guildId = data.payload.params?.guildId ?? getGuildId();
|
|
902
|
+
const userId = data.payload.params?.userId ?? getUserId();
|
|
861
903
|
const res = await client
|
|
862
904
|
.guildsMembersMessage(guildId, userId)
|
|
863
905
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
@@ -865,7 +907,7 @@ const register = (client, options) => {
|
|
|
865
907
|
consume([res]);
|
|
866
908
|
}
|
|
867
909
|
else if (data.action === 'member.list') {
|
|
868
|
-
const guildId =
|
|
910
|
+
const guildId = getGuildId();
|
|
869
911
|
const after = data.payload.params?.After ?? '0';
|
|
870
912
|
const limit = data.payload.params?.Limit ?? 100;
|
|
871
913
|
const res = await client
|
|
@@ -876,14 +918,14 @@ const register = (client, options) => {
|
|
|
876
918
|
}
|
|
877
919
|
else if (data.action === 'member.kick') {
|
|
878
920
|
const res = await client
|
|
879
|
-
.guildsMembersDelete(
|
|
921
|
+
.guildsMembersDelete(getGuildId(), getUserId())
|
|
880
922
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
881
923
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
882
924
|
consume([res]);
|
|
883
925
|
}
|
|
884
926
|
else if (data.action === 'member.ban') {
|
|
885
|
-
const guildId =
|
|
886
|
-
const userId =
|
|
927
|
+
const guildId = getGuildId();
|
|
928
|
+
const userId = getUserId();
|
|
887
929
|
const duration = data.payload.params?.duration ?? 0;
|
|
888
930
|
const mute_seconds = String(duration > 0 ? duration : 604800);
|
|
889
931
|
const res = await client
|
|
@@ -894,14 +936,14 @@ const register = (client, options) => {
|
|
|
894
936
|
}
|
|
895
937
|
else if (data.action === 'member.unban') {
|
|
896
938
|
const res = await client
|
|
897
|
-
.guildsMemberMute(
|
|
939
|
+
.guildsMemberMute(getGuildId(), getUserId(), { mute_seconds: '0' })
|
|
898
940
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
899
941
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
900
942
|
consume([res]);
|
|
901
943
|
}
|
|
902
944
|
else if (data.action === 'member.mute') {
|
|
903
|
-
const guildId =
|
|
904
|
-
const userId =
|
|
945
|
+
const guildId = getGuildId();
|
|
946
|
+
const userId = getUserId();
|
|
905
947
|
const duration = data.payload.params?.duration ?? 0;
|
|
906
948
|
const mute_seconds = String(duration);
|
|
907
949
|
const res = await client
|
|
@@ -912,7 +954,7 @@ const register = (client, options) => {
|
|
|
912
954
|
}
|
|
913
955
|
else if (data.action === 'guild.info') {
|
|
914
956
|
const res = await client
|
|
915
|
-
.guilds(
|
|
957
|
+
.guilds(getGuildId())
|
|
916
958
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
917
959
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
918
960
|
consume([res]);
|
|
@@ -925,7 +967,7 @@ const register = (client, options) => {
|
|
|
925
967
|
consume([res]);
|
|
926
968
|
}
|
|
927
969
|
else if (data.action === 'guild.mute') {
|
|
928
|
-
const guildId =
|
|
970
|
+
const guildId = getGuildId();
|
|
929
971
|
const duration = data.payload.params?.duration ?? 0;
|
|
930
972
|
const mute_seconds = String(duration);
|
|
931
973
|
const res = await client
|
|
@@ -934,22 +976,135 @@ const register = (client, options) => {
|
|
|
934
976
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
935
977
|
consume([res]);
|
|
936
978
|
}
|
|
979
|
+
else if (data.action === 'group.info') {
|
|
980
|
+
const res = await client
|
|
981
|
+
.groupsInfo(getGroupOpenId())
|
|
982
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
983
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
984
|
+
consume([res]);
|
|
985
|
+
}
|
|
986
|
+
else if (data.action === 'group.botState') {
|
|
987
|
+
const res = await client
|
|
988
|
+
.groupsBotState(getGroupOpenId())
|
|
989
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
990
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
991
|
+
consume([res]);
|
|
992
|
+
}
|
|
993
|
+
else if (data.action === 'group.member.info') {
|
|
994
|
+
const res = await client
|
|
995
|
+
.groupsMembersMessage(getGroupOpenId(), getMemberOpenId())
|
|
996
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
997
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
998
|
+
consume([res]);
|
|
999
|
+
}
|
|
1000
|
+
else if (data.action === 'group.joinRequest.list') {
|
|
1001
|
+
const params = data.payload.params ?? {};
|
|
1002
|
+
const res = await client
|
|
1003
|
+
.groupsJoinRequestList(getGroupOpenId(), { cursor: params.cursor, limit: params.limit })
|
|
1004
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1005
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1006
|
+
consume([res]);
|
|
1007
|
+
}
|
|
1008
|
+
else if (data.action === 'group.joinRequest.approve') {
|
|
1009
|
+
const params = data.payload.params ?? {};
|
|
1010
|
+
const res = await client
|
|
1011
|
+
.groupsApprovalJoinRequest(getGroupOpenId(), getMemberOpenId(), {
|
|
1012
|
+
op: params.op,
|
|
1013
|
+
join_request_id: params.joinRequestId,
|
|
1014
|
+
reject_reason: params.rejectReason,
|
|
1015
|
+
add_to_member_blacklist: params.addToMemberBlacklist
|
|
1016
|
+
})
|
|
1017
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1018
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1019
|
+
consume([res]);
|
|
1020
|
+
}
|
|
1021
|
+
else if (data.action === 'group.mute.setting') {
|
|
1022
|
+
const res = await client
|
|
1023
|
+
.groupsRestrictChatSetting(getGroupOpenId())
|
|
1024
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1025
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1026
|
+
consume([res]);
|
|
1027
|
+
}
|
|
1028
|
+
else if (data.action === 'group.mute.set') {
|
|
1029
|
+
const res = await client
|
|
1030
|
+
.groupsRestrictChatSettingPost(getGroupOpenId(), { members: data.payload.params?.members })
|
|
1031
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1032
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1033
|
+
consume([res]);
|
|
1034
|
+
}
|
|
1035
|
+
else if (data.action === 'group.strategy.list') {
|
|
1036
|
+
const params = data.payload.params ?? {};
|
|
1037
|
+
const res = await client
|
|
1038
|
+
.groupsJoinApprovalStrategies({ cursor: params.cursor, limit: params.limit })
|
|
1039
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1040
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1041
|
+
consume([res]);
|
|
1042
|
+
}
|
|
1043
|
+
else if (data.action === 'group.strategy.create') {
|
|
1044
|
+
const params = data.payload.params ?? {};
|
|
1045
|
+
const res = await client
|
|
1046
|
+
.groupsJoinApprovalStrategyCreate({
|
|
1047
|
+
group_openids: params.groupOpenIds,
|
|
1048
|
+
group_ids: params.groupIds,
|
|
1049
|
+
is_enable: params.isEnable,
|
|
1050
|
+
expire_at: params.expireAt,
|
|
1051
|
+
remark: params.remark
|
|
1052
|
+
})
|
|
1053
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1054
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1055
|
+
consume([res]);
|
|
1056
|
+
}
|
|
1057
|
+
else if (data.action === 'group.strategy.update') {
|
|
1058
|
+
const params = data.payload.params ?? {};
|
|
1059
|
+
const res = await client
|
|
1060
|
+
.groupsJoinApprovalStrategyPatch(data.payload.StrategyId, {
|
|
1061
|
+
is_enable: params.isEnable,
|
|
1062
|
+
expire_at: params.expireAt,
|
|
1063
|
+
group_action: params.groupAction,
|
|
1064
|
+
remark: params.remark
|
|
1065
|
+
})
|
|
1066
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1067
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1068
|
+
consume([res]);
|
|
1069
|
+
}
|
|
1070
|
+
else if (data.action === 'group.strategy.delete') {
|
|
1071
|
+
const res = await client
|
|
1072
|
+
.groupsJoinApprovalStrategyDelete(data.payload.StrategyId)
|
|
1073
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1074
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1075
|
+
consume([res]);
|
|
1076
|
+
}
|
|
1077
|
+
else if (data.action === 'group.strategy.execute') {
|
|
1078
|
+
const res = await client
|
|
1079
|
+
.groupsJoinApprovalStrategyExecute(data.payload.StrategyId)
|
|
1080
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1081
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1082
|
+
consume([res]);
|
|
1083
|
+
}
|
|
1084
|
+
else if (data.action === 'group.strategy.whitelist') {
|
|
1085
|
+
const params = data.payload.params ?? {};
|
|
1086
|
+
const res = await client
|
|
1087
|
+
.groupsJoinApprovalStrategyWhitelistUsers(data.payload.StrategyId, { op: params.op, whitelist_users: params.whitelistUsers })
|
|
1088
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1089
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1090
|
+
consume([res]);
|
|
1091
|
+
}
|
|
937
1092
|
else if (data.action === 'channel.info') {
|
|
938
1093
|
const res = await client
|
|
939
|
-
.channels(
|
|
1094
|
+
.channels(getChannelId())
|
|
940
1095
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
941
1096
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
942
1097
|
consume([res]);
|
|
943
1098
|
}
|
|
944
1099
|
else if (data.action === 'channel.list') {
|
|
945
1100
|
const res = await client
|
|
946
|
-
.guildsChannels(
|
|
1101
|
+
.guildsChannels(getGuildId())
|
|
947
1102
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
948
1103
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
949
1104
|
consume([res]);
|
|
950
1105
|
}
|
|
951
1106
|
else if (data.action === 'channel.create') {
|
|
952
|
-
const guildId =
|
|
1107
|
+
const guildId = getGuildId();
|
|
953
1108
|
const params = data.payload.params;
|
|
954
1109
|
const res = await client
|
|
955
1110
|
.guildsChannelsCreate(guildId, { name: params.name, type: params.type ? Number(params.type) : 0, position: 0, parent_id: params.parentId ?? '' })
|
|
@@ -958,7 +1113,7 @@ const register = (client, options) => {
|
|
|
958
1113
|
consume([res]);
|
|
959
1114
|
}
|
|
960
1115
|
else if (data.action === 'channel.update') {
|
|
961
|
-
const channelId =
|
|
1116
|
+
const channelId = getChannelId();
|
|
962
1117
|
const params = data.payload.params;
|
|
963
1118
|
const res = await client
|
|
964
1119
|
.guildsChannelsUpdate(channelId, { name: params.name ?? '', position: params.position ?? 0 })
|
|
@@ -968,14 +1123,14 @@ const register = (client, options) => {
|
|
|
968
1123
|
}
|
|
969
1124
|
else if (data.action === 'channel.delete') {
|
|
970
1125
|
const res = await client
|
|
971
|
-
.guildsChannelsdelete(
|
|
1126
|
+
.guildsChannelsdelete(getChannelId(), {})
|
|
972
1127
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
973
1128
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
974
1129
|
consume([res]);
|
|
975
1130
|
}
|
|
976
1131
|
else if (data.action === 'role.list') {
|
|
977
1132
|
const res = await client
|
|
978
|
-
.guildsRoles(
|
|
1133
|
+
.guildsRoles(getGuildId())
|
|
979
1134
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
980
1135
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
981
1136
|
consume([res]);
|
|
@@ -983,7 +1138,7 @@ const register = (client, options) => {
|
|
|
983
1138
|
else if (data.action === 'role.create') {
|
|
984
1139
|
const params = data.payload.params;
|
|
985
1140
|
const res = await client
|
|
986
|
-
.guildsRolesPost(
|
|
1141
|
+
.guildsRolesPost(getGuildId(), { name: params.name, color: params.color })
|
|
987
1142
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
988
1143
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
989
1144
|
consume([res]);
|
|
@@ -991,35 +1146,35 @@ const register = (client, options) => {
|
|
|
991
1146
|
else if (data.action === 'role.update') {
|
|
992
1147
|
const params = data.payload.params;
|
|
993
1148
|
const res = await client
|
|
994
|
-
.guildsRolesPatch(
|
|
1149
|
+
.guildsRolesPatch(getGuildId(), data.payload.RoleId, { name: params.name, color: params.color })
|
|
995
1150
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
996
1151
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
997
1152
|
consume([res]);
|
|
998
1153
|
}
|
|
999
1154
|
else if (data.action === 'role.delete') {
|
|
1000
1155
|
const res = await client
|
|
1001
|
-
.guildsRolesDelete(
|
|
1156
|
+
.guildsRolesDelete(getGuildId(), data.payload.RoleId)
|
|
1002
1157
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1003
1158
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1004
1159
|
consume([res]);
|
|
1005
1160
|
}
|
|
1006
1161
|
else if (data.action === 'role.assign') {
|
|
1007
1162
|
const res = await client
|
|
1008
|
-
.guildsRolesMembersPut(
|
|
1163
|
+
.guildsRolesMembersPut(getGuildId(), '', getUserId(), data.payload.RoleId)
|
|
1009
1164
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1010
1165
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1011
1166
|
consume([res]);
|
|
1012
1167
|
}
|
|
1013
1168
|
else if (data.action === 'role.remove') {
|
|
1014
1169
|
const res = await client
|
|
1015
|
-
.guildsRolesMembersDelete(
|
|
1170
|
+
.guildsRolesMembersDelete(getGuildId(), '', getUserId(), data.payload.RoleId)
|
|
1016
1171
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1017
1172
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1018
1173
|
consume([res]);
|
|
1019
1174
|
}
|
|
1020
1175
|
else if (data.action === 'file.send.channel') {
|
|
1021
1176
|
const res = await client
|
|
1022
|
-
.postRichMediaByGroup(
|
|
1177
|
+
.postRichMediaByGroup(getGroupOpenId(), {
|
|
1023
1178
|
file_type: data.payload.params?.file_type ?? 1,
|
|
1024
1179
|
url: data.payload.params?.url,
|
|
1025
1180
|
file_data: data.payload.params?.file_data,
|
|
@@ -1031,7 +1186,7 @@ const register = (client, options) => {
|
|
|
1031
1186
|
}
|
|
1032
1187
|
else if (data.action === 'file.send.user') {
|
|
1033
1188
|
const res = await client
|
|
1034
|
-
.postRichMediaByUser(
|
|
1189
|
+
.postRichMediaByUser(getUserId(), {
|
|
1035
1190
|
file_type: data.payload.params?.file_type ?? 1,
|
|
1036
1191
|
url: data.payload.params?.url,
|
|
1037
1192
|
file_data: data.payload.params?.file_data,
|
|
@@ -1052,7 +1207,7 @@ const register = (client, options) => {
|
|
|
1052
1207
|
consume([createResult(ResultCode.Warn, 'media.send.channel not directly supported, use message.send with format', null)]);
|
|
1053
1208
|
}
|
|
1054
1209
|
else if (data.action === 'media.send.user') {
|
|
1055
|
-
const userId =
|
|
1210
|
+
const userId = getUserId();
|
|
1056
1211
|
const params = data.payload.params;
|
|
1057
1212
|
const fileType = params?.type === 'image' ? 1 : params?.type === 'video' ? 2 : params?.type === 'audio' ? 3 : 4;
|
|
1058
1213
|
const res = await client
|
|
@@ -1120,9 +1275,58 @@ const register = (client, options) => {
|
|
|
1120
1275
|
})
|
|
1121
1276
|
]);
|
|
1122
1277
|
}
|
|
1278
|
+
else if (data.action === 'media.upload.prepare') {
|
|
1279
|
+
const userId = getUserId();
|
|
1280
|
+
const groupId = getGroupOpenId();
|
|
1281
|
+
const res = await (userId ? client.usersUploadPrepare(userId, data.payload.params) : client.groupUploadPrepare(groupId, data.payload.params))
|
|
1282
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1283
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1284
|
+
consume([res]);
|
|
1285
|
+
}
|
|
1286
|
+
else if (data.action === 'media.upload.part.finish') {
|
|
1287
|
+
const userId = getUserId();
|
|
1288
|
+
const groupId = getGroupOpenId();
|
|
1289
|
+
const res = await (userId ? client.usersUploadPartFinish(userId, data.payload.params) : client.groupUploadPartFinish(groupId, data.payload.params))
|
|
1290
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1291
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1292
|
+
consume([res]);
|
|
1293
|
+
}
|
|
1294
|
+
else if (data.action === 'media.upload.chunked') {
|
|
1295
|
+
const userId = getUserId();
|
|
1296
|
+
const groupId = getGroupOpenId();
|
|
1297
|
+
const params = data.payload.params ?? {};
|
|
1298
|
+
const res = await chunkedUpload(client, userId ? 'user' : 'group', userId || groupId, params.file ?? params.file_path, {
|
|
1299
|
+
file_type: params.file_type ?? 1,
|
|
1300
|
+
file_name: params.file_name,
|
|
1301
|
+
srv_send_msg: params.srv_send_msg
|
|
1302
|
+
})
|
|
1303
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1304
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1305
|
+
consume([res]);
|
|
1306
|
+
}
|
|
1307
|
+
else if (data.action === 'stream.message.send') {
|
|
1308
|
+
const res = await client
|
|
1309
|
+
.streamMessages(getUserId(), data.payload.params ?? {})
|
|
1310
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1311
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1312
|
+
consume([res]);
|
|
1313
|
+
}
|
|
1314
|
+
else if (data.action === 'message.input.notify') {
|
|
1315
|
+
const params = data.payload.params ?? {};
|
|
1316
|
+
const res = await client
|
|
1317
|
+
.usersOpenMessages(getUserId(), {
|
|
1318
|
+
msg_type: 6,
|
|
1319
|
+
input_notify: { input_type: params.input_type ?? 1, input_second: params.input_second ?? 60 },
|
|
1320
|
+
msg_seq: params.msg_seq,
|
|
1321
|
+
msg_id: params.msg_id
|
|
1322
|
+
})
|
|
1323
|
+
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1324
|
+
.catch(err => createResult(ResultCode.Fail, data.action, err?.response?.data ?? err?.message ?? err));
|
|
1325
|
+
consume([res]);
|
|
1326
|
+
}
|
|
1123
1327
|
else if (data.action === 'permission.get') {
|
|
1124
1328
|
const res = await client
|
|
1125
|
-
.channelsPermissions(
|
|
1329
|
+
.channelsPermissions(getChannelId(), getUserId())
|
|
1126
1330
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1127
1331
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1128
1332
|
consume([res]);
|
|
@@ -1130,20 +1334,20 @@ const register = (client, options) => {
|
|
|
1130
1334
|
else if (data.action === 'permission.set') {
|
|
1131
1335
|
const params = data.payload.params;
|
|
1132
1336
|
const res = await client
|
|
1133
|
-
.channelsPermissionsPut(
|
|
1337
|
+
.channelsPermissionsPut(getChannelId(), getUserId(), params?.allow ?? '0', params?.deny ?? '0')
|
|
1134
1338
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1135
1339
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1136
1340
|
consume([res]);
|
|
1137
1341
|
}
|
|
1138
1342
|
else if (data.action === 'reaction.list') {
|
|
1139
1343
|
const res = await client
|
|
1140
|
-
.channelsMessagesReactionsUsers(
|
|
1344
|
+
.channelsMessagesReactionsUsers(getChannelId(), data.payload.MessageId, 1, data.payload.EmojiId, { limit: data.payload.params?.limit ?? 20 })
|
|
1141
1345
|
.then(r => createResult(ResultCode.Ok, data.action, r))
|
|
1142
1346
|
.catch(err => createResult(ResultCode.Fail, data.action, err));
|
|
1143
1347
|
consume([res]);
|
|
1144
1348
|
}
|
|
1145
1349
|
else if (data.action === 'channel.announce') {
|
|
1146
|
-
const guildId =
|
|
1350
|
+
const guildId = getGuildId();
|
|
1147
1351
|
const params = data.payload.params;
|
|
1148
1352
|
if (params?.remove) {
|
|
1149
1353
|
const res = await client
|