Skip to content

Commit

Permalink
feat: add qq guild bot
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Sep 29, 2024
1 parent e11687b commit 4a0ab18
Show file tree
Hide file tree
Showing 25 changed files with 665 additions and 104 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions demo/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://q.qq.com/qqbot/#/developer/developer-setting
QQ_BOT_APP_ID=
QQ_BOT_APP_TOKEN=
2 changes: 2 additions & 0 deletions demo/bot/plugins/qq/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ylfTestGuildID = '8023676110463580325'
export const xyLabSubGuildId = '665652769'
97 changes: 97 additions & 0 deletions demo/bot/plugins/qq/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { MessageToCreate } from 'qq-guild-bot'

/**
* @see https://bot.q.qq.com/wiki/develop/nodesdk/message/message_template.html#list-%E7%BB%93%E6%9E%84
*/
export const arkTemplateMessage: MessageToCreate = {
ark: {
template_id: 23,
kv: [
{
key: '#DESC#',
value: 'descaaaaaa',
},
{
key: '#PROMPT#',
value: 'promptaaaa',
},
{
key: '#LIST#',
obj: [
{
obj_kv: [
{
key: 'desc',
value: '需求标题:UI问题解决',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '当前状态"体验中"点击下列动作直接扭转状态到:',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '已评审',
},
{
key: 'link',
// value: 'https://yunyoujun.cn/about',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '已排期',
},
{
key: 'link',
// value: 'https://yunyoujun.cn/about',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '开发中',
},
{
key: 'link',
// value: 'https://yunyoujun.cn/about',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '增量测试中',
},
{
key: 'link',
// value: 'https://yunyoujun.cn/about',
},
],
},
{
obj_kv: [
{
key: 'desc',
value: '请关注',
},
],
},
],
},
],
} as any,
}
82 changes: 82 additions & 0 deletions demo/bot/plugins/qq/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { consola, defineBotPlugin } from 'el-bot'
import colors from 'picocolors'

export default defineBotPlugin({
pkg: {
name: 'qq',
},
setup: async (ctx) => {
const { qq } = ctx
if (!qq)
return

const { client, ws } = qq

const { data } = await client.meApi.me()
consola.info('QQ 频道机器人', colors.green(data.username), colors.dim(data.union_openid))

// const channelsRes = await client.channelApi.channels(ylfTestGuildID)
// const channels = channelsRes.data as IChannel[]

ws.on('GUILD_MESSAGES', (data) => {
consola.info('GUILD_MESSAGES', data)

const channelId = data.msg.channel_id
// 主动消息不能在00:00:00 - 05:59:59 推送
client.messageApi
.postMessage(channelId, {
content: '2',
msg_id: data.msg.id,
})

// 链接、文本列表模板
// client.messageApi.postMessage(channelId, {
// ark: arkTemplateMessage.ark,
// })

// keyboard
// 无 markdown 权限
// client.messageApi.postMessage(channelId, {
// markdown: {
// template_id: 1,
// params: [
// {
// key: 'title',
// value: ['标题'],
// },
// ],
// },
// msg_id: 'xxxxxx',
// keyboard: {
// content: {
// rows: [
// {
// buttons: [
// {
// id: '1',
// render_data: {
// label: 'AtBot-按钮1',
// visited_label: '点击后按钮1上文字',
// },
// action: {
// type: 2,
// permission: {
// type: 2,
// specify_role_ids: ['1', '2', '3'],
// },
// click_limit: 10,
// unsupport_tips: '编辑-兼容文本',
// data: '/搜索',
// at_bot_show_channel_list: true,
// },
// },
// ],
// },
// ],
// bot_appid: 123123123,
// },
// },
// })
})
},
})
23 changes: 23 additions & 0 deletions demo/el-bot.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import process from 'node:process'
import { answerPlugin, defineConfig } from 'el-bot'
import { AvailableIntentsEventsEnum } from 'qq-guild-bot'

const answer = answerPlugin({
list: [
Expand Down Expand Up @@ -41,4 +43,25 @@ export default defineConfig({
delay: 5000,
},
},

qq: {
appID: process.env.QQ_BOT_APP_ID || '', // 申请机器人时获取到的机器人 BotAppID
token: process.env.QQ_BOT_APP_TOKEN || '', // 申请机器人时获取到的机器人 BotToken
/**
* 事件订阅,用于开启可接收的消息类型
* 传递了无权限的 intents,websocket 会报错
*/
intents: [
// 默认权限
AvailableIntentsEventsEnum.GUILDS,
AvailableIntentsEventsEnum.GUILD_MEMBERS,
AvailableIntentsEventsEnum.PUBLIC_GUILD_MESSAGES,
// only for 私域机器人
AvailableIntentsEventsEnum.FORUMS_EVENT,
AvailableIntentsEventsEnum.GUILD_MESSAGES,
AvailableIntentsEventsEnum.GUILD_MESSAGE_REACTIONS,
AvailableIntentsEventsEnum.FORUMS_EVENT,
], //
sandbox: true, // 沙箱支持,可选,默认false. v2.7.0+
},
})
3 changes: 2 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"version": "0.1.0",
"description": "A dev demo for el-bot.",
"scripts": {
"dev": "bun --hot bot/index.ts",
"dev": "bun run watch",
"dev:hmr": "bun --hot bot/index.ts",
"dev:v": "vite-node -w ../packages/el-bot/bin/el-bot.ts",
"build": "tsup",
"pm2": "pm2 start pm2.config.cjs",
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "AGPL-3.0",
"dependencies": {
"sass": "^1.79.3",
"sass": "^1.79.4",
"vitepress": "^1.3.4",
"vitepress-theme-you": "^0.1.0-alpha.1"
},
Expand Down
44 changes: 21 additions & 23 deletions examples/nestjs-demo/config/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ export default defineBotConfig({
'name': '嘿',
'autoloadPlugins': true,

'plugins': {
default: [
// # - dev
'admin',
'answer',
// "blacklist",
// "counter",
// "feeder",
// "forward",
// "limit",
// "memo",
'nbnhhsh',
'qrcode',
// "rss",
// "report",
// "search",
// "search-image",
'teach',
// "workflow",
],
official: [],
custom: ['./plugins/webhook', './plugins/command'],
},
// plugins
// default: [
// // # - dev
// 'admin',
// 'answer',
// // "blacklist",
// // "counter",
// // "feeder",
// // "forward",
// // "limit",
// // "memo",
// 'nbnhhsh',
// 'qrcode',
// // "rss",
// // "report",
// // "search",
// // "search-image",
// 'teach',
// // "workflow",
// ],
// custom: ['./plugins/webhook', './plugins/command'],

'master': [910426929],

Expand Down
3 changes: 3 additions & 0 deletions examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"nodemon": "^3.1.7",
"qq-sdk": "workspace:*",
"tsup": "^8.3.0"
},
"dependencies": {
"axios": "^1.7.7"
}
}
Loading

0 comments on commit 4a0ab18

Please sign in to comment.