onebots 0.1.2 → 0.1.4

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.
@@ -9,7 +9,7 @@ class CommonAction {
9
9
  */
10
10
  getLoginInfo() {
11
11
  return {
12
- user_id: this.client.uin,
12
+ user_id: this.oneBot.uin,
13
13
  nickname: this.client.nickname
14
14
  };
15
15
  }
@@ -83,17 +83,17 @@ class CommonAction {
83
83
  callLogin(func, ...args) {
84
84
  return new Promise(async (resolve) => {
85
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);
86
+ this.client.offTrap('system.login.qrcode', receiveResult);
87
+ this.client.offTrap('system.login.device', receiveResult);
88
+ this.client.offTrap('system.login.slider', receiveResult);
89
+ this.client.offTrap('system.login.error', receiveResult);
90
90
  resolve(event);
91
91
  };
92
- this.client.on('system.login.qrcode', receiveResult);
93
- this.client.on('system.login.device', receiveResult);
94
- this.client.on('system.login.slider', receiveResult);
95
- this.client.on('system.login.error', receiveResult);
96
- this.client.once('system.online', receiveResult);
92
+ this.client.trap('system.login.qrcode', receiveResult);
93
+ this.client.trap('system.login.device', receiveResult);
94
+ this.client.trap('system.login.slider', receiveResult);
95
+ this.client.trap('system.login.error', receiveResult);
96
+ this.client.trapOnce('system.online', receiveResult);
97
97
  try {
98
98
  await this.client[func](...args);
99
99
  }
@@ -112,16 +112,16 @@ class CommonAction {
112
112
  return new Promise(resolve => {
113
113
  const receiveResult = (e) => {
114
114
  const callback = (data) => {
115
- this.client.off('internal.verbose', receiveResult);
116
- this.client.off('system.login.error', receiveResult);
115
+ this.client.offTrap('internal.verbose', receiveResult);
116
+ this.client.offTrap('system.login.error', receiveResult);
117
117
  resolve(data);
118
118
  };
119
119
  if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
120
120
  callback(e);
121
121
  }
122
122
  };
123
- this.client.on('internal.verbose', receiveResult);
124
- this.client.on('system.login.error', receiveResult);
123
+ this.client.trap('internal.verbose', receiveResult);
124
+ this.client.trap('system.login.error', receiveResult);
125
125
  this.client.sendSmsCode();
126
126
  });
127
127
  }
@@ -131,10 +131,10 @@ class CommonAction {
131
131
  logout(keepalive) {
132
132
  return new Promise(async (resolve) => {
133
133
  const receiveResult = (e) => {
134
- this.client.off('system.offline', receiveResult);
134
+ this.client.offTrap('system.offline', receiveResult);
135
135
  resolve(e);
136
136
  };
137
- this.client.on('system.offline', receiveResult);
137
+ this.client.trap('system.offline', receiveResult);
138
138
  await this.client.logout(keepalive);
139
139
  });
140
140
  }
@@ -1,6 +1,7 @@
1
1
  import { V12 } from '../../../service/V12';
2
2
  import { OnlineStatus } from "icqq";
3
3
  import { Action } from "./";
4
+ import { V11 } from "../../../service/V11";
4
5
  export declare class CommonAction {
5
6
  sendMessage(): void;
6
7
  /**
@@ -9,11 +10,16 @@ export declare class CommonAction {
9
10
  */
10
11
  deleteMsg(this: V12, message_id: string): Promise<boolean>;
11
12
  getSelfInfo(this: V12): {
12
- user_id: number;
13
+ user_id: string;
13
14
  platform: string;
14
15
  nickname: string;
15
16
  user_displayname: string;
16
17
  };
18
+ /**
19
+ * 获取 Cookies
20
+ * @param domain {string} 域名
21
+ */
22
+ getCookies(this: V11, domain: string): string;
17
23
  getStatus(this: V12): {
18
24
  good: boolean;
19
25
  bots: {
@@ -32,7 +38,7 @@ export declare class CommonAction {
32
38
  submitSlider(this: V12, ticket: string): Promise<any>;
33
39
  submitSmsCode(this: V12, code: string): Promise<any>;
34
40
  sendSmsCode(this: V12): Promise<any>;
35
- login(this: V12, password?: string): any;
41
+ login(this: V12, password?: string): Promise<unknown>;
36
42
  logout(this: V12, keepalive?: boolean): Promise<unknown>;
37
43
  getSupportedActions(this: V12): string[];
38
44
  }
@@ -15,12 +15,19 @@ class CommonAction {
15
15
  }
16
16
  getSelfInfo() {
17
17
  return {
18
- user_id: this.client.uin,
18
+ user_id: this.oneBot.uin + '',
19
19
  platform: 'qq',
20
20
  nickname: this.client.nickname,
21
21
  user_displayname: ''
22
22
  };
23
23
  }
24
+ /**
25
+ * 获取 Cookies
26
+ * @param domain {string} 域名
27
+ */
28
+ getCookies(domain) {
29
+ return this.client.cookies[domain];
30
+ }
24
31
  getStatus() {
25
32
  return {
26
33
  good: this.oneBot.status === onebot_1.OneBotStatus.Good,
@@ -51,17 +58,17 @@ class CommonAction {
51
58
  callLogin(func, ...args) {
52
59
  return new Promise(async (resolve) => {
53
60
  const receiveResult = (event) => {
54
- this.client.off('system.login.qrcode', receiveResult);
55
- this.client.off('system.login.device', receiveResult);
56
- this.client.off('system.login.slider', receiveResult);
57
- this.client.off('system.login.error', receiveResult);
61
+ this.client.offTrap('system.login.qrcode', receiveResult);
62
+ this.client.offTrap('system.login.device', receiveResult);
63
+ this.client.offTrap('system.login.slider', receiveResult);
64
+ this.client.offTrap('system.login.error', receiveResult);
58
65
  resolve(event);
59
66
  };
60
- this.client.on('system.login.qrcode', receiveResult);
61
- this.client.on('system.login.device', receiveResult);
62
- this.client.on('system.login.slider', receiveResult);
63
- this.client.on('system.login.error', receiveResult);
64
- this.client.once('system.online', receiveResult);
67
+ this.client.trap('system.login.qrcode', receiveResult);
68
+ this.client.trap('system.login.device', receiveResult);
69
+ this.client.trap('system.login.slider', receiveResult);
70
+ this.client.trap('system.login.error', receiveResult);
71
+ this.client.trapOnce('system.online', receiveResult);
65
72
  try {
66
73
  await this.client[func](...args);
67
74
  }
@@ -80,16 +87,16 @@ class CommonAction {
80
87
  return new Promise(resolve => {
81
88
  const receiveResult = (e) => {
82
89
  const callback = (data) => {
83
- this.client.off('internal.verbose', receiveResult);
84
- this.client.off('system.login.error', receiveResult);
90
+ this.client.offTrap('internal.verbose', receiveResult);
91
+ this.client.offTrap('system.login.error', receiveResult);
85
92
  resolve(data);
86
93
  };
87
94
  if ((typeof e === 'string' && e.includes('已发送')) || typeof e !== 'string') {
88
95
  callback(e);
89
96
  }
90
97
  };
91
- this.client.on('internal.verbose', receiveResult);
92
- this.client.on('system.login.error', receiveResult);
98
+ this.client.trap('internal.verbose', receiveResult);
99
+ this.client.trap('system.login.error', receiveResult);
93
100
  this.client.sendSmsCode();
94
101
  });
95
102
  }
@@ -99,7 +106,7 @@ class CommonAction {
99
106
  logout(keepalive) {
100
107
  return new Promise(async (resolve) => {
101
108
  const receiveResult = (e) => {
102
- this.client.off('system.offline', receiveResult);
109
+ this.client.offTrap('system.offline', receiveResult);
103
110
  resolve(e);
104
111
  };
105
112
  this.client.on('system.offline', receiveResult);
@@ -1,2 +1,20 @@
1
+ import { V12 } from "../../../service/V12";
2
+ import SegmentElem = V12.SegmentElem;
1
3
  export declare class GuildAction {
4
+ getGuildList(this: V12): {
5
+ guild_id: string;
6
+ guild_name: string;
7
+ }[];
8
+ getChannelList(this: V12, guild_id: string): {
9
+ guild_id: string;
10
+ channel_id: string;
11
+ channel_name: string;
12
+ channel_type: import("icqq/lib/channel").ChannelType;
13
+ }[];
14
+ getGuildMemberList(this: V12, guild_id: string): never[] | Promise<import("icqq/lib/guild").GuildMember[]>;
15
+ sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: SegmentElem[]): Promise<{
16
+ seq: number;
17
+ rand: number;
18
+ time: number;
19
+ }>;
2
20
  }
@@ -1,6 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GuildAction = void 0;
4
+ const V12_1 = require("../../../service/V12");
5
+ const utils_1 = require("../../../utils");
4
6
  class GuildAction {
7
+ getGuildList() {
8
+ return this.client.getGuildList();
9
+ }
10
+ getChannelList(guild_id) {
11
+ return this.client.getChannelList(guild_id);
12
+ }
13
+ getGuildMemberList(guild_id) {
14
+ return this.client.getGuildMemberList(guild_id);
15
+ }
16
+ async sendGuildMsg(guild_id, channel_id, message) {
17
+ const forward = message.find(e => e.type === 'node');
18
+ if (forward)
19
+ (0, utils_1.remove)(message, forward);
20
+ let quote = message.find(e => e.type === 'reply');
21
+ if (quote)
22
+ (0, utils_1.remove)(message, quote);
23
+ const element = V12_1.V12.fromSegment(message);
24
+ // if(forward) element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment=>{
25
+ // return {
26
+ // message:V12.fromSegment([segment]),
27
+ // user_id:forward.data.user_id,
28
+ // nickname:forward.data.user_name,
29
+ // time:forward.data.time
30
+ // }
31
+ // })))
32
+ // if(quote && !message_id) message_id=quote.data.message_id
33
+ return await this.client.sendGuildMsg(guild_id, channel_id, element);
34
+ }
5
35
  }
6
36
  exports.GuildAction = GuildAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@koa/router": "^10.1.1",
53
- "icqq": "^0.0.13-4",
53
+ "icqq": "^0.0.13-6",
54
54
  "icqq-cq-enable": "^1.0.0",
55
55
  "js-yaml": "^4.1.0",
56
56
  "koa": "^2.13.4",