Skip to content

Commit b3f3bc8

Browse files
Joy-Wangjoyqwang
andauthored
更新SDK (#66)
* feat: 1.修改intents类型;2.消息撤回;3.添加批量禁言API; * feat: 添加BotLogger代替console.log * feat: 修改example示例 Co-authored-by: joyqwang <[email protected]>
1 parent 2f1f184 commit b3f3bc8

File tree

13 files changed

+606
-14589
lines changed

13 files changed

+606
-14589
lines changed

example/config.example.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

example/index.js

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,61 @@
11
// 以下仅为用法示意,详情请参照文档:https://bot.q.qq.com/wiki/develop/nodesdk/
2+
const { createOpenAPI, createWebsocket } = require('qq-guild-bot');
23

3-
const fs = require('fs');
4-
const path = require('path');
5-
const { createOpenAPI, createWebsocket } = require('../lib/index.js');
4+
const testConfigWs = {
5+
appID: '',
6+
token: '',
7+
};
68

7-
let config = {};
8-
// config.json需要您用自己的机器人信息配置
9-
const configPath = path.join(__dirname, 'config.json');
10-
if (fs.existsSync(configPath)) {
11-
config = fs.readFileSync(configPath).toString();
12-
config = JSON.parse(config);
13-
}
9+
const client = createOpenAPI(testConfigWs);
1410

15-
console.log(`config信息:\n\n ${JSON.stringify(config)} \n`);
11+
const ws = createWebsocket(testConfigWs);
12+
ws.on('READY', (wsdata) => {
13+
console.log('[READY] 事件接收 :', wsdata);
14+
});
1615

17-
(async function () {
18-
// API Demo
19-
const client = createOpenAPI(config);
20-
let res = await client.meApi.me();
21-
console.log(`\n meApi.me() res: \n\n ${JSON.stringify(res.data)} \n`);
16+
ws.on('ERROR', (data) => {
17+
console.log('[ERROR] 事件接收 :', data);
18+
});
19+
ws.on('GUILDS', (data) => {
20+
console.log('[GUILDS] 事件接收 :', data);
21+
});
22+
ws.on('GUILD_MEMBERS', (data) => {
23+
console.log('[GUILD_MEMBERS] 事件接收 :', data);
24+
});
25+
ws.on('GUILD_MESSAGES', (data) => {
26+
console.log('[GUILD_MESSAGES] 事件接收 :', data);
27+
});
28+
ws.on('GUILD_MESSAGE_REACTIONS', (data) => {
29+
console.log('[GUILD_MESSAGE_REACTIONS] 事件接收 :', data);
30+
});
31+
ws.on('DIRECT_MESSAGE', (data) => {
32+
console.log('[DIRECT_MESSAGE] 事件接收 :', data);
33+
});
34+
ws.on('INTERACTION', (data) => {
35+
console.log('[INTERACTION] 事件接收 :', data);
36+
});
37+
ws.on('MESSAGE_AUDIT', (data) => {
38+
console.log('[MESSAGE_AUDIT] 事件接收 :', data);
39+
});
40+
ws.on('FORUMS_EVENT', (data) => {
41+
console.log('[FORUMS_EVENT] 事件接收 :', data);
42+
});
43+
ws.on('AUDIO_ACTION', (data) => {
44+
console.log('[AUDIO_ACTION] 事件接收 :', data);
45+
});
46+
ws.on('PUBLIC_GUILD_MESSAGES', async (eventData) => {
47+
console.log('[PUBLIC_GUILD_MESSAGES] 事件接收 :', eventData);
48+
const {data} = await client.messageApi.postMessage('', {
49+
content: 'test'
50+
})
51+
console.log(data);
52+
});
2253

23-
res = await client.meApi.meGuilds();
24-
console.log(`\n meApi.meGuilds() res: \n\n ${JSON.stringify(res.data)} \n`);
54+
// client.guildApi.guild('').then((data) => {
55+
// console.log(data);
56+
// });
2557

26-
//WS Demo
27-
const ws = createWebsocket(config);
28-
ws.on('READY', (data) => {
29-
console.log('[READY] 事件接收 :', data);
30-
});
31-
ws.on('ERROR', (data) => {
32-
console.log('[ERROR] 事件接收 :', data);
33-
});
34-
ws.on('GUILDS', (data) => {
35-
console.log('[GUILDS] 事件接收 :', data);
36-
});
37-
ws.on('GUILD_MEMBERS', (data) => {
38-
console.log('[GUILD_MEMBERS] 事件接收 :', data);
39-
});
40-
ws.on('DIRECT_MESSAGE', (data) => {
41-
console.log('[DIRECT_MESSAGE] 事件接收 :', data);
42-
});
43-
ws.on('AUDIO_ACTION', (data) => {
44-
console.log('[AUDIO_ACTION] 事件接收 :', data);
45-
});
46-
ws.on('AT_MESSAGES', (data) => {
47-
console.log('[AT_MESSAGES] 事件接收 :', data);
48-
const msg = data.msg;
49-
client.messageApi.postMessage(msg.channel_id, {
50-
content: `<@!${msg.author.id}> hi 收到你的消息啦`,
51-
msg_id: msg.id,
52-
});
53-
});
54-
})();
58+
// // ✅
59+
// client.channelApi.channels(guildID).then((res) => {
60+
// console.log(res.data);
61+
// });

0 commit comments

Comments
 (0)