@alemonjs/onebot 0.2.6 → 0.2.8
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/index.js +10 -9
- package/lib/server/index.js +73 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -321,23 +321,24 @@ var index = definePlatform(() => {
|
|
|
321
321
|
mention: async (event) => {
|
|
322
322
|
const uis = config?.master_id ?? [];
|
|
323
323
|
const e = event.value;
|
|
324
|
-
if (
|
|
324
|
+
if (event['name'] == 'message.create' || event['name'] == 'private.message.create') {
|
|
325
325
|
const Metions = [];
|
|
326
326
|
for (const item of e.message) {
|
|
327
327
|
if (item.type == 'at') {
|
|
328
328
|
let isBot = false;
|
|
329
|
-
|
|
329
|
+
const uid = String(item.data.qq);
|
|
330
|
+
if (uid == 'all') {
|
|
330
331
|
continue;
|
|
331
332
|
}
|
|
332
|
-
if (
|
|
333
|
+
if (uid == MyBot.id) {
|
|
333
334
|
isBot = true;
|
|
334
335
|
}
|
|
335
|
-
const avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${
|
|
336
|
+
const avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${uid}`;
|
|
336
337
|
Metions.push({
|
|
337
|
-
UserId:
|
|
338
|
+
UserId: uid,
|
|
338
339
|
UserKey: useUserHashKey({
|
|
339
340
|
Platform: platform,
|
|
340
|
-
UserId:
|
|
341
|
+
UserId: uid
|
|
341
342
|
}),
|
|
342
343
|
UserName: item.data?.nickname,
|
|
343
344
|
UserAvatar: {
|
|
@@ -353,14 +354,14 @@ var index = definePlatform(() => {
|
|
|
353
354
|
return avatar;
|
|
354
355
|
}
|
|
355
356
|
},
|
|
356
|
-
IsMaster: uis.includes(
|
|
357
|
+
IsMaster: uis.includes(uid),
|
|
357
358
|
IsBot: isBot
|
|
358
359
|
});
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
|
-
return;
|
|
362
|
+
return Metions;
|
|
362
363
|
}
|
|
363
|
-
return
|
|
364
|
+
return [];
|
|
364
365
|
}
|
|
365
366
|
}
|
|
366
367
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Koa from 'koa'
|
|
2
|
+
import Router from 'koa-router'
|
|
3
|
+
|
|
4
|
+
// 使用koa + router 写 hello world
|
|
5
|
+
const createServer = client => {
|
|
6
|
+
const app = new Koa()
|
|
7
|
+
const router = new Router()
|
|
8
|
+
const port = 8080 // 端口号
|
|
9
|
+
// 检测
|
|
10
|
+
router.get('/', ctx => {
|
|
11
|
+
ctx.body = 'Hello, World!'
|
|
12
|
+
})
|
|
13
|
+
// 获取群列表
|
|
14
|
+
router.get('/get_group_list', async ctx => {
|
|
15
|
+
client.getGroupList()
|
|
16
|
+
ctx.body = 'Hello, World!'
|
|
17
|
+
})
|
|
18
|
+
// 获取好友列表
|
|
19
|
+
router.get('/get_friend_list', async ctx => {
|
|
20
|
+
client.getFriendList()
|
|
21
|
+
ctx.body = 'Hello, World!'
|
|
22
|
+
})
|
|
23
|
+
// 获取群成员列表
|
|
24
|
+
router.get('/get_group_member_list', async ctx => {
|
|
25
|
+
const group_id = ctx.query.group_id
|
|
26
|
+
if (!group_id) {
|
|
27
|
+
ctx.status = 400
|
|
28
|
+
ctx.body = 'group_id is required'
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
client.getGroupMemberList({ group_id: Number(group_id) })
|
|
32
|
+
ctx.body = 'Hello, World!'
|
|
33
|
+
})
|
|
34
|
+
// 同意加群
|
|
35
|
+
router.get('/set_group_add_request', async ctx => {
|
|
36
|
+
const flag = ctx.query.flag
|
|
37
|
+
const sub_type = ctx.query.sub_type
|
|
38
|
+
const approve = ctx.query.approve
|
|
39
|
+
if (!flag || !sub_type || !approve) {
|
|
40
|
+
ctx.status = 400
|
|
41
|
+
ctx.body = 'flag, sub_type and approve are required'
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
client.setGroupAddRequest({
|
|
45
|
+
flag: String(flag),
|
|
46
|
+
sub_type: String(sub_type),
|
|
47
|
+
approve: Boolean(approve)
|
|
48
|
+
})
|
|
49
|
+
ctx.body = 'Hello, World!'
|
|
50
|
+
})
|
|
51
|
+
// 同意加好友
|
|
52
|
+
router.get('/set_friend_add_request', async ctx => {
|
|
53
|
+
const flag = ctx.query.flag
|
|
54
|
+
const approve = ctx.query.approve
|
|
55
|
+
if (!flag || !approve) {
|
|
56
|
+
ctx.status = 400
|
|
57
|
+
ctx.body = 'flag and approve are required'
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
client.setFriendAddRequest({
|
|
61
|
+
flag: String(flag),
|
|
62
|
+
approve: Boolean(approve)
|
|
63
|
+
})
|
|
64
|
+
ctx.body = 'Hello, World!'
|
|
65
|
+
})
|
|
66
|
+
app.use(router.routes())
|
|
67
|
+
app.use(router.allowedMethods())
|
|
68
|
+
app.listen(port, () => {
|
|
69
|
+
console.log(`Server is running at http://localhost:${port}`)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { createServer }
|