@alemonjs/onebot 0.2.5 → 0.2.6

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 CHANGED
@@ -2,6 +2,8 @@ import { getConfigValue, useUserHashKey, onProcessor, createResult, ResultCode }
2
2
  import { OneBotClient } from './sdk/wss.js';
3
3
  import { readFileSync } from 'fs';
4
4
 
5
+ const MyBot = {
6
+ id: ''};
5
7
  const ImageURLToBuffer = async (url) => {
6
8
  const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
7
9
  return Buffer.from(arrayBuffer);
@@ -35,11 +37,11 @@ var index = definePlatform(() => {
35
37
  client.connect();
36
38
  client.on('META', event => {
37
39
  if (event?.self_id) {
38
- String(event.self_id);
40
+ MyBot.id = String(event.self_id);
39
41
  }
40
42
  });
41
43
  client.on('MESSAGES', event => {
42
- const uis = config.master_uids ?? [];
44
+ const uis = config?.master_id ?? [];
43
45
  let msg = '';
44
46
  const arr = [];
45
47
  for (const item of event.message) {
@@ -99,8 +101,8 @@ var index = definePlatform(() => {
99
101
  // 处理消息
100
102
  onProcessor('message.create', e, event);
101
103
  });
102
- client.on('DIRECT_MESSAGE', (event) => {
103
- const uis = config.master_uids ?? [];
104
+ client.on('DIRECT_MESSAGE', event => {
105
+ const uis = config?.master_id ?? [];
104
106
  let msg = '';
105
107
  const arr = [];
106
108
  for (const item of event.message) {
@@ -316,8 +318,49 @@ var index = definePlatform(() => {
316
318
  }
317
319
  return Promise.all([]);
318
320
  },
319
- mention: async () => {
320
- return [];
321
+ mention: async (event) => {
322
+ const uis = config?.master_id ?? [];
323
+ const e = event.value;
324
+ if (e?.type == 'message.create' || e?.type == 'private.message.create') {
325
+ const Metions = [];
326
+ for (const item of e.message) {
327
+ if (item.type == 'at') {
328
+ let isBot = false;
329
+ if (item.data.qq == 'all') {
330
+ continue;
331
+ }
332
+ if (item.data.qq == MyBot.id) {
333
+ isBot = true;
334
+ }
335
+ const avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${item.data.qq}`;
336
+ Metions.push({
337
+ UserId: item.data.qq,
338
+ UserKey: useUserHashKey({
339
+ Platform: platform,
340
+ UserId: item.data.qq
341
+ }),
342
+ UserName: item.data?.nickname,
343
+ UserAvatar: {
344
+ toBuffer: async () => {
345
+ const arrayBuffer = await fetch(avatar).then(res => res.arrayBuffer());
346
+ return Buffer.from(arrayBuffer);
347
+ },
348
+ toBase64: async () => {
349
+ const arrayBuffer = await fetch(avatar).then(res => res.arrayBuffer());
350
+ return Buffer.from(arrayBuffer).toString('base64');
351
+ },
352
+ toURL: async () => {
353
+ return avatar;
354
+ }
355
+ },
356
+ IsMaster: uis.includes(item.data.qq),
357
+ IsBot: isBot
358
+ });
359
+ }
360
+ }
361
+ return;
362
+ }
363
+ return Promise.all([]);
321
364
  }
322
365
  }
323
366
  }
package/lib/sdk/wss.js CHANGED
@@ -98,7 +98,9 @@ class OneBotClient {
98
98
  }
99
99
  return;
100
100
  }
101
- else if (event?.echo === 'get_friend_list' || event?.echo === 'get_group_list' || event?.echo === 'get_group_member_list') {
101
+ else if (event?.echo === 'get_friend_list' ||
102
+ event?.echo === 'get_group_list' ||
103
+ event?.echo === 'get_group_member_list') {
102
104
  // 处理获取好友列表和群列表的响应
103
105
  // if (this.#events['META']) this.#events['META'](event)
104
106
  // console.debug('响应', event)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "onebot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -1,73 +0,0 @@
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 };