Skip to content

Commit

Permalink
wip: qq-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Aug 18, 2024
1 parent d171ef5 commit 355f79d
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/simple/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
QQ_BOT_APP_ID=
QQ_BOT_APP_TOKEN=
1 change: 1 addition & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"el-bot": "workspace:*",
"nodemon": "^3.1.4",
"qq-sdk": "workspace:*",
"tsup": "^8.2.4"
}
}
72 changes: 69 additions & 3 deletions examples/simple/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
import { Bot } from 'el-bot'
// import { Bot } from 'el-bot'

const bot = new Bot({})
bot.start()
// const bot = new Bot({})
// bot.start()

import process from 'node:process'
import consola from 'consola'

import { AvailableIntentsEventsEnum, GetWsParam } from 'qq-guild-bot'
import 'dotenv/config'

import { DOMAINS } from 'qq-sdk'
import axios from 'axios'

export const testConfig: GetWsParam = {
appID: process.env.QQ_BOT_APP_ID || '', // 申请机器人时获取到的机器人 BotAppID
token: process.env.QQ_BOT_APP_TOKEN || '', // 申请机器人时获取到的机器人 BotToken
intents: [
AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES,
], // 事件订阅,用于开启可接收的消息类型
sandbox: true, // 沙箱支持,可选,默认false. v2.7.0+
}

export async function main() {
// 创建 client
// const client = createOpenAPI(testConfig)
// client.messageApi
// .postMessage('120117362', {
// content: 'Hello, World!',
// })
// .catch((err) => {
// // err信息错误码请参考API文档错误码描述
// console.log(err)
// })

// // 创建 websocket 连接
// const ws = createWebsocket(testConfig)
// ws.connect(testConfig)
// // ws.on('PUBLIC_GUILD_MESSAGES', (data) => {
// // console.log('[PUBLIC_GUILD_MESSAGES] 事件接收 :', data)
// // })

// return {
// client,
// ws,
// }

consola.info(
process.env.QQ_BOT_APP_ID,
process.env.QQ_BOT_APP_TOKEN,
)
// const data = await getAppAccessToken({
// appId: process.env.QQ_BOT_APP_ID || '',
// clientSecret: process.env.QQ_BOT_APP_TOKEN || '',
// })

// 测试群
const groupId = 120117362
const { data } = await axios.post(`${DOMAINS.SANDBOX}/v2/groups/${groupId}/messages`, {
content: 'Hello, World!',
msg_type: 0,
}, {
headers: {
Authorization: `QQBot ${process.env.QQ_BOT_APP_TOKEN}`,
},
})
consola.info(data)
}

main()
Loading

0 comments on commit 355f79d

Please sign in to comment.