@alemonjs/qq-bot 2.1.0-alpha.29 → 2.1.0-alpha.30

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/hook.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { EventKeys, Events } from 'alemonjs';
2
2
  import { GROUP_AT_MESSAGE_CREATE_TYPE } from './message/group/GROUP_AT_MESSAGE_CREATE';
3
- import { QQBotAPI as API } from './sdk/api';
4
3
  import { AT_MESSAGE_CREATE_TYPE } from './message/AT_MESSAGE_CREATE';
5
4
  import { INTERACTION_CREATE_TYPE } from './message/INTERACTION_CREATE';
6
5
  import { DIRECT_MESSAGE_CREATE_TYPE } from './message/DIRECT_MESSAGE_CREATE';
@@ -26,6 +25,197 @@ type MAP = {
26
25
  'private.guild.add': undefined;
27
26
  };
28
27
  export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
29
- export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
28
+ export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [{
29
+ getAuthentication: () => Promise<import("alemonjs").Result<any>>;
30
+ groupService: (options: import("axios").AxiosRequestConfig<any>) => Promise<import("alemonjs").Result<any>>;
31
+ guildServer: (opstion: import("axios").AxiosRequestConfig<any>) => Promise<import("alemonjs").Result<any>>;
32
+ gateway: () => Promise<import("alemonjs").Result<any>>;
33
+ usersOpenMessages: (openid: string, data: import("./sdk/typing").ApiRequestData) => Promise<import("alemonjs").Result<{
34
+ id: string;
35
+ timestamp: number;
36
+ }>>;
37
+ getMessageSeq: (MessageId: string) => Promise<import("alemonjs").Result<number>>;
38
+ groupOpenMessages: (group_openid: string, data: import("./sdk/typing").ApiRequestData) => Promise<import("alemonjs").Result<{
39
+ id: string;
40
+ timestamp: number;
41
+ }>>;
42
+ postRichMediaByUser: (openid: string, data: {
43
+ srv_send_msg?: boolean;
44
+ file_type: import("./sdk/typing").FileType;
45
+ url?: string;
46
+ file_data?: any;
47
+ }) => Promise<import("alemonjs").Result<{
48
+ file_uuid: string;
49
+ file_info: string;
50
+ ttl: number;
51
+ }>>;
52
+ postRichMediaByGroup: (openid: string, data: {
53
+ srv_send_msg?: boolean;
54
+ file_type: import("./sdk/typing").FileType;
55
+ url?: string;
56
+ file_data?: any;
57
+ }) => Promise<import("alemonjs").Result<{
58
+ file_uuid: string;
59
+ file_info: string;
60
+ ttl: number;
61
+ }>>;
62
+ userMessageDelete: (openid: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
63
+ grouMessageDelte: (group_openid: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
64
+ channelsMessages: (channel_id: string, message: {
65
+ content?: string;
66
+ embed?: any;
67
+ ark?: any;
68
+ message_reference?: any;
69
+ image?: string;
70
+ msg_id?: string;
71
+ event_id?: string;
72
+ markdown?: any;
73
+ }, image?: Buffer<ArrayBufferLike>) => Promise<import("alemonjs").Result<any>>;
74
+ dmsMessages: (guild_id: string, message: {
75
+ content?: string;
76
+ embed?: any;
77
+ ark?: any;
78
+ message_reference?: any;
79
+ image?: string;
80
+ msg_id?: string;
81
+ event_id?: string;
82
+ markdown?: any;
83
+ }, image?: Buffer<ArrayBufferLike>) => Promise<import("alemonjs").Result<any>>;
84
+ usersMe: () => Promise<import("alemonjs").Result<any>>;
85
+ usersMeGuilds: (params: {
86
+ before: string;
87
+ after: string;
88
+ limit: number;
89
+ }) => Promise<import("alemonjs").Result<any>>;
90
+ guilds: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
91
+ guildsChannels: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
92
+ channels: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
93
+ guildsChannelsCreate: (guild_id: string, data: {
94
+ name: string;
95
+ type: number;
96
+ sub_type: number;
97
+ position: number;
98
+ parent_id: string;
99
+ private_type: number;
100
+ private_user_ids: string[];
101
+ speak_permission: number;
102
+ application_id: string;
103
+ }) => Promise<import("alemonjs").Result<any>>;
104
+ guildsChannelsUpdate: (channel_id: string, data: {
105
+ name: string;
106
+ position: number;
107
+ parent_id: string;
108
+ private_type: number;
109
+ speak_permission: number;
110
+ }) => Promise<import("alemonjs").Result<any>>;
111
+ guildsChannelsdelete: (channel_id: string, data: {
112
+ name: string;
113
+ position: number;
114
+ parent_id: string;
115
+ private_type: number;
116
+ speak_permission: number;
117
+ }) => Promise<import("alemonjs").Result<any>>;
118
+ channelsChannelOnlineNums: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
119
+ guildsMembers: (guild_id: string, params: {
120
+ after: string;
121
+ limit: number;
122
+ }) => Promise<import("alemonjs").Result<any>>;
123
+ guildsRolesMembers: (guild_id: string, role_id: string, params: {
124
+ start_index: string;
125
+ limit: number;
126
+ }) => Promise<import("alemonjs").Result<any>>;
127
+ guildsMembersMessage: (guild_id: string, user_id: string) => Promise<import("alemonjs").Result<any>>;
128
+ guildsMembersDelete: (guild_id: string, user_id: string) => Promise<import("alemonjs").Result<any>>;
129
+ channelsMessagesById: (channel_id: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
130
+ channelsMessagesDelete: (channel_id: string, message_id: string, hidetip?: boolean) => Promise<import("alemonjs").Result<any>>;
131
+ guildsRoles: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
132
+ guildsRolesPost: (guild_id: string, data: {
133
+ name?: string;
134
+ color?: number;
135
+ hoist?: 0 | 1;
136
+ }) => Promise<import("alemonjs").Result<any>>;
137
+ guildsRolesPatch: (guild_id: string, role_id: string, data: {
138
+ name?: string;
139
+ color?: number;
140
+ hoist?: 0 | 1;
141
+ }) => Promise<import("alemonjs").Result<any>>;
142
+ guildsRolesDelete: (guild_id: string, role_id: string) => Promise<import("alemonjs").Result<any>>;
143
+ guildsRolesMembersPut: (guild_id: string, channel_id: string, user_id: string, role_id: string) => Promise<import("alemonjs").Result<any>>;
144
+ guildsRolesMembersDelete: (guild_id: string, channel_id: string, user_id: string, role_id: string) => Promise<import("alemonjs").Result<any>>;
145
+ channelsPermissions: (channel_id: string, user_id: string) => Promise<import("alemonjs").Result<any>>;
146
+ channelsPermissionsPut: (channel_id: string, user_id: string, add: string, remove: string) => Promise<import("alemonjs").Result<any>>;
147
+ guildsMessageSetting: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
148
+ usersMeDms: () => Promise<import("alemonjs").Result<any>>;
149
+ dmsMessageDelete: (guild_id: string, message_id: string, hidetip?: boolean) => Promise<import("alemonjs").Result<any>>;
150
+ guildsMuteAll: (guild_id: string, data: {
151
+ mute_end_timestamp?: string;
152
+ mute_seconds?: string;
153
+ }) => Promise<import("alemonjs").Result<any>>;
154
+ guildsMemberMute: (guild_id: string, user_id: string, data: {
155
+ mute_end_timestamp?: string;
156
+ mute_seconds?: string;
157
+ }) => Promise<import("alemonjs").Result<any>>;
158
+ guildsMute: (guild_id: string, data: {
159
+ mute_end_timestamp?: string;
160
+ mute_seconds?: string;
161
+ user_ids: string[];
162
+ }) => Promise<import("alemonjs").Result<any>>;
163
+ guildsAnnounces: (guild_id: string, data: {
164
+ message_id?: string;
165
+ channel_id?: string;
166
+ announces_type?: 0 | 1;
167
+ recommend_channels?: string[];
168
+ }) => Promise<import("alemonjs").Result<any>>;
169
+ guildsAnnouncesDelete: (guild_id: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
170
+ channelsPinsPut: (channel_id: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
171
+ channelsPinsDelete: (channel_id: string, message_id: string) => Promise<import("alemonjs").Result<any>>;
172
+ channelsPins: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
173
+ channelsSchedules: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
174
+ channelsSchedulesSchedule: (channel_id: string, schedule_id: string) => Promise<import("alemonjs").Result<any>>;
175
+ channelsSchedulesPost: (channel_id: string, data: {
176
+ schedule: {
177
+ name: string;
178
+ description?: string;
179
+ start_timestamp: string;
180
+ end_timestamp: string;
181
+ jump_channel_id: string;
182
+ remind_type: number;
183
+ };
184
+ }) => Promise<import("alemonjs").Result<any>>;
185
+ channelsSchedulesSchedulePatch: (channel_id: string, schedule_id: string, data: {
186
+ schedule: {
187
+ name: string;
188
+ description?: string;
189
+ start_timestamp: string;
190
+ end_timestamp: string;
191
+ jump_channel_id: string;
192
+ remind_type: number;
193
+ };
194
+ }) => Promise<import("alemonjs").Result<any>>;
195
+ channelsSchedulesScheduleDelete: (channel_id: string, schedule_id: string) => Promise<import("alemonjs").Result<any>>;
196
+ channelsMessagesReactionsPut: (channel_id: string, message_id: string, type: 1 | 2, id: string) => Promise<import("alemonjs").Result<any>>;
197
+ channelsMessagesReactionsDelete: (channel_id: string, message_id: string, type: 1 | 2, id: string) => Promise<import("alemonjs").Result<any>>;
198
+ channelsMessagesReactionsUsers: (channel_id: string, message_id: string, type: 1 | 2, id: string, data: {
199
+ cookie?: string;
200
+ limit?: number;
201
+ }) => Promise<import("alemonjs").Result<any>>;
202
+ channelsAudioPost: (channel_id: string, data: {
203
+ audio_url?: string;
204
+ text?: string;
205
+ status: 0 | 1 | 2 | 3;
206
+ }) => Promise<import("alemonjs").Result<any>>;
207
+ channelsMicPut: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
208
+ channelsMicDelete: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
209
+ channelsThreads: (channel_id: string) => Promise<import("alemonjs").Result<any>>;
210
+ channelsThreadsThread: (channel_id: string, thread_id: string) => Promise<import("alemonjs").Result<any>>;
211
+ channelsThreadsPut: (channel_id: string, data: {
212
+ title: string;
213
+ content: string;
214
+ format: 1 | 2 | 3 | 4;
215
+ }) => Promise<import("alemonjs").Result<any>>;
216
+ channelsThreadsDelete: (channel_id: string, thread_id: string) => Promise<import("alemonjs").Result<any>>;
217
+ guildApiPermission: (guild_id: string) => Promise<import("alemonjs").Result<any>>;
218
+ interactionResponse: (mode: "guild" | "group", interaction_id: string, code?: number) => Promise<import("alemonjs").Result<any>>;
219
+ }, MAP[T]];
30
220
  export declare const useMode: <T extends EventKeys>(event: Events[T]) => (mode: "guild" | "group" | "c2c") => boolean;
31
221
  export {};
package/lib/sdk/api.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare const BOTS_API_RUL = "https://bots.qq.com";
4
4
  export declare const API_URL_SANDBOX = "https://sandbox.api.sgroup.qq.com";
5
5
  export declare const API_URL = "https://api.sgroup.qq.com";
6
6
  export declare class QQBotAPI {
7
- getAuthentication(app_id: string, clientSecret: string): Promise<import("axios").AxiosResponse<any, any>>;
7
+ getAuthentication(): Promise<any>;
8
8
  groupService(options: AxiosRequestConfig): Promise<any>;
9
9
  guildServer(opstion: AxiosRequestConfig): Promise<any>;
10
10
  gateway(): Promise<any>;
package/lib/sdk/api.js CHANGED
@@ -9,10 +9,20 @@ const API_URL_SANDBOX = 'https://sandbox.api.sgroup.qq.com';
9
9
  const API_URL = 'https://api.sgroup.qq.com';
10
10
  const msgMap = new Map();
11
11
  class QQBotAPI {
12
- getAuthentication(app_id, clientSecret) {
13
- return axios.post(`${BOTS_API_RUL}/app/getAppAccessToken`, {
14
- appId: app_id,
15
- clientSecret: clientSecret
12
+ getAuthentication() {
13
+ const app_id = config.get('app_id');
14
+ const secret = config.get('secret');
15
+ const service = axios.create({
16
+ baseURL: BOTS_API_RUL,
17
+ timeout: 20000
18
+ });
19
+ return createAxiosInstance(service, {
20
+ url: '/app/getAppAccessToken',
21
+ method: 'post',
22
+ data: {
23
+ appId: `${app_id}`,
24
+ clientSecret: `${secret}`
25
+ }
16
26
  });
17
27
  }
18
28
  groupService(options) {
@@ -29,14 +29,11 @@ class QQBotClient extends QQBotAPI {
29
29
  async #setTimeoutBotConfig() {
30
30
  const callBack = async () => {
31
31
  const app_id = config.get('app_id');
32
- if (!app_id) {
33
- return;
34
- }
35
32
  const secret = config.get('secret');
36
- if (!secret) {
33
+ if (!app_id || !secret) {
37
34
  return;
38
35
  }
39
- const data = await this.getAuthentication(app_id, secret).then(res => res.data);
36
+ const data = await this.getAuthentication();
40
37
  config.set('access_token', data.access_token);
41
38
  console.info('refresh', data.expires_in, 's');
42
39
  setTimeout(() => void callBack(), data.expires_in * 1000);
@@ -23,7 +23,7 @@ class QQBotClients extends QQBotAPI {
23
23
  if (!app_id || !secret) {
24
24
  return;
25
25
  }
26
- const data = await this.getAuthentication(app_id, secret).then(res => res.data);
26
+ const data = await this.getAuthentication();
27
27
  config.set('access_token', data.access_token);
28
28
  console.info('refresh', data.expires_in, 's');
29
29
  setTimeout(() => void accessToken(), data.expires_in * 1000);
@@ -159,6 +159,11 @@ class QQBotClients extends QQBotAPI {
159
159
  }
160
160
  });
161
161
  this.#ws.on('close', err => {
162
+ this.#isConnected = false;
163
+ if (this.#IntervalId) {
164
+ clearInterval(this.#IntervalId);
165
+ this.#IntervalId = null;
166
+ }
162
167
  void reconnect();
163
168
  console.info('[ws-qqbot] close', err);
164
169
  });
package/lib/sends.js CHANGED
@@ -125,7 +125,7 @@ const createMarkdownText = (data) => {
125
125
  const listStr = mdItem.value.map(listItem => {
126
126
  return typeof listItem.value === 'object' ? `\n${listItem.value.index}. ${listItem.value.text}` : `\n- ${listItem.value}`;
127
127
  });
128
- return `${listStr}\n`;
128
+ return `${listStr.join('')}\n`;
129
129
  }
130
130
  if (mdItem.type === 'MD.code') {
131
131
  const language = mdItem?.options?.language || '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.0-alpha.29",
3
+ "version": "2.1.0-alpha.30",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",