@alemonjs/qq-bot 2.1.7 → 2.1.9

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/lib/config.d.ts CHANGED
@@ -7,4 +7,4 @@ export type Options = {
7
7
  hideUnsupported?: boolean | number;
8
8
  } & sdkOptions;
9
9
  export declare const getQQBotConfig: () => Options;
10
- export declare const getMaster: (UserId: string) => readonly [boolean, string];
10
+ export declare const getMaster: (UserId: string) => readonly [any, string];
package/lib/config.js CHANGED
@@ -6,14 +6,17 @@ const getQQBotConfig = () => {
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 = getQQBotConfig();
10
- const master_key = config.master_key || [];
11
- const master_id = config.master_id || [];
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 = master_key.includes(UserKey) || master_id.includes(UserId);
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/format.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const markdownToText = (items, hideUnsupported) => {
2
- if (Number(hideUnsupported) >= 4)
2
+ if (Number(hideUnsupported) >= 4) {
3
3
  return '';
4
+ }
4
5
  return items
5
6
  .map(item => {
6
7
  switch (item.type) {
@@ -17,8 +18,9 @@ const markdownToText = (items, hideUnsupported) => {
17
18
  return item.value;
18
19
  case 'MD.link': {
19
20
  const v = item.value;
20
- if (Number(hideUnsupported) >= 3)
21
+ if (Number(hideUnsupported) >= 3) {
21
22
  return '';
23
+ }
22
24
  return Number(hideUnsupported) >= 2 ? v.url : `${v.text}( ${v.url} )`;
23
25
  }
24
26
  case 'MD.image':
@@ -48,8 +50,9 @@ const markdownToText = (items, hideUnsupported) => {
48
50
  case 'MD.content':
49
51
  return item.value;
50
52
  case 'MD.button':
51
- if (Number(hideUnsupported) >= 3)
53
+ if (Number(hideUnsupported) >= 3) {
52
54
  return '';
55
+ }
53
56
  if (Number(hideUnsupported) >= 2) {
54
57
  return item.options?.data || String(item.value);
55
58
  }
@@ -64,8 +67,9 @@ const buttonsToText = (rows) => {
64
67
  return rows.map((row) => row.value.map((btn) => `[${btn.value}]`).join(' ')).join('\n');
65
68
  };
66
69
  const markdownRawToText = (raw, hideUnsupported) => {
67
- if (Number(hideUnsupported) >= 4)
70
+ if (Number(hideUnsupported) >= 4) {
68
71
  return '';
72
+ }
69
73
  let text = raw;
70
74
  text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, hideUnsupported ? '' : '[图片]');
71
75
  text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, Number(hideUnsupported) >= 2 ? '$2' : '$1');
@@ -86,8 +90,9 @@ const markdownRawToText = (raw, hideUnsupported) => {
86
90
  return text;
87
91
  };
88
92
  const dataEnumToText = (item, hideUnsupported) => {
89
- if (Number(hideUnsupported) >= 4)
93
+ if (Number(hideUnsupported) >= 4) {
90
94
  return '';
95
+ }
91
96
  switch (item.type) {
92
97
  case 'MarkdownOriginal':
93
98
  return markdownRawToText(String(item.value), hideUnsupported);
package/lib/register.js CHANGED
@@ -748,6 +748,299 @@ const register = (client) => {
748
748
  const res = await api.active.send.user(userId, paramFormat);
749
749
  consume(res);
750
750
  }
751
+ else if (data.action === 'message.delete') {
752
+ const channelId = data.payload.ChannelId;
753
+ const messageId = data.payload.MessageId;
754
+ const res = await client
755
+ .channelsMessagesDelete(channelId, messageId)
756
+ .then(r => createResult(ResultCode.Ok, data.action, r))
757
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
758
+ consume([res]);
759
+ }
760
+ else if (data.action === 'message.pin') {
761
+ const res = await client
762
+ .channelsPinsPut(data.payload.ChannelId, data.payload.MessageId)
763
+ .then(r => createResult(ResultCode.Ok, data.action, r))
764
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
765
+ consume([res]);
766
+ }
767
+ else if (data.action === 'message.unpin') {
768
+ const res = await client
769
+ .channelsPinsDelete(data.payload.ChannelId, data.payload.MessageId)
770
+ .then(r => createResult(ResultCode.Ok, data.action, r))
771
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
772
+ consume([res]);
773
+ }
774
+ else if (data.action === 'reaction.add') {
775
+ const res = await client
776
+ .channelsMessagesReactionsPut(data.payload.ChannelId, data.payload.MessageId, 1, data.payload.EmojiId)
777
+ .then(r => createResult(ResultCode.Ok, data.action, r))
778
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
779
+ consume([res]);
780
+ }
781
+ else if (data.action === 'reaction.remove') {
782
+ const res = await client
783
+ .channelsMessagesReactionsDelete(data.payload.ChannelId, data.payload.MessageId, 1, data.payload.EmojiId)
784
+ .then(r => createResult(ResultCode.Ok, data.action, r))
785
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
786
+ consume([res]);
787
+ }
788
+ else if (data.action === 'message.get') {
789
+ const res = await client
790
+ .channelsMessagesById(data.payload.ChannelId, data.payload.MessageId)
791
+ .then(r => createResult(ResultCode.Ok, data.action, r))
792
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
793
+ consume([res]);
794
+ }
795
+ else if (data.action === 'member.info') {
796
+ const guildId = data.payload.params?.guildId ?? data.payload.GuildId;
797
+ const userId = data.payload.params?.userId ?? data.payload.UserId;
798
+ const res = await client
799
+ .guildsMembersMessage(guildId, userId)
800
+ .then(r => createResult(ResultCode.Ok, data.action, r))
801
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
802
+ consume([res]);
803
+ }
804
+ else if (data.action === 'member.list') {
805
+ const guildId = data.payload.GuildId;
806
+ const after = data.payload.params?.After ?? '0';
807
+ const limit = data.payload.params?.Limit ?? 100;
808
+ const res = await client
809
+ .guildsMembers(guildId, { after, limit })
810
+ .then(r => createResult(ResultCode.Ok, data.action, r))
811
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
812
+ consume([res]);
813
+ }
814
+ else if (data.action === 'member.kick') {
815
+ const res = await client
816
+ .guildsMembersDelete(data.payload.GuildId, data.payload.UserId)
817
+ .then(r => createResult(ResultCode.Ok, data.action, r))
818
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
819
+ consume([res]);
820
+ }
821
+ else if (data.action === 'member.ban') {
822
+ const guildId = data.payload.GuildId;
823
+ const userId = data.payload.UserId;
824
+ const duration = data.payload.params?.duration ?? 0;
825
+ const mute_seconds = String(duration > 0 ? duration : 604800);
826
+ const res = await client
827
+ .guildsMemberMute(guildId, userId, { mute_seconds })
828
+ .then(r => createResult(ResultCode.Ok, data.action, r))
829
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
830
+ consume([res]);
831
+ }
832
+ else if (data.action === 'member.unban') {
833
+ const res = await client
834
+ .guildsMemberMute(data.payload.GuildId, data.payload.UserId, { mute_seconds: '0' })
835
+ .then(r => createResult(ResultCode.Ok, data.action, r))
836
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
837
+ consume([res]);
838
+ }
839
+ else if (data.action === 'member.mute') {
840
+ const guildId = data.payload.GuildId;
841
+ const userId = data.payload.UserId;
842
+ const duration = data.payload.params?.duration ?? 0;
843
+ const mute_seconds = String(duration);
844
+ const res = await client
845
+ .guildsMemberMute(guildId, userId, { mute_seconds })
846
+ .then(r => createResult(ResultCode.Ok, data.action, r))
847
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
848
+ consume([res]);
849
+ }
850
+ else if (data.action === 'guild.info') {
851
+ const res = await client
852
+ .guilds(data.payload.GuildId)
853
+ .then(r => createResult(ResultCode.Ok, data.action, r))
854
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
855
+ consume([res]);
856
+ }
857
+ else if (data.action === 'guild.list') {
858
+ const res = await client
859
+ .usersMeGuilds({ before: '', after: '', limit: 100 })
860
+ .then(r => createResult(ResultCode.Ok, data.action, r))
861
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
862
+ consume([res]);
863
+ }
864
+ else if (data.action === 'guild.mute') {
865
+ const guildId = data.payload.GuildId;
866
+ const duration = data.payload.params?.duration ?? 0;
867
+ const mute_seconds = String(duration);
868
+ const res = await client
869
+ .guildsMuteAll(guildId, { mute_seconds })
870
+ .then(r => createResult(ResultCode.Ok, data.action, r))
871
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
872
+ consume([res]);
873
+ }
874
+ else if (data.action === 'channel.info') {
875
+ const res = await client
876
+ .channels(data.payload.ChannelId)
877
+ .then(r => createResult(ResultCode.Ok, data.action, r))
878
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
879
+ consume([res]);
880
+ }
881
+ else if (data.action === 'channel.list') {
882
+ const res = await client
883
+ .guildsChannels(data.payload.GuildId)
884
+ .then(r => createResult(ResultCode.Ok, data.action, r))
885
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
886
+ consume([res]);
887
+ }
888
+ else if (data.action === 'channel.create') {
889
+ const guildId = data.payload.GuildId;
890
+ const params = data.payload.params;
891
+ const res = await client
892
+ .guildsChannelsCreate(guildId, { name: params.name, type: params.type ? Number(params.type) : 0, position: 0, parent_id: params.parentId ?? '' })
893
+ .then(r => createResult(ResultCode.Ok, data.action, r))
894
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
895
+ consume([res]);
896
+ }
897
+ else if (data.action === 'channel.update') {
898
+ const channelId = data.payload.ChannelId;
899
+ const params = data.payload.params;
900
+ const res = await client
901
+ .guildsChannelsUpdate(channelId, { name: params.name ?? '', position: params.position ?? 0 })
902
+ .then(r => createResult(ResultCode.Ok, data.action, r))
903
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
904
+ consume([res]);
905
+ }
906
+ else if (data.action === 'channel.delete') {
907
+ const res = await client
908
+ .guildsChannelsdelete(data.payload.ChannelId, {})
909
+ .then(r => createResult(ResultCode.Ok, data.action, r))
910
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
911
+ consume([res]);
912
+ }
913
+ else if (data.action === 'role.list') {
914
+ const res = await client
915
+ .guildsRoles(data.payload.GuildId)
916
+ .then(r => createResult(ResultCode.Ok, data.action, r))
917
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
918
+ consume([res]);
919
+ }
920
+ else if (data.action === 'role.create') {
921
+ const params = data.payload.params;
922
+ const res = await client
923
+ .guildsRolesPost(data.payload.GuildId, { name: params.name, color: params.color })
924
+ .then(r => createResult(ResultCode.Ok, data.action, r))
925
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
926
+ consume([res]);
927
+ }
928
+ else if (data.action === 'role.update') {
929
+ const params = data.payload.params;
930
+ const res = await client
931
+ .guildsRolesPatch(data.payload.GuildId, data.payload.RoleId, { name: params.name, color: params.color })
932
+ .then(r => createResult(ResultCode.Ok, data.action, r))
933
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
934
+ consume([res]);
935
+ }
936
+ else if (data.action === 'role.delete') {
937
+ const res = await client
938
+ .guildsRolesDelete(data.payload.GuildId, data.payload.RoleId)
939
+ .then(r => createResult(ResultCode.Ok, data.action, r))
940
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
941
+ consume([res]);
942
+ }
943
+ else if (data.action === 'role.assign') {
944
+ const res = await client
945
+ .guildsRolesMembersPut(data.payload.GuildId, '', data.payload.UserId, data.payload.RoleId)
946
+ .then(r => createResult(ResultCode.Ok, data.action, r))
947
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
948
+ consume([res]);
949
+ }
950
+ else if (data.action === 'role.remove') {
951
+ const res = await client
952
+ .guildsRolesMembersDelete(data.payload.GuildId, '', data.payload.UserId, data.payload.RoleId)
953
+ .then(r => createResult(ResultCode.Ok, data.action, r))
954
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
955
+ consume([res]);
956
+ }
957
+ else if (data.action === 'file.send.channel') {
958
+ const res = await client
959
+ .postRichMediaByGroup(data.payload.ChannelId, {
960
+ file_type: data.payload.params?.file_type ?? 1,
961
+ url: data.payload.params?.url,
962
+ file_data: data.payload.params?.file_data,
963
+ srv_send_msg: data.payload.params?.srv_send_msg ?? false
964
+ })
965
+ .then(r => createResult(ResultCode.Ok, data.action, r))
966
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
967
+ consume([res]);
968
+ }
969
+ else if (data.action === 'file.send.user') {
970
+ const res = await client
971
+ .postRichMediaByUser(data.payload.UserId, {
972
+ file_type: data.payload.params?.file_type ?? 1,
973
+ url: data.payload.params?.url,
974
+ file_data: data.payload.params?.file_data,
975
+ srv_send_msg: data.payload.params?.srv_send_msg ?? false
976
+ })
977
+ .then(r => createResult(ResultCode.Ok, data.action, r))
978
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
979
+ consume([res]);
980
+ }
981
+ else if (data.action === 'me.guilds') {
982
+ const res = await client
983
+ .usersMeGuilds({ before: '', after: '', limit: 100 })
984
+ .then(r => createResult(ResultCode.Ok, data.action, r))
985
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
986
+ consume([res]);
987
+ }
988
+ else if (data.action === 'media.send.channel') {
989
+ consume([createResult(ResultCode.Warn, 'media.send.channel not directly supported, use message.send with format', null)]);
990
+ }
991
+ else if (data.action === 'media.send.user') {
992
+ const userId = data.payload.UserId;
993
+ const params = data.payload.params;
994
+ const fileType = params?.type === 'image' ? 1 : params?.type === 'video' ? 2 : params?.type === 'audio' ? 3 : 4;
995
+ const res = await client
996
+ .postRichMediaByUser(userId, { file_type: fileType, url: params?.url, file_data: params?.data })
997
+ .then(r => createResult(ResultCode.Ok, data.action, r))
998
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
999
+ consume([res]);
1000
+ }
1001
+ else if (data.action === 'media.upload') {
1002
+ consume([createResult(ResultCode.Warn, 'media.upload not supported, use media.send.user or media.send.channel', null)]);
1003
+ }
1004
+ else if (data.action === 'permission.get') {
1005
+ const res = await client
1006
+ .channelsPermissions(data.payload.ChannelId, data.payload.UserId)
1007
+ .then(r => createResult(ResultCode.Ok, data.action, r))
1008
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
1009
+ consume([res]);
1010
+ }
1011
+ else if (data.action === 'permission.set') {
1012
+ const params = data.payload.params;
1013
+ const res = await client
1014
+ .channelsPermissionsPut(data.payload.ChannelId, data.payload.UserId, params?.allow ?? '0', params?.deny ?? '0')
1015
+ .then(r => createResult(ResultCode.Ok, data.action, r))
1016
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
1017
+ consume([res]);
1018
+ }
1019
+ else if (data.action === 'reaction.list') {
1020
+ const res = await client
1021
+ .channelsMessagesReactionsUsers(data.payload.ChannelId, data.payload.MessageId, 1, data.payload.EmojiId, { limit: data.payload.params?.limit ?? 20 })
1022
+ .then(r => createResult(ResultCode.Ok, data.action, r))
1023
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
1024
+ consume([res]);
1025
+ }
1026
+ else if (data.action === 'channel.announce') {
1027
+ const guildId = data.payload.GuildId;
1028
+ const params = data.payload.params;
1029
+ if (params?.remove) {
1030
+ const res = await client
1031
+ .guildsAnnouncesDelete(guildId, params?.messageId ?? 'all')
1032
+ .then(r => createResult(ResultCode.Ok, data.action, r))
1033
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
1034
+ consume([res]);
1035
+ }
1036
+ else {
1037
+ const res = await client
1038
+ .guildsAnnounces(guildId, { message_id: params?.messageId, channel_id: params?.channelId })
1039
+ .then(r => createResult(ResultCode.Ok, data.action, r))
1040
+ .catch(err => createResult(ResultCode.Fail, data.action, err));
1041
+ consume([res]);
1042
+ }
1043
+ }
751
1044
  else {
752
1045
  consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
753
1046
  }
package/lib/sdk/api.d.ts CHANGED
@@ -70,28 +70,28 @@ export declare class QQBotAPI {
70
70
  channels(channel_id: string): Promise<any>;
71
71
  guildsChannelsCreate(guild_id: string, data: {
72
72
  name: string;
73
- type: number;
74
- sub_type: number;
75
- position: number;
76
- parent_id: string;
77
- private_type: number;
78
- private_user_ids: string[];
79
- speak_permission: number;
80
- application_id: string;
73
+ type?: number;
74
+ sub_type?: number;
75
+ position?: number;
76
+ parent_id?: string;
77
+ private_type?: number;
78
+ private_user_ids?: string[];
79
+ speak_permission?: number;
80
+ application_id?: string;
81
81
  }): Promise<any>;
82
82
  guildsChannelsUpdate(channel_id: string, data: {
83
- name: string;
84
- position: number;
85
- parent_id: string;
86
- private_type: number;
87
- speak_permission: number;
83
+ name?: string;
84
+ position?: number;
85
+ parent_id?: string;
86
+ private_type?: number;
87
+ speak_permission?: number;
88
88
  }): Promise<any>;
89
- guildsChannelsdelete(channel_id: string, data: {
90
- name: string;
91
- position: number;
92
- parent_id: string;
93
- private_type: number;
94
- speak_permission: number;
89
+ guildsChannelsdelete(channel_id: string, data?: {
90
+ name?: string;
91
+ position?: number;
92
+ parent_id?: string;
93
+ private_type?: number;
94
+ speak_permission?: number;
95
95
  }): Promise<any>;
96
96
  channelsChannelOnlineNums(channel_id: string): Promise<any>;
97
97
  guildsMembers(guild_id: string, params: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -10,6 +10,7 @@
10
10
  "build": "lvy build"
11
11
  },
12
12
  "dependencies": {
13
+ "@noble/curves": "^1.7.0",
13
14
  "axios": "^1.4.0",
14
15
  "file-type": "^18.5.0",
15
16
  "form-data": "^4.0.0",
@@ -21,9 +22,8 @@
21
22
  "mime-types": "^2.1.35",
22
23
  "public-ip": "^6.0.1",
23
24
  "qrcode": "^1.5.3",
24
- "ws": "^8.13.0",
25
25
  "uuid": "^11.0.3",
26
- "@noble/curves": "^1.7.0"
26
+ "ws": "^8.13.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "alemonjs": "^2.1.0-alpha.15"
@@ -73,5 +73,6 @@
73
73
  "repository": {
74
74
  "type": "git",
75
75
  "url": "https://github.com/lemonade-lab/alemonjs.git"
76
- }
77
- }
76
+ },
77
+ "gitHead": "743b70375f728a1584ae149bbadcd04378540ade"
78
+ }