mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: msg
This commit is contained in:
14
CHANGELOG
14
CHANGELOG
@@ -1,14 +0,0 @@
|
|||||||
# 3.24.0
|
|
||||||
|
|
||||||
## 修复
|
|
||||||
|
|
||||||
* 修复图片rkey导致链接失效的问题
|
|
||||||
* 修复/get_image, /get_file 无法获取图片的问题
|
|
||||||
* 修复上报他人管理员被取消通知
|
|
||||||
|
|
||||||
## 新增
|
|
||||||
|
|
||||||
* 新增表情回应发送和上报
|
|
||||||
* 新增商城表情发送,和上报 url
|
|
||||||
* 新增转发单条消息接口 `forward_friend_single_msg`, `forward_group_single_msg`
|
|
||||||
* 新增新增好友事件
|
|
@@ -3,7 +3,7 @@
|
|||||||
LiteLoaderQQNT 插件,实现 OneBot 11 协议,用以 QQ 机器人开发
|
LiteLoaderQQNT 插件,实现 OneBot 11 协议,用以 QQ 机器人开发
|
||||||
|
|
||||||
> [!CAUTION]\
|
> [!CAUTION]\
|
||||||
> **请不要在 QQ 官方群聊和任何影响力较大的简中互联网平台(包括但不限于: B站,微博,知乎,抖音等)发布和讨论*任何*与本插件存在相关性的信息**
|
> **请不要在 QQ 官方群聊和任何影响力较大的简中互联网平台(包括但不限于: 哔哩哔哩,微博,知乎,抖音等)发布和讨论*任何*与本插件存在相关性的信息**
|
||||||
|
|
||||||
TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||||
|
|
||||||
|
@@ -5,14 +5,7 @@ import './scripts/gen-manifest'
|
|||||||
const external = [
|
const external = [
|
||||||
'silk-wasm',
|
'silk-wasm',
|
||||||
'ws',
|
'ws',
|
||||||
'level',
|
'@minatojs/sql.js',
|
||||||
'classic-level',
|
|
||||||
'abstract-level',
|
|
||||||
'level-supports',
|
|
||||||
'level-transcoder',
|
|
||||||
'module-error',
|
|
||||||
'catering',
|
|
||||||
'node-gyp-build',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
function genCpModule(module: string) {
|
function genCpModule(module: string) {
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "实现 OneBot 11 协议,用以 QQ 机器人开发",
|
"description": "实现 OneBot 11 协议,用以 QQ 机器人开发",
|
||||||
"version": "3.28.6",
|
"version": "3.28.7",
|
||||||
"icon": "./icon.webp",
|
"icon": "./icon.webp",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -16,13 +16,15 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@minatojs/driver-sqlite": "^4.4.1",
|
||||||
"compressing": "^1.10.1",
|
"compressing": "^1.10.1",
|
||||||
|
"cordis": "^3.17.9",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"fast-xml-parser": "^4.4.1",
|
"fast-xml-parser": "^4.4.1",
|
||||||
"file-type": "^19.4.0",
|
"file-type": "^19.4.0",
|
||||||
"fluent-ffmpeg": "^2.1.3",
|
"fluent-ffmpeg": "^2.1.3",
|
||||||
"level": "^8.0.1",
|
"minato": "^3.4.3",
|
||||||
"silk-wasm": "^3.6.1",
|
"silk-wasm": "^3.6.1",
|
||||||
"ws": "^8.18.0"
|
"ws": "^8.18.0"
|
||||||
},
|
},
|
||||||
|
@@ -16,7 +16,7 @@ export const llonebotError: LLOneBotError = {
|
|||||||
ffmpegError: '',
|
ffmpegError: '',
|
||||||
httpServerError: '',
|
httpServerError: '',
|
||||||
wsServerError: '',
|
wsServerError: '',
|
||||||
otherError: 'LLOnebot未能正常启动,请检查日志查看错误',
|
otherError: 'LLOnebot 未能正常启动,请检查日志查看错误',
|
||||||
}
|
}
|
||||||
// 群号 -> 群成员map(uid=>GroupMember)
|
// 群号 -> 群成员map(uid=>GroupMember)
|
||||||
export const groupMembers: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>()
|
export const groupMembers: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>()
|
||||||
@@ -102,7 +102,7 @@ const selfInfo: SelfInfo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getSelfNick(force = false): Promise<string> {
|
export async function getSelfNick(force = false): Promise<string> {
|
||||||
if (!selfInfo.nick || force) {
|
if ((!selfInfo.nick || force) && selfInfo.uid) {
|
||||||
const userInfo = await NTQQUserApi.getUserDetailInfo(selfInfo.uid)
|
const userInfo = await NTQQUserApi.getUserDetailInfo(selfInfo.uid)
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
selfInfo.nick = userInfo.nick
|
selfInfo.nick = userInfo.nick
|
||||||
|
253
src/common/db.ts
253
src/common/db.ts
@@ -1,253 +0,0 @@
|
|||||||
import { Level } from 'level'
|
|
||||||
import { type GroupNotify, RawMessage } from '../ntqqapi/types'
|
|
||||||
import { DATA_DIR } from './utils'
|
|
||||||
import { FileCache } from './types'
|
|
||||||
import { log } from './utils/log'
|
|
||||||
|
|
||||||
type ReceiveTempUinMap = Record<string, string>
|
|
||||||
|
|
||||||
class DBUtil {
|
|
||||||
public readonly DB_KEY_PREFIX_MSG_ID = 'msg_id_'
|
|
||||||
public readonly DB_KEY_PREFIX_MSG_SHORT_ID = 'msg_short_id_'
|
|
||||||
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = 'msg_seq_id_'
|
|
||||||
public readonly DB_KEY_PREFIX_FILE = 'file_'
|
|
||||||
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = 'group_notify_'
|
|
||||||
private readonly DB_KEY_RECEIVED_TEMP_UIN_MAP = 'received_temp_uin_map'
|
|
||||||
public db: Level | undefined
|
|
||||||
public cache: Record<string, RawMessage | string | FileCache | GroupNotify | ReceiveTempUinMap> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
|
||||||
private currentShortId: number | undefined
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 数据库结构
|
|
||||||
* msg_id_101231230999: {} // 长id: RawMessage
|
|
||||||
* msg_short_id_1: 101231230999 // 短id: 长id
|
|
||||||
* msg_seq_id_1: 101231230999 // 序列id: 长id
|
|
||||||
* file_7827DBAFJFW2323.png: {} // 文件名: FileCache
|
|
||||||
* */
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
init(uin: string) {
|
|
||||||
const DB_PATH = DATA_DIR + `/msg_${uin}`
|
|
||||||
this.db = new Level(DB_PATH, { valueEncoding: 'json' })
|
|
||||||
const expiredMilliSecond = 1000 * 60 * 60
|
|
||||||
setInterval(() => {
|
|
||||||
// this.cache = {}
|
|
||||||
// 清理时间较久的缓存
|
|
||||||
const now = Date.now()
|
|
||||||
for (let key in this.cache) {
|
|
||||||
let message: RawMessage = this.cache[key] as RawMessage
|
|
||||||
if (message?.msgTime) {
|
|
||||||
if (now - parseInt(message.msgTime) * 1000 > expiredMilliSecond) {
|
|
||||||
delete this.cache[key]
|
|
||||||
// log("clear cache", key, message.msgTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, expiredMilliSecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getReceivedTempUinMap(): Promise<ReceiveTempUinMap> {
|
|
||||||
try {
|
|
||||||
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = JSON.parse(await this.db?.get(this.DB_KEY_RECEIVED_TEMP_UIN_MAP)!)
|
|
||||||
} catch (e) { }
|
|
||||||
return (this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] || {}) as ReceiveTempUinMap
|
|
||||||
}
|
|
||||||
public setReceivedTempUinMap(data: ReceiveTempUinMap) {
|
|
||||||
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = data
|
|
||||||
this.db?.put(this.DB_KEY_RECEIVED_TEMP_UIN_MAP, JSON.stringify(data)).then()
|
|
||||||
}
|
|
||||||
private addCache(msg: RawMessage) {
|
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
|
||||||
this.cache[longIdKey] = this.cache[shortIdKey] = msg
|
|
||||||
}
|
|
||||||
|
|
||||||
public clearCache() {
|
|
||||||
this.cache = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getMsgByShortId(shortMsgId: number): Promise<RawMessage | undefined> {
|
|
||||||
const shortMsgIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId
|
|
||||||
if (this.cache[shortMsgIdKey]) {
|
|
||||||
// log("getMsgByShortId cache", shortMsgIdKey, this.cache[shortMsgIdKey])
|
|
||||||
return this.cache[shortMsgIdKey] as RawMessage
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const longId = await this.db?.get(shortMsgIdKey)
|
|
||||||
const msg = await this.getMsgByLongId(longId!)
|
|
||||||
this.addCache(msg!)
|
|
||||||
return msg
|
|
||||||
} catch (e: any) {
|
|
||||||
log('getMsgByShortId db error', e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getMsgByLongId(longId: string): Promise<RawMessage | undefined> {
|
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + longId
|
|
||||||
if (this.cache[longIdKey]) {
|
|
||||||
return this.cache[longIdKey] as RawMessage
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const data = await this.db?.get(longIdKey)
|
|
||||||
const msg = JSON.parse(data!)
|
|
||||||
this.addCache(msg)
|
|
||||||
return msg
|
|
||||||
} catch (e) {
|
|
||||||
// log("getMsgByLongId db error", e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getMsgBySeqId(seqId: string): Promise<RawMessage | undefined> {
|
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + seqId
|
|
||||||
if (this.cache[seqIdKey]) {
|
|
||||||
return this.cache[seqIdKey] as RawMessage
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const longId = await this.db?.get(seqIdKey)
|
|
||||||
const msg = await this.getMsgByLongId(longId!)
|
|
||||||
this.addCache(msg!)
|
|
||||||
return msg
|
|
||||||
} catch (e: any) {
|
|
||||||
log('getMsgBySeqId db error', e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async addMsg(msg: RawMessage) {
|
|
||||||
// 有则更新,无则添加
|
|
||||||
// log("addMsg", msg.msgId, msg.msgSeq, msg.msgShortId);
|
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
|
||||||
let existMsg: RawMessage | undefined = this.cache[longIdKey] as RawMessage
|
|
||||||
if (!existMsg) {
|
|
||||||
try {
|
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
|
||||||
} catch (e) {
|
|
||||||
// log("addMsg getMsgByLongId error", e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (existMsg) {
|
|
||||||
// log("消息已存在", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId)
|
|
||||||
this.updateMsg(msg).then()
|
|
||||||
return existMsg.msgShortId
|
|
||||||
}
|
|
||||||
|
|
||||||
const shortMsgId = await this.genMsgShortId()
|
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId
|
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
|
||||||
msg.msgShortId = shortMsgId
|
|
||||||
this.addCache(msg)
|
|
||||||
// log("新增消息记录", msg.msgId)
|
|
||||||
this.db?.put(shortIdKey, msg.msgId).then().catch()
|
|
||||||
this.db?.put(longIdKey, JSON.stringify(msg)).then().catch()
|
|
||||||
try {
|
|
||||||
await this.db?.get(seqIdKey)
|
|
||||||
} catch (e) {
|
|
||||||
// log("新的seqId", seqIdKey)
|
|
||||||
this.db?.put(seqIdKey, msg.msgId).then().catch()
|
|
||||||
}
|
|
||||||
if (!this.cache[seqIdKey]) {
|
|
||||||
this.cache[seqIdKey] = msg
|
|
||||||
}
|
|
||||||
return shortMsgId
|
|
||||||
// log(`消息入库 ${seqIdKey}: ${msg.msgId}, ${shortMsgId}: ${msg.msgId}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateMsg(msg: RawMessage) {
|
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
|
||||||
let existMsg: RawMessage | undefined = this.cache[longIdKey] as RawMessage
|
|
||||||
if (!existMsg) {
|
|
||||||
try {
|
|
||||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
|
||||||
} catch (e) {
|
|
||||||
existMsg = msg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.assign(existMsg!, msg)
|
|
||||||
this.db?.put(longIdKey, JSON.stringify(existMsg)).then().catch()
|
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + existMsg?.msgShortId
|
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
|
||||||
if (!this.cache[seqIdKey]) {
|
|
||||||
this.cache[seqIdKey] = existMsg!
|
|
||||||
}
|
|
||||||
this.db?.put(shortIdKey, msg.msgId).then().catch()
|
|
||||||
try {
|
|
||||||
await this.db?.get(seqIdKey)
|
|
||||||
} catch (e) {
|
|
||||||
this.db?.put(seqIdKey, msg.msgId).then().catch()
|
|
||||||
// log("更新seqId error", e.stack, seqIdKey);
|
|
||||||
}
|
|
||||||
// log("更新消息", existMsg.msgSeq, existMsg.msgShortId, existMsg.msgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async genMsgShortId(): Promise<number> {
|
|
||||||
const key = 'msg_current_short_id'
|
|
||||||
if (this.currentShortId === undefined) {
|
|
||||||
try {
|
|
||||||
const id = await this.db?.get(key)
|
|
||||||
this.currentShortId = parseInt(id!)
|
|
||||||
} catch (e) {
|
|
||||||
this.currentShortId = -2147483640
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentShortId++
|
|
||||||
this.db?.put(key, this.currentShortId.toString()).then().catch()
|
|
||||||
return this.currentShortId
|
|
||||||
}
|
|
||||||
|
|
||||||
async addFileCache(fileNameOrUuid: string, data: FileCache) {
|
|
||||||
const key = this.DB_KEY_PREFIX_FILE + fileNameOrUuid
|
|
||||||
if (this.cache[key]) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let cacheDBData = { ...data }
|
|
||||||
delete cacheDBData['downloadFunc']
|
|
||||||
this.cache[fileNameOrUuid] = data
|
|
||||||
try {
|
|
||||||
await this.db?.put(key, JSON.stringify(cacheDBData))
|
|
||||||
} catch (e: any) {
|
|
||||||
log('addFileCache db error', e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getFileCache(fileNameOrUuid: string): Promise<FileCache | undefined> {
|
|
||||||
const key = this.DB_KEY_PREFIX_FILE + fileNameOrUuid
|
|
||||||
if (this.cache[key]) {
|
|
||||||
return this.cache[key] as FileCache
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const data = await this.db?.get(key)
|
|
||||||
return JSON.parse(data!)
|
|
||||||
} catch (e) {
|
|
||||||
// log("getFileCache db error", e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async addGroupNotify(notify: GroupNotify) {
|
|
||||||
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + notify.seq
|
|
||||||
let existNotify = this.cache[key] as GroupNotify
|
|
||||||
if (existNotify) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.cache[key] = notify
|
|
||||||
this.db?.put(key, JSON.stringify(notify)).then().catch()
|
|
||||||
}
|
|
||||||
|
|
||||||
async getGroupNotify(seq: string): Promise<GroupNotify | undefined> {
|
|
||||||
const key = this.DB_KEY_PREFIX_GROUP_NOTIFY + seq
|
|
||||||
if (this.cache[key]) {
|
|
||||||
return this.cache[key] as GroupNotify
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const data = await this.db?.get(key)
|
|
||||||
return JSON.parse(data!)
|
|
||||||
} catch (e) {
|
|
||||||
// log("getGroupNotify db error", e.stack.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const dbUtil = new DBUtil()
|
|
@@ -16,6 +16,7 @@ export interface ListenerIBase {
|
|||||||
new(listener: any): ListenerClassBase
|
new(listener: any): ListenerClassBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/common/utils/EventTask.ts#L20
|
||||||
export class NTEventWrapper {
|
export class NTEventWrapper {
|
||||||
private ListenerMap: { [key: string]: ListenerIBase } | undefined//ListenerName-Unique -> Listener构造函数
|
private ListenerMap: { [key: string]: ListenerIBase } | undefined//ListenerName-Unique -> Listener构造函数
|
||||||
private WrapperSession: NodeIQQNTWrapperSession | undefined//WrapperSession
|
private WrapperSession: NodeIQQNTWrapperSession | undefined//WrapperSession
|
||||||
@@ -68,6 +69,8 @@ export class NTEventWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createEventFunction = this.CreatEventFunction
|
||||||
|
|
||||||
CreatListenerFunction<T>(listenerMainName: string, uniqueCode: string = ''): T {
|
CreatListenerFunction<T>(listenerMainName: string, uniqueCode: string = ''): T {
|
||||||
const ListenerType = this.ListenerMap![listenerMainName]
|
const ListenerType = this.ListenerMap![listenerMainName]
|
||||||
let Listener = this.ListenerManger.get(listenerMainName + uniqueCode)
|
let Listener = this.ListenerManger.get(listenerMainName + uniqueCode)
|
||||||
|
133
src/common/utils/MessageUnique.ts
Normal file
133
src/common/utils/MessageUnique.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { Peer } from '@/ntqqapi/types'
|
||||||
|
import { createHash } from 'node:crypto'
|
||||||
|
import { LimitedHashTable } from './table'
|
||||||
|
import { DATA_DIR } from './index'
|
||||||
|
import Database, { Tables } from 'minato'
|
||||||
|
import SQLite from '@minatojs/driver-sqlite'
|
||||||
|
import fsPromise from 'node:fs/promises'
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
interface SQLiteTables extends Tables {
|
||||||
|
message: {
|
||||||
|
shortId: number
|
||||||
|
msgId: string
|
||||||
|
chatType: number
|
||||||
|
peerUid: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MsgIdAndPeerByShortId {
|
||||||
|
MsgId: string
|
||||||
|
Peer: Peer
|
||||||
|
}
|
||||||
|
|
||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/common/utils/MessageUnique.ts#L84
|
||||||
|
class MessageUniqueWrapper {
|
||||||
|
private msgDataMap: LimitedHashTable<string, number>
|
||||||
|
private msgIdMap: LimitedHashTable<string, number>
|
||||||
|
private db: Database<SQLiteTables> | undefined
|
||||||
|
|
||||||
|
constructor(maxMap: number = 1000) {
|
||||||
|
this.msgIdMap = new LimitedHashTable<string, number>(maxMap)
|
||||||
|
this.msgDataMap = new LimitedHashTable<string, number>(maxMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(uin: string) {
|
||||||
|
const dbDir = path.join(DATA_DIR, 'database')
|
||||||
|
if (!fs.existsSync(dbDir)) {
|
||||||
|
await fsPromise.mkdir(dbDir)
|
||||||
|
}
|
||||||
|
const database = new Database<SQLiteTables>()
|
||||||
|
await database.connect(SQLite, {
|
||||||
|
path: path.join(dbDir, `${uin}.db`)
|
||||||
|
})
|
||||||
|
database.extend('message', {
|
||||||
|
shortId: 'integer(10)',
|
||||||
|
chatType: 'unsigned',
|
||||||
|
msgId: 'string(24)',
|
||||||
|
peerUid: 'string(24)'
|
||||||
|
}, {
|
||||||
|
primary: 'shortId'
|
||||||
|
})
|
||||||
|
this.db = database
|
||||||
|
}
|
||||||
|
|
||||||
|
async getRecentMsgIds(Peer: Peer, size: number): Promise<string[]> {
|
||||||
|
const heads = this.msgIdMap.getHeads(size)
|
||||||
|
if (!heads) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const data: (MsgIdAndPeerByShortId | undefined)[] = []
|
||||||
|
for (const t of heads) {
|
||||||
|
data.push(await MessageUnique.getMsgIdAndPeerByShortId(t.value))
|
||||||
|
}
|
||||||
|
const ret = data.filter((t) => t?.Peer.chatType === Peer.chatType && t?.Peer.peerUid === Peer.peerUid)
|
||||||
|
return ret.map((t) => t?.MsgId).filter((t) => t !== undefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
createMsg(peer: Peer, msgId: string): number | undefined {
|
||||||
|
const key = `${msgId}|${peer.chatType}|${peer.peerUid}`
|
||||||
|
const hash = createHash('md5').update(key).digest()
|
||||||
|
//设置第一个bit为0 保证shortId为正数
|
||||||
|
hash[0] &= 0x7f
|
||||||
|
const shortId = hash.readInt32BE(0)
|
||||||
|
//减少性能损耗
|
||||||
|
// const isExist = this.msgIdMap.getKey(shortId)
|
||||||
|
// if (isExist && isExist === msgId) {
|
||||||
|
// return shortId
|
||||||
|
// }
|
||||||
|
this.msgIdMap.set(msgId, shortId)
|
||||||
|
this.msgDataMap.set(key, shortId)
|
||||||
|
this.db?.upsert('message', [{
|
||||||
|
msgId,
|
||||||
|
shortId,
|
||||||
|
chatType: peer.chatType,
|
||||||
|
peerUid: peer.peerUid
|
||||||
|
}], 'shortId').then()
|
||||||
|
return shortId
|
||||||
|
}
|
||||||
|
|
||||||
|
async getMsgIdAndPeerByShortId(shortId: number): Promise<MsgIdAndPeerByShortId | undefined> {
|
||||||
|
const data = this.msgDataMap.getKey(shortId)
|
||||||
|
if (data) {
|
||||||
|
const [msgId, chatTypeStr, peerUid] = data.split('|')
|
||||||
|
const peer: Peer = {
|
||||||
|
chatType: parseInt(chatTypeStr),
|
||||||
|
peerUid,
|
||||||
|
guildId: '',
|
||||||
|
}
|
||||||
|
return { MsgId: msgId, Peer: peer }
|
||||||
|
}
|
||||||
|
const items = await this.db?.get('message', { shortId })
|
||||||
|
if (items?.length) {
|
||||||
|
const { msgId, chatType, peerUid } = items[0]
|
||||||
|
return {
|
||||||
|
MsgId: msgId,
|
||||||
|
Peer: {
|
||||||
|
chatType,
|
||||||
|
peerUid,
|
||||||
|
guildId: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
getShortIdByMsgId(msgId: string): number | undefined {
|
||||||
|
return this.msgIdMap.getValue(msgId)
|
||||||
|
}
|
||||||
|
|
||||||
|
async getPeerByMsgId(msgId: string) {
|
||||||
|
const shortId = this.msgIdMap.getValue(msgId)
|
||||||
|
if (!shortId) return undefined
|
||||||
|
return await this.getMsgIdAndPeerByShortId(shortId)
|
||||||
|
}
|
||||||
|
|
||||||
|
resize(maxSize: number): void {
|
||||||
|
this.msgIdMap.resize(maxSize)
|
||||||
|
this.msgDataMap.resize(maxSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MessageUnique: MessageUniqueWrapper = new MessageUniqueWrapper()
|
@@ -2,7 +2,6 @@ import fs from 'node:fs'
|
|||||||
import fsPromise from 'node:fs/promises'
|
import fsPromise from 'node:fs/promises'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { log, TEMP_DIR } from './index'
|
import { log, TEMP_DIR } from './index'
|
||||||
import { dbUtil } from '../db'
|
|
||||||
import * as fileType from 'file-type'
|
import * as fileType from 'file-type'
|
||||||
import { randomUUID, createHash } from 'node:crypto'
|
import { randomUUID, createHash } from 'node:crypto'
|
||||||
|
|
||||||
@@ -187,13 +186,6 @@ export async function uri2local(uri: string, fileName: string | null = null): Pr
|
|||||||
} else {
|
} else {
|
||||||
filePath = pathname
|
filePath = pathname
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const cache = await dbUtil.getFileCache(uri)
|
|
||||||
if (cache) {
|
|
||||||
filePath = cache.filePath
|
|
||||||
} else {
|
|
||||||
filePath = uri
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.isLocal = true
|
res.isLocal = true
|
||||||
|
@@ -144,3 +144,26 @@ export function CacheClassFuncAsyncExtend(ttl: number = 3600 * 1000, customKey:
|
|||||||
}
|
}
|
||||||
return logExecutionTime
|
return logExecutionTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/common/utils/helper.ts#L14
|
||||||
|
export class UUIDConverter {
|
||||||
|
static encode(highStr: string, lowStr: string): string {
|
||||||
|
const high = BigInt(highStr)
|
||||||
|
const low = BigInt(lowStr)
|
||||||
|
const highHex = high.toString(16).padStart(16, '0')
|
||||||
|
const lowHex = low.toString(16).padStart(16, '0')
|
||||||
|
const combinedHex = highHex + lowHex
|
||||||
|
const uuid = `${combinedHex.substring(0, 8)}-${combinedHex.substring(8, 12)}-${combinedHex.substring(
|
||||||
|
12,
|
||||||
|
16,
|
||||||
|
)}-${combinedHex.substring(16, 20)}-${combinedHex.substring(20)}`
|
||||||
|
return uuid
|
||||||
|
}
|
||||||
|
|
||||||
|
static decode(uuid: string): { high: string; low: string } {
|
||||||
|
const hex = uuid.replace(/-/g, '')
|
||||||
|
const high = BigInt('0x' + hex.substring(0, 16))
|
||||||
|
const low = BigInt('0x' + hex.substring(16))
|
||||||
|
return { high: high.toString(), low: low.toString() }
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import fs from 'fs'
|
|
||||||
|
|
||||||
export * from './file'
|
export * from './file'
|
||||||
export * from './helper'
|
export * from './helper'
|
||||||
@@ -7,12 +6,9 @@ export * from './log'
|
|||||||
export * from './qqlevel'
|
export * from './qqlevel'
|
||||||
export * from './QQBasicInfo'
|
export * from './QQBasicInfo'
|
||||||
export * from './upgrade'
|
export * from './upgrade'
|
||||||
export const DATA_DIR = global.LiteLoader.plugins['LLOneBot'].path.data
|
export const DATA_DIR: string = global.LiteLoader.plugins['LLOneBot'].path.data
|
||||||
export const TEMP_DIR = path.join(DATA_DIR, 'temp')
|
export const TEMP_DIR: string = path.join(DATA_DIR, 'temp')
|
||||||
export const PLUGIN_DIR = global.LiteLoader.plugins['LLOneBot'].path.plugin
|
export const PLUGIN_DIR: string = global.LiteLoader.plugins['LLOneBot'].path.plugin
|
||||||
if (!fs.existsSync(TEMP_DIR)) {
|
|
||||||
fs.mkdirSync(TEMP_DIR, { recursive: true })
|
|
||||||
}
|
|
||||||
export { getVideoInfo } from './video'
|
export { getVideoInfo } from './video'
|
||||||
export { checkFfmpeg } from './video'
|
export { checkFfmpeg } from './video'
|
||||||
export { encodeSilk } from './audio'
|
export { encodeSilk } from './audio'
|
@@ -1,3 +1,4 @@
|
|||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/common/utils/MessageUnique.ts#L5
|
||||||
export class LimitedHashTable<K, V> {
|
export class LimitedHashTable<K, V> {
|
||||||
private keyToValue: Map<K, V> = new Map()
|
private keyToValue: Map<K, V> = new Map()
|
||||||
private valueToKey: Map<V, K> = new Map()
|
private valueToKey: Map<V, K> = new Map()
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
// 运行在 Electron 主进程 下的插件入口
|
// 运行在 Electron 主进程 下的插件入口
|
||||||
|
|
||||||
import { BrowserWindow, dialog, ipcMain } from 'electron'
|
import { BrowserWindow, dialog, ipcMain } from 'electron'
|
||||||
|
import path from 'node:path'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { Config } from '../common/types'
|
import { Config } from '../common/types'
|
||||||
import {
|
import {
|
||||||
@@ -13,7 +14,7 @@ import {
|
|||||||
CHANNEL_UPDATE,
|
CHANNEL_UPDATE,
|
||||||
} from '../common/channels'
|
} from '../common/channels'
|
||||||
import { ob11WebsocketServer } from '../onebot11/server/ws/WebsocketServer'
|
import { ob11WebsocketServer } from '../onebot11/server/ws/WebsocketServer'
|
||||||
import { DATA_DIR } from '../common/utils'
|
import { DATA_DIR, TEMP_DIR } from '../common/utils'
|
||||||
import {
|
import {
|
||||||
getGroupMember,
|
getGroupMember,
|
||||||
llonebotError,
|
llonebotError,
|
||||||
@@ -36,8 +37,7 @@ import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
|||||||
import { ob11ReverseWebsockets } from '../onebot11/server/ws/ReverseWebsocket'
|
import { ob11ReverseWebsockets } from '../onebot11/server/ws/ReverseWebsocket'
|
||||||
import { OB11GroupRequestEvent } from '../onebot11/event/request/OB11GroupRequest'
|
import { OB11GroupRequestEvent } from '../onebot11/event/request/OB11GroupRequest'
|
||||||
import { OB11FriendRequestEvent } from '../onebot11/event/request/OB11FriendRequest'
|
import { OB11FriendRequestEvent } from '../onebot11/event/request/OB11FriendRequest'
|
||||||
import path from 'node:path'
|
import { MessageUnique } from '../common/utils/MessageUnique'
|
||||||
import { dbUtil } from '../common/db'
|
|
||||||
import { setConfig } from './setConfig'
|
import { setConfig } from './setConfig'
|
||||||
import { NTQQUserApi, NTQQGroupApi } from '../ntqqapi/api'
|
import { NTQQUserApi, NTQQGroupApi } from '../ntqqapi/api'
|
||||||
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
||||||
@@ -48,6 +48,7 @@ import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/
|
|||||||
import '../ntqqapi/wrapper'
|
import '../ntqqapi/wrapper'
|
||||||
import { NTEventDispatch } from '../common/utils/EventTask'
|
import { NTEventDispatch } from '../common/utils/EventTask'
|
||||||
import { wrapperConstructor, getSession } from '../ntqqapi/wrapper'
|
import { wrapperConstructor, getSession } from '../ntqqapi/wrapper'
|
||||||
|
import { Peer } from '../ntqqapi/types'
|
||||||
|
|
||||||
let mainWindow: BrowserWindow | null = null
|
let mainWindow: BrowserWindow | null = null
|
||||||
|
|
||||||
@@ -153,9 +154,11 @@ function onLoad() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// log("收到新消息", message.msgId, message.msgSeq)
|
// log("收到新消息", message.msgId, message.msgSeq)
|
||||||
// if (message.senderUin !== selfInfo.uin){
|
const peer: Peer = {
|
||||||
message.msgShortId = await dbUtil.addMsg(message)
|
chatType: message.chatType,
|
||||||
// }
|
peerUid: message.peerUid
|
||||||
|
}
|
||||||
|
message.msgShortId = MessageUnique.createMsg(peer, message.msgId)
|
||||||
|
|
||||||
OB11Constructor.message(message)
|
OB11Constructor.message(message)
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
@@ -210,29 +213,22 @@ function onLoad() {
|
|||||||
const recallMsgIds: string[] = [] // 避免重复上报
|
const recallMsgIds: string[] = [] // 避免重复上报
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
log('message update', message.msgId, message)
|
|
||||||
if (message.recallTime != '0') {
|
if (message.recallTime != '0') {
|
||||||
if (recallMsgIds.includes(message.msgId)) {
|
if (recallMsgIds.includes(message.msgId)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
recallMsgIds.push(message.msgId)
|
recallMsgIds.push(message.msgId)
|
||||||
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
const oriMessageId = MessageUnique.getShortIdByMsgId(message.msgId)
|
||||||
if (!oriMessage) {
|
if (!oriMessageId) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
oriMessage.recallTime = message.recallTime
|
OB11Constructor.RecallEvent(message, oriMessageId).then((recallEvent) => {
|
||||||
dbUtil.updateMsg(oriMessage).then()
|
|
||||||
message.msgShortId = oriMessage.msgShortId
|
|
||||||
OB11Constructor.RecallEvent(message).then((recallEvent) => {
|
|
||||||
if (recallEvent) {
|
if (recallEvent) {
|
||||||
log('post recall event', recallEvent)
|
//log('post recall event', recallEvent)
|
||||||
postOb11Event(recallEvent)
|
postOb11Event(recallEvent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
dbUtil.updateMsg(message).then()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, async (payload) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, async (payload) => {
|
||||||
@@ -268,17 +264,11 @@ function onLoad() {
|
|||||||
for (const notify of notifies) {
|
for (const notify of notifies) {
|
||||||
try {
|
try {
|
||||||
notify.time = Date.now()
|
notify.time = Date.now()
|
||||||
// const notifyTime = parseInt(notify.seq) / 1000
|
const notifyTime = parseInt(notify.seq) / 1000
|
||||||
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
if (notifyTime < startTime) {
|
||||||
// if (notifyTime < startTime) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
let existNotify = await dbUtil.getGroupNotify(notify.seq)
|
|
||||||
if (existNotify) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log('收到群通知', notify)
|
log('收到群通知', notify)
|
||||||
await dbUtil.addGroupNotify(notify)
|
|
||||||
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
|
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
|
||||||
if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
||||||
log('有成员退出通知', notify)
|
log('有成员退出通知', notify)
|
||||||
@@ -392,17 +382,22 @@ function onLoad() {
|
|||||||
log('llonebot pid', process.pid)
|
log('llonebot pid', process.pid)
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
if (!config.enableLLOB) {
|
if (!config.enableLLOB) {
|
||||||
|
llonebotError.otherError = 'LLOnebot 未启动'
|
||||||
log('LLOneBot 开关设置为关闭,不启动LLOneBot')
|
log('LLOneBot 开关设置为关闭,不启动LLOneBot')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!fs.existsSync(TEMP_DIR)) {
|
||||||
|
fs.mkdirSync(TEMP_DIR, { recursive: true })
|
||||||
|
}
|
||||||
llonebotError.otherError = ''
|
llonebotError.otherError = ''
|
||||||
startTime = Date.now()
|
startTime = Date.now()
|
||||||
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
|
NTEventDispatch.init({ ListenerMap: wrapperConstructor, WrapperSession: getSession()! })
|
||||||
dbUtil.init(uin)
|
MessageUnique.init(uin)
|
||||||
|
|
||||||
log('start activate group member info')
|
log('start activate group member info')
|
||||||
NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
// 下面两个会导致CPU占用过高,QQ卡死
|
||||||
NTQQGroupApi.activateMemberListChange().then().catch(log)
|
// NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
||||||
|
// NTQQGroupApi.activateMemberListChange().then().catch(log)
|
||||||
startReceiveHook().then()
|
startReceiveHook().then()
|
||||||
|
|
||||||
if (config.ob11.enableHttp) {
|
if (config.ob11.enableHttp) {
|
||||||
@@ -421,7 +416,7 @@ function onLoad() {
|
|||||||
log('LLOneBot start')
|
log('LLOneBot start')
|
||||||
}
|
}
|
||||||
|
|
||||||
const init = async () => {
|
const intervalId = setInterval(() => {
|
||||||
const current = getSelfInfo()
|
const current = getSelfInfo()
|
||||||
if (!current.uin) {
|
if (!current.uin) {
|
||||||
setSelfInfo({
|
setSelfInfo({
|
||||||
@@ -430,15 +425,11 @@ function onLoad() {
|
|||||||
nick: current.uin,
|
nick: current.uin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//log('self info', selfInfo, globalThis.authData)
|
if (current.uin && getSession()) {
|
||||||
if (current.uin) {
|
clearInterval(intervalId)
|
||||||
start(current.uid, current.uin)
|
start(current.uid, current.uin)
|
||||||
}
|
}
|
||||||
else {
|
}, 600)
|
||||||
setTimeout(init, 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建窗口时触发
|
// 创建窗口时触发
|
||||||
|
@@ -24,6 +24,7 @@ import { fileTypeFromFile } from 'file-type'
|
|||||||
import fsPromise from 'node:fs/promises'
|
import fsPromise from 'node:fs/promises'
|
||||||
import { NTEventDispatch } from '@/common/utils/EventTask'
|
import { NTEventDispatch } from '@/common/utils/EventTask'
|
||||||
import { OnRichMediaDownloadCompleteParams } from '@/ntqqapi/listeners'
|
import { OnRichMediaDownloadCompleteParams } from '@/ntqqapi/listeners'
|
||||||
|
import { NodeIKernelSearchService } from '@/ntqqapi/services'
|
||||||
|
|
||||||
export class NTQQFileApi {
|
export class NTQQFileApi {
|
||||||
static async getVideoUrl(peer: Peer, msgId: string, elementId: string): Promise<string> {
|
static async getVideoUrl(peer: Peer, msgId: string, elementId: string): Promise<string> {
|
||||||
@@ -203,6 +204,122 @@ export class NTQQFileApi {
|
|||||||
log('图片url获取失败', element)
|
log('图片url获取失败', element)
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/core/src/apis/file.ts#L149
|
||||||
|
static async addFileCache(peer: Peer, msgId: string, msgSeq: string, senderUid: string, elemId: string, elemType: string, fileSize: string, fileName: string) {
|
||||||
|
let GroupData: any[] | undefined
|
||||||
|
let BuddyData: any[] | undefined
|
||||||
|
if (peer.chatType === ChatType.group) {
|
||||||
|
GroupData =
|
||||||
|
[{
|
||||||
|
groupCode: peer.peerUid,
|
||||||
|
isConf: false,
|
||||||
|
hasModifyConfGroupFace: true,
|
||||||
|
hasModifyConfGroupName: true,
|
||||||
|
groupName: 'LLOneBot.Cached',
|
||||||
|
remark: 'LLOneBot.Cached',
|
||||||
|
}];
|
||||||
|
} else if (peer.chatType === ChatType.friend) {
|
||||||
|
BuddyData = [{
|
||||||
|
category_name: 'LLOneBot.Cached',
|
||||||
|
peerUid: peer.peerUid,
|
||||||
|
peerUin: peer.peerUid,
|
||||||
|
remark: 'LLOneBot.Cached',
|
||||||
|
}]
|
||||||
|
} else {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const session = getSession()
|
||||||
|
return session?.getSearchService().addSearchHistory({
|
||||||
|
type: 4,
|
||||||
|
contactList: [],
|
||||||
|
id: -1,
|
||||||
|
groupInfos: [],
|
||||||
|
msgs: [],
|
||||||
|
fileInfos: [
|
||||||
|
{
|
||||||
|
chatType: peer.chatType,
|
||||||
|
buddyChatInfo: BuddyData || [],
|
||||||
|
discussChatInfo: [],
|
||||||
|
groupChatInfo: GroupData || [],
|
||||||
|
dataLineChatInfo: [],
|
||||||
|
tmpChatInfo: [],
|
||||||
|
msgId: msgId,
|
||||||
|
msgSeq: msgSeq,
|
||||||
|
msgTime: Math.floor(Date.now() / 1000).toString(),
|
||||||
|
senderUid: senderUid,
|
||||||
|
senderNick: 'LLOneBot.Cached',
|
||||||
|
senderRemark: 'LLOneBot.Cached',
|
||||||
|
senderCard: 'LLOneBot.Cached',
|
||||||
|
elemId: elemId,
|
||||||
|
elemType: elemType,
|
||||||
|
fileSize: fileSize,
|
||||||
|
filePath: '',
|
||||||
|
fileName: fileName,
|
||||||
|
hits: [{
|
||||||
|
start: 12,
|
||||||
|
end: 14,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async searchfile(keys: string[]) {
|
||||||
|
type EventType = NodeIKernelSearchService['searchFileWithKeywords']
|
||||||
|
|
||||||
|
interface OnListener {
|
||||||
|
searchId: string,
|
||||||
|
hasMore: boolean,
|
||||||
|
resultItems: {
|
||||||
|
chatType: ChatType,
|
||||||
|
buddyChatInfo: any[],
|
||||||
|
discussChatInfo: any[],
|
||||||
|
groupChatInfo:
|
||||||
|
{
|
||||||
|
groupCode: string,
|
||||||
|
isConf: boolean,
|
||||||
|
hasModifyConfGroupFace: boolean,
|
||||||
|
hasModifyConfGroupName: boolean,
|
||||||
|
groupName: string,
|
||||||
|
remark: string
|
||||||
|
}[],
|
||||||
|
dataLineChatInfo: any[],
|
||||||
|
tmpChatInfo: any[],
|
||||||
|
msgId: string,
|
||||||
|
msgSeq: string,
|
||||||
|
msgTime: string,
|
||||||
|
senderUid: string,
|
||||||
|
senderNick: string,
|
||||||
|
senderRemark: string,
|
||||||
|
senderCard: string,
|
||||||
|
elemId: string,
|
||||||
|
elemType: number,
|
||||||
|
fileSize: string,
|
||||||
|
filePath: string,
|
||||||
|
fileName: string,
|
||||||
|
hits:
|
||||||
|
{
|
||||||
|
start: number,
|
||||||
|
end: number
|
||||||
|
}[]
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const Event = NTEventDispatch.createEventFunction<EventType>('NodeIKernelSearchService/searchFileWithKeywords')
|
||||||
|
let id = ''
|
||||||
|
const Listener = NTEventDispatch.RegisterListen<(params: OnListener) => void>
|
||||||
|
(
|
||||||
|
'NodeIKernelSearchListener/onSearchFileKeywordsResult',
|
||||||
|
1,
|
||||||
|
20000,
|
||||||
|
(params) => id !== '' && params.searchId == id,
|
||||||
|
)
|
||||||
|
id = await Event!(keys, 12)
|
||||||
|
const [ret] = await Listener
|
||||||
|
return ret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQFileCacheApi {
|
export class NTQQFileCacheApi {
|
||||||
|
@@ -270,4 +270,24 @@ export class NTQQMsgApi {
|
|||||||
const session = getSession()
|
const session = getSession()
|
||||||
return await session?.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z)!
|
return await session?.getMsgService().getMsgsBySeqAndCount(peer, seq, count, desc, z)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getLastestMsgByUids(peer: Peer, count = 20, isReverseOrder = false) {
|
||||||
|
const session = getSession()
|
||||||
|
const ret = await session?.getMsgService().queryMsgsWithFilterEx('0', '0', '0', {
|
||||||
|
chatInfo: peer,
|
||||||
|
filterMsgType: [],
|
||||||
|
filterSendersUid: [],
|
||||||
|
filterMsgToTime: '0',
|
||||||
|
filterMsgFromTime: '0',
|
||||||
|
isReverseOrder: isReverseOrder, //此参数有点离谱 注意不是本次查询的排序 而是全部消历史信息的排序 默认false 从新消息拉取到旧消息
|
||||||
|
isIncludeCurrent: true,
|
||||||
|
pageLimit: count,
|
||||||
|
})
|
||||||
|
return ret!
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getSingleMsg(peer: Peer, seq: string) {
|
||||||
|
const session = getSession()
|
||||||
|
return await session?.getMsgService().getSingleMsg(peer, seq)!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,16 @@
|
|||||||
import type { BrowserWindow } from 'electron'
|
import type { BrowserWindow } from 'electron'
|
||||||
import { NTQQApiClass, NTQQApiMethod } from './ntcall'
|
import { NTQQApiClass, NTQQApiMethod } from './ntcall'
|
||||||
import { NTQQMsgApi } from './api/msg'
|
import { NTQQMsgApi } from './api/msg'
|
||||||
import { CategoryFriend, ChatType, Group, GroupMember, GroupMemberRole, RawMessage } from './types'
|
import {
|
||||||
|
CategoryFriend,
|
||||||
|
ChatType,
|
||||||
|
FriendV2,
|
||||||
|
Group,
|
||||||
|
GroupMember,
|
||||||
|
GroupMemberRole,
|
||||||
|
RawMessage,
|
||||||
|
SimpleInfo, User,
|
||||||
|
} from './types'
|
||||||
import {
|
import {
|
||||||
deleteGroup,
|
deleteGroup,
|
||||||
friends,
|
friends,
|
||||||
@@ -14,15 +23,15 @@ import {
|
|||||||
import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
||||||
import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
||||||
import { getConfigUtil, HOOK_LOG } from '@/common/config'
|
import { getConfigUtil, HOOK_LOG } from '@/common/config'
|
||||||
import fs from 'fs'
|
import fs from 'node:fs'
|
||||||
import { dbUtil } from '@/common/db'
|
|
||||||
import { NTQQGroupApi } from './api/group'
|
import { NTQQGroupApi } from './api/group'
|
||||||
import { log } from '@/common/utils'
|
import { log } from '@/common/utils'
|
||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
import { MessageUnique } from '../common/utils/MessageUnique'
|
||||||
import { isNumeric, sleep } from '@/common/utils'
|
import { isNumeric, sleep } from '@/common/utils'
|
||||||
import { OB11Constructor } from '../onebot11/constructor'
|
import { OB11Constructor } from '../onebot11/constructor'
|
||||||
import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent'
|
import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent'
|
||||||
import { OB11GroupAdminNoticeEvent } from '../onebot11/event/notice/OB11GroupAdminNoticeEvent'
|
import { OB11GroupAdminNoticeEvent } from '../onebot11/event/notice/OB11GroupAdminNoticeEvent'
|
||||||
import { randomUUID } from 'node:crypto'
|
|
||||||
|
|
||||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||||
|
|
||||||
@@ -103,8 +112,8 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
|||||||
if (hook.hookFunc.constructor.name === 'AsyncFunction') {
|
if (hook.hookFunc.constructor.name === 'AsyncFunction') {
|
||||||
; (_ as Promise<void>).then()
|
; (_ as Promise<void>).then()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
log('hook error', e, receiveData.payload)
|
log('hook error', ntQQApiMethodName, e.stack.toString())
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
}
|
}
|
||||||
@@ -332,7 +341,7 @@ export async function startHook() {
|
|||||||
})
|
})
|
||||||
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
||||||
// updateType 3是群列表变动,2是群成员变动
|
// updateType 3是群列表变动,2是群成员变动
|
||||||
// log("群列表变动", payload.updateType, payload.groupList)
|
// log("群列表变动, store", payload.updateType, payload.groupList)
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then()
|
updateGroups(payload.groupList).then()
|
||||||
}
|
}
|
||||||
@@ -391,17 +400,32 @@ export async function startHook() {
|
|||||||
registerReceiveHook<{
|
registerReceiveHook<{
|
||||||
data: CategoryFriend[]
|
data: CategoryFriend[]
|
||||||
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
||||||
for (const fData of payload.data) {
|
// log("onBuddyListChange", payload)
|
||||||
const _friends = fData.buddyList
|
// let friendListV2: {userSimpleInfos: Map<string, SimpleInfo>} = []
|
||||||
for (let friend of _friends) {
|
type V2data = {userSimpleInfos: Map<string, SimpleInfo>}
|
||||||
NTQQMsgApi.activateChat({ peerUid: friend.uid, chatType: ChatType.friend }).then()
|
let friendList: User[] = [];
|
||||||
let existFriend = friends.find((f) => f.uin == friend.uin)
|
if ((payload as any).userSimpleInfos) {
|
||||||
if (!existFriend) {
|
// friendListV2 = payload as any
|
||||||
friends.push(friend)
|
friendList = Object.values((payload as unknown as V2data).userSimpleInfos).map((v: SimpleInfo) => {
|
||||||
}
|
return {
|
||||||
else {
|
...v.coreInfo,
|
||||||
Object.assign(existFriend, friend)
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (const fData of payload.data) {
|
||||||
|
friendList.push(...fData.buddyList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log('好友列表变动', friendList)
|
||||||
|
for (let friend of friendList) {
|
||||||
|
NTQQMsgApi.activateChat({ peerUid: friend.uid, chatType: ChatType.friend }).then()
|
||||||
|
let existFriend = friends.find((f) => f.uin == friend.uin)
|
||||||
|
if (!existFriend) {
|
||||||
|
friends.push(friend)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object.assign(existFriend, friend)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -444,8 +468,12 @@ export async function startHook() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({ msgRecord }) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({ msgRecord }) => {
|
||||||
const message = msgRecord
|
const { msgId, chatType, peerUid } = msgRecord
|
||||||
dbUtil.addMsg(message).then()
|
const peer = {
|
||||||
|
chatType,
|
||||||
|
peerUid
|
||||||
|
}
|
||||||
|
MessageUnique.createMsg(peer, msgId)
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
||||||
|
128
src/ntqqapi/services/NodeIKernelSearchService.ts
Normal file
128
src/ntqqapi/services/NodeIKernelSearchService.ts
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
import { ChatType } from '../types'
|
||||||
|
|
||||||
|
export interface NodeIKernelSearchService {
|
||||||
|
addKernelSearchListener(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
removeKernelSearchListener(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
searchStranger(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchGroup(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
searchLocalInfo(keywords: string, unknown: number/*4*/): unknown
|
||||||
|
|
||||||
|
cancelSearchLocalInfo(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchBuddyChatInfo(...args: any[]): unknown// needs 2 arguments
|
||||||
|
|
||||||
|
searchMoreBuddyChatInfo(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchBuddyChatInfo(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchContact(...args: any[]): unknown// needs 2 arguments
|
||||||
|
|
||||||
|
searchMoreContact(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchContact(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchGroupChatInfo(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
resetSearchGroupChatInfoSortType(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
resetSearchGroupChatInfoFilterMembers(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchMoreGroupChatInfo(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchGroupChatInfo(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchChatsWithKeywords(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchMoreChatsWithKeywords(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchChatsWithKeywords(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchChatMsgs(...args: any[]): unknown// needs 2 arguments
|
||||||
|
|
||||||
|
searchMoreChatMsgs(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchChatMsgs(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchMsgWithKeywords(...args: any[]): unknown// needs 2 arguments
|
||||||
|
|
||||||
|
searchMoreMsgWithKeywords(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchMsgWithKeywords(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchFileWithKeywords(keywords: string[], source: number): Promise<string>// needs 2 arguments
|
||||||
|
|
||||||
|
searchMoreFileWithKeywords(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchFileWithKeywords(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchAtMeChats(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchMoreAtMeChats(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchAtMeChats(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
searchChatAtMeMsgs(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
searchMoreChatAtMeMsgs(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
cancelSearchChatAtMeMsgs(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
addSearchHistory(param: {
|
||||||
|
type: number,//4
|
||||||
|
contactList: [],
|
||||||
|
id: number,//-1
|
||||||
|
groupInfos: [],
|
||||||
|
msgs: [],
|
||||||
|
fileInfos: [
|
||||||
|
{
|
||||||
|
chatType: ChatType,
|
||||||
|
buddyChatInfo: Array<{ category_name: string, peerUid: string, peerUin: string, remark: string }>,
|
||||||
|
discussChatInfo: [],
|
||||||
|
groupChatInfo: Array<
|
||||||
|
{
|
||||||
|
groupCode: string,
|
||||||
|
isConf: boolean,
|
||||||
|
hasModifyConfGroupFace: boolean,
|
||||||
|
hasModifyConfGroupName: boolean,
|
||||||
|
groupName: string,
|
||||||
|
remark: string
|
||||||
|
}>,
|
||||||
|
dataLineChatInfo: [],
|
||||||
|
tmpChatInfo: [],
|
||||||
|
msgId: string,
|
||||||
|
msgSeq: string,
|
||||||
|
msgTime: string,
|
||||||
|
senderUid: string,
|
||||||
|
senderNick: string,
|
||||||
|
senderRemark: string,
|
||||||
|
senderCard: string,
|
||||||
|
elemId: string,
|
||||||
|
elemType: string,//3
|
||||||
|
fileSize: string,
|
||||||
|
filePath: string,
|
||||||
|
fileName: string,
|
||||||
|
hits: Array<
|
||||||
|
{
|
||||||
|
start: 12,
|
||||||
|
end: 14
|
||||||
|
}
|
||||||
|
>
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}): Promise<{
|
||||||
|
result: number,
|
||||||
|
errMsg: string,
|
||||||
|
id?: number
|
||||||
|
}>
|
||||||
|
|
||||||
|
removeSearchHistory(...args: any[]): unknown// needs 1 arguments
|
||||||
|
|
||||||
|
searchCache(...args: any[]): unknown// needs 3 arguments
|
||||||
|
|
||||||
|
clearSearchCache(...args: any[]): unknown// needs 1 arguments
|
||||||
|
}
|
@@ -8,3 +8,4 @@ export * from './NodeIKernelUixConvertService'
|
|||||||
export * from './NodeIKernelRichMediaService'
|
export * from './NodeIKernelRichMediaService'
|
||||||
export * from './NodeIKernelTicketService'
|
export * from './NodeIKernelTicketService'
|
||||||
export * from './NodeIKernelTipOffService'
|
export * from './NodeIKernelTipOffService'
|
||||||
|
export * from './NodeIKernelSearchService'
|
@@ -8,7 +8,8 @@ import {
|
|||||||
NodeIKernelUixConvertService,
|
NodeIKernelUixConvertService,
|
||||||
NodeIKernelRichMediaService,
|
NodeIKernelRichMediaService,
|
||||||
NodeIKernelTicketService,
|
NodeIKernelTicketService,
|
||||||
NodeIKernelTipOffService
|
NodeIKernelTipOffService,
|
||||||
|
NodeIKernelSearchService
|
||||||
} from './services'
|
} from './services'
|
||||||
import os from 'node:os'
|
import os from 'node:os'
|
||||||
const Process = require('node:process')
|
const Process = require('node:process')
|
||||||
@@ -25,6 +26,7 @@ export interface NodeIQQNTWrapperSession {
|
|||||||
getRichMediaService(): NodeIKernelRichMediaService
|
getRichMediaService(): NodeIKernelRichMediaService
|
||||||
getTicketService(): NodeIKernelTicketService
|
getTicketService(): NodeIKernelTicketService
|
||||||
getTipOffService(): NodeIKernelTipOffService
|
getTipOffService(): NodeIKernelTipOffService
|
||||||
|
getSearchService(): NodeIKernelSearchService
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WrapperApi {
|
export interface WrapperApi {
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import fs from 'fs/promises'
|
import fsPromise from 'node:fs/promises'
|
||||||
import { dbUtil } from '@/common/db'
|
|
||||||
import { getConfigUtil } from '@/common/config'
|
import { getConfigUtil } from '@/common/config'
|
||||||
import { checkFileReceived, log, sleep, uri2local } from '@/common/utils'
|
import { NTQQFileApi, NTQQGroupApi, NTQQUserApi, NTQQFriendApi, NTQQMsgApi } from '@/ntqqapi/api'
|
||||||
import { NTQQFileApi } from '@/ntqqapi/api'
|
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { FileElement, RawMessage, VideoElement } from '@/ntqqapi/types'
|
import { RawMessage } from '@/ntqqapi/types'
|
||||||
import { FileCache } from '@/common/types'
|
import { UUIDConverter } from '@/common/utils/helper'
|
||||||
|
import { Peer, ChatType, ElementType } from '@/ntqqapi/types'
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名或者fileUuid
|
file: string // 文件名或者fileUuid
|
||||||
@@ -21,79 +20,105 @@ export interface GetFileResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
export abstract class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
private getElement(msg: RawMessage, elementId: string): VideoElement | FileElement {
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/file/GetFile.ts#L44
|
||||||
let element = msg.elements.find((e) => e.elementId === elementId)
|
|
||||||
if (!element) {
|
|
||||||
throw new Error('element not found')
|
|
||||||
}
|
|
||||||
return element.fileElement
|
|
||||||
}
|
|
||||||
private async download(cache: FileCache, file: string) {
|
|
||||||
log('需要调用 NTQQ 下载文件api')
|
|
||||||
if (cache.msgId) {
|
|
||||||
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
|
||||||
if (msg) {
|
|
||||||
log('找到了文件 msg', msg)
|
|
||||||
let element = this.getElement(msg, cache.elementId)
|
|
||||||
log('找到了文件 element', element)
|
|
||||||
// 构建下载函数
|
|
||||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, cache.elementId, '', '')
|
|
||||||
// 等待文件下载完成
|
|
||||||
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
|
||||||
log('下载完成后的msg', msg)
|
|
||||||
cache.filePath = this.getElement(msg!, cache.elementId).filePath
|
|
||||||
await checkFileReceived(cache.filePath, 10 * 1000)
|
|
||||||
dbUtil.addFileCache(file, cache).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||||
let cache = await dbUtil.getFileCache(payload.file)
|
const { enableLocalFile2Url } = getConfigUtil().getConfig()
|
||||||
if (!cache) {
|
let UuidData: {
|
||||||
throw new Error('file not found')
|
high: string
|
||||||
}
|
low: string
|
||||||
const { autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond } = getConfigUtil().getConfig()
|
} | undefined
|
||||||
if (cache.downloadFunc) {
|
|
||||||
await cache.downloadFunc()
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await fs.access(cache.filePath, fs.constants.F_OK)
|
UuidData = UUIDConverter.decode(payload.file)
|
||||||
} catch (e) {
|
if (UuidData) {
|
||||||
// log("file not found", e)
|
const peerUin = UuidData.high
|
||||||
if (cache.url) {
|
const msgId = UuidData.low
|
||||||
const downloadResult = await uri2local(cache.url)
|
const isGroup: boolean = !!(await NTQQGroupApi.getGroups(false)).find(e => e.groupCode == peerUin)
|
||||||
if (downloadResult.success) {
|
let peer: Peer | undefined
|
||||||
cache.filePath = downloadResult.path
|
//识别Peer
|
||||||
dbUtil.addFileCache(payload.file, cache).then()
|
if (isGroup) {
|
||||||
} else {
|
peer = { chatType: ChatType.group, peerUid: peerUin }
|
||||||
await this.download(cache, payload.file)
|
|
||||||
}
|
}
|
||||||
} else {
|
const PeerUid = await NTQQUserApi.getUidByUinV2(peerUin)
|
||||||
// 没有url的可能是私聊文件或者群文件,需要自己下载
|
if (PeerUid) {
|
||||||
await this.download(cache, payload.file)
|
const isBuddy = await NTQQFriendApi.isBuddy(PeerUid)
|
||||||
|
if (isBuddy) {
|
||||||
|
peer = { chatType: ChatType.friend, peerUid: PeerUid }
|
||||||
|
} else {
|
||||||
|
peer = { chatType: ChatType.temp, peerUid: PeerUid }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!peer) {
|
||||||
|
throw new Error('chattype not support')
|
||||||
|
}
|
||||||
|
const msgList = await NTQQMsgApi.getMsgsByMsgId(peer, [msgId])
|
||||||
|
if (msgList.msgList.length == 0) {
|
||||||
|
throw new Error('msg not found')
|
||||||
|
}
|
||||||
|
const msg = msgList.msgList[0];
|
||||||
|
const findEle = msg.elements.find(e => e.elementType == ElementType.VIDEO || e.elementType == ElementType.FILE || e.elementType == ElementType.PTT)
|
||||||
|
if (!findEle) {
|
||||||
|
throw new Error('element not found')
|
||||||
|
}
|
||||||
|
const downloadPath = await NTQQFileApi.downloadMedia(msgId, msg.chatType, msg.peerUid, findEle.elementId, '', '')
|
||||||
|
const fileSize = findEle?.videoElement?.fileSize || findEle?.fileElement?.fileSize || findEle?.pttElement?.fileSize || '0'
|
||||||
|
const fileName = findEle?.videoElement?.fileName || findEle?.fileElement?.fileName || findEle?.pttElement?.fileName || ''
|
||||||
|
const res: GetFileResponse = {
|
||||||
|
file: downloadPath,
|
||||||
|
url: downloadPath,
|
||||||
|
file_size: fileSize,
|
||||||
|
file_name: fileName,
|
||||||
|
}
|
||||||
|
if (enableLocalFile2Url) {
|
||||||
|
try {
|
||||||
|
res.base64 = await fsPromise.readFile(downloadPath, 'base64')
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error('文件下载失败. ' + e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//不手动删除?文件持久化了
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
let res: GetFileResponse = {
|
|
||||||
file: cache.filePath,
|
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems
|
||||||
url: cache.url,
|
if (NTSearchNameResult.length !== 0) {
|
||||||
file_size: cache.fileSize,
|
const MsgId = NTSearchNameResult[0].msgId
|
||||||
file_name: cache.fileName,
|
let peer: Peer | undefined = undefined
|
||||||
}
|
if (NTSearchNameResult[0].chatType == ChatType.group) {
|
||||||
if (enableLocalFile2Url) {
|
peer = { chatType: ChatType.group, peerUid: NTSearchNameResult[0].groupChatInfo[0].groupCode }
|
||||||
if (!cache.url) {
|
}
|
||||||
|
if (!peer) {
|
||||||
|
throw new Error('chattype not support')
|
||||||
|
}
|
||||||
|
const msgList: RawMessage[] = (await NTQQMsgApi.getMsgsByMsgId(peer, [MsgId]))?.msgList
|
||||||
|
if (!msgList || msgList.length == 0) {
|
||||||
|
throw new Error('msg not found')
|
||||||
|
}
|
||||||
|
const msg = msgList[0]
|
||||||
|
const file = msg.elements.filter(e => e.elementType == NTSearchNameResult[0].elemType)
|
||||||
|
if (file.length == 0) {
|
||||||
|
throw new Error('file not found')
|
||||||
|
}
|
||||||
|
const downloadPath = await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, file[0].elementId, '', '')
|
||||||
|
const res: GetFileResponse = {
|
||||||
|
file: downloadPath,
|
||||||
|
url: downloadPath,
|
||||||
|
file_size: NTSearchNameResult[0].fileSize.toString(),
|
||||||
|
file_name: NTSearchNameResult[0].fileName,
|
||||||
|
}
|
||||||
|
if (enableLocalFile2Url) {
|
||||||
try {
|
try {
|
||||||
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
res.base64 = await fsPromise.readFile(downloadPath, 'base64')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('文件下载失败. ' + e)
|
throw new Error('文件下载失败. ' + e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//不手动删除?文件持久化了
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
// if (autoDeleteFile) {
|
throw new Error('file not found')
|
||||||
// setTimeout(() => {
|
|
||||||
// fs.unlink(cache.filePath)
|
|
||||||
// }, autoDeleteFileSecond * 1000)
|
|
||||||
// }
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,24 +1,27 @@
|
|||||||
|
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQGroupApi } from '../../../ntqqapi/api/group'
|
import { NTQQGroupApi } from '@/ntqqapi/api/group'
|
||||||
import { dbUtil } from '@/common/db';
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number | string;
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GoCQHTTPDelEssenceMsg extends BaseAction<Payload, any> {
|
export default class GoCQHTTPDelEssenceMsg extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_DelEssenceMsg;
|
actionName = ActionName.GoCQHTTP_DelEssenceMsg;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
const msg = await dbUtil.getMsgByShortId(parseInt(payload.message_id.toString()));
|
if (!payload.message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found')
|
||||||
}
|
}
|
||||||
return await NTQQGroupApi.removeGroupEssence(
|
return await NTQQGroupApi.removeGroupEssence(
|
||||||
msg.peerUid,
|
msg.Peer.peerUid,
|
||||||
msg.msgId
|
msg.MsgId,
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { join as joinPath } from 'node:path'
|
import fsPromise from 'fs/promises'
|
||||||
import { calculateFileMD5, httpDownload, TEMP_DIR } from '../../../common/utils'
|
import path from 'node:path'
|
||||||
|
import { calculateFileMD5, httpDownload, TEMP_DIR } from '@/common/utils'
|
||||||
import { randomUUID } from 'node:crypto'
|
import { randomUUID } from 'node:crypto'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
@@ -22,15 +23,15 @@ export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileRespon
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<FileResponse> {
|
protected async _handle(payload: Payload): Promise<FileResponse> {
|
||||||
const isRandomName = !payload.name
|
const isRandomName = !payload.name
|
||||||
let name = payload.name || randomUUID()
|
const name = payload.name ? path.basename(payload.name) : randomUUID()
|
||||||
const filePath = joinPath(TEMP_DIR, name)
|
const filePath = path.join(TEMP_DIR, name)
|
||||||
|
|
||||||
if (payload.base64) {
|
if (payload.base64) {
|
||||||
fs.writeFileSync(filePath, payload.base64, 'base64')
|
await fsPromise.writeFile(filePath, payload.base64, 'base64')
|
||||||
} else if (payload.url) {
|
} else if (payload.url) {
|
||||||
const headers = this.getHeaders(payload.headers)
|
const headers = this.getHeaders(payload.headers)
|
||||||
let buffer = await httpDownload({ url: payload.url, headers: headers })
|
const buffer = await httpDownload({ url: payload.url, headers: headers })
|
||||||
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary')
|
await fsPromise.writeFile(filePath, buffer)
|
||||||
} else {
|
} else {
|
||||||
throw new Error('不存在任何文件, 无法下载')
|
throw new Error('不存在任何文件, 无法下载')
|
||||||
}
|
}
|
||||||
@@ -38,8 +39,8 @@ export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileRespon
|
|||||||
if (isRandomName) {
|
if (isRandomName) {
|
||||||
// 默认实现要名称未填写时文件名为文件 md5
|
// 默认实现要名称未填写时文件名为文件 md5
|
||||||
const md5 = await calculateFileMD5(filePath)
|
const md5 = await calculateFileMD5(filePath)
|
||||||
const newPath = joinPath(TEMP_DIR, md5)
|
const newPath = path.join(TEMP_DIR, md5)
|
||||||
fs.renameSync(filePath, newPath)
|
await fsPromise.rename(filePath, newPath)
|
||||||
return { file: newPath }
|
return { file: newPath }
|
||||||
}
|
}
|
||||||
return { file: filePath }
|
return { file: filePath }
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types'
|
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types'
|
||||||
import { NTQQMsgApi } from '@/ntqqapi/api'
|
import { NTQQMsgApi } from '@/ntqqapi/api'
|
||||||
import { dbUtil } from '../../../common/db'
|
|
||||||
import { OB11Constructor } from '../../constructor'
|
import { OB11Constructor } from '../../constructor'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: string // long msg id,gocq
|
message_id: string // long msg id,gocq
|
||||||
@@ -14,30 +14,30 @@ interface Response {
|
|||||||
messages: (OB11Message & { content: OB11MessageData })[]
|
messages: (OB11Message & { content: OB11MessageData })[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
|
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, Response> {
|
||||||
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
const message_id = payload.id || payload.message_id
|
const msgId = payload.id || payload.message_id
|
||||||
if (!message_id) {
|
if (!msgId) {
|
||||||
throw Error('message_id不能为空')
|
throw Error('message_id不能为空')
|
||||||
}
|
}
|
||||||
const rootMsg = await dbUtil.getMsgByLongId(message_id)
|
const rootMsgId = MessageUnique.getShortIdByMsgId(msgId)
|
||||||
|
const rootMsg = await MessageUnique.getMsgIdAndPeerByShortId(rootMsgId || +msgId)
|
||||||
if (!rootMsg) {
|
if (!rootMsg) {
|
||||||
throw Error('msg not found')
|
throw Error('msg not found')
|
||||||
}
|
}
|
||||||
let data = await NTQQMsgApi.getMultiMsg(
|
const data = await NTQQMsgApi.getMultiMsg(rootMsg.Peer, rootMsg.MsgId, rootMsg.MsgId)
|
||||||
{ chatType: rootMsg.chatType, peerUid: rootMsg.peerUid },
|
if (data?.result !== 0) {
|
||||||
rootMsg.msgId,
|
throw Error('找不到相关的聊天记录' + data?.errMsg)
|
||||||
rootMsg.msgId,
|
|
||||||
)
|
|
||||||
if (data.result !== 0) {
|
|
||||||
throw Error('找不到相关的聊天记录' + data.errMsg)
|
|
||||||
}
|
}
|
||||||
let msgList = data.msgList
|
const msgList = data.msgList
|
||||||
let messages = await Promise.all(
|
const messages = await Promise.all(
|
||||||
msgList.map(async (msg) => {
|
msgList.map(async (msg) => {
|
||||||
let resMsg = await OB11Constructor.message(msg)
|
const resMsg = await OB11Constructor.message(msg)
|
||||||
resMsg.message_id = (await dbUtil.addMsg(msg))!
|
resMsg.message_id = MessageUnique.createMsg({
|
||||||
|
chatType: msg.chatType,
|
||||||
|
peerUid: msg.peerUid,
|
||||||
|
}, msg.msgId)!
|
||||||
return resMsg
|
return resMsg
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { OB11Message, OB11User } from '../../types'
|
import { OB11Message } from '../../types'
|
||||||
import { groups } from '../../../common/data'
|
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { ChatType } from '../../../ntqqapi/types'
|
import { ChatType } from '@/ntqqapi/types'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { NTQQMsgApi } from '@/ntqqapi/api/msg'
|
||||||
import { NTQQMsgApi } from '../../../ntqqapi/api/msg'
|
|
||||||
import { OB11Constructor } from '../../constructor'
|
import { OB11Constructor } from '../../constructor'
|
||||||
|
import { RawMessage } from '@/ntqqapi/types'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number
|
group_id: number | string
|
||||||
message_seq: number
|
message_seq?: number
|
||||||
count: number
|
count?: number
|
||||||
|
reverseOrder?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
@@ -21,23 +22,23 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
|
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<Response> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
const group = groups.find((group) => group.groupCode === payload.group_id.toString())
|
const count = payload.count || 20
|
||||||
if (!group) {
|
const isReverseOrder = payload.reverseOrder || true
|
||||||
throw `群${payload.group_id}不存在`
|
const peer = { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
||||||
|
let msgList: RawMessage[]
|
||||||
|
// 包含 message_seq 0
|
||||||
|
if (!payload.message_seq) {
|
||||||
|
msgList = (await NTQQMsgApi.getLastestMsgByUids(peer, count)).msgList
|
||||||
|
} else {
|
||||||
|
const startMsgId = (await MessageUnique.getMsgIdAndPeerByShortId(payload.message_seq))?.MsgId
|
||||||
|
if (!startMsgId) throw `消息${payload.message_seq}不存在`
|
||||||
|
msgList = (await NTQQMsgApi.getMsgHistory(peer, startMsgId, count)).msgList
|
||||||
}
|
}
|
||||||
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0'
|
if (isReverseOrder) msgList.reverse()
|
||||||
// log("startMsgId", startMsgId)
|
|
||||||
let msgList = (
|
|
||||||
await NTQQMsgApi.getMsgHistory(
|
|
||||||
{ chatType: ChatType.group, peerUid: group.groupCode },
|
|
||||||
startMsgId,
|
|
||||||
parseInt(payload.count?.toString()) || 20,
|
|
||||||
)
|
|
||||||
).msgList
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
msgList.map(async (msg) => {
|
msgList.map(async msg => {
|
||||||
msg.msgShortId = await dbUtil.addMsg(msg)
|
msg.msgShortId = MessageUnique.createMsg({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
const ob11MsgList = await Promise.all(msgList.map((msg) => OB11Constructor.message(msg)))
|
const ob11MsgList = await Promise.all(msgList.map((msg) => OB11Constructor.message(msg)))
|
||||||
return { messages: ob11MsgList }
|
return { messages: ob11MsgList }
|
||||||
|
@@ -1,23 +1,26 @@
|
|||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types'
|
||||||
import { NTQQGroupApi } from '../../../ntqqapi/api/group'
|
import { NTQQGroupApi } from '@/ntqqapi/api/group'
|
||||||
import { dbUtil } from '@/common/db';
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number | string;
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GoCQHTTPSetEssenceMsg extends BaseAction<Payload, any> {
|
export default class GoCQHTTPSetEssenceMsg extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_SetEssenceMsg;
|
actionName = ActionName.GoCQHTTP_SetEssenceMsg;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
const msg = await dbUtil.getMsgByShortId(parseInt(payload.message_id.toString()));
|
if (!payload.message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found');
|
throw new Error('msg not found')
|
||||||
}
|
}
|
||||||
return await NTQQGroupApi.addGroupEssence(
|
return await NTQQGroupApi.addGroupEssence(
|
||||||
msg.peerUid,
|
msg.Peer.peerUid,
|
||||||
msg.msgId
|
msg.MsgId
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,27 +1,24 @@
|
|||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { NTQQMsgApi } from '@/ntqqapi/api/msg'
|
||||||
import { NTQQMsgApi } from '../../../ntqqapi/api/msg'
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeleteMsg extends BaseAction<Payload, void> {
|
class DeleteMsg extends BaseAction<Payload, void> {
|
||||||
actionName = ActionName.DeleteMsg
|
actionName = ActionName.DeleteMsg
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
if (!payload.message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw `消息${payload.message_id}不存在`
|
throw `消息${payload.message_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQMsgApi.recallMsg(
|
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId])
|
||||||
{
|
|
||||||
chatType: msg.chatType,
|
|
||||||
peerUid: msg.peerUid,
|
|
||||||
},
|
|
||||||
[msg.msgId],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
import { NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
||||||
import { ChatType } from '@/ntqqapi/types'
|
import { ChatType } from '@/ntqqapi/types'
|
||||||
import { dbUtil } from '@/common/db'
|
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { Peer } from '@/ntqqapi/types'
|
import { Peer } from '@/ntqqapi/types'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number | string
|
||||||
group_id: number | string
|
group_id: number | string
|
||||||
user_id?: number | string
|
user_id?: number | string
|
||||||
}
|
}
|
||||||
@@ -24,19 +24,15 @@ abstract class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
if (!payload.message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error(`无法找到消息${payload.message_id}`)
|
throw new Error(`无法找到消息${payload.message_id}`)
|
||||||
}
|
}
|
||||||
const peer = await this.getTargetPeer(payload)
|
const peer = await this.getTargetPeer(payload)
|
||||||
const ret = await NTQQMsgApi.forwardMsg(
|
const ret = await NTQQMsgApi.forwardMsg(msg.Peer, peer, [msg.MsgId])
|
||||||
{
|
|
||||||
chatType: msg.chatType,
|
|
||||||
peerUid: msg.peerUid,
|
|
||||||
},
|
|
||||||
peer,
|
|
||||||
[msg.msgId],
|
|
||||||
)
|
|
||||||
if (ret.result !== 0) {
|
if (ret.result !== 0) {
|
||||||
throw new Error(`转发消息失败 ${ret.errMsg}`)
|
throw new Error(`转发消息失败 ${ret.errMsg}`)
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,11 @@ import { OB11Message } from '../../types'
|
|||||||
import { OB11Constructor } from '../../constructor'
|
import { OB11Constructor } from '../../constructor'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { NTQQMsgApi } from '@/ntqqapi/api'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
message_id: number
|
message_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ReturnDataType = OB11Message
|
export type ReturnDataType = OB11Message
|
||||||
@@ -18,14 +19,25 @@ class GetMsg extends BaseAction<PayloadType, OB11Message> {
|
|||||||
if (!payload.message_id) {
|
if (!payload.message_id) {
|
||||||
throw '参数message_id不能为空'
|
throw '参数message_id不能为空'
|
||||||
}
|
}
|
||||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
const msgShortId = MessageUnique.getShortIdByMsgId(payload.message_id.toString())
|
||||||
if (!msg) {
|
const msgIdWithPeer = await MessageUnique.getMsgIdAndPeerByShortId(msgShortId || +payload.message_id)
|
||||||
msg = await dbUtil.getMsgByLongId(payload.message_id.toString())
|
if (!msgIdWithPeer) {
|
||||||
|
throw ('消息不存在')
|
||||||
}
|
}
|
||||||
if (!msg) {
|
const peer = {
|
||||||
throw '消息不存在'
|
guildId: '',
|
||||||
|
peerUid: msgIdWithPeer.Peer.peerUid,
|
||||||
|
chatType: msgIdWithPeer.Peer.chatType
|
||||||
}
|
}
|
||||||
return await OB11Constructor.message(msg)
|
const msg = await NTQQMsgApi.getMsgsByMsgId(
|
||||||
|
peer,
|
||||||
|
[msgIdWithPeer?.MsgId || payload.message_id.toString()]
|
||||||
|
)
|
||||||
|
const retMsg = await OB11Constructor.message(msg.msgList[0])
|
||||||
|
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!
|
||||||
|
retMsg.message_seq = retMsg.message_id
|
||||||
|
retMsg.real_id = retMsg.message_id
|
||||||
|
return retMsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,35 +3,35 @@ import {
|
|||||||
ChatType,
|
ChatType,
|
||||||
ElementType,
|
ElementType,
|
||||||
GroupMemberRole,
|
GroupMemberRole,
|
||||||
PicSubType,
|
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SendMessageElement,
|
SendMessageElement,
|
||||||
} from '../../../ntqqapi/types'
|
} from '@/ntqqapi/types'
|
||||||
import { getGroup, getGroupMember, getSelfUid, getSelfUin } from '../../../common/data'
|
import { getGroup, getGroupMember, getSelfUid, getSelfUin } from '@/common/data'
|
||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
OB11MessageDataType,
|
OB11MessageDataType,
|
||||||
OB11MessageFile,
|
|
||||||
OB11MessageJson,
|
OB11MessageJson,
|
||||||
OB11MessageMixType,
|
OB11MessageMixType,
|
||||||
OB11MessageMusic,
|
OB11MessageMusic,
|
||||||
OB11MessageNode,
|
OB11MessageNode,
|
||||||
OB11PostSendMsg,
|
OB11PostSendMsg,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { SendMsgElementConstructor } from '../../../ntqqapi/constructor'
|
import { SendMsgElementConstructor } from '@/ntqqapi/constructor'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName, BaseCheckResult } from '../types'
|
import { ActionName, BaseCheckResult } from '../types'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
|
import fsPromise from 'node:fs/promises'
|
||||||
import { decodeCQCode } from '../../cqcode'
|
import { decodeCQCode } from '../../cqcode'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { getConfigUtil } from '@/common/config'
|
||||||
import { getConfigUtil } from '../../../common/config'
|
import { log } from '@/common/utils/log'
|
||||||
import { log } from '../../../common/utils/log'
|
import { sleep } from '@/common/utils/helper'
|
||||||
import { sleep } from '../../../common/utils/helper'
|
import { uri2local } from '@/common/utils'
|
||||||
import { uri2local } from '../../../common/utils'
|
|
||||||
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi, NTQQFriendApi } from '@/ntqqapi/api'
|
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi, NTQQFriendApi } from '@/ntqqapi/api'
|
||||||
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign'
|
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign'
|
||||||
import { Peer } from '@/ntqqapi/types/msg'
|
import { Peer } from '@/ntqqapi/types/msg'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
import { OB11MessageFileBase } from '../../types'
|
||||||
|
|
||||||
export interface ReturnDataType {
|
export interface ReturnDataType {
|
||||||
message_id: number
|
message_id: number
|
||||||
@@ -43,6 +43,11 @@ export enum ContextMode {
|
|||||||
Group = 2
|
Group = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface MessageContext {
|
||||||
|
deleteAfterSentFiles: string[]
|
||||||
|
peer: Peer
|
||||||
|
}
|
||||||
|
|
||||||
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
||||||
if (typeof message === 'string') {
|
if (typeof message === 'string') {
|
||||||
if (autoEscape === true) {
|
if (autoEscape === true) {
|
||||||
@@ -65,6 +70,32 @@ export function convertMessage2List(message: OB11MessageMixType, autoEscape = fa
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/msg/SendMsg/create-send-elements.ts#L26
|
||||||
|
async function handleOb11FileLikeMessage(
|
||||||
|
{ data: inputdata }: OB11MessageFileBase,
|
||||||
|
{ deleteAfterSentFiles }: Pick<MessageContext, 'deleteAfterSentFiles'>,
|
||||||
|
) {
|
||||||
|
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||||
|
const {
|
||||||
|
path,
|
||||||
|
isLocal,
|
||||||
|
fileName,
|
||||||
|
errMsg,
|
||||||
|
success,
|
||||||
|
} = (await uri2local(inputdata?.url || inputdata.file))
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
log('文件下载失败', errMsg)
|
||||||
|
throw Error('文件下载失败' + errMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||||
|
deleteAfterSentFiles.push(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { path, fileName: inputdata.name || fileName }
|
||||||
|
}
|
||||||
|
|
||||||
export async function createSendElements(
|
export async function createSendElements(
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
@@ -130,9 +161,16 @@ export async function createSendElements(
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.reply: {
|
case OB11MessageDataType.reply: {
|
||||||
let replyMsgId = sendMsg.data.id
|
if (sendMsg.data.id) {
|
||||||
if (replyMsgId) {
|
const replyMsgId = await MessageUnique.getMsgIdAndPeerByShortId(+sendMsg.data.id)
|
||||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
if (!replyMsgId) {
|
||||||
|
log('回复消息不存在', replyMsgId)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(
|
||||||
|
replyMsgId.Peer,
|
||||||
|
[replyMsgId.MsgId!]
|
||||||
|
)).msgList[0]
|
||||||
if (replyMsg) {
|
if (replyMsg) {
|
||||||
sendElements.push(
|
sendElements.push(
|
||||||
SendMsgElementConstructor.reply(
|
SendMsgElementConstructor.reply(
|
||||||
@@ -164,66 +202,36 @@ export async function createSendElements(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.image:
|
case OB11MessageDataType.image: {
|
||||||
case OB11MessageDataType.file:
|
const res = await SendMsgElementConstructor.pic(
|
||||||
case OB11MessageDataType.video:
|
(await handleOb11FileLikeMessage(sendMsg, { deleteAfterSentFiles })).path,
|
||||||
case OB11MessageDataType.voice: {
|
sendMsg.data.summary || '',
|
||||||
const data = (sendMsg as OB11MessageFile).data
|
sendMsg.data.subType || 0
|
||||||
let file = data.file
|
)
|
||||||
const payloadFileName = data?.name
|
deleteAfterSentFiles.push(res.picElement.sourcePath)
|
||||||
if (file) {
|
sendElements.push(res)
|
||||||
const cache = await dbUtil.getFileCache(file)
|
}
|
||||||
if (cache) {
|
break
|
||||||
if (fs.existsSync(cache.filePath)) {
|
case OB11MessageDataType.file: {
|
||||||
file = 'file://' + cache.filePath
|
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, { deleteAfterSentFiles })
|
||||||
}
|
sendElements.push(await SendMsgElementConstructor.file(path, fileName))
|
||||||
else if (cache.downloadFunc) {
|
}
|
||||||
await cache.downloadFunc()
|
break
|
||||||
file = cache.filePath
|
case OB11MessageDataType.video: {
|
||||||
}
|
const { path, fileName } = await handleOb11FileLikeMessage(sendMsg, { deleteAfterSentFiles })
|
||||||
else if (cache.url) {
|
let thumb = sendMsg.data.thumb
|
||||||
file = cache.url
|
if (thumb) {
|
||||||
}
|
const uri2LocalRes = await uri2local(thumb)
|
||||||
log('找到文件缓存', file)
|
if (uri2LocalRes.success) thumb = uri2LocalRes.path
|
||||||
}
|
|
||||||
const { path, isLocal, fileName, errMsg } = await uri2local(file)
|
|
||||||
if (errMsg) {
|
|
||||||
throw errMsg
|
|
||||||
}
|
|
||||||
if (path) {
|
|
||||||
if (!isLocal) {
|
|
||||||
// 只删除http和base64转过来的文件
|
|
||||||
deleteAfterSentFiles.push(path)
|
|
||||||
}
|
|
||||||
if (sendMsg.type === OB11MessageDataType.file) {
|
|
||||||
log('发送文件', path, payloadFileName || fileName)
|
|
||||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName))
|
|
||||||
}
|
|
||||||
else if (sendMsg.type === OB11MessageDataType.video) {
|
|
||||||
log('发送视频', path, payloadFileName || fileName)
|
|
||||||
let thumb = sendMsg.data?.thumb
|
|
||||||
if (thumb) {
|
|
||||||
let uri2LocalRes = await uri2local(thumb)
|
|
||||||
if (uri2LocalRes.success) {
|
|
||||||
thumb = uri2LocalRes.path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb))
|
|
||||||
}
|
|
||||||
else if (sendMsg.type === OB11MessageDataType.voice) {
|
|
||||||
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
|
||||||
}
|
|
||||||
else if (sendMsg.type === OB11MessageDataType.image) {
|
|
||||||
sendElements.push(
|
|
||||||
await SendMsgElementConstructor.pic(
|
|
||||||
path,
|
|
||||||
sendMsg.data.summary || '',
|
|
||||||
<PicSubType>parseInt(sendMsg.data?.subType?.toString()!) || 0,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
const res = await SendMsgElementConstructor.video(path, fileName, thumb)
|
||||||
|
deleteAfterSentFiles.push(res.videoElement.filePath)
|
||||||
|
sendElements.push(res)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case OB11MessageDataType.voice: {
|
||||||
|
const { path } = await handleOb11FileLikeMessage(sendMsg, { deleteAfterSentFiles })
|
||||||
|
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.json: {
|
case OB11MessageDataType.json: {
|
||||||
@@ -287,9 +295,8 @@ export async function sendMsg(
|
|||||||
log('设置消息超时时间', timeout)
|
log('设置消息超时时间', timeout)
|
||||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout)
|
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout)
|
||||||
log('消息发送结果', returnMsg)
|
log('消息发送结果', returnMsg)
|
||||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
returnMsg.msgShortId = MessageUnique.createMsg(peer, returnMsg.msgId)
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
deleteAfterSentFiles.map(path => fsPromise.unlink(path))
|
||||||
}))
|
|
||||||
return returnMsg
|
return returnMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,8 +435,6 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
|
||||||
}))
|
|
||||||
return { message_id: returnMsg.msgShortId! }
|
return { message_id: returnMsg.msgShortId! }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +467,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
sendElements,
|
sendElements,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
await sleep(500)
|
await sleep(400)
|
||||||
return nodeMsg
|
return nodeMsg
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e, '克隆转发消息失败,将忽略本条消息', msg)
|
log(e, '克隆转发消息失败,将忽略本条消息', msg)
|
||||||
@@ -477,25 +482,17 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
let nodeMsgIds: string[] = []
|
let nodeMsgIds: string[] = []
|
||||||
// 先判断一遍是不是id和自定义混用
|
// 先判断一遍是不是id和自定义混用
|
||||||
let needClone =
|
|
||||||
messageNodes.filter((node) => node.data.id).length && messageNodes.filter((node) => !node.data.id).length
|
|
||||||
for (const messageNode of messageNodes) {
|
for (const messageNode of messageNodes) {
|
||||||
// 一个node表示一个人的消息
|
// 一个node表示一个人的消息
|
||||||
let nodeId = messageNode.data.id
|
let nodeId = messageNode.data.id
|
||||||
// 有nodeId表示一个子转发消息卡片
|
// 有nodeId表示一个子转发消息卡片
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId))
|
const nodeMsg = await MessageUnique.getMsgIdAndPeerByShortId(+nodeId) || await MessageUnique.getPeerByMsgId(nodeId)
|
||||||
if (!needClone) {
|
if (!nodeMsg) {
|
||||||
nodeMsgIds.push(nodeMsg?.msgId!)
|
log('转发消息失败,未找到消息', nodeId)
|
||||||
}
|
continue
|
||||||
else {
|
|
||||||
if (nodeMsg?.peerUid !== selfPeer.peerUid) {
|
|
||||||
const cloneMsg = await this.cloneMsg(nodeMsg!)
|
|
||||||
if (cloneMsg) {
|
|
||||||
nodeMsgIds.push(cloneMsg.msgId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
nodeMsgIds.push(nodeMsg.MsgId)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 自定义的消息
|
// 自定义的消息
|
||||||
@@ -529,7 +526,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
for (const eles of sendElementsSplit) {
|
for (const eles of sendElementsSplit) {
|
||||||
const nodeMsg = await sendMsg(selfPeer, eles, [], true)
|
const nodeMsg = await sendMsg(selfPeer, eles, [], true)
|
||||||
nodeMsgIds.push(nodeMsg.msgId)
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
await sleep(500)
|
await sleep(400)
|
||||||
log('转发节点生成成功', nodeMsg.msgId)
|
log('转发节点生成成功', nodeMsg.msgId)
|
||||||
}
|
}
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
||||||
@@ -541,33 +538,25 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
// 检查srcPeer是否一致,不一致则需要克隆成自己的消息, 让所有srcPeer都变成自己的,使其保持一致才能够转发
|
||||||
let nodeMsgArray: Array<RawMessage> = []
|
const nodeMsgArray: RawMessage[] = []
|
||||||
let srcPeer: Peer | null = null
|
let srcPeer: Peer | null = null
|
||||||
let needSendSelf = false
|
let needSendSelf = false
|
||||||
for (const [index, msgId] of nodeMsgIds.entries()) {
|
for (const msgId of nodeMsgIds) {
|
||||||
const nodeMsg = await dbUtil.getMsgByLongId(msgId)
|
const nodeMsgPeer = await MessageUnique.getPeerByMsgId(msgId)
|
||||||
if (nodeMsg) {
|
if (nodeMsgPeer) {
|
||||||
nodeMsgArray.push(nodeMsg)
|
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0]
|
||||||
if (!srcPeer) {
|
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }
|
||||||
srcPeer = { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }
|
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
}
|
|
||||||
else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
|
||||||
needSendSelf = true
|
needSendSelf = true
|
||||||
srcPeer = selfPeer
|
|
||||||
}
|
}
|
||||||
|
nodeMsgArray.push(nodeMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log('nodeMsgArray', nodeMsgArray)
|
|
||||||
nodeMsgIds = nodeMsgArray.map((msg) => msg.msgId)
|
nodeMsgIds = nodeMsgArray.map((msg) => msg.msgId)
|
||||||
if (needSendSelf) {
|
if (needSendSelf) {
|
||||||
log('需要克隆转发消息')
|
for (const msg of nodeMsgArray) {
|
||||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
if (msg.peerUid === selfPeer.peerUid) continue
|
||||||
if (msg.peerUid !== selfPeer.peerUid) {
|
await this.cloneMsg(msg)
|
||||||
const cloneMsg = await this.cloneMsg(msg)
|
|
||||||
if (cloneMsg) {
|
|
||||||
nodeMsgIds[index] = cloneMsg.msgId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// elements之间用换行符分隔
|
// elements之间用换行符分隔
|
||||||
@@ -584,7 +573,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
throw Error('转发消息失败,节点为空')
|
throw Error('转发消息失败,节点为空')
|
||||||
}
|
}
|
||||||
const returnMsg = await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds)
|
const returnMsg = await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds)
|
||||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
returnMsg.msgShortId = MessageUnique.createMsg(destPeer, returnMsg.msgId)
|
||||||
return returnMsg
|
return returnMsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,36 @@
|
|||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { NTQQMsgApi } from '@/ntqqapi/api/msg'
|
||||||
import { NTQQMsgApi } from '../../../ntqqapi/api/msg'
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number | string
|
||||||
emoji_id: string
|
emoji_id: number | string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetMsgEmojiLike extends BaseAction<Payload, any> {
|
export class SetMsgEmojiLike extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.SetMsgEmojiLike
|
actionName = ActionName.SetMsgEmojiLike
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
if (!payload.message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id)
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
throw new Error('msg not found')
|
throw new Error('msg not found')
|
||||||
}
|
}
|
||||||
if (!payload.emoji_id) {
|
if (!payload.emoji_id) {
|
||||||
throw new Error('emojiId not found')
|
throw new Error('emojiId not found')
|
||||||
}
|
}
|
||||||
|
const msgData = (await NTQQMsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList
|
||||||
|
if (!msgData || msgData.length == 0 || !msgData[0].msgSeq) {
|
||||||
|
throw new Error('find msg by msgid error')
|
||||||
|
}
|
||||||
return await NTQQMsgApi.setEmojiLike(
|
return await NTQQMsgApi.setEmojiLike(
|
||||||
{
|
msg.Peer,
|
||||||
chatType: msg.chatType,
|
msgData[0].msgSeq,
|
||||||
peerUid: msg.peerUid,
|
payload.emoji_id.toString(),
|
||||||
},
|
true
|
||||||
msg.msgSeq,
|
|
||||||
payload.emoji_id,
|
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,12 +4,12 @@
|
|||||||
import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from '../types'
|
import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from '../types'
|
||||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
||||||
import { dbUtil } from '@/common/db'
|
|
||||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/ntqqapi/api'
|
||||||
import { ChatType, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types'
|
import { ChatType, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types'
|
||||||
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
||||||
import { isNull, log } from '@/common/utils'
|
import { isNull, log } from '@/common/utils'
|
||||||
import { getConfigUtil } from '@/common/config'
|
import { getConfigUtil } from '@/common/config'
|
||||||
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
||||||
|
|
||||||
|
|
||||||
interface QuickOperationPrivateMessage {
|
interface QuickOperationPrivateMessage {
|
||||||
@@ -61,7 +61,6 @@ export async function handleQuickOperation(context: QuickOperationEvent, quickAc
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMessage | QuickOperationGroupMessage) {
|
async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMessage | QuickOperationGroupMessage) {
|
||||||
const rawMessage = await dbUtil.getMsgByShortId(msg.message_id)
|
|
||||||
const reply = quickAction.reply
|
const reply = quickAction.reply
|
||||||
const ob11Config = getConfigUtil().getConfig().ob11
|
const ob11Config = getConfigUtil().getConfig().ob11
|
||||||
const peer: Peer = {
|
const peer: Peer = {
|
||||||
@@ -105,17 +104,21 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
|
|||||||
}
|
}
|
||||||
if (msg.message_type === 'group') {
|
if (msg.message_type === 'group') {
|
||||||
const groupMsgQuickAction = quickAction as QuickOperationGroupMessage
|
const groupMsgQuickAction = quickAction as QuickOperationGroupMessage
|
||||||
|
const rawMessage = await MessageUnique.getMsgIdAndPeerByShortId(+(msg.message_id ?? 0))
|
||||||
|
if (!rawMessage) return
|
||||||
// handle group msg
|
// handle group msg
|
||||||
if (groupMsgQuickAction.delete) {
|
if (groupMsgQuickAction.delete) {
|
||||||
NTQQMsgApi.recallMsg(peer, [rawMessage?.msgId!]).then().catch(log)
|
NTQQMsgApi.recallMsg(peer, [rawMessage.MsgId]).then().catch(log)
|
||||||
}
|
}
|
||||||
if (groupMsgQuickAction.kick) {
|
if (groupMsgQuickAction.kick) {
|
||||||
NTQQGroupApi.kickMember(peer.peerUid, [rawMessage?.senderUid!]).then().catch(log)
|
const { msgList } = await NTQQMsgApi.getMsgsByMsgId(peer, [rawMessage.MsgId])
|
||||||
|
NTQQGroupApi.kickMember(peer.peerUid, [msgList[0].senderUid]).then().catch(log)
|
||||||
}
|
}
|
||||||
if (groupMsgQuickAction.ban) {
|
if (groupMsgQuickAction.ban) {
|
||||||
|
const { msgList } = await NTQQMsgApi.getMsgsByMsgId(peer, [rawMessage.MsgId])
|
||||||
NTQQGroupApi.banMember(peer.peerUid, [
|
NTQQGroupApi.banMember(peer.peerUid, [
|
||||||
{
|
{
|
||||||
uid: rawMessage?.senderUid!,
|
uid: msgList[0].senderUid,
|
||||||
timeStamp: groupMsgQuickAction.ban_duration || 60 * 30,
|
timeStamp: groupMsgQuickAction.ban_duration || 60 * 30,
|
||||||
},
|
},
|
||||||
]).then().catch(log)
|
]).then().catch(log)
|
||||||
|
@@ -23,14 +23,14 @@ import {
|
|||||||
Sex,
|
Sex,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
User,
|
User,
|
||||||
VideoElement,
|
|
||||||
FriendV2,
|
FriendV2,
|
||||||
ChatType2
|
ChatType2
|
||||||
} from '../ntqqapi/types'
|
} from '../ntqqapi/types'
|
||||||
import { deleteGroup, getGroupMember, getSelfUin } from '../common/data'
|
import { deleteGroup, getGroupMember, getSelfUin } from '../common/data'
|
||||||
import { EventType } from './event/OB11BaseEvent'
|
import { EventType } from './event/OB11BaseEvent'
|
||||||
import { encodeCQCode } from './cqcode'
|
import { encodeCQCode } from './cqcode'
|
||||||
import { dbUtil } from '../common/db'
|
import { MessageUnique } from '../common/utils/MessageUnique'
|
||||||
|
import { UUIDConverter } from '../common/utils/helper'
|
||||||
import { OB11GroupIncreaseEvent } from './event/notice/OB11GroupIncreaseEvent'
|
import { OB11GroupIncreaseEvent } from './event/notice/OB11GroupIncreaseEvent'
|
||||||
import { OB11GroupBanEvent } from './event/notice/OB11GroupBanEvent'
|
import { OB11GroupBanEvent } from './event/notice/OB11GroupBanEvent'
|
||||||
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent'
|
import { OB11GroupUploadNoticeEvent } from './event/notice/OB11GroupUploadNoticeEvent'
|
||||||
@@ -152,55 +152,47 @@ export class OB11Constructor {
|
|||||||
}
|
}
|
||||||
else if (element.replyElement) {
|
else if (element.replyElement) {
|
||||||
message_data['type'] = OB11MessageDataType.reply
|
message_data['type'] = OB11MessageDataType.reply
|
||||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
|
||||||
try {
|
try {
|
||||||
const replyMsg = await dbUtil.getMsgBySeqId(element.replyElement.replayMsgSeq)
|
const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords)
|
||||||
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
if (!records) throw new Error('找不到回复消息')
|
||||||
if (replyMsg) {
|
let replyMsg = (await NTQQMsgApi.getMsgsBySeqAndCount({
|
||||||
message_data['data']['id'] = replyMsg.msgShortId?.toString()
|
peerUid: msg.peerUid,
|
||||||
|
guildId: '',
|
||||||
|
chatType: msg.chatType,
|
||||||
|
}, element.replyElement.replayMsgSeq, 1, true, true)).msgList[0]
|
||||||
|
if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {
|
||||||
|
const peer = {
|
||||||
|
chatType: msg.chatType,
|
||||||
|
peerUid: msg.peerUid,
|
||||||
|
guildId: '',
|
||||||
|
}
|
||||||
|
replyMsg = (await NTQQMsgApi.getSingleMsg(peer, element.replyElement.replayMsgSeq)).msgList[0]
|
||||||
}
|
}
|
||||||
else {
|
if ((!replyMsg || records.msgRandom !== replyMsg.msgRandom) && msg.peerUin !== '284840486') {
|
||||||
continue
|
throw new Error('回复消息消息验证失败')
|
||||||
}
|
}
|
||||||
|
message_data['data']['id'] = MessageUnique.createMsg({
|
||||||
|
peerUid: msg.peerUid,
|
||||||
|
guildId: '',
|
||||||
|
chatType: msg.chatType,
|
||||||
|
}, replyMsg.msgId)?.toString()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
log('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq)
|
log('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (element.picElement) {
|
else if (element.picElement) {
|
||||||
message_data['type'] = OB11MessageDataType.image
|
message_data['type'] = OB11MessageDataType.image
|
||||||
// message_data["data"]["file"] = element.picElement.sourcePath
|
|
||||||
let fileName = element.picElement.fileName
|
let fileName = element.picElement.fileName
|
||||||
const sourcePath = element.picElement.sourcePath
|
|
||||||
const isGif = element.picElement.picType === PicType.gif
|
const isGif = element.picElement.picType === PicType.gif
|
||||||
if (isGif && !fileName.endsWith('.gif')) {
|
if (isGif && !fileName.endsWith('.gif')) {
|
||||||
fileName += '.gif'
|
fileName += '.gif'
|
||||||
}
|
}
|
||||||
message_data['data']['file'] = fileName
|
message_data['data']['file'] = fileName
|
||||||
message_data['data']['subType'] = element.picElement.picSubType
|
message_data['data']['subType'] = element.picElement.picSubType
|
||||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
message_data['data']['file_id'] = UUIDConverter.encode(msg.peerUin, msg.msgId)
|
||||||
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
|
||||||
|
|
||||||
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement)
|
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement)
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
|
||||||
message_data['data']['file_size'] = element.picElement.fileSize
|
message_data['data']['file_size'] = element.picElement.fileSize
|
||||||
dbUtil
|
|
||||||
.addFileCache(fileName, {
|
|
||||||
fileName,
|
|
||||||
elementId: element.elementId,
|
|
||||||
filePath: sourcePath,
|
|
||||||
fileSize: element.picElement.fileSize.toString(),
|
|
||||||
url: message_data['data']['url'],
|
|
||||||
downloadFunc: async () => {
|
|
||||||
await NTQQFileApi.downloadMedia(
|
|
||||||
msg.msgId,
|
|
||||||
msg.chatType,
|
|
||||||
msg.peerUid,
|
|
||||||
element.elementId,
|
|
||||||
element.picElement.thumbPath?.get(0) || '',
|
|
||||||
element.picElement.sourcePath,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}).then()
|
|
||||||
}
|
}
|
||||||
else if (element.videoElement || element.fileElement) {
|
else if (element.videoElement || element.fileElement) {
|
||||||
const videoOrFileElement = element.videoElement || element.fileElement
|
const videoOrFileElement = element.videoElement || element.fileElement
|
||||||
@@ -208,7 +200,7 @@ export class OB11Constructor {
|
|||||||
message_data['type'] = ob11MessageDataType
|
message_data['type'] = ob11MessageDataType
|
||||||
message_data['data']['file'] = videoOrFileElement.fileName
|
message_data['data']['file'] = videoOrFileElement.fileName
|
||||||
message_data['data']['path'] = videoOrFileElement.filePath
|
message_data['data']['path'] = videoOrFileElement.filePath
|
||||||
message_data['data']['file_id'] = videoOrFileElement.fileUuid
|
message_data['data']['file_id'] = UUIDConverter.encode(msg.peerUin, msg.msgId)
|
||||||
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
||||||
if (element.videoElement) {
|
if (element.videoElement) {
|
||||||
message_data['data']['url'] = await NTQQFileApi.getVideoUrl({
|
message_data['data']['url'] = await NTQQFileApi.getVideoUrl({
|
||||||
@@ -217,50 +209,40 @@ export class OB11Constructor {
|
|||||||
}, msg.msgId, element.elementId,
|
}, msg.msgId, element.elementId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
dbUtil
|
NTQQFileApi.addFileCache(
|
||||||
.addFileCache(videoOrFileElement.fileUuid!, {
|
{
|
||||||
msgId: msg.msgId,
|
peerUid: msg.peerUid,
|
||||||
elementId: element.elementId,
|
chatType: msg.chatType,
|
||||||
fileName: videoOrFileElement.fileName,
|
guildId: '',
|
||||||
filePath: videoOrFileElement.filePath,
|
},
|
||||||
fileSize: videoOrFileElement.fileSize!,
|
msg.msgId,
|
||||||
downloadFunc: async () => {
|
msg.msgSeq,
|
||||||
await NTQQFileApi.downloadMedia(
|
msg.senderUid,
|
||||||
msg.msgId,
|
element.elementId,
|
||||||
msg.chatType,
|
element.elementType.toString(),
|
||||||
msg.peerUid,
|
videoOrFileElement.fileSize || '0',
|
||||||
element.elementId,
|
videoOrFileElement.fileName,
|
||||||
ob11MessageDataType == OB11MessageDataType.video
|
)
|
||||||
? (videoOrFileElement as VideoElement).thumbPath?.get(0)
|
|
||||||
: null,
|
|
||||||
videoOrFileElement.filePath,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then()
|
|
||||||
// 怎么拿到url呢
|
|
||||||
}
|
}
|
||||||
else if (element.pttElement) {
|
else if (element.pttElement) {
|
||||||
message_data['type'] = OB11MessageDataType.voice
|
message_data['type'] = OB11MessageDataType.voice
|
||||||
message_data['data']['file'] = element.pttElement.fileName
|
message_data['data']['file'] = element.pttElement.fileName
|
||||||
message_data['data']['path'] = element.pttElement.filePath
|
message_data['data']['path'] = element.pttElement.filePath
|
||||||
// message_data["data"]["file_id"] = element.pttElement.fileUuid
|
message_data['data']['file_id'] = UUIDConverter.encode(msg.peerUin, msg.msgId)
|
||||||
message_data['data']['file_size'] = element.pttElement.fileSize
|
message_data['data']['file_size'] = element.pttElement.fileSize
|
||||||
dbUtil
|
NTQQFileApi.addFileCache({
|
||||||
.addFileCache(element.pttElement.fileName, {
|
peerUid: msg.peerUid,
|
||||||
elementId: element.elementId,
|
chatType: msg.chatType,
|
||||||
fileName: element.pttElement.fileName,
|
guildId: '',
|
||||||
filePath: element.pttElement.filePath,
|
},
|
||||||
fileSize: element.pttElement.fileSize,
|
msg.msgId,
|
||||||
})
|
msg.msgSeq,
|
||||||
.then()
|
msg.senderUid,
|
||||||
|
element.elementId,
|
||||||
// log("收到语音消息", msg)
|
element.elementType.toString(),
|
||||||
// window.LLAPI.Ptt2Text(message.raw.msgId, message.peer, messages).then(text => {
|
element.pttElement.fileSize || '0',
|
||||||
// console.log("语音转文字结果", text)
|
element.pttElement.fileUuid || '',
|
||||||
// }).catch(err => {
|
)
|
||||||
// console.log("语音转文字失败", err)
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
else if (element.arkElement) {
|
else if (element.arkElement) {
|
||||||
message_data['type'] = OB11MessageDataType.json
|
message_data['type'] = OB11MessageDataType.json
|
||||||
@@ -474,16 +456,27 @@ export class OB11Constructor {
|
|||||||
const senderUin = emojiLikeData.gtip.qq.jp
|
const senderUin = emojiLikeData.gtip.qq.jp
|
||||||
const msgSeq = emojiLikeData.gtip.url.msgseq
|
const msgSeq = emojiLikeData.gtip.url.msgseq
|
||||||
const emojiId = emojiLikeData.gtip.face.id
|
const emojiId = emojiLikeData.gtip.face.id
|
||||||
const msg = await dbUtil.getMsgBySeqId(msgSeq)
|
const replyMsgList = (await NTQQMsgApi.getMsgsBySeqAndCount({
|
||||||
if (!msg) {
|
chatType: ChatType.group,
|
||||||
|
guildId: '',
|
||||||
|
peerUid: msg.peerUid,
|
||||||
|
}, msgSeq, 1, true, true)).msgList
|
||||||
|
if (replyMsgList.length < 1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return new OB11GroupMsgEmojiLikeEvent(parseInt(msg.peerUid), parseInt(senderUin), msg.msgShortId!, [
|
const likes = [
|
||||||
{
|
{
|
||||||
emoji_id: emojiId,
|
emoji_id: emojiId,
|
||||||
count: 1,
|
count: 1,
|
||||||
},
|
},
|
||||||
])
|
]
|
||||||
|
const shortId = MessageUnique.getShortIdByMsgId(replyMsgList[0].msgId)
|
||||||
|
return new OB11GroupMsgEmojiLikeEvent(
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
parseInt(senderUin),
|
||||||
|
shortId!,
|
||||||
|
likes
|
||||||
|
)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
log('解析表情回应消息失败', e.stack)
|
log('解析表情回应消息失败', e.stack)
|
||||||
}
|
}
|
||||||
@@ -556,20 +549,23 @@ export class OB11Constructor {
|
|||||||
const searchParams = new URL(json.items[0].jp).searchParams
|
const searchParams = new URL(json.items[0].jp).searchParams
|
||||||
const msgSeq = searchParams.get('msgSeq')!
|
const msgSeq = searchParams.get('msgSeq')!
|
||||||
const Group = searchParams.get('groupCode')
|
const Group = searchParams.get('groupCode')
|
||||||
const Businessid = searchParams.get('businessid')
|
|
||||||
const Peer: Peer = {
|
const Peer: Peer = {
|
||||||
guildId: '',
|
guildId: '',
|
||||||
chatType: ChatType.group,
|
chatType: ChatType.group,
|
||||||
peerUid: Group!
|
peerUid: Group!
|
||||||
}
|
}
|
||||||
let msgList = (await NTQQMsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true)).msgList
|
const { msgList } = await NTQQMsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true)
|
||||||
const origMsg = await dbUtil.getMsgByLongId(msgList[0].msgId)
|
//const origMsg = await dbUtil.getMsgByLongId(msgList[0].msgId)
|
||||||
const postMsg = await dbUtil.getMsgBySeqId(origMsg?.msgSeq!) ?? origMsg
|
//const postMsg = await dbUtil.getMsgBySeqId(origMsg?.msgSeq!) ?? origMsg
|
||||||
// 如果 senderUin 为 0,可能是 历史消息 或 自身消息
|
// 如果 senderUin 为 0,可能是 历史消息 或 自身消息
|
||||||
if (msgList[0].senderUin === '0') {
|
//if (msgList[0].senderUin === '0') {
|
||||||
msgList[0].senderUin = postMsg?.senderUin ?? getSelfUin()
|
//msgList[0].senderUin = postMsg?.senderUin ?? getSelfUin()
|
||||||
}
|
//}
|
||||||
return new OB11GroupEssenceEvent(parseInt(msg.peerUid), postMsg?.msgShortId!, parseInt(msgList[0].senderUin!))
|
return new OB11GroupEssenceEvent(
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
MessageUnique.getShortIdByMsgId(msgList[0].msgId)!,
|
||||||
|
parseInt(msgList[0].senderUin!)
|
||||||
|
)
|
||||||
// 获取MsgSeq+Peer可获取具体消息
|
// 获取MsgSeq+Peer可获取具体消息
|
||||||
}
|
}
|
||||||
if (grayTipElement.jsonGrayTipElement.busiId == 2407) {
|
if (grayTipElement.jsonGrayTipElement.busiId == 2407) {
|
||||||
@@ -590,6 +586,7 @@ export class OB11Constructor {
|
|||||||
|
|
||||||
static async RecallEvent(
|
static async RecallEvent(
|
||||||
msg: RawMessage,
|
msg: RawMessage,
|
||||||
|
shortId: number
|
||||||
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
|
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
|
||||||
let msgElement = msg.elements.find(
|
let msgElement = msg.elements.find(
|
||||||
(element) => element.grayTipElement?.subElementType === GrayTipElementSubType.RECALL,
|
(element) => element.grayTipElement?.subElementType === GrayTipElementSubType.RECALL,
|
||||||
@@ -606,11 +603,11 @@ export class OB11Constructor {
|
|||||||
parseInt(msg.peerUid),
|
parseInt(msg.peerUid),
|
||||||
parseInt(sender?.uin!),
|
parseInt(sender?.uin!),
|
||||||
parseInt(operator?.uin!),
|
parseInt(operator?.uin!),
|
||||||
msg.msgShortId!,
|
shortId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new OB11FriendRecallNoticeEvent(parseInt(msg.senderUin!), msg.msgShortId!)
|
return new OB11FriendRecallNoticeEvent(parseInt(msg.senderUin!), shortId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,12 +6,12 @@ import { isNull } from '../../../common/utils/helper'
|
|||||||
|
|
||||||
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
|
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
|
||||||
try {
|
try {
|
||||||
let packet = Object.assign({}, data)
|
const packet = Object.assign({}, data)
|
||||||
if (isNull(packet['echo'])) {
|
if (isNull(packet['echo'])) {
|
||||||
delete packet['echo']
|
delete packet['echo']
|
||||||
}
|
}
|
||||||
wsClient.send(JSON.stringify(packet))
|
wsClient.send(JSON.stringify(packet))
|
||||||
log('ws 消息上报', wsClient.url || '', data)
|
//log('ws 消息上报', wsClient.url || '', data)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
log('websocket 回复失败', e.stack, data)
|
log('websocket 回复失败', e.stack, data)
|
||||||
}
|
}
|
||||||
|
@@ -164,7 +164,7 @@ export interface OB11MessagePoke {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OB11MessageFileBase {
|
export interface OB11MessageFileBase {
|
||||||
data: {
|
data: {
|
||||||
thumb?: string
|
thumb?: string
|
||||||
name?: string
|
name?: string
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = '3.28.6'
|
export const version = '3.28.7'
|
||||||
|
Reference in New Issue
Block a user