@alemonjs/onebot 0.2.4 → 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
@@ -1,8 +1,9 @@
1
1
  import { getConfigValue, useUserHashKey, onProcessor, createResult, ResultCode } from 'alemonjs';
2
2
  import { OneBotClient } from './sdk/wss.js';
3
- import { createServer } from './server/index.js';
4
3
  import { readFileSync } from 'fs';
5
4
 
5
+ const MyBot = {
6
+ id: ''};
6
7
  const ImageURLToBuffer = async (url) => {
7
8
  const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
8
9
  return Buffer.from(arrayBuffer);
@@ -36,11 +37,11 @@ var index = definePlatform(() => {
36
37
  client.connect();
37
38
  client.on('META', event => {
38
39
  if (event?.self_id) {
39
- String(event.self_id);
40
+ MyBot.id = String(event.self_id);
40
41
  }
41
42
  });
42
43
  client.on('MESSAGES', event => {
43
- const uis = config.master_uids ?? [];
44
+ const uis = config?.master_id ?? [];
44
45
  let msg = '';
45
46
  const arr = [];
46
47
  for (const item of event.message) {
@@ -100,8 +101,8 @@ var index = definePlatform(() => {
100
101
  // 处理消息
101
102
  onProcessor('message.create', e, event);
102
103
  });
103
- client.on('DIRECT_MESSAGE', (event) => {
104
- const uis = config.master_uids ?? [];
104
+ client.on('DIRECT_MESSAGE', event => {
105
+ const uis = config?.master_id ?? [];
105
106
  let msg = '';
106
107
  const arr = [];
107
108
  for (const item of event.message) {
@@ -166,7 +167,6 @@ var index = definePlatform(() => {
166
167
  console.error('ERROR', event);
167
168
  });
168
169
  global.client = client;
169
- createServer(client);
170
170
  const sendGroup = async (event, val) => {
171
171
  if (val.length < 0)
172
172
  return Promise.all([]);
@@ -318,8 +318,49 @@ var index = definePlatform(() => {
318
318
  }
319
319
  return Promise.all([]);
320
320
  },
321
- mention: async () => {
322
- 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([]);
323
364
  }
324
365
  }
325
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.4",
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 };