node-karin 0.8.4 → 0.8.5
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.
|
@@ -92,7 +92,7 @@ export class AdapterInput {
|
|
|
92
92
|
e.bot = this;
|
|
93
93
|
e.replyCallback = async (elements) => {
|
|
94
94
|
this.SendMessage(e.contact, elements);
|
|
95
|
-
return { message_id: e.message_id };
|
|
95
|
+
return { message_id: e.message_id, message_time: Date.now(), raw_data: elements };
|
|
96
96
|
};
|
|
97
97
|
listener.emit('message', e);
|
|
98
98
|
}
|
package/lib/core/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PluginType, KarinElement, NodeElement, stateArrType, KarinNoticeType, KarinRequestType, KarinEventTypes } from '../types/index.js';
|
|
1
|
+
import { PluginType, KarinElement, NodeElement, stateArrType, KarinNoticeType, KarinRequestType, KarinEventTypes, ReplyReturn } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* 插件基类
|
|
4
4
|
*/
|
|
@@ -115,17 +115,12 @@ export declare class Plugin implements PluginType {
|
|
|
115
115
|
* @default 1
|
|
116
116
|
*/
|
|
117
117
|
retry_count?: number;
|
|
118
|
-
}): Promise<
|
|
119
|
-
/**
|
|
120
|
-
* @param message_id - 消息发送成功返回的消息ID
|
|
121
|
-
*/
|
|
122
|
-
message_id?: string;
|
|
123
|
-
}>;
|
|
118
|
+
}): Promise<ReplyReturn>;
|
|
124
119
|
/**
|
|
125
120
|
* - 快速回复合并转发
|
|
126
121
|
*/
|
|
127
122
|
replyForward(msg: NodeElement[]): Promise<{
|
|
128
|
-
message_id
|
|
123
|
+
message_id: string;
|
|
129
124
|
}>;
|
|
130
125
|
/**
|
|
131
126
|
* - 构建上下文键
|
|
@@ -139,22 +139,28 @@ export default class EventHandler {
|
|
|
139
139
|
} else {
|
|
140
140
|
this.e.self_id !== 'input' && logger.bot('info', this.e.self_id, `${logger.green(`Send private ${this.e.user_id}: `)}${ReplyLog}`)
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
const request = {
|
|
143
|
+
message_id: '',
|
|
144
|
+
message_time: 0,
|
|
145
|
+
raw_data: undefined,
|
|
146
|
+
}
|
|
143
147
|
try {
|
|
144
148
|
listener.emit('karin:count:send', 1)
|
|
145
149
|
/** 取结果 */
|
|
146
150
|
const Res = await result
|
|
147
|
-
message_id = Res.message_id || ''
|
|
151
|
+
request.message_id = Res.message_id || ''
|
|
152
|
+
request.message_time = Res.message_time || Date.now()
|
|
153
|
+
request.raw_data = Res.raw_data || undefined
|
|
148
154
|
logger.bot('debug', this.e.self_id, `回复消息结果:${JSON.stringify(result)}`)
|
|
149
155
|
} catch (error) {
|
|
150
156
|
logger.bot('error', this.e.self_id, `回复消息失败:${ReplyLog}`)
|
|
151
157
|
logger.bot('error', this.e.self_id, error.stack || error.message || JSON.stringify(error))
|
|
152
158
|
}
|
|
153
159
|
/** 快速撤回 */
|
|
154
|
-
if (recallMsg > 0 && message_id) {
|
|
155
|
-
setTimeout(() => this.e.bot.RecallMessage(this.e.contact, message_id), recallMsg * 1000)
|
|
160
|
+
if (recallMsg > 0 && request.message_id) {
|
|
161
|
+
setTimeout(() => this.e.bot.RecallMessage(this.e.contact, request.message_id), recallMsg * 1000)
|
|
156
162
|
}
|
|
157
|
-
return
|
|
163
|
+
return request
|
|
158
164
|
}
|
|
159
165
|
Object.freeze(this.e.reply)
|
|
160
166
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebSocket } from 'ws';
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
|
-
import { Contact } from '../event/index.js';
|
|
3
|
+
import { Contact, ReplyReturn } from '../event/index.js';
|
|
4
4
|
import { KarinElement, NodeElement } from '../element.js';
|
|
5
5
|
import { LoggerLevel } from '../logger.js';
|
|
6
6
|
import { PushMessageBody, EssenceMessageBody, FriendInfo, GroupInfo, GroupMemberInfo, GroupHonorInfo, GroupFileInfo, GroupFolderInfo, GetRemainCountAtAllResponse } from './api.js';
|
|
@@ -117,11 +117,7 @@ export interface KarinAdapter {
|
|
|
117
117
|
* @param retry_count - 重试次数 默认为1
|
|
118
118
|
* @returns 此接口因各平台问题,允许返回更多自定义数据
|
|
119
119
|
*/
|
|
120
|
-
SendMessage(contact: Contact, elements: Array<KarinElement>, retry_count?: number): Promise<
|
|
121
|
-
message_id?: string;
|
|
122
|
-
message_time?: number;
|
|
123
|
-
[key: string]: any;
|
|
124
|
-
}>;
|
|
120
|
+
SendMessage(contact: Contact, elements: Array<KarinElement>, retry_count?: number): Promise<ReplyReturn>;
|
|
125
121
|
/**
|
|
126
122
|
* 上传合并转发消息返回一个资源ID
|
|
127
123
|
* @param contact - 联系人信息
|
|
@@ -353,7 +349,7 @@ export interface KarinAdapter {
|
|
|
353
349
|
* @param elements 消息元素
|
|
354
350
|
*/
|
|
355
351
|
sendForwardMessage(contact: Contact, elements: Array<NodeElement>): Promise<{
|
|
356
|
-
message_id
|
|
352
|
+
message_id: string;
|
|
357
353
|
}>;
|
|
358
354
|
/**
|
|
359
355
|
* 对消息进行表情回应 icqq需要传递seq
|
|
@@ -24,9 +24,20 @@ options?: {
|
|
|
24
24
|
* 重试次数
|
|
25
25
|
*/
|
|
26
26
|
retry_count?: number;
|
|
27
|
-
}) => Promise<
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
}) => Promise<ReplyReturn>;
|
|
28
|
+
/**
|
|
29
|
+
* 发送消息后返回信息
|
|
30
|
+
*/
|
|
31
|
+
export interface ReplyReturn {
|
|
32
|
+
/**
|
|
33
|
+
* 消息ID
|
|
34
|
+
*/
|
|
35
|
+
message_id: string;
|
|
36
|
+
/** 消息发送时间戳 */
|
|
37
|
+
message_time?: number;
|
|
38
|
+
/** 原始结果 QQBot适配器下为数组 */
|
|
39
|
+
raw_data?: any;
|
|
40
|
+
}
|
|
30
41
|
export type replyCallback = (
|
|
31
42
|
/**
|
|
32
43
|
* 发送的消息
|
|
@@ -35,9 +46,5 @@ elements: KarinElement[],
|
|
|
35
46
|
/**
|
|
36
47
|
* 重试次数
|
|
37
48
|
*/
|
|
38
|
-
retry_count?: number) => Promise<
|
|
39
|
-
|
|
40
|
-
}>;
|
|
41
|
-
export type replyForward = (msg: NodeElement[]) => Promise<{
|
|
42
|
-
message_id?: string;
|
|
43
|
-
}>;
|
|
49
|
+
retry_count?: number) => Promise<ReplyReturn>;
|
|
50
|
+
export type replyForward = (msg: NodeElement[]) => Promise<ReplyReturn>;
|
package/lib/utils/config.js
CHANGED
|
@@ -213,7 +213,7 @@ export const config = new (class Cfg {
|
|
|
213
213
|
* 实时获取packageon文件
|
|
214
214
|
*/
|
|
215
215
|
get package () {
|
|
216
|
-
const data = fs.readFileSync('
|
|
216
|
+
const data = fs.readFileSync(this.pkgDir + '/package.json', 'utf8')
|
|
217
217
|
const pack = JSON.parse(data)
|
|
218
218
|
return pack
|
|
219
219
|
}
|
|
@@ -244,7 +244,7 @@ export const config = new (class Cfg {
|
|
|
244
244
|
*/
|
|
245
245
|
getYaml (type, name, isWatch = false) {
|
|
246
246
|
/** 文件路径 */
|
|
247
|
-
const file =
|
|
247
|
+
const file = type === 'defSet' ? `${this.pkgCfgDir}/${name}.yaml` : `${this.cfgDir}/${name}.yaml`
|
|
248
248
|
/** 读取文件 */
|
|
249
249
|
const data = Yaml.parse(fs.readFileSync(file, 'utf8'))
|
|
250
250
|
/** 监听文件 */
|