onebots 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <h1>基于icqq的oneBot实现</h1>
2
+ <h1>基于oicq的oneBot实现</h1>
3
3
  <p>
4
4
 
5
5
  [![dm](https://shields.io/npm/dm/onebots)](https://www.npmjs.com/package/onebots)
@@ -8,6 +8,9 @@
8
8
  [![node engine](https://img.shields.io/node/v/oitq?color=339933&style=flat-square&labelColor=FAFAFA&logo=Node.js)](https://nodejs.org)
9
9
  [![qq group](https://img.shields.io/badge/group-860669870-blue?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,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&logoColor=000000)](https://jq.qq.com/?_wv=1027&k=B22VGXov)
10
10
 
11
+ [![Star History Chart](https://api.star-history.com/svg?repos=lc-cn/onebots&type=Date)](https://star-history.com/#lc-cn/onebots&Date)
12
+
13
+
11
14
  [Type Docs](https://lc-cn.github.io/onebots)
12
15
 
13
16
 
@@ -25,7 +28,7 @@ npm install onebots
25
28
  ```
26
29
  3. 在项目跟目录添加配置文件config.yaml
27
30
  ```yaml
28
- port: 6727 # 项目icqq-oneBot监听的端口(默认:6727)
31
+ port: 6727 # 项目onebots监听的端口(默认:6727)
29
32
  1472258369: # 你的机器人账户
30
33
  version: V11 # oneBot版本(V11 或 V12)
31
34
  ```
@@ -56,5 +59,5 @@ onebots
56
59
  | /remove | get | uin | 移除机器人 |
57
60
 
58
61
  # 鸣谢
59
- 1. [icqqjs/icqq](https://github.com/takayama-lily/icqq) 底层服务支持
62
+ 1. [takayama-lily/oicq](https://github.com/takayama-lily/oicq) 底层服务支持
60
63
  2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBots原先版本
package/lib/onebot.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
+ import 'oicq2-cq-enable';
2
3
  import { EventEmitter } from 'events';
3
4
  import { App } from "./server/app";
4
- import { Client } from "icqq";
5
+ import { Client } from "oicq";
5
6
  import { V11 } from "./service/V11";
6
7
  import { V12 } from "./service/V12";
7
8
  import { MayBeArray } from "./types";
package/lib/onebot.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
4
+ require("oicq2-cq-enable");
4
5
  const events_1 = require("events");
5
6
  const app_1 = require("./server/app");
6
7
  const utils_1 = require("./utils");
7
8
  const path_1 = require("path");
8
- const icqq_1 = require("icqq");
9
+ const oicq_1 = require("oicq");
9
10
  const V11_1 = require("./service/V11");
10
11
  const V12_1 = require("./service/V12");
11
12
  class NotFoundError extends Error {
@@ -36,7 +37,7 @@ class OneBot extends events_1.EventEmitter {
36
37
  throw new Error('不支持的oneBot版本:' + c.version);
37
38
  }
38
39
  });
39
- this.client = new icqq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
40
+ this.client = new oicq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
40
41
  this.instances = this.config.map(c => {
41
42
  switch (c.version) {
42
43
  case 'V11':
@@ -8,7 +8,7 @@ import { Router } from "./router";
8
8
  import { V11 } from "../service/V11";
9
9
  import { V12 } from "../service/V12";
10
10
  import { LogLevel, MayBeArray } from "../types";
11
- import { Platform } from "icqq";
11
+ import { Platform } from "oicq";
12
12
  export interface KoaOptions {
13
13
  env?: string;
14
14
  keys?: string[];
package/lib/server/app.js CHANGED
@@ -48,7 +48,7 @@ class App extends koa_1.default {
48
48
  super(config);
49
49
  this.oneBots = [];
50
50
  this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
51
- this.logger = (0, log4js_1.getLogger)('[icqq-oneBot]');
51
+ this.logger = (0, log4js_1.getLogger)('[oicq-oneBot]');
52
52
  this.logger.level = this.config.log_level;
53
53
  this.router = new router_1.Router({ prefix: config.path });
54
54
  this.use((0, koa_bodyparser_1.default)())
@@ -58,7 +58,7 @@ class App extends koa_1.default {
58
58
  this.createOneBots();
59
59
  }
60
60
  getLogger(uin, version = '') {
61
- const logger = (0, log4js_1.getLogger)(`[icqq-oneBot${version}:${uin}]`);
61
+ const logger = (0, log4js_1.getLogger)(`[oicq-oneBot${version}:${uin}]`);
62
62
  logger.level = this.config.log_level;
63
63
  return logger;
64
64
  }
@@ -1,4 +1,4 @@
1
- import { OnlineStatus } from "icqq";
1
+ import { OnlineStatus } from "oicq";
2
2
  import { V11 } from "../../../service/V11";
3
3
  export declare class CommonAction {
4
4
  /**
@@ -17,12 +17,12 @@ export declare class CommonAction {
17
17
  * 获取消息
18
18
  * @param message_id {string} 消息id
19
19
  */
20
- getMsg(this: V11, message_id: string): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
20
+ getMsg(this: V11, message_id: string): Promise<import("oicq").GroupMessage | import("oicq").PrivateMessage>;
21
21
  /**
22
22
  * 获取合并消息
23
23
  * @param id {string} 合并id
24
24
  */
25
- getForwardMsg(this: V11, id: string): Promise<import("icqq").ForwardMessage[]>;
25
+ getForwardMsg(this: V11, id: string): Promise<import("oicq").ForwardMessage[]>;
26
26
  /**
27
27
  * 获取 Cookies
28
28
  * @param domain {string} 域名
@@ -57,8 +57,9 @@ export declare class CommonAction {
57
57
  online: OnlineStatus;
58
58
  good: boolean;
59
59
  };
60
- login(this: V11, password?: string): Promise<unknown>;
60
+ callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
61
61
  submitSlider(this: V11, ticket: string): Promise<any>;
62
+ login(this: V11, password?: string): any;
62
63
  submitSmsCode(this: V11, code: string): Promise<any>;
63
64
  sendSmsCode(this: V11): void;
64
65
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonAction = void 0;
4
- const icqq_1 = require("icqq");
4
+ const oicq_1 = require("oicq");
5
5
  const onebot_1 = require("../../../onebot");
6
6
  class CommonAction {
7
7
  /**
@@ -62,7 +62,7 @@ class CommonAction {
62
62
  */
63
63
  getVersion() {
64
64
  return {
65
- app_name: 'icqq',
65
+ app_name: 'oicq',
66
66
  app_version: '2.x',
67
67
  protocol_version: 'v11'
68
68
  };
@@ -76,41 +76,40 @@ class CommonAction {
76
76
  }
77
77
  getStatus() {
78
78
  return {
79
- online: this.client.status = icqq_1.OnlineStatus.Online,
79
+ online: this.client.status = oicq_1.OnlineStatus.Online,
80
80
  good: this.oneBot.status === onebot_1.OneBotStatus.Good
81
81
  };
82
82
  }
83
- login(password) {
84
- const _this = this;
83
+ callLogin(func, ...args) {
85
84
  return new Promise(async (resolve) => {
86
- const timer = setTimeout(() => {
87
- receiveResult('登录超时');
88
- }, 5000);
89
- function receiveResult(event) {
90
- _this.client.off('system.login.qrcode', receiveResult);
91
- _this.client.off('system.login.device', receiveResult);
92
- _this.client.off('system.login.slider', receiveResult);
93
- _this.client.off('system.login.error', receiveResult);
94
- clearTimeout(timer);
85
+ const receiveResult = (event) => {
86
+ this.client.off('system.login.qrcode', receiveResult);
87
+ this.client.off('system.login.device', receiveResult);
88
+ this.client.off('system.login.slider', receiveResult);
89
+ this.client.off('system.login.error', receiveResult);
95
90
  resolve(event);
96
- }
91
+ };
97
92
  this.client.on('system.login.qrcode', receiveResult);
98
93
  this.client.on('system.login.device', receiveResult);
99
94
  this.client.on('system.login.slider', receiveResult);
100
95
  this.client.on('system.login.error', receiveResult);
101
- this.client.on('system.online', receiveResult);
102
- await this.client.login(password).catch(() => resolve('登录失败'));
96
+ this.client.once('system.online', receiveResult);
97
+ try {
98
+ await this.client[func](...args);
99
+ }
100
+ catch (reason) {
101
+ receiveResult(reason);
102
+ }
103
103
  });
104
104
  }
105
105
  async submitSlider(ticket) {
106
- await this.client.submitSlider(ticket);
107
- // @ts-ignore
108
- return this.action.login.apply(this, []);
106
+ return this.action.callLogin.apply(this, ['submitSlider', ticket]);
107
+ }
108
+ login(password) {
109
+ return this.action.callLogin.apply(this, ['login', password]);
109
110
  }
110
111
  async submitSmsCode(code) {
111
- await this.client.submitSmsCode(code);
112
- // @ts-ignore
113
- return this.action.login.apply(this, []);
112
+ return this.action.login.apply(this, ['submitSmsCode', code]);
114
113
  }
115
114
  sendSmsCode() {
116
115
  return this.client.sendSmsCode();
@@ -1,16 +1,16 @@
1
1
  import { OneBot } from "../../../onebot";
2
- import { Sendable } from "icqq";
2
+ import { Sendable } from "oicq";
3
3
  export declare class FriendAction {
4
4
  /**
5
5
  * 发送私聊消息
6
6
  * @param user_id {number} 用户id
7
- * @param message {import('icqq').Sendable} 发送的消息
7
+ * @param message {import('oicq').Sendable} 发送的消息
8
8
  */
9
- sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
9
+ sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
10
10
  /**
11
11
  * 获取好友列表
12
12
  */
13
- getFriendList(this: OneBot<'V11'>): Promise<import("icqq").FriendInfo[]>;
13
+ getFriendList(this: OneBot<'V11'>): Promise<import("oicq").FriendInfo[]>;
14
14
  /**
15
15
  * 处理好友添加请求
16
16
  * @param flag {string} 请求flag
@@ -25,7 +25,7 @@ export declare class FriendAction {
25
25
  getStrangerInfo(this: OneBot<'V11'>, user_id: number): Promise<{
26
26
  user_id: number;
27
27
  nickname: string;
28
- sex: import("icqq").Gender;
28
+ sex: import("oicq").Gender;
29
29
  age: number;
30
30
  area: string;
31
31
  }>;
@@ -5,7 +5,7 @@ class FriendAction {
5
5
  /**
6
6
  * 发送私聊消息
7
7
  * @param user_id {number} 用户id
8
- * @param message {import('icqq').Sendable} 发送的消息
8
+ * @param message {import('oicq').Sendable} 发送的消息
9
9
  */
10
10
  sendPrivateMsg(user_id, message) {
11
11
  return this.client.sendPrivateMsg(user_id, message);
@@ -1,12 +1,12 @@
1
- import { Sendable } from "icqq";
1
+ import { Sendable } from "oicq";
2
2
  import { V11 } from "../../../service/V11";
3
3
  export declare class GroupAction {
4
4
  /**
5
5
  * 发送群聊消息
6
6
  * @param group_id {number} 群id
7
- * @param message {import('icqq').Sendable} 消息
7
+ * @param message {import('oicq').Sendable} 消息
8
8
  */
9
- sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
9
+ sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
10
10
  /**
11
11
  * 群组踢人
12
12
  * @param group_id {number} 群id
@@ -84,21 +84,21 @@ export declare class GroupAction {
84
84
  /**
85
85
  * 获取群列表
86
86
  */
87
- getGroupList(this: V11): Promise<Map<number, import("icqq").GroupInfo>>;
87
+ getGroupList(this: V11): Promise<Map<number, import("oicq").GroupInfo>>;
88
88
  /**
89
89
  * 获取指定群信息
90
90
  * @param group_id
91
91
  */
92
- getGroupInfo(this: V11, group_id: number): Promise<import("icqq").GroupInfo>;
92
+ getGroupInfo(this: V11, group_id: number): Promise<import("oicq").GroupInfo>;
93
93
  /**
94
94
  * 获取群成员列表
95
95
  * @param group_id
96
96
  */
97
- getGroupMemberList(this: V11, group_id: number): Promise<Map<number, import("icqq").MemberInfo>>;
97
+ getGroupMemberList(this: V11, group_id: number): Promise<Map<number, import("oicq").MemberInfo>>;
98
98
  /**
99
99
  * 获取指定群成员信息
100
100
  * @param group_id
101
101
  * @param user_id
102
102
  */
103
- getGroupMemberInfo(this: V11, group_id: number, user_id: number): Promise<import("icqq").MemberInfo>;
103
+ getGroupMemberInfo(this: V11, group_id: number, user_id: number): Promise<import("oicq").MemberInfo>;
104
104
  }
@@ -5,7 +5,7 @@ class GroupAction {
5
5
  /**
6
6
  * 发送群聊消息
7
7
  * @param group_id {number} 群id
8
- * @param message {import('icqq').Sendable} 消息
8
+ * @param message {import('oicq').Sendable} 消息
9
9
  */
10
10
  sendGroupMsg(group_id, message) {
11
11
  return this.client.sendGroupMsg(group_id, message);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Client } from "icqq";
3
+ import { Client } from "oicq";
4
4
  import { Config } from "./config";
5
5
  import { Action } from "./action";
6
6
  import { OneBot } from "../../onebot";
@@ -8,7 +8,7 @@ const action_1 = require("./action");
8
8
  const ws_1 = require("ws");
9
9
  const url_1 = require("url");
10
10
  const utils_1 = require("../../utils");
11
- const icqq_cq_enable_1 = require("icqq-cq-enable");
11
+ const oicq2_cq_enable_1 = require("oicq2-cq-enable");
12
12
  const onebot_1 = require("../../onebot");
13
13
  const http_1 = __importDefault(require("http"));
14
14
  const https_1 = __importDefault(require("https"));
@@ -170,7 +170,7 @@ class V11 extends events_1.EventEmitter {
170
170
  if (data.post_type === 'system') {
171
171
  }
172
172
  if (data.message && data.post_type === 'message') {
173
- data.message = this.config.post_message_format === 'array' ? (0, icqq_cq_enable_1.toSegment)(data.message) : (0, icqq_cq_enable_1.toCqcode)(data);
173
+ data.message = this.config.post_message_format === 'array' ? (0, oicq2_cq_enable_1.toSegment)(data.message) : (0, oicq2_cq_enable_1.toCqcode)(data);
174
174
  }
175
175
  this.emit('dispatch', JSON.stringify(data));
176
176
  }
@@ -372,10 +372,10 @@ class V11 extends events_1.EventEmitter {
372
372
  params[k] = (0, utils_1.toBool)(params[k]);
373
373
  if (k === 'message') {
374
374
  if (typeof params[k] === 'string') {
375
- params[k] = (0, icqq_cq_enable_1.fromCqcode)(params[k]);
375
+ params[k] = (0, oicq2_cq_enable_1.fromCqcode)(params[k]);
376
376
  }
377
377
  else {
378
- params[k] = (0, icqq_cq_enable_1.fromSegment)(params[k]);
378
+ params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
379
379
  }
380
380
  }
381
381
  args.push(params[k]);
@@ -1,6 +1,7 @@
1
1
  import { V12 } from '../../../service/V12';
2
- import { OnlineStatus } from "icqq";
2
+ import { OnlineStatus } from "oicq";
3
3
  import { Action } from "./";
4
+ import { V11 } from "../../../service/V11";
4
5
  export declare class CommonAction {
5
6
  sendMsg(): void;
6
7
  /**
@@ -23,9 +24,10 @@ export declare class CommonAction {
23
24
  version: string;
24
25
  onebot_version: string;
25
26
  };
26
- submitSlider(this: V12, ticket: string): Promise<unknown>;
27
- submitSmsCode(this: V12, code: string): Promise<unknown>;
27
+ callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
28
+ submitSlider(this: V11, ticket: string): Promise<any>;
29
+ login(this: V11, password?: string): any;
30
+ submitSmsCode(this: V11, code: string): Promise<any>;
28
31
  sendSmsCode(this: V12): void;
29
- login(this: V12, password?: string): Promise<unknown>;
30
32
  getSupportedActions(this: V12): string[];
31
33
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonAction = void 0;
4
- const icqq_1 = require("icqq");
4
+ const oicq_1 = require("oicq");
5
5
  const onebot_1 = require("../../../onebot");
6
6
  const utils_1 = require("../../../utils");
7
7
  class CommonAction {
@@ -21,7 +21,7 @@ class CommonAction {
21
21
  }
22
22
  getStatus() {
23
23
  return {
24
- online: this.client.status = icqq_1.OnlineStatus.Online,
24
+ online: this.client.status = oicq_1.OnlineStatus.Online,
25
25
  good: this.oneBot.status === onebot_1.OneBotStatus.Good
26
26
  };
27
27
  }
@@ -35,71 +35,46 @@ class CommonAction {
35
35
  }
36
36
  getVersion() {
37
37
  return {
38
- impl: 'icqq_onebot',
38
+ impl: 'onebots',
39
39
  platform: 'qq',
40
- version: '0.0.1',
40
+ version: '0.0.5',
41
41
  onebot_version: '12'
42
42
  };
43
43
  }
44
+ callLogin(func, ...args) {
45
+ return new Promise(async (resolve) => {
46
+ const receiveResult = (event) => {
47
+ this.client.off('system.login.qrcode', receiveResult);
48
+ this.client.off('system.login.device', receiveResult);
49
+ this.client.off('system.login.slider', receiveResult);
50
+ this.client.off('system.login.error', receiveResult);
51
+ resolve(event);
52
+ };
53
+ this.client.on('system.login.qrcode', receiveResult);
54
+ this.client.on('system.login.device', receiveResult);
55
+ this.client.on('system.login.slider', receiveResult);
56
+ this.client.on('system.login.error', receiveResult);
57
+ this.client.once('system.online', receiveResult);
58
+ try {
59
+ await this.client[func](...args);
60
+ }
61
+ catch (reason) {
62
+ receiveResult(reason);
63
+ }
64
+ });
65
+ }
44
66
  async submitSlider(ticket) {
45
- await this.client.submitSlider(ticket);
46
- // @ts-ignore
47
- return this.action.login();
67
+ return this.action.callLogin.apply(this, ['submitSlider', ticket]);
68
+ }
69
+ login(password) {
70
+ return this.action.callLogin.apply(this, ['login', password]);
48
71
  }
49
72
  async submitSmsCode(code) {
50
- await this.client.submitSmsCode(code);
51
- // @ts-ignore
52
- return this.action.login();
73
+ return this.action.login.apply(this, ['submitSmsCode', code]);
53
74
  }
54
75
  sendSmsCode() {
55
76
  return this.client.sendSmsCode();
56
77
  }
57
- login(password) {
58
- const _this = this;
59
- return new Promise(async (resolve) => {
60
- const timer = setTimeout(() => {
61
- resolve('登录超时');
62
- }, 5000);
63
- function receiveQrcode(event) {
64
- _this.client.off('system.login.device', receiveDevice);
65
- _this.client.off('system.login.slider', receiveSlider);
66
- _this.client.off('system.online', closeListen);
67
- clearTimeout(timer);
68
- resolve(event);
69
- }
70
- function receiveDevice(event) {
71
- _this.client.off('system.login.qrcode', receiveQrcode);
72
- _this.client.off('system.login.slider', receiveSlider);
73
- _this.client.off('system.online', closeListen);
74
- clearTimeout(timer);
75
- resolve(event);
76
- }
77
- function receiveError(event) {
78
- clearTimeout(timer);
79
- resolve(event);
80
- }
81
- function receiveSlider(event) {
82
- _this.client.off('system.login.qrcode', receiveQrcode);
83
- _this.client.off('system.login.device', receiveDevice);
84
- _this.client.off('system.online', closeListen);
85
- clearTimeout(timer);
86
- resolve(event);
87
- }
88
- function closeListen() {
89
- _this.client.off('system.login.slider', receiveSlider);
90
- _this.client.off('system.login.qrcode', receiveQrcode);
91
- _this.client.off('system.login.device', receiveDevice);
92
- clearTimeout(timer);
93
- resolve('登录成功');
94
- }
95
- this.client.once('system.login.qrcode', receiveQrcode);
96
- this.client.once('system.login.device', receiveDevice);
97
- this.client.once('system.login.slider', receiveSlider);
98
- this.client.once('system.login.error', receiveError);
99
- this.client.once('system.online', closeListen);
100
- await this.client.login(password).catch(() => resolve('登录失败'));
101
- });
102
- }
103
78
  getSupportedActions() {
104
79
  return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
105
80
  return key !== 'constructor';
@@ -1,13 +1,13 @@
1
1
  import { V12 } from "../index";
2
- import { Sendable } from "icqq";
2
+ import { Sendable } from "oicq";
3
3
  export declare class FriendAction {
4
4
  getUserInfo(this: V12, user_id: number): Promise<{
5
5
  user_id: number;
6
6
  nickname: string;
7
- sex: import("icqq").Gender;
7
+ sex: import("oicq").Gender;
8
8
  age: number;
9
9
  area: string;
10
10
  }>;
11
- getFriendList(this: V12): Map<number, import("icqq").FriendInfo>;
12
- sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
11
+ getFriendList(this: V12): Map<number, import("oicq").FriendInfo>;
12
+ sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
13
13
  }
@@ -1,12 +1,12 @@
1
1
  import { V12 } from "../index";
2
- import { Sendable } from "icqq";
2
+ import { Sendable } from "oicq";
3
3
  export declare class GroupAction {
4
4
  /**
5
5
  * 发送群聊消息
6
6
  * @param group_id {number} 群id
7
- * @param message {import('icqq').Sendable} 消息
7
+ * @param message {import('oicq').Sendable} 消息
8
8
  */
9
- sendGroupMsg(this: V12, group_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
9
+ sendGroupMsg(this: V12, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
10
10
  /**
11
11
  * 群组踢人
12
12
  * @param group_id {number} 群id
@@ -84,21 +84,21 @@ export declare class GroupAction {
84
84
  /**
85
85
  * 获取群列表
86
86
  */
87
- getGroupList(this: V12): Promise<Map<number, import("icqq").GroupInfo>>;
87
+ getGroupList(this: V12): Promise<Map<number, import("oicq").GroupInfo>>;
88
88
  /**
89
89
  * 获取指定群信息
90
90
  * @param group_id
91
91
  */
92
- getGroupInfo(this: V12, group_id: number): Promise<import("icqq").GroupInfo>;
92
+ getGroupInfo(this: V12, group_id: number): Promise<import("oicq").GroupInfo>;
93
93
  /**
94
94
  * 获取群成员列表
95
95
  * @param group_id
96
96
  */
97
- getGroupMemberList(this: V12, group_id: number): Promise<Map<number, import("icqq").MemberInfo>>;
97
+ getGroupMemberList(this: V12, group_id: number): Promise<Map<number, import("oicq").MemberInfo>>;
98
98
  /**
99
99
  * 获取指定群成员信息
100
100
  * @param group_id
101
101
  * @param user_id
102
102
  */
103
- getGroupMemberInfo(this: V12, group_id: number, user_id: number): Promise<import("icqq").MemberInfo>;
103
+ getGroupMemberInfo(this: V12, group_id: number, user_id: number): Promise<import("oicq").MemberInfo>;
104
104
  }
@@ -5,7 +5,7 @@ class GroupAction {
5
5
  /**
6
6
  * 发送群聊消息
7
7
  * @param group_id {number} 群id
8
- * @param message {import('icqq').Sendable} 消息
8
+ * @param message {import('oicq').Sendable} 消息
9
9
  */
10
10
  sendGroupMsg(group_id, message) {
11
11
  return this.client.sendGroupMsg(group_id, message);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Client } from "icqq";
3
+ import { Client } from "oicq";
4
4
  import { Config } from './config';
5
5
  import { OneBot } from "../../onebot";
6
6
  import { Action } from "./action";
@@ -77,7 +77,7 @@ export declare namespace V12 {
77
77
  const defaultConfig: Config;
78
78
  type Payload<T extends any> = {
79
79
  id: string;
80
- impl: 'icqq_onebot';
80
+ impl: 'oicq_onebot';
81
81
  platform: 'qq';
82
82
  self_id: `${number}`;
83
83
  time: number;
@@ -12,7 +12,7 @@ const url_1 = require("url");
12
12
  const http_1 = __importDefault(require("http"));
13
13
  const https_1 = __importDefault(require("https"));
14
14
  const ws_1 = require("ws");
15
- const icqq_cq_enable_1 = require("icqq-cq-enable");
15
+ const oicq2_cq_enable_1 = require("oicq2-cq-enable");
16
16
  const utils_1 = require("../../utils");
17
17
  const db_1 = require("../../db");
18
18
  const app_1 = require("../../server/app");
@@ -231,7 +231,7 @@ class V12 extends events_1.EventEmitter {
231
231
  }
232
232
  const payload = {
233
233
  id: (0, utils_1.uuid)(),
234
- impl: 'icqq_onebot',
234
+ impl: 'oicq_onebot',
235
235
  platform: 'qq',
236
236
  self_id: `${this.client.uin}`,
237
237
  type: data.post_type || 'meta',
@@ -287,10 +287,10 @@ class V12 extends events_1.EventEmitter {
287
287
  params[k] = (0, utils_1.toBool)(params[k]);
288
288
  if (k === 'message') {
289
289
  if (typeof params[k] === 'string') {
290
- params[k] = (0, icqq_cq_enable_1.fromCqcode)(params[k]);
290
+ params[k] = (0, oicq2_cq_enable_1.fromCqcode)(params[k]);
291
291
  }
292
292
  else {
293
- params[k] = (0, icqq_cq_enable_1.fromSegment)(params[k]);
293
+ params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
294
294
  }
295
295
  }
296
296
  args.push(params[k]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.0.5",
4
- "description": "基于icqq的多例oneBot实现",
3
+ "version": "0.0.7",
4
+ "description": "基于oicq的多例oneBot实现",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
7
7
  "onebots": "./lib/bin.js"
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "keywords": [
21
21
  "onebot",
22
- "icqq",
22
+ "oicq",
23
23
  "cq-http"
24
24
  ],
25
25
  "author": "凉菜",
@@ -47,12 +47,12 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@koa/router": "^10.1.1",
50
- "icqq": "^0.0.1",
51
- "icqq-cq-enable": "^1.0.0",
52
50
  "js-yaml": "^4.1.0",
53
51
  "koa": "^2.13.4",
54
52
  "koa-bodyparser": "^4.3.0",
55
53
  "log4js": "^6.5.2",
54
+ "oicq": "^2.3.1",
55
+ "oicq2-cq-enable": "^1.0.6",
56
56
  "ws": "^8.8.0"
57
57
  }
58
58
  }