Compare commits

...

42 Commits
v4.0.12 ... dev

Author SHA1 Message Date
linyuchen
b7a7eeecd3 feat: moehoo version checker 2024-11-17 17:19:17 +08:00
idranme
d66d42cb5d refactor 2024-11-17 16:33:57 +08:00
linyuchen
5514bf0bb8 chore: bump version 2024-11-17 15:20:22 +08:00
linyuchen
f5d093cc45 fix: 调用发包接口时检查 QQ 版本,兼容 27333 - 27597 的戳一戳 2024-11-17 15:19:48 +08:00
linyuchen
2c1d12e04b Merge remote-tracking branch 'origin/dev' into dev 2024-11-16 23:01:39 +08:00
linyuchen
110193ea15 fix: 调用发包接口时检查QQ版本 2024-11-16 23:01:24 +08:00
idranme
fafcf058b1 refactor 2024-11-16 19:39:14 +08:00
linyuchen
c8d5eebe5d feat: new api set_friend_remark, set_friend_category, set_group_remark, set_group_msg_mask, set_restart 2024-11-16 14:48:45 +08:00
linyuchen
f6263375f1 chore: version 4.2.2 2024-11-15 11:01:25 +08:00
linyuchen
f79581d97e 🐛修复 hook ipc 时获取不到 callbackId 导致其他插件 ipc 通信失败 2024-11-15 10:58:35 +08:00
idranme
1f02c98c8f chore 2024-11-14 15:24:46 +08:00
linyuchen
e1e5c278b9 🐛修复 hook ipc 时获取不到 eventName 导致其他插件 ipc 通信失败 2024-11-14 14:51:01 +08:00
idranme
104839f7ea fix 2024-11-14 12:34:48 +08:00
idranme
bb8771a5b4 refactor 2024-11-14 11:40:19 +08:00
linyuchen
5c5105ce88 chore: version 4.2.0 2024-11-13 19:33:29 +08:00
linyuchen
1bf5e41bdc chore: 协议包支持 macOS 2024-11-13 19:27:50 +08:00
linyuchen
cd679cc041 refactor: 设置群员头衔的时候检查是否群主 2024-11-13 19:27:21 +08:00
linyuchen
eabee466bb refactor: 使用 napcat packet 实现戳一戳、群头衔、群打卡 2024-11-12 22:09:50 +08:00
idranme
d3f93257ce feat: get_stranger_info API adds city field 2024-11-10 16:59:58 +08:00
idranme
33f340ca81 chore 2024-11-10 14:18:09 +08:00
idranme
479e8c9d25 optimize 2024-11-09 22:21:04 +08:00
linyuchen
30b8793ee1 fix: 修复 IPC 超时 2024-11-09 21:37:41 +08:00
linyuchen
47b068737d chore: bump version, add author 2024-11-08 06:05:17 +08:00
linyuchen
bfb67188ce fix: DownloadFile接口参数url和base64二选一即可 2024-11-08 05:45:21 +08:00
linyuchen
7ad384d407 fix: 发送文件路径包含#%时发送失败 2024-11-08 05:44:55 +08:00
idranme
f7926c2e1b chore: bump versions 2024-10-27 12:07:21 +08:00
idranme
b669e28038 fix 2024-10-27 12:06:33 +08:00
idranme
94f1d84dd8 chore: bump versions 2024-10-26 00:16:18 +08:00
idranme
aa2b4a160d fix 2024-10-26 00:15:48 +08:00
idranme
9be43de04b fix: forward 2024-10-26 00:14:27 +08:00
idranme
78f04f0ba2 chore: bump versions 2024-10-24 22:09:33 +08:00
idranme
f1027ec0d9 fix 2024-10-24 22:09:12 +08:00
idranme
f1b0be710a refactor 2024-10-24 20:46:21 +08:00
idranme
91ca4e96c4 fix 2024-10-24 17:40:35 +08:00
idranme
c9e39769dd feat: support for fake forward message 2024-10-23 23:30:27 +08:00
linyuchen
8b04833a6a 退出设置界面时检查配置是否改动并提示用户保存配置 2024-10-23 17:10:33 +08:00
idranme
2a67ffae24 chore: bump versions 2024-10-19 18:12:07 +08:00
idranme
78def9ebf8 fix 2024-10-19 18:09:33 +08:00
idranme
c6dddcd664 refactor 2024-10-19 18:09:23 +08:00
idranme
5b90a25f8f refactor 2024-10-19 15:57:58 +08:00
idranme
364dfe8b93 feat: get_group_file_system_info API 2024-10-19 10:31:14 +08:00
idranme
0fe725eb32 fix 2024-10-19 10:07:59 +08:00
85 changed files with 12859 additions and 1380 deletions

View File

@@ -39,6 +39,7 @@ const config: ElectronViteConfig = {
...external.map(genCpModule),
{ src: './manifest.json', dest: 'dist' },
{ src: './icon.webp', dest: 'dist' },
{ src: './src/ntqqapi/native/napcat-protocol-packet/Moehoo/*', dest: 'dist/main/Moehoo' },
],
}),
],

View File

@@ -4,12 +4,16 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "实现 OneBot 11 和 Satori 协议,用于 QQ 机器人开发",
"version": "4.0.12",
"version": "4.3.2",
"icon": "./icon.webp",
"authors": [
{
"name": "linyuchen",
"link": "https://github.com/linyuchen"
},
{
"name": "idranme",
"link": "https://github.com/idranme"
}
],
"repository": {

View File

@@ -12,7 +12,7 @@
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %LITELOADERQQNT_PROFILE%\\plugins\\LLOneBot\\\"",
"format": "prettier -cw .",
"check": "tsc",
"compile:proto": "pbjs --no-create --no-convert --no-encode --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js systemMessage.proto profileLikeTip.proto groupMemberIncrease.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js"
"compile:proto": "pbjs --no-create --no-convert --no-delimited --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js profileLikeTip.proto groupNotify.proto message.proto richMedia.proto oidb.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js"
},
"author": "",
"license": "MIT",
@@ -25,26 +25,25 @@
"cors": "^2.8.5",
"cosmokit": "^1.6.3",
"express": "^5.0.1",
"fast-xml-parser": "^4.5.0",
"fluent-ffmpeg": "^2.1.3",
"minato": "^3.6.0",
"minato": "^3.6.1",
"protobufjs": "^7.4.0",
"silk-wasm": "^3.6.1",
"silk-wasm": "^3.6.3",
"ts-case-convert": "^2.1.0",
"ws": "^8.18.0"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/fluent-ffmpeg": "^2.1.26",
"@types/fluent-ffmpeg": "^2.1.27",
"@types/node": "^20.14.15",
"@types/ws": "^8.5.12",
"@types/ws": "^8.5.13",
"electron": "^31.4.0",
"electron-vite": "^2.3.0",
"protobufjs-cli": "^1.1.3",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vite": "^5.4.11",
"vite-plugin-cp": "^4.0.8"
},
"packageManager": "yarn@4.5.0"
"packageManager": "yarn@4.5.1"
}

View File

@@ -13,6 +13,10 @@ const manifest = {
{
name: 'linyuchen',
link: 'https://github.com/linyuchen'
},
{
"name": "idranme",
"link": "https://github.com/idranme"
}
],
repository: {

View File

@@ -44,6 +44,7 @@ export class ConfigUtil {
token: ''
}
const defaultConfig: Config = {
enableLLOB: true,
satori: satoriDefault,
ob11: ob11Default,
heartInterval: 60000,

View File

@@ -28,6 +28,7 @@ export interface SatoriConfig {
}
export interface Config {
enableLLOB: boolean
satori: SatoriConfig
ob11: OB11Config
token?: string
@@ -49,8 +50,6 @@ export interface Config {
/** @deprecated */
wsPort?: string
/** @deprecated */
enableLLOB?: boolean
/** @deprecated */
reportSelfMessage?: boolean
}

View File

@@ -27,9 +27,10 @@ export function checkFileReceived(path: string, timeout: number = 3000): Promise
export function calculateFileMD5(filePath: string): Promise<string> {
return new Promise((resolve, reject) => {
const hash = createHash('md5')
// 创建一个流式读取器
const stream = fs.createReadStream(filePath)
const hash = createHash('md5')
stream.on('data', (data: Buffer) => {
// 当读取到数据时,更新哈希对象的状态
@@ -122,8 +123,11 @@ export async function uri2local(ctx: Context, uri: string, needExt?: boolean): P
const { type } = checkUriType(uri)
if (type === FileUriType.FileURL) {
const filePath = fileURLToPath(uri)
const fileUri = uri.replace('%', '%25').replace('#', '%23')
const filePath = fileURLToPath(fileUri)
const fileName = path.basename(filePath)
// console.log('fileURLToPath', filePath)
// console.log('fileName', fileName)
return { success: true, errMsg: '', fileName, path: filePath, isLocal: true }
}

View File

@@ -17,6 +17,11 @@ export function getBuildVersion(): number {
return +globalThis.LiteLoader.package.qqnt.buildVersion
}
/** QQ Full Version */
export function getFullVersion(): string {
return globalThis.LiteLoader.versions.qqnt
}
/** 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象 */
export function mergeNewProperties(newObj: Dict, oldObj: Dict) {
Object.keys(newObj).forEach((key) => {

View File

@@ -0,0 +1,9 @@
import { BrowserWindow } from 'electron'
import { log } from '@/common/utils'
export function getAllWindowIds(): number[] {
const allWindows = BrowserWindow.getAllWindows();
const ids = allWindows.map(window => window.id);
log('getAllWindowIds', ids);
return ids;
}

View File

@@ -35,6 +35,7 @@ import {
NTQQWindowApi
} from '../ntqqapi/api'
import { existsSync, mkdirSync } from 'node:fs'
import { NTQQSystemApi } from '@/ntqqapi/api/system'
declare module 'cordis' {
interface Events {
@@ -74,6 +75,7 @@ function onLoad() {
ctx.plugin(NTQQWebApi)
ctx.plugin(NTQQWindowApi)
ctx.plugin(Database)
ctx.plugin(NTQQSystemApi)
let started = false
@@ -171,7 +173,7 @@ function onLoad() {
log(arg)
})
const intervalId = setInterval(() => {
const intervalId = setInterval(async () => {
const self = Object.assign(selfInfo, {
uin: globalThis.authData?.uin,
uid: globalThis.authData?.uid,
@@ -180,8 +182,16 @@ function onLoad() {
if (self.uin) {
clearInterval(intervalId)
log('process pid', process.pid)
const config = getConfigUtil().getConfig()
if (config.enableLLOB && (config.satori.enable || config.ob11.enable)) {
startHook()
await ctx.sleep(600)
} else {
llonebotError.otherError = 'LLOneBot 未启动'
log('LLOneBot 开关设置为关闭,不启动 LLOneBot')
return
}
ctx.plugin(Log, {
enable: config.log!,
filename: logFileName
@@ -215,16 +225,18 @@ function onLoad() {
started = true
llonebotError.otherError = ''
}
}, 600)
}, 500)
}
// 创建窗口时触发
function onBrowserWindowCreated(window: BrowserWindow) {
if (window.id === 2) {
mainWindow = window
}
}
try {
onLoad()
startHook()
} catch (e) {
console.log(e)
}

View File

@@ -16,7 +16,7 @@ import path from 'node:path'
import { existsSync } from 'node:fs'
import { ReceiveCmdS } from '../hook'
import { RkeyManager } from '@/ntqqapi/helper/rkey'
import { RichMediaDownloadCompleteNotify, Peer } from '@/ntqqapi/types/msg'
import { RichMediaDownloadCompleteNotify, RichMediaUploadCompleteNotify, RMBizType, Peer } from '@/ntqqapi/types/msg'
import { calculateFileMD5 } from '@/common/utils/file'
import { copyFile, stat, unlink } from 'node:fs/promises'
import { Time } from 'cosmokit'
@@ -43,7 +43,7 @@ export class NTQQFileApi extends Service {
msgId,
elemId: elementId,
videoCodecFormat: 0,
params: {
exParams: {
downSourceType: 1,
triggerType: 1
}
@@ -211,6 +211,28 @@ export class NTQQFileApi extends Service {
]
)
}
async uploadRMFileWithoutMsg(filePath: string, bizType: RMBizType, peerUid: string) {
const data = await invoke<{
notifyInfo: RichMediaUploadCompleteNotify
}>(
'nodeIKernelRichMediaService/uploadRMFileWithoutMsg',
[{
params: {
filePath,
bizType,
peerUid,
useNTV2: true
}
}],
{
cbCmd: ReceiveCmdS.MEDIA_UPLOAD_COMPLETE,
cmdCB: payload => payload.notifyInfo.filePath === filePath,
timeout: 10 * Time.second,
}
)
return data.notifyInfo
}
}
export class NTQQFileCacheApi extends Service {

View File

@@ -107,7 +107,7 @@ export class NTQQFriendApi extends Service {
return ret.arkMsg
}
async setBuddyRemark(uid: string, remark: string) {
async setBuddyRemark(uid: string, remark = '') {
return await invoke('nodeIKernelBuddyService/setBuddyRemark', [{
remarkParams: { uid, remark }
}])
@@ -122,4 +122,8 @@ export class NTQQFriendApi extends Service {
}
}])
}
async setBuddyCategory(uid: string, categoryId: number) {
return await invoke('nodeIKernelBuddyService/setBuddyCategory', [{ uid, categoryId }])
}
}

View File

@@ -9,7 +9,8 @@ import {
PublishGroupBulletinReq,
GroupAllInfo,
GroupFileInfo,
GroupBulletinListResult
GroupBulletinListResult,
GroupMsgMask
} from '../types'
import { invoke, NTClass, NTMethod } from '../ntcall'
import { GeneralCallResult } from '../services'
@@ -83,7 +84,7 @@ export class NTQQGroupApi extends Service {
}
async getGroupIgnoreNotifies() {
await this.getSingleScreenNotifies(14)
await this.getSingleScreenNotifies(false, 14)
return await this.ctx.ntWindowApi.openWindow<GeneralCallResult & GroupNotifies>(
NTQQWindows.GroupNotifyFilterWindow,
[],
@@ -91,17 +92,18 @@ export class NTQQGroupApi extends Service {
)
}
async getSingleScreenNotifies(number: number, startSeq = '') {
invoke(ReceiveCmdS.GROUP_NOTIFY, [], { registerEvent: true })
async getSingleScreenNotifies(doubt: boolean, number: number, startSeq = '') {
await invoke(ReceiveCmdS.GROUP_NOTIFY, [], { registerEvent: true })
return (await invoke<GroupNotifies>(
const data = await invoke<GroupNotifies>(
'nodeIKernelGroupService/getSingleScreenNotifies',
[{ doubt: false, startSeq, number }],
[{ doubt, startSeq, number }],
{
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
afterFirstCmd: false,
}
)).notifies
)
return data.notifies
}
async handleGroupRequest(flag: string, operateType: GroupRequestOperateTypes, reason?: string) {
@@ -109,8 +111,9 @@ export class NTQQGroupApi extends Service {
const groupCode = flagitem[0]
const seq = flagitem[1]
const type = parseInt(flagitem[2])
const doubt = flagitem[3] === '1'
return await invoke(NTMethod.HANDLE_GROUP_REQUEST, [{
doubt: false,
doubt,
operateMsg: {
operateType,
targetMsg: {
@@ -325,4 +328,26 @@ export class NTQQGroupApi extends Service {
)
return data.infos
}
async getGroupFileCount(groupId: string) {
return await invoke(
'nodeIKernelRichMediaService/batchGetGroupFileCount',
[{ groupIds: [groupId] }]
)
}
async getGroupFileSpace(groupId: string) {
return await invoke(
'nodeIKernelRichMediaService/getGroupSpace',
[{ groupId }]
)
}
async setGroupMsgMask(groupCode: string, msgMask: GroupMsgMask) {
return await invoke('nodeIKernelGroupService/setGroupMsgMask', [{ groupCode, msgMask }])
}
async setGroupRemark(groupCode: string, groupRemark = '') {
return await invoke('nodeIKernelGroupService/modifyGroupRemark', [{ groupCode, groupRemark }])
}
}

View File

@@ -153,7 +153,17 @@ export class NTQQMsgApi extends Service {
afterFirstCmd: false,
cmdCB: payload => {
for (const msgRecord of payload.msgList) {
if (msgRecord.peerUid === destPeer.peerUid && msgRecord.senderUid === selfUid) {
if (
msgRecord.msgType === 11 &&
msgRecord.subMsgType === 7 &&
msgRecord.peerUid === destPeer.peerUid &&
msgRecord.senderUid === selfUid
) {
const element = msgRecord.elements[0]
const data = JSON.parse(element.arkElement!.bytesData)
if (data.app !== 'com.tencent.multimsg' || !data.meta.detail.resid) {
continue
}
return true
}
}
@@ -161,20 +171,12 @@ export class NTQQMsgApi extends Service {
}
}
)
for (const msg of data.msgList) {
const arkElement = msg.elements.find(ele => ele.arkElement)
if (!arkElement) {
continue
return data.msgList.find(msgRecord => {
const { arkElement } = msgRecord.elements[0]
if (arkElement?.bytesData.includes('com.tencent.multimsg')) {
return true
}
const forwardData = JSON.parse(arkElement.arkElement!.bytesData)
if (forwardData.app !== 'com.tencent.multimsg') {
continue
}
if (msg.peerUid === destPeer.peerUid && msg.senderUid === selfUid) {
return msg
}
}
throw new Error('转发消息超时')
})!
}
async getSingleMsg(peer: Peer, msgSeq: string) {
@@ -282,4 +284,8 @@ export class NTQQMsgApi extends Service {
async fetchUnitedCommendConfig(groups: string[]) {
return await invoke('nodeIKernelUnitedConfigService/fetchUnitedCommendConfig', [{ groups }])
}
async sendSsoCmdReqByContend(ssoCmd: string, content: string) {
return await invoke('nodeIKernelMsgService/sendSsoCmdReqByContend', [{ ssoCmd, content }])
}
}

38
src/ntqqapi/api/system.ts Normal file
View File

@@ -0,0 +1,38 @@
import { Context, Service } from 'cordis'
import { invoke, NTClass } from '@/ntqqapi/ntcall'
declare module 'cordis' {
interface Context {
ntSystemApi: NTQQSystemApi
}
}
export class NTQQSystemApi extends Service {
constructor(protected ctx: Context) {
super(ctx, 'ntSystemApi', true)
}
async restart() {
// todo: 调用此接口后会将 NTQQ 设置里面的自动登录和无需手机确认打开,重启后将状态恢复到之前的状态
// 设置自动登录
await this.setSettingAutoLogin(true)
// 退出账号
invoke('quitAccount', [], {
className: NTClass.BUSINESS_API
}).then()
invoke('notifyQQClose', [{ type: 1 }], { className: NTClass.QQ_EX_API }).then()
// 等待登录界面,模拟点击登录按钮?还是直接调用登录方法?
}
async getSettingAutoLogin() {
// 查询是否自动登录
return invoke('nodeIKernelNodeMiscService/queryAutoRun', [])
}
async setSettingAutoLogin(state: boolean) {
await invoke('nodeIKernelSettingService/setNeedConfirmSwitch', [{ state: 1 }]) // 1不需要手机确认2需要手机确认
await invoke('nodeIKernelSettingService/setAutoLoginSwitch', [{ state }])
}
}

View File

@@ -1,5 +1,5 @@
import { User, UserDetailInfoByUin, UserDetailInfoByUinV2, UserDetailInfo, UserDetailSource, ProfileBizType, SimpleInfo } from '../types'
import { invoke } from '../ntcall'
import { invoke, NTClass } from '../ntcall'
import { getBuildVersion } from '@/common/utils'
import { RequestUtil } from '@/common/utils/request'
import { isNullable, pick, Time } from 'cosmokit'
@@ -173,7 +173,7 @@ export class NTQQUserApi extends Service {
async getUinByUidV2(uid: string) {
let uin = (await invoke('nodeIKernelGroupService/getUinByUids', [{ uidList: [uid] }])).uins.get(uid)
if (uin) return uin
if (uin && uin !== '0') return uin
uin = (await invoke('nodeIKernelProfileService/getUinByUid', [{ callFrom: 'FriendsServiceImpl', uid: [uid] }])).get(uid)
if (uin) return uin
uin = (await invoke('nodeIKernelUixConvertService/getUin', [{ uids: [uid] }])).uinInfo.get(uid)
@@ -288,4 +288,14 @@ export class NTQQUserApi extends Service {
)
return data.response.robotUinRanges
}
async quitAccount() {
return await invoke(
'quitAccount',
[],
{
className: NTClass.BUSINESS_API,
}
)
}
}

View File

@@ -16,10 +16,11 @@ import {
BuddyReqType,
GrayTipElementSubType
} from './types'
import { selfInfo, llonebotError } from '../common/globalVars'
import { selfInfo } from '../common/globalVars'
import { version } from '../version'
import { invoke } from './ntcall'
import { Native } from './native/index'
import { Native } from './native/crychic'
import { initWrapperSession, NTQQPacketApi } from './native/napcat-protocol-packet'
declare module 'cordis' {
interface Context {
@@ -29,7 +30,7 @@ declare module 'cordis' {
'nt/message-created': (input: RawMessage) => void
'nt/message-deleted': (input: RawMessage) => void
'nt/message-sent': (input: RawMessage) => void
'nt/group-notify': (input: GroupNotify) => void
'nt/group-notify': (input: { notify: GroupNotify, doubt: boolean }) => void
'nt/friend-request': (input: FriendRequest) => void
'nt/group-member-info-updated': (input: { groupCode: string, members: GroupMember[] }) => void
'nt/system-message-created': (input: Uint8Array) => void
@@ -40,18 +41,17 @@ class Core extends Service {
static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi', 'store']
public startTime = 0
public native
public packet!: NTQQPacketApi
constructor(protected ctx: Context, public config: Core.Config) {
super(ctx, 'app', true)
this.native = new Native(ctx)
initWrapperSession().then(session => {
this.packet = new NTQQPacketApi(session)
})
}
public start() {
if (!this.config.ob11.enable && !this.config.satori.enable) {
llonebotError.otherError = 'LLOneBot 未启动'
this.ctx.logger.info('LLOneBot 开关设置为关闭,不启动 LLOneBot')
return
}
this.startTime = Date.now()
this.registerListener()
this.ctx.logger.info(`LLOneBot/${version}`)
@@ -202,8 +202,8 @@ class Core extends Service {
recallMsgIds.push(msg.msgId)
this.ctx.parallel('nt/message-deleted', msg)
} else if (sentMsgIds.get(msg.msgId)) {
sentMsgIds.delete(msg.msgId)
if (msg.sendStatus === 2) {
sentMsgIds.delete(msg.msgId)
this.ctx.parallel('nt/message-sent', msg)
}
}
@@ -223,7 +223,7 @@ class Core extends Service {
if (payload.unreadCount) {
let notifies: GroupNotify[]
try {
notifies = await this.ctx.ntGroupApi.getSingleScreenNotifies(payload.unreadCount)
notifies = await this.ctx.ntGroupApi.getSingleScreenNotifies(payload.doubt, payload.unreadCount)
} catch (e) {
return
}
@@ -233,7 +233,7 @@ class Core extends Service {
continue
}
groupNotifyIgnore.push(notify.seq)
this.ctx.parallel('nt/group-notify', notify)
this.ctx.parallel('nt/group-notify', { notify, doubt: payload.doubt })
}
}
})

View File

@@ -0,0 +1,86 @@
{
"3.2.12-28418-x64": {
"recv": "A0723E0",
"send": "A06EAE0"
},
"9.9.15-28418-x64": {
"recv": "37A9004",
"send": "37A4BD0"
},
"6.9.56-28418-x64": {
"send": "4471360",
"recv": "4473BCC"
},
"6.9.56-28418-arm64": {
"send": "3FBDBF8",
"recv": "3FC0410"
},
"9.9.15-28498-x64": {
"recv": "37A9004",
"send": "37A4BD0"
},
"9.9.16-28788-x64": {
"send": "38076D0",
"recv": "380BB04"
},
"3.2.13-28788-x64": {
"send": "A0CEC20",
"recv": "A0D2520"
},
"3.2.13-28788-arm64": {
"send": "6E91018",
"recv": "6E94850"
},
"9.9.16-28971-x64": {
"send": "38079F0",
"recv": "380BE24"
},
"3.2.13-28971-x64": {
"send": "A0CEF60",
"recv": "A0D2860"
},
"3.2.12-28971-arm64": {
"send": "6E91318",
"recv": "6E94B50"
},
"6.9.58-28971-x64": {
"send": "449ACA0",
"recv": "449D50C"
},
"6.9.58-28971-arm64": {
"send": "3FE0DB0",
"recv": "3FE35C8"
},
"9.9.16-29271-x64": {
"send": "3833510",
"recv": "3837944"
},
"3.2.13-29271-x64": {
"send": "A11E680",
"recv": "A121F80"
},
"3.2.13-29271-arm64": {
"send": "6ECA098",
"recv": "6ECD8D0"
},
"9.9.16-29456-x64": {
"send": "3835CD0",
"recv": "383A104"
},
"3.2.13-29456-x64": {
"send": "A11E820",
"recv": "A122120"
},
"3.2.13-29456-arm64": {
"send": "6ECA130",
"recv": "6ECD968"
},
"6.9.59-29456-x64": {
"send": "44C57A0",
"recv": "44C800C"
},
"6.9.59-29456-arm64": {
"send": "4005FE8",
"recv": "4008800"
}
}

View File

@@ -2,6 +2,7 @@ import { NTMethod } from './ntcall'
import { log } from '@/common/utils'
import { randomUUID } from 'node:crypto'
import { ipcMain } from 'electron'
import { Dict } from 'cosmokit'
export const hookApiCallbacks: Record<string, (res: any) => void> = {}
@@ -40,40 +41,43 @@ const callHooks: Array<{
}> = []
export function startHook() {
log('start hook')
const senderExclude = Symbol()
ipcMain.emit = new Proxy(ipcMain.emit, {
apply(target, thisArg, args: [eventName: string, ...args: any]) {
if (args[2]?.eventName.startsWith('ns-LoggerApi')) {
apply(target, thisArg, args: [channel: string, ...args: any]) {
if (args[2]?.eventName?.startsWith('ns-LoggerApi')) {
return target.apply(thisArg, args)
}
if (logHook) {
log('request', args)
}
const event = args[1]
if (event.sender && !event.sender[senderExclude]) {
event.sender[senderExclude] = true
event.sender.send = new Proxy(event.sender.send, {
apply(target, thisArg, args: any[]) {
if (args[1].eventName?.startsWith('ns-LoggerApi')) {
apply(target, thisArg, args: [channel: string, meta: Dict, data: Dict[]]) {
if (args[1]?.eventName?.startsWith('ns-LoggerApi')) {
return target.apply(thisArg, args)
}
if (logHook) {
log('received', args)
}
const callbackId = args[1].callbackId
const callbackId = args[1]?.callbackId
if (callbackId) {
if (hookApiCallbacks[callbackId]) {
Promise.resolve(hookApiCallbacks[callbackId](args[2]))
delete hookApiCallbacks[callbackId]
}
} else if (args[2]) {
for (const receiveData of args[2]) {
for (const hook of receiveHooks.values()) {
if (hook.method.includes(receiveData.cmdName)) {
Promise.resolve(hook.hookFunc(receiveData.payload))
if (['IPC_DOWN_2', 'IPC_DOWN_3'].includes(args[0])) {
for (const receiveData of args[2]) {
for (const hook of receiveHooks.values()) {
if (hook.method.includes(receiveData.cmdName)) {
Promise.resolve(hook.hookFunc(receiveData.payload))
}
}
}
}
@@ -93,7 +97,7 @@ export function startHook() {
}
}
return target.apply(thisArg, args)
}
},
})
}

View File

@@ -1,13 +1,17 @@
import { Context } from 'cordis'
import { Dict } from 'cosmokit'
import { getBuildVersion } from '@/common/utils/misc'
import { TEMP_DIR } from '@/common/globalVars'
import { getBuildVersion } from '../../../common/utils/misc'
import { TEMP_DIR } from '../../../common/globalVars'
import { copyFile } from 'fs/promises'
import { ChatType, Peer } from '../../types'
import path from 'node:path'
import addon from './external/crychic-win32-x64.node?asset'
export class Native {
public activated = false
private crychic?: Dict
private seq = 0
private cb: Map<number, (res: any) => void> = new Map()
constructor(private ctx: Context) {
ctx.on('ready', () => {
@@ -35,12 +39,24 @@ export class Native {
if (!this.checkVersion()) {
return
}
const handler = async (name: string, ...e: unknown[]) => {
if (name === 'cb') {
this.cb.get(e[0] as number)?.(e[1])
}
}
try {
const fileName = path.basename(addon)
const dest = path.join(TEMP_DIR, fileName)
await copyFile(addon, dest)
try {
await copyFile(addon, dest)
} catch (e) {
// resource busy or locked?
this.ctx.logger.warn(e)
}
this.crychic = require(dest)
this.crychic!.setCryHandler(handler)
this.crychic!.init()
this.activated = true
} catch (e) {
this.ctx.logger.warn('crychic 加载失败', e)
}
@@ -57,4 +73,27 @@ export class Native {
this.crychic.sendGroupPoke(memberUin, groupCode)
await this.ctx.ntMsgApi.fetchUnitedCommendConfig(['100243'])
}
uploadForward(peer: Peer, transmit: Uint8Array) {
return new Promise<string>(async (resolve, reject) => {
if (!this.crychic) return
let groupCode = 0
const uid = peer.peerUid
const isGroup = peer.chatType === ChatType.Group
if (isGroup) {
groupCode = +uid
}
const seq = ++this.seq
this.cb.set(seq, (resid: string) => {
this.cb.delete(seq)
resolve(resid)
})
setTimeout(() => {
this.cb.delete(seq)
reject(new Error('fake forward timeout'))
}, 5000)
this.crychic.uploadForward(seq, isGroup, uid, groupCode, transmit)
await this.ctx.ntMsgApi.fetchUnitedCommendConfig(['100243'])
})
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,138 @@
import { Context } from 'cordis'
import { arch } from 'node:os'
import { getFullVersion, getBuildVersion } from '@/common/utils/misc'
import { selfInfo, TEMP_DIR } from '@/common/globalVars'
import { Dict } from 'cosmokit'
import { copyFile } from 'node:fs/promises'
import { createHash } from 'node:crypto'
import { Oidb } from '@/ntqqapi/proto/compiled'
import path from 'node:path'
import offset from '@/ntqqapi/helper/offset.json'
interface Offset {
[key: string]: {
recv: string
send: string
}
}
export class Native {
available = false
moehoo?: Dict
constructor(private ctx: Context) {
ctx.on('ready', async () => {
this.init()
})
}
private async init() {
const key = getFullVersion() + '-' + arch()
const currOffset = (offset as Offset)[key]
if (!currOffset) {
return
}
const platform = process.platform + '.' + process.arch
try {
const fileName = 'MoeHoo.' + platform + '.node' // todo: 需要加入版本号或者hash不然多开QQ时会导致copyFile失败从而无法进行在线更新
const src = path.join(__dirname, 'Moehoo', fileName)
const dest = path.join(TEMP_DIR, fileName)
try {
await copyFile(src, dest)
} catch (e) {
// resource busy or locked?
this.ctx.logger.warn(e)
}
this.moehoo = require(dest)
this.moehoo!.InitHook(currOffset.send, currOffset.recv, () => {
})
this.available = true
} catch (e) {
this.ctx.logger.warn('moehoo 加载失败', e)
}
}
private async sendPacket(cmd: string, data: string) {
const traceId = `${Date.now()}${data}`.slice(0, data.length / 2)
const traceIdMd5 = createHash('md5').update(traceId).digest('hex')
this.moehoo!.SendPacket(cmd, data, traceIdMd5)
const res = await this.ctx.ntMsgApi.sendSsoCmdReqByContend(cmd, traceId)
if (res.result !== 0) {
throw new Error(res.errMsg)
}
}
private check() {
if (this.available) {
return
}
const minVersion = 28418
const maxVersion = 29456
const currVersion = getBuildVersion()
if (currVersion < minVersion || currVersion > maxVersion) {
throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 ${minVersion}${maxVersion}`)
} else {
throw new Error('packet backend 当前不可用')
}
}
async groupPoke(groupCode: number, uin: number) {
this.check()
const data = Oidb.Oidb_0xED3_1.encode({
uin,
groupCode
}).finish()
const req = buildOidbRequest(0xED3, 1, data)
await this.sendPacket(req.cmd, req.data)
}
async friendPoke(uin: number) {
this.check()
const data = Oidb.Oidb_0xED3_1.encode({
uin,
friendUin: uin
}).finish()
const req = buildOidbRequest(0xED3, 1, data)
await this.sendPacket(req.cmd, req.data)
}
async groupSign(groupCode: string) {
this.check()
const data = Oidb.Oidb_0xEB7_1.encode({
body: {
uin: selfInfo.uin,
groupCode
}
}).finish()
const req = buildOidbRequest(0xEB7, 1, data)
await this.sendPacket(req.cmd, req.data)
}
async setGroupSpecialTitle(groupCode: number, uid: string, title: string) {
this.check()
const data = Oidb.Oidb_0X8FC_2.encode({
groupCode,
body: {
targetUid: uid,
specialTitle: title,
expiredTime: -1,
uinName: title
}
}).finish()
const req = buildOidbRequest(0X8FC, 2, data, false)
await this.sendPacket(req.cmd, req.data)
}
}
function buildOidbRequest(cmd: number, subCmd: number, body: Uint8Array, reserved = true) {
const data = Oidb.Base.encode({
command: cmd,
subCommand: subCmd,
body,
isReserved: reserved ? 1 : 0
}).finish()
return {
cmd: `OidbSvcTrpcTcp.0x${cmd.toString(16).toUpperCase()}_${subCmd}`,
data: Buffer.from(data).toString('hex')
}
}

View File

@@ -0,0 +1,35 @@
import os from 'os'
import offset from '@/ntqqapi/helper/offset.json'
import { getFullVersion } from '@/common/utils'
function getSupportVersions() {
let fullVersionStart: string = ''
switch (os.platform()) {
case 'linux':
fullVersionStart = '3'
break
case 'darwin':
fullVersionStart = '6'
break
case 'win32':
fullVersionStart = '9'
break
}
const supportVersions: string[] = []
for (const offsetKey in offset) {
if (offsetKey.startsWith(fullVersionStart) && offsetKey.endsWith(os.arch())) {
supportVersions.push(offsetKey)
}
}
return supportVersions
}
export function checkSupportVersion(){
// 检查当前 QQ 版本是否支持,不支持则抛出异常
const qqFullVersion = getFullVersion() // todo: 去除llqqnt依赖
const _ = offset[qqFullVersion + '-' + os.arch()]
if (!_) {
const supportVersion = getSupportVersions()
throw new Error('当前 QQ 版本不支持, 只支持: ' + supportVersion.join(', '))
}
}

View File

@@ -0,0 +1,17 @@
import { WrapperSession } from './wrapper-session/types';
export { initWrapperSession } from './wrapper-session';
export declare function checkSupportVersion(): void;
export declare class NTQQPacketApi {
private qqVersion;
private readonly packetClient;
private readonly packer;
private logger;
private readonly wrapperSession;
constructor(wrapperSession: WrapperSession);
private InitSendPacket;
private sendPacket;
private sendOidbPacket;
sendPokePacket(peer: number, group?: number): Promise<void>;
sendGroupSignPacket(selfUin: string, groupCode: string): Promise<void>;
sendSetSpecialTittlePacket(groupCode: string, uid: string, tittle: string): Promise<void>;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export declare function initWrapperSession(): Promise<any>;

View File

@@ -0,0 +1,6 @@
export interface MsgService {
sendSsoCmdReqByContend: (cmd: string, trace_id: string) => Promise<unknown>;
}
export type WrapperSession = {
getMsgService(): MsgService;
};

View File

@@ -1,6 +1,6 @@
import { ipcMain } from 'electron'
import { hookApiCallbacks, registerReceiveHook, removeReceiveHook } from './hook'
import { log } from '../common/utils/legacyLog'
import { log } from '../common/utils'
import { randomUUID } from 'node:crypto'
import {
GeneralCallResult,
@@ -29,7 +29,8 @@ export enum NTClass {
SKEY_API = 'ns-SkeyApi',
GROUP_HOME_WORK = 'ns-GroupHomeWork',
GROUP_ESSENCE = 'ns-GroupEssence',
NODE_STORE_API = 'ns-NodeStoreApi'
NODE_STORE_API = 'ns-NodeStoreApi',
QQ_EX_API = 'ns-QQEXApi',
}
export enum NTMethod {
@@ -108,13 +109,26 @@ interface InvokeOptions<ReturnType> {
timeout?: number
}
let channel: NTChannel
function getChannel() {
if (channel) {
return channel
}
if (ipcMain.eventNames().includes(NTChannel.IPC_UP_2)) {
return channel = NTChannel.IPC_UP_2
} else {
return channel = NTChannel.IPC_UP_3
}
}
export function invoke<
R extends Awaited<ReturnType<Extract<NTService[S][M], (...args: any) => unknown>>>,
S extends keyof NTService = any,
M extends keyof NTService[S] & string = any
>(method: Extract<unknown, `${S}/${M}`> | string, args: unknown[], options: InvokeOptions<R> = {}) {
const className = options.className ?? NTClass.NT_API
const channel = options.channel ?? NTChannel.IPC_UP_2
const channel = options.channel ?? getChannel()
const timeout = options.timeout ?? 5000
const afterFirstCmd = options.afterFirstCmd ?? true
let eventName = className + '-' + channel[channel.length - 1]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
syntax = "proto3";
package SysMsg;
// GroupChange?
message GroupMemberIncrease {
uint32 groupCode = 1;
string memberUid = 3;
uint32 type = 4; // 130:主动 131:被邀请
string adminUid = 5;
}

View File

@@ -0,0 +1,14 @@
syntax = "proto3";
package SysMsg;
message GroupMemberChange {
uint32 groupCode = 1;
string memberUid = 3;
uint32 type = 4; // 130:主动 131:被动
string adminUid = 5;
}
message GroupInvite {
uint32 groupCode = 1;
string operatorUid = 5;
}

View File

@@ -0,0 +1,134 @@
syntax = "proto3";
package Msg;
message RoutingHead {
optional uint64 fromUin = 1;
optional string fromUid = 2;
optional uint32 fromAppid = 3;
optional uint32 fromInstid = 4;
optional uint64 toUin = 5;
optional string toUid = 6;
optional C2c c2c = 7;
optional Group group = 8;
}
message C2c {
optional string friendName = 6;
}
message Group {
optional uint64 groupCode = 1;
optional uint32 groupType = 2;
optional uint64 groupInfoSeq = 3;
optional string groupCard = 4;
optional uint32 groupCardType = 5;
optional uint32 groupLevel = 6;
optional string groupName = 7;
optional string extGroupKeyInfo = 8;
optional uint32 msgFlag = 9;
}
message ContentHead {
optional uint64 msgType = 1;
optional uint64 subType = 2;
optional uint32 c2cCmd = 3;
optional uint64 random = 4;
optional uint64 msgSeq = 5;
optional uint64 msgTime = 6;
optional uint32 pkgNum = 7;
optional uint32 pkgIndex = 8;
optional uint32 divSeq = 9;
optional uint32 autoReply = 10;
optional uint64 ntMsgSeq = 11;
optional uint64 msgUid = 12;
optional ContentHeadField15 field15 = 15;
}
message ContentHeadField15 {
optional uint32 field1 = 1;
optional uint32 field2 = 2;
optional uint32 field3 = 3;
optional string field4 = 4;
optional string field5 = 5;
}
message Message {
optional RoutingHead routingHead = 1;
optional ContentHead contentHead = 2;
optional MessageBody body = 3;
}
message MessageBody {
optional RichText richText = 1;
optional bytes msgContent = 2;
optional bytes msgEncryptContent = 3;
}
message RichText {
optional Attr attr = 1;
repeated Elem elems = 2;
}
message Elem {
optional Text text = 1;
optional Face face = 2;
optional LightAppElem lightApp = 51;
optional CommonElem commonElem = 53;
}
message Text {
optional string str = 1;
optional string link = 2;
optional bytes attr6Buf = 3;
optional bytes attr7Buf = 4;
optional bytes buf = 11;
optional bytes pbReserve = 12;
}
message Face {
optional uint32 index = 1;
optional bytes old = 2;
optional bytes buf = 11;
}
message LightAppElem {
optional bytes data = 1;
optional bytes msgResid = 2;
}
message CommonElem {
required uint32 serviceType = 1;
optional bytes pbElem = 2;
optional uint32 businessType = 3;
}
message Attr {
optional int32 codePage = 1;
optional int32 time = 2;
optional int32 random = 3;
optional int32 color = 4;
optional int32 size = 5;
optional int32 effect = 6;
optional int32 charSet = 7;
optional int32 pitchAndFamily = 8;
optional string fontName = 9;
optional bytes reserveData = 10;
}
message MarkdownElem {
string content = 1;
}
message PbMultiMsgItem {
string fileName = 1;
PbMultiMsgNew buffer = 2;
}
message PbMultiMsgNew {
repeated Message msg = 1;
}
message PbMultiMsgTransmit {
repeated Message msg = 1;
repeated PbMultiMsgItem pbItemList = 2;
}

View File

@@ -0,0 +1,41 @@
syntax = "proto3";
package Oidb;
message Base {
uint32 command = 1;
uint32 subCommand = 2;
uint32 errorCode = 3;
bytes body = 4;
optional string errorMsg = 5;
uint32 isReserved = 12;
}
message Oidb_0xED3_1 {
uint32 uin = 1;
uint32 groupCode = 2;
uint32 friendUin = 5;
optional uint32 ext = 6;
}
message Oidb_0xEB7_1 {
Oidb_0xEB7_1_Body body = 2;
}
message Oidb_0xEB7_1_Body {
string uin = 1;
string groupCode = 2;
string version = 3;
}
message Oidb_0X8FC_2 {
uint32 groupCode = 1;
Oidb_0X8FC_2_Body body = 3;
}
message Oidb_0X8FC_2_Body {
string targetUid = 1;
string specialTitle = 5;
sint32 expiredTime = 6;
string uinName = 7;
string targetName = 8;
}

View File

@@ -0,0 +1,76 @@
syntax = "proto3";
package RichMedia;
message MsgInfo {
repeated MsgInfoBody msgInfoBody = 1;
ExtBizInfo extBizInfo = 2;
}
message MsgInfoBody {
IndexNode index = 1;
PicInfo pic = 2;
bool fileExist = 5;
}
message IndexNode {
FileInfo info = 1;
string fileUuid = 2;
uint32 storeID = 3;
uint32 uploadTime = 4;
uint32 expire = 5;
uint32 type = 6; //0
}
message FileInfo {
uint32 fileSize = 1;
string md5HexStr = 2;
string sha1HexStr = 3;
string fileName = 4;
FileType fileType = 5;
uint32 width = 6;
uint32 height = 7;
uint32 time = 8;
uint32 original = 9;
}
message FileType {
uint32 type = 1;
uint32 picFormat = 2;
uint32 videoFormat = 3;
uint32 pttFormat = 4;
}
message PicInfo {
string urlPath = 1;
PicUrlExtParams ext = 2;
string domain = 3;
}
message PicUrlExtParams {
string originalParam = 1;
string bigParam = 2;
string thumbParam = 3;
}
message ExtBizInfo {
PicExtBizInfo pic = 1;
VideoExtBizInfo video = 2;
uint32 busiType = 10;
}
message PicExtBizInfo {
uint32 bizType = 1;
string summary = 2;
}
message VideoExtBizInfo {
bytes pbReserve = 3;
}
message PicFileIdInfo {
bytes sha1 = 2;
uint32 size = 3;
uint32 appid = 4;
uint32 time = 5;
uint32 expire = 10;
}

View File

@@ -1,29 +0,0 @@
syntax = "proto3";
package SysMsg;
message SystemMessage {
repeated SystemMessageHeader header = 1;
repeated SystemMessageMsgSpec msgSpec = 2;
SystemMessageBodyWrapper bodyWrapper = 3;
}
message SystemMessageHeader {
uint32 peerUin = 1;
//string peerUid = 2;
uint32 uin = 5;
optional string uid = 6;
}
message SystemMessageMsgSpec {
uint32 msgType = 1;
optional uint32 subType = 2;
optional uint32 subSubType = 3;
uint32 msgSeq = 5;
uint32 time = 6;
//uint64 msgId = 12;
optional uint32 other = 13;
}
message SystemMessageBodyWrapper {
bytes body = 2;
}

View File

@@ -13,7 +13,7 @@ export interface NodeIKernelBuddyService {
}[]
}>
setBuddyRemark(uid: number, remark: string): void
setBuddyRemark(arg: unknown): Promise<GeneralCallResult>
isBuddy(uid: string): boolean

View File

@@ -12,4 +12,6 @@ export interface NodeIKernelNodeMiscService {
score: ''
}[]
}>
queryAutoRun(): Promise<boolean>
}

View File

@@ -39,5 +39,21 @@ export interface NodeIKernelRichMediaService {
failFileIdList: Array<unknown>
}
}>
batchGetGroupFileCount(groupIds: string[]): Promise<GeneralCallResult & {
groupCodes: string[]
groupFileCounts: number[]
}>
getGroupSpace(groupId: string): Promise<GeneralCallResult & {
groupSpaceResult: {
retCode: number
retMsg: string
clientWording: string
totalSpace: string
usedSpace: string
allUpload: boolean
}
}>
}

View File

@@ -1,10 +1,3 @@
export enum GroupListUpdateType {
REFRESHALL,
GETALL,
MODIFIED,
REMOVE
}
export interface Group {
groupCode: string
maxMember: number
@@ -188,3 +181,10 @@ export interface GroupBulletinListResult {
nextIndex: number
jointime: string
}
export enum GroupMsgMask {
AllowNotify = 1, // 允许提醒
AllowNotNotify = 4, // 接受消息不提醒
BoxNotNotify = 2, // 收进群助手不提醒
NotAllow = 3, // 屏蔽
}

View File

@@ -80,7 +80,7 @@ export interface SendVideoElement {
export interface SendArkElement {
elementType: ElementType.Ark
elementId: ''
arkElement: ArkElement
arkElement: Partial<ArkElement>
}
export type SendMessageElement =
@@ -442,6 +442,7 @@ export interface RawMessage {
attrType: number
attrId: string
}>
isOnlineMsg: boolean
}
export interface Peer {
@@ -587,3 +588,31 @@ export interface GetFileListParam {
showOnlinedocFolder: number
folderId?: string
}
export interface RichMediaUploadCompleteNotify {
fileId: string
fileDownType: number
filePath: string
totalSize: string
trasferStatus: number
commonFileInfo: {
uuid: string
fileName: string
fileSize: string
md5: string
sha: string
}
}
export enum RMBizType {
Unknown,
C2CFile,
GroupFile,
C2CPic,
GroupPic,
DiscPic,
C2CVideo,
GroupVideo,
C2CPtt,
GroupPtt,
}

View File

@@ -1,7 +1,8 @@
export enum Sex {
male = 0,
female = 2,
unknown = 255,
Unknown = 0,
Male = 1,
Female = 2,
Hidden = 255
}
export interface QQLevel {
@@ -101,7 +102,7 @@ export interface BaseInfo {
birthday_month: number
birthday_day: number
age: number
sex: number
sex: Sex
eMail: string
phoneNum: string
categoryId: number

View File

@@ -23,8 +23,8 @@ interface FileResponse {
export class DownloadFile extends BaseAction<Payload, FileResponse> {
actionName = ActionName.GoCQHTTP_DownloadFile
payloadSchema = Schema.object({
url: String,
base64: String,
url: Schema.string(),
base64: Schema.string(),
headers: Schema.union([String, Schema.array(String)])
})

View File

@@ -0,0 +1,32 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
group_id: number | string
}
interface Response {
file_count: number
limit_count: number
used_space: number
total_space: number
}
export class GetGroupFileSystemInfo extends BaseAction<Payload, Response> {
actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo
payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required()
})
async _handle(payload: Payload) {
const groupId = payload.group_id.toString()
const { groupFileCounts } = await this.ctx.ntGroupApi.getGroupFileCount(groupId)
const { groupSpaceResult } = await this.ctx.ntGroupApi.getGroupFileSpace(groupId)
return {
file_count: groupFileCounts[0],
limit_count: 10000,
used_space: +groupSpaceResult.usedSpace,
total_space: +groupSpaceResult.totalSpace,
}
}
}

View File

@@ -28,7 +28,7 @@ export class GetGroupSystemMsg extends BaseAction<void, Response> {
actionName = ActionName.GoCQHTTP_GetGroupSystemMsg
async _handle() {
const singleScreenNotifies = await this.ctx.ntGroupApi.getSingleScreenNotifies(10)
const singleScreenNotifies = await this.ctx.ntGroupApi.getSingleScreenNotifies(false, 10)
const data: Response = { invited_requests: [], join_requests: [] }
for (const notify of singleScreenNotifies) {
if (notify.type == 1) {

View File

@@ -12,6 +12,7 @@ interface Payload {
interface Response extends OB11User {
reg_time: number
long_nick: string
city: string
}
export class GetStrangerInfo extends BaseAction<Payload, Response> {
@@ -33,7 +34,8 @@ export class GetStrangerInfo extends BaseAction<Payload, Response> {
level: data.detail.commonExt.qqLevel && calcQQLevel(data.detail.commonExt.qqLevel) || 0,
login_days: 0,
reg_time: data.detail.commonExt.regTime,
long_nick: data.detail.simpleInfo.baseInfo.longNick
long_nick: data.detail.simpleInfo.baseInfo.longNick,
city: data.detail.commonExt.city
}
} else {
const data = await this.ctx.ntUserApi.getUserDetailInfoByUin(uin)
@@ -46,7 +48,8 @@ export class GetStrangerInfo extends BaseAction<Payload, Response> {
level: data.info.qqLevel && calcQQLevel(data.info.qqLevel) || 0,
login_days: 0,
reg_time: data.info.regTime,
long_nick: data.info.longNick
long_nick: data.info.longNick,
city: data.info.city
}
}
}

View File

@@ -1,11 +1,13 @@
import { unlink } from 'node:fs/promises'
import { OB11MessageNode } from '../../types'
import { OB11MessageData, OB11MessageNode } from '../../types'
import { ActionName } from '../types'
import { BaseAction, Schema } from '../BaseAction'
import { Peer } from '@/ntqqapi/types/msg'
import { ChatType, ElementType, RawMessage, SendMessageElement } from '@/ntqqapi/types'
import { selfInfo } from '@/common/globalVars'
import { convertMessage2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
import { message2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
import { MessageEncoder } from '@/onebot11/helper/createMultiMessage'
import { Msg } from '@/ntqqapi/proto/compiled'
interface Payload {
user_id?: string | number
@@ -17,7 +19,7 @@ interface Payload {
interface Response {
message_id: number
forward_id?: string
forward_id: string
}
export class SendForwardMsg extends BaseAction<Payload, Response> {
@@ -42,9 +44,90 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
contextMode = CreatePeerMode.Private
}
const peer = await createPeer(this.ctx, payload, contextMode)
const msg = await this.handleForwardNode(peer, messages)
const msgShortId = this.ctx.store.createMsgShortId({ chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)
return { message_id: msgShortId }
const nodes = this.parseNodeContent(messages)
let fake = true
for (const node of nodes) {
if (node.data.id) {
fake = false
break
}
if (node.data.content?.some(e => {
return !MessageEncoder.support.includes(e.type)
})) {
fake = false
break
}
}
if (fake && this.ctx.app.native.activated) {
return await this.handleFakeForwardNode(peer, nodes)
} else {
return await this.handleForwardNode(peer, nodes)
}
}
private parseNodeContent(nodes: OB11MessageNode[]) {
return nodes.map(e => {
return {
type: e.type,
data: {
...e.data,
content: e.data.content ? message2List(e.data.content) : undefined
}
}
})
}
private async handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[]): Promise<Response> {
const encoder = new MessageEncoder(this.ctx, peer)
const raw = await encoder.generate(nodes)
const transmit = Msg.PbMultiMsgTransmit.encode({ pbItemList: raw.multiMsgItems }).finish()
const resid = await this.ctx.app.native.uploadForward(peer, transmit.subarray(1))
const uuid = crypto.randomUUID()
try {
const msg = await this.ctx.ntMsgApi.sendMsg(peer, [{
elementType: 10,
elementId: '',
arkElement: {
bytesData: JSON.stringify({
app: 'com.tencent.multimsg',
config: {
autosize: 1,
forward: 1,
round: 1,
type: 'normal',
width: 300
},
desc: '[聊天记录]',
extra: JSON.stringify({
filename: uuid,
tsum: raw.tsum,
}),
meta: {
detail: {
news: raw.news,
resid,
source: raw.source,
summary: raw.summary,
uniseq: uuid,
}
},
prompt: '[聊天记录]',
ver: '0.0.0.5',
view: 'contact'
})
}
}], 1800)
const msgShortId = this.ctx.store.createMsgShortId({
chatType: msg!.chatType,
peerUid: msg!.peerUid
}, msg!.msgId)
return { message_id: msgShortId, forward_id: resid }
} catch (e) {
this.ctx.logger.error('合并转发失败', e)
throw new Error(`发送伪造合并转发消息失败 (res_id: ${resid} `)
}
}
private async cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
@@ -71,7 +154,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
}
// 返回一个合并转发的消息id
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[]) {
private async handleForwardNode(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<Response> {
const selfPeer = {
chatType: ChatType.C2C,
peerUid: selfInfo.uid,
@@ -96,7 +179,7 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
try {
const { sendElements, deleteAfterSentFiles } = await createSendElements(
this.ctx,
convertMessage2List(messageNode.data.content),
messageNode.data.content as OB11MessageData[],
destPeer
)
this.ctx.logger.info('开始生成转发节点', sendElements)
@@ -163,8 +246,13 @@ export class SendForwardMsg extends BaseAction<Payload, Response> {
if (retMsgIds.length === 0) {
throw Error('转发消息失败,节点为空')
}
const returnMsg = await this.ctx.ntMsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds)
return returnMsg
const msg = await this.ctx.ntMsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds)
const resid = JSON.parse(msg.elements[0].arkElement!.bytesData).meta.detail.resid
const msgShortId = this.ctx.store.createMsgShortId({
chatType: msg.chatType,
peerUid: msg.peerUid
}, msg.msgId)
return { message_id: msgShortId, forward_id: resid }
}
}

View File

@@ -0,0 +1,19 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
import { selfInfo } from '@/common/globalVars'
interface Payload {
group_id: number | string
}
export class SendGroupSign extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SendGroupSign
payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(),
})
async _handle(payload: Payload) {
await this.ctx.app.packet.sendGroupSignPacket(selfInfo.uin, payload.group_id.toString())
return null
}
}

View File

@@ -0,0 +1,30 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
import { selfInfo } from '@/common/globalVars'
import { GroupMemberRole } from '@/ntqqapi/types'
interface Payload {
group_id: number | string
user_id: number | string
special_title?: string
}
export class SetGroupSpecialTitle extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SetGroupSpecialTitle
payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(),
user_id: Schema.union([Number, String]).required(),
special_title: Schema.string()
})
async _handle(payload: Payload) {
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString(), payload.group_id.toString())
if (!uid) throw new Error(`用户${payload.user_id}的uid获取失败`)
const self = await this.ctx.ntGroupApi.getGroupMember(payload.group_id.toString(), selfInfo.uid, false)
if (self.role !== GroupMemberRole.Owner){
throw new Error(`不是群${payload.group_id}的群主,无法设置群头衔`)
}
await this.ctx.app.packet.sendSetSpecialTittlePacket(payload.group_id.toString(), uid, payload.special_title || "")
return null
}
}

View File

@@ -20,7 +20,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
protected async _handle(payload: Payload) {
const groupCode = payload.group_id.toString()
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString(), groupCode)
if (!uid) throw new Error('无法获取用户信息')
const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, uid, payload.no_cache)
if (member) {

View File

@@ -76,6 +76,15 @@ import { DeleteFriend } from './go-cqhttp/DeleteFriend'
import { OCRImage } from './go-cqhttp/OCRImage'
import { GroupPoke } from './llonebot/GroupPoke'
import { FriendPoke } from './llonebot/FriendPoke'
import { GetGroupFileSystemInfo } from './go-cqhttp/GetGroupFileSystemInfo'
import { GetCredentials } from './system/GetCredentials'
import { SetGroupSpecialTitle } from '@/onebot11/action/go-cqhttp/SetGroupSpecialTitle'
import { SendGroupSign } from '@/onebot11/action/go-cqhttp/SendGroupSign'
import { SetRestart } from '@/onebot11/action/system/SetRestart'
import { SetFriendCategory } from '@/onebot11/action/llonebot/SetFriendCategory'
import { SetFriendRemark } from '@/onebot11/action/llonebot/SetFriendRemark'
import { SetGroupMsgMask } from '@/onebot11/action/llonebot/SetGroupMsgMask'
import { SetGroupRemark } from '@/onebot11/action/llonebot/SetGroupRemark'
export function initActionMap(adapter: Adapter) {
const actionHandlers = [
@@ -96,6 +105,10 @@ export function initActionMap(adapter: Adapter) {
new GetRobotUinRange(adapter),
new GroupPoke(adapter),
new FriendPoke(adapter),
new SetFriendCategory(adapter),
new SetFriendRemark(adapter),
new SetGroupMsgMask(adapter),
new SetGroupRemark(adapter),
// onebot11
new SendLike(adapter),
new GetMsg(adapter),
@@ -128,6 +141,8 @@ export function initActionMap(adapter: Adapter) {
new GetCookies(adapter),
new ForwardFriendSingleMsg(adapter),
new ForwardGroupSingleMsg(adapter),
new GetCredentials(adapter),
new SetRestart(adapter),
// go-cqhttp
new GetEssenceMsgList(adapter),
new GetGroupHonorInfo(adapter),
@@ -157,8 +172,11 @@ export function initActionMap(adapter: Adapter) {
new GetGroupNotice(adapter),
new DeleteFriend(adapter),
new OCRImage(adapter),
new GetGroupFileSystemInfo(adapter),
new SetGroupSpecialTitle(adapter),
new SendGroupSign(adapter),
]
const actionMap = new Map<string, BaseAction<any, unknown>>()
const actionMap = new Map()
for (const action of actionHandlers) {
actionMap.set(action.actionName, action)
actionMap.set(action.actionName + '_async', action)

View File

@@ -1,6 +1,6 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
import { getBuildVersion } from '@/common/utils'
interface Payload {
user_id: number | string
@@ -13,13 +13,12 @@ export class FriendPoke extends BaseAction<Payload, null> {
})
async _handle(payload: Payload) {
if (!this.ctx.app.native.checkPlatform()) {
throw new Error('当前系统平台或架构不支持')
if (!this.ctx.app.native.checkPlatform() || !this.ctx.app.native.checkVersion()) {
await this.ctx.app.packet.sendPokePacket(+payload.user_id)
}
if (!this.ctx.app.native.checkVersion()) {
throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 27333—27597`)
else{
await this.ctx.app.native.sendFriendPoke(+payload.user_id)
}
await this.ctx.app.native.sendFriendPoke(+payload.user_id)
return null
}
}

View File

@@ -1,6 +1,6 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils/misc'
import { getBuildVersion } from '@/common/utils'
interface Payload {
group_id: number | string
@@ -15,13 +15,12 @@ export class GroupPoke extends BaseAction<Payload, null> {
})
async _handle(payload: Payload) {
if (!this.ctx.app.native.checkPlatform()) {
throw new Error('当前系统平台或架构不支持')
if (!this.ctx.app.native.checkPlatform() || !this.ctx.app.native.checkVersion()) {
await this.ctx.app.packet.sendPokePacket(+payload.user_id, +payload.group_id)
}
if (!this.ctx.app.native.checkVersion()) {
throw new Error(`当前 QQ 版本 ${getBuildVersion()} 不支持,可尝试其他版本 27333—27597`)
else{
await this.ctx.app.native.sendGroupPoke(+payload.group_id, +payload.user_id)
}
await this.ctx.app.native.sendGroupPoke(+payload.group_id, +payload.user_id)
return null
}
}

View File

@@ -0,0 +1,21 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
user_id: number | string
category_id: number | string
}
export class SetFriendCategory extends BaseAction<Payload, unknown> {
actionName = ActionName.SetFriendCategory
payloadSchema = Schema.object({
user_id: Schema.union([Number, String]).required(),
category_id: Schema.union([Number, String]).required()
})
protected async _handle(payload: Payload) {
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
if (!uid) throw new Error('无法获取好友信息')
return this.ctx.ntFriendApi.setBuddyCategory(uid, +payload.category_id)
}
}

View File

@@ -0,0 +1,21 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
user_id: number | string
remark?: string
}
export class SetFriendRemark extends BaseAction<Payload, unknown> {
actionName = ActionName.SetFriendRemark
payloadSchema = Schema.object({
user_id: Schema.union([Number, String]).required(),
remark: Schema.string()
})
protected async _handle(payload: Payload) {
const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString())
if (!uid) throw new Error('无法获取好友信息')
return this.ctx.ntFriendApi.setBuddyRemark(uid, payload.remark || '')
}
}

View File

@@ -0,0 +1,19 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
group_id: number | string
mask: number | string // 1, 2, 3, 4
}
export class SetGroupMsgMask extends BaseAction<Payload, unknown> {
actionName = ActionName.SetGroupMsgMask
payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(),
mask: Schema.union([Number, String]).required()
})
protected async _handle(payload: Payload) {
return this.ctx.ntGroupApi.setGroupMsgMask(payload.group_id.toString(), +payload.mask)
}
}

View File

@@ -0,0 +1,15 @@
import { BaseAction } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
group_id: string,
remark?: string
}
export class SetGroupRemark extends BaseAction<Payload, unknown> {
actionName = ActionName.SetGroupRemark
protected async _handle(payload: Payload): Promise<unknown>{
return this.ctx.ntGroupApi.setGroupRemark(payload.group_id.toString(), payload.remark)
}
}

View File

@@ -9,7 +9,7 @@ import {
import { BaseAction } from '../BaseAction'
import { ActionName } from '../types'
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign'
import { convertMessage2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
import { message2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage'
interface ReturnData {
message_id: number
@@ -26,14 +26,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
contextMode = CreatePeerMode.Private
}
const peer = await createPeer(this.ctx, payload, contextMode)
const messages = convertMessage2List(
const messages = message2List(
payload.message,
payload.auto_escape === true || payload.auto_escape === 'true',
)
if (this.getSpecialMsgNum(messages, OB11MessageDataType.node)) {
if (this.getSpecialMsgNum(messages, OB11MessageDataType.Node)) {
throw new Error('请使用 /send_group_forward_msg 或 /send_private_forward_msg 进行合并转发')
}
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.Music)) {
const music = messages[0] as OB11MessageMusic
if (music) {
const { musicSignUrl } = this.adapter.config
@@ -78,7 +78,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
throw `签名音乐消息失败:${e}`
}
messages[0] = {
type: OB11MessageDataType.json,
type: OB11MessageDataType.Json,
data: { data: jsonContent },
} as OB11MessageJson
}

View File

@@ -7,62 +7,52 @@ import { ChatCacheListItemBasic, CacheFileType } from '@/ntqqapi/types'
export default class CleanCache extends BaseAction<void, void> {
actionName = ActionName.CleanCache
protected _handle(): Promise<void> {
return new Promise<void>(async (res, rej) => {
try {
// dbUtil.clearCache()
const cacheFilePaths: string[] = []
protected async _handle(): Promise<void> {
const cacheFilePaths: string[] = []
await this.ctx.ntFileCacheApi.setCacheSilentScan(false)
await this.ctx.ntFileCacheApi.setCacheSilentScan(false)
cacheFilePaths.push(await this.ctx.ntFileCacheApi.getHotUpdateCachePath())
cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath())
cacheFilePaths.push(await this.ctx.ntFileCacheApi.getHotUpdateCachePath())
cacheFilePaths.push(await this.ctx.ntFileCacheApi.getDesktopTmpPath())
const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList()
list.forEach((e) => cacheFilePaths.push(e.value))
const list = await this.ctx.ntFileCacheApi.getCacheSessionPathList()
list.forEach((e) => cacheFilePaths.push(e.value))
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache()
const cacheSize = parseInt(cacheScanResult.size[6])
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
const cacheScanResult = await this.ctx.ntFileCacheApi.scanCache()
const cacheSize = parseInt(cacheScanResult.size[6])
if (cacheScanResult.result !== 0) {
throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result
}
if (cacheScanResult.result !== 0) {
throw 'Something went wrong while scanning cache. Code: ' + cacheScanResult.result
}
await this.ctx.ntFileCacheApi.setCacheSilentScan(true)
if (cacheSize > 0 && cacheFilePaths.length > 2) {
// 存在缓存文件且大小不为 0 时执行清理动作
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
deleteCachePath(cacheFilePaths)
}
await this.ctx.ntFileCacheApi.setCacheSilentScan(true)
if (cacheSize > 0 && cacheFilePaths.length > 2) {
// 存在缓存文件且大小不为 0 时执行清理动作
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
deleteCachePath(cacheFilePaths)
}
// 获取聊天记录列表
// NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
// const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
// const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
// const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
const chatCacheList: ChatCacheListItemBasic[] = []
// 获取聊天记录列表
// NOTE: 以防有人不需要删除聊天记录,暂时先注释掉,日后加个开关
// const privateChatCache = await getCacheList(ChatType.friend); // 私聊消息
// const groupChatCache = await getCacheList(ChatType.group); // 群聊消息
// const chatCacheList = [ ...privateChatCache, ...groupChatCache ];
const chatCacheList: ChatCacheListItemBasic[] = []
// 获取聊天缓存文件列表
const cacheFileList: string[] = []
// 获取聊天缓存文件列表
const cacheFileList: string[] = []
for (const name in CacheFileType) {
if (!isNaN(parseInt(name))) continue
for (const name in CacheFileType) {
if (!isNaN(parseInt(name))) continue
const fileTypeAny: any = CacheFileType[name]
const fileType: CacheFileType = fileTypeAny
const fileType = CacheFileType[name] as unknown as CacheFileType
cacheFileList.push(...(await this.ctx.ntFileCacheApi.getFileCacheInfo(fileType)).infos.map((file) => file.fileKey))
}
cacheFileList.push(...(await this.ctx.ntFileCacheApi.getFileCacheInfo(fileType)).infos.map((file) => file.fileKey))
}
// 一并清除
await this.ctx.ntFileCacheApi.clearChatCache(chatCacheList, cacheFileList)
res()
} catch (e) {
console.error('清理缓存时发生了错误')
rej(e)
}
})
// 一并清除
await this.ctx.ntFileCacheApi.clearChatCache(chatCacheList, cacheFileList)
}
}

View File

@@ -0,0 +1,26 @@
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
domain: string
}
interface Response {
cookies: string
csrf_token: number
}
export class GetCredentials extends BaseAction<Payload, Response> {
actionName = ActionName.GetCredentials
payloadSchema = Schema.object({
domain: Schema.string().required()
})
protected async _handle(payload: Payload) {
const cookiesObject = await this.ctx.ntUserApi.getCookies(payload.domain)
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ')
const bkn = cookiesObject.skey ? this.ctx.ntWebApi.genBkn(cookiesObject.skey) : ''
return { cookies, csrf_token: +bkn }
}
}

View File

@@ -0,0 +1,10 @@
import { BaseAction } from '@/onebot11/action/BaseAction'
import { ActionName } from '@/onebot11/action/types'
export class SetRestart extends BaseAction<null, void> {
actionName = ActionName.SetRestart
protected async _handle() {
await this.ctx.ntSystemApi.restart()
}
}

View File

@@ -29,6 +29,10 @@ export enum ActionName {
GetRobotUinRange = 'get_robot_uin_range',
GroupPoke = 'group_poke',
FriendPoke = 'friend_poke',
SetFriendRemark = 'set_friend_remark',
SetFriendCategory = 'set_friend_category',
SetGroupMsgMask = 'set_group_msg_mask',
SetGroupRemark = 'set_group_remark',
// onebot 11
SendLike = 'send_like',
GetLoginInfo = 'get_login_info',
@@ -47,6 +51,7 @@ export enum ActionName {
SetGroupLeave = 'set_group_leave',
GetVersionInfo = 'get_version_info',
GetStatus = 'get_status',
SetRestart = 'set_restart',
CanSendRecord = 'can_send_record',
CanSendImage = 'can_send_image',
SetGroupKick = 'set_group_kick',
@@ -61,6 +66,7 @@ export enum ActionName {
GetCookies = 'get_cookies',
ForwardFriendSingleMsg = 'forward_friend_single_msg',
ForwardGroupSingleMsg = 'forward_group_single_msg',
GetCredentials = 'get_credentials',
// go-cqhttp
GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg',
GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg',
@@ -89,4 +95,7 @@ export enum ActionName {
GoCQHTTP_GetGroupNotice = '_get_group_notice',
GoCQHTTP_DeleteFriend = 'delete_friend',
GoCQHTTP_OCRImage = 'ocr_image',
GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info',
GoCQHTTP_SetGroupSpecialTitle = 'set_group_special_title',
GoCQHTTP_SendGroupSign = 'send_group_sign',
}

View File

@@ -1,22 +1,22 @@
import { BaseAction } from '../BaseAction'
import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types'
interface Payload {
domain: string
}
interface Response {
cookies: string
bkn: string
}
interface Payload {
domain: string
}
export class GetCookies extends BaseAction<Payload, Response> {
actionName = ActionName.GetCookies
payloadSchema = Schema.object({
domain: Schema.string().required()
})
protected async _handle(payload: Payload) {
if (!payload.domain) {
throw '缺少参数 domain'
}
const cookiesObject = await this.ctx.ntUserApi.getCookies(payload.domain)
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ')

View File

@@ -9,20 +9,19 @@ import {
} from '../ntqqapi/types'
import { OB11GroupRequestEvent } from './event/request/OB11GroupRequest'
import { OB11FriendRequestEvent } from './event/request/OB11FriendRequest'
import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'
import { selfInfo } from '../common/globalVars'
import { OB11Config, Config as LLOBConfig } from '../common/types'
import { OB11WebSocket, OB11WebSocketReverseManager } from './connect/ws'
import { OB11Http, OB11HttpPost } from './connect/http'
import { OB11BaseEvent } from './event/OB11BaseEvent'
import { OB11Message } from './types'
import { OB11BaseMetaEvent } from './event/meta/OB11BaseMetaEvent'
import { postHttpEvent } from './helper/eventForHttp'
import { initActionMap } from './action'
import { llonebotError } from '../common/globalVars'
import { OB11GroupAdminNoticeEvent } from './event/notice/OB11GroupAdminNoticeEvent'
import { OB11ProfileLikeEvent } from './event/notice/OB11ProfileLikeEvent'
import { SysMsg } from '@/ntqqapi/proto/compiled'
import { Msg, SysMsg } from '@/ntqqapi/proto/compiled'
import { OB11GroupIncreaseEvent } from './event/notice/OB11GroupIncreaseEvent'
declare module 'cordis' {
@@ -72,7 +71,7 @@ class OneBot11Adapter extends Service {
})
}
public dispatch(event: OB11BaseEvent | OB11Message) {
public dispatch(event: OB11BaseEvent) {
if (this.config.enableWs) {
this.ob11WebSocket.emitEvent(event)
}
@@ -88,29 +87,22 @@ class OneBot11Adapter extends Service {
}
}
private async handleGroupNotify(notify: GroupNotify) {
private async handleGroupNotify(notify: GroupNotify, doubt: boolean) {
try {
const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type
const flag = `${notify.group.groupCode}|${notify.seq}|${notify.type}|${doubt === true ? '1' : '0'}`
if ([GroupNotifyType.MemberLeaveNotifyAdmin, GroupNotifyType.KickMemberNotifyAdmin].includes(notify.type)) {
this.ctx.logger.info('有成员退出通知', notify)
const member1Uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)
let operatorId = member1Uin
let subType: GroupDecreaseSubType = 'leave'
if (notify.user2.uid) {
// 是被踢的
const member2Uin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)
if (member2Uin) {
operatorId = member2Uin
}
subType = 'kick'
this.ctx.logger.info('有群成员被踢', notify.group.groupCode, notify.user1.uid, notify.user2.uid)
const memberUin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)
const adminUin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)
const event = new OB11GroupDecreaseEvent(
parseInt(notify.group.groupCode),
parseInt(memberUin),
parseInt(adminUin),
'kick',
)
this.dispatch(event)
}
const event = new OB11GroupDecreaseEvent(
parseInt(notify.group.groupCode),
parseInt(member1Uin),
parseInt(operatorId),
subType,
)
this.dispatch(event)
}
else if (notify.type === GroupNotifyType.RequestJoinNeedAdminiStratorPass && notify.status === GroupNotifyStatus.Unhandle) {
this.ctx.logger.info('有加群请求')
@@ -345,16 +337,17 @@ class OneBot11Adapter extends Service {
this.handleMsg(input)
})
this.ctx.on('nt/group-notify', input => {
this.handleGroupNotify(input)
const { doubt, notify } = input
this.handleGroupNotify(notify, doubt)
})
this.ctx.on('nt/friend-request', input => {
this.handleFriendRequest(input)
})
this.ctx.on('nt/system-message-created', async input => {
const sysMsg = SysMsg.SystemMessage.decode(input)
const { msgType, subType, subSubType } = sysMsg.msgSpec[0] ?? {}
if (msgType === 528 && subType === 39 && subSubType === 39) {
const tip = SysMsg.ProfileLikeTip.decode(sysMsg.bodyWrapper!.body!)
const sysMsg = Msg.Message.decode(input)
const { msgType, subType } = sysMsg.contentHead ?? {}
if (msgType === 528 && subType === 39) {
const tip = SysMsg.ProfileLikeTip.decode(sysMsg.body!.msgContent!)
if (tip.msgType !== 0 || tip.subType !== 203) return
const detail = tip.content?.msg?.detail
if (!detail) return
@@ -362,13 +355,21 @@ class OneBot11Adapter extends Service {
const event = new OB11ProfileLikeEvent(detail.uin!, detail.nickname!, +times)
this.dispatch(event)
} else if (msgType === 33) {
const tip = SysMsg.GroupMemberIncrease.decode(sysMsg.bodyWrapper!.body!)
const tip = SysMsg.GroupMemberChange.decode(sysMsg.body!.msgContent!)
if (tip.type !== 130) return
this.ctx.logger.info('群成员增加', tip)
const memberUin = await this.ctx.ntUserApi.getUinByUid(tip.memberUid)
const operatorUin = await this.ctx.ntUserApi.getUinByUid(tip.adminUid)
const event = new OB11GroupIncreaseEvent(tip.groupCode, +memberUin, +operatorUin)
this.dispatch(event)
} else if (msgType === 34) {
const tip = SysMsg.GroupMemberChange.decode(sysMsg.body!.msgContent!)
if (tip.type !== 130) return // adminUid: 0
this.ctx.logger.info('群成员减少', tip)
const memberUin = await this.ctx.ntUserApi.getUinByUid(tip.memberUid)
const userId = Number(memberUin)
const event = new OB11GroupDecreaseEvent(tip.groupCode, userId, userId)
this.dispatch(event)
}
})
}

View File

@@ -154,7 +154,7 @@ class OB11HttpPost {
this.disposeInterval?.()
}
public async emitEvent(event: OB11BaseEvent | OB11Message) {
public async emitEvent(event: OB11BaseEvent) {
if (!this.activated || !this.config.hosts.length) {
return
}
@@ -177,7 +177,8 @@ class OB11HttpPost {
}).then(
async (res) => {
if (event.post_type) {
this.ctx.logger.info(`HTTP 事件上报: ${host}`, event.post_type, res.status)
const eventName = event.post_type + '.' + event[event.post_type + '_type']
this.ctx.logger.info(`HTTP 事件上报: ${host}`, eventName, res.status)
}
try {
const resJson = await res.json()

View File

@@ -57,11 +57,12 @@ class OB11WebSocket {
})
}
public async emitEvent(event: OB11BaseEvent | OB11Message) {
public async emitEvent(event: OB11BaseEvent) {
this.wsClients.forEach(({ socket, emitEvent }) => {
if (emitEvent && socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify(event))
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', event.post_type)
const eventName = event.post_type + '.' + event[event.post_type + '_type']
this.ctx.logger.info('WebSocket 事件上报', socket.url ?? '', eventName)
}
})
}
@@ -193,10 +194,11 @@ class OB11WebSocketReverse {
this.wsClient?.close()
}
public emitEvent(event: OB11BaseEvent | OB11Message) {
public emitEvent(event: OB11BaseEvent) {
if (this.wsClient && this.wsClient.readyState === WebSocket.OPEN) {
this.wsClient.send(JSON.stringify(event))
this.ctx.logger.info('WebSocket 事件上报', this.wsClient.url ?? '', event.post_type)
const eventName = event.post_type + '.' + event[event.post_type + '_type']
this.ctx.logger.info('WebSocket 事件上报', this.wsClient.url ?? '', eventName)
}
}

View File

@@ -1,4 +1,3 @@
import { XMLParser } from 'fast-xml-parser'
import {
OB11Group,
OB11GroupMember,
@@ -122,7 +121,7 @@ export namespace OB11Entities {
name = content.replace('@', '')
}
messageSegment = {
type: OB11MessageDataType.at,
type: OB11MessageDataType.At,
data: {
qq,
name
@@ -135,7 +134,7 @@ export namespace OB11Entities {
continue
}
messageSegment = {
type: OB11MessageDataType.text,
type: OB11MessageDataType.Text,
data: {
text
}
@@ -171,7 +170,7 @@ export namespace OB11Entities {
throw new Error('回复消息验证失败')
}
messageSegment = {
type: OB11MessageDataType.reply,
type: OB11MessageDataType.Reply,
data: {
id: ctx.store.createMsgShortId(peer, replyMsg ? replyMsg.msgId : records.msgId).toString()
}
@@ -185,7 +184,7 @@ export namespace OB11Entities {
const { picElement } = element
const fileSize = picElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.image,
type: OB11MessageDataType.Image,
data: {
file: picElement.fileName,
subType: picElement.picSubType,
@@ -213,7 +212,7 @@ export namespace OB11Entities {
}, msg.msgId, element.elementId)
const fileSize = videoElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.video,
type: OB11MessageDataType.Video,
data: {
file: videoElement.fileName,
url: videoUrl || pathToFileURL(videoElement.filePath).href,
@@ -237,7 +236,7 @@ export namespace OB11Entities {
const { fileElement } = element
const fileSize = fileElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.file,
type: OB11MessageDataType.File,
data: {
file: fileElement.fileName,
url: pathToFileURL(fileElement.filePath).href,
@@ -262,7 +261,7 @@ export namespace OB11Entities {
const { pttElement } = element
const fileSize = pttElement.fileSize ?? '0'
messageSegment = {
type: OB11MessageDataType.voice,
type: OB11MessageDataType.Record,
data: {
file: pttElement.fileName,
url: pathToFileURL(pttElement.filePath).href,
@@ -285,7 +284,7 @@ export namespace OB11Entities {
else if (element.arkElement) {
const { arkElement } = element
messageSegment = {
type: OB11MessageDataType.json,
type: OB11MessageDataType.Json,
data: {
data: arkElement.bytesData
}
@@ -296,14 +295,14 @@ export namespace OB11Entities {
const { faceIndex, pokeType } = faceElement
if (faceIndex === FaceIndex.Dice) {
messageSegment = {
type: OB11MessageDataType.dice,
type: OB11MessageDataType.Dice,
data: {
result: faceElement.resultId!
}
}
} else if (faceIndex === FaceIndex.RPS) {
messageSegment = {
type: OB11MessageDataType.RPS,
type: OB11MessageDataType.Rps,
data: {
result: faceElement.resultId!
}
@@ -315,7 +314,7 @@ export namespace OB11Entities {
}*/
} else {
messageSegment = {
type: OB11MessageDataType.face,
type: OB11MessageDataType.Face,
data: {
id: faceIndex.toString()
}
@@ -331,7 +330,7 @@ export namespace OB11Entities {
// const url = `https://p.qpic.cn/CDN_STATIC/0/data/imgcache/htdocs/club/item/parcel/item/${dir}/${md5}/300x300.gif?max_age=31536000`
const url = `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`
messageSegment = {
type: OB11MessageDataType.mface,
type: OB11MessageDataType.Mface,
data: {
summary: marketFaceElement.faceName!,
url,
@@ -344,15 +343,15 @@ export namespace OB11Entities {
else if (element.markdownElement) {
const { markdownElement } = element
messageSegment = {
type: OB11MessageDataType.markdown,
type: OB11MessageDataType.Markdown,
data: {
data: markdownElement.content
content: markdownElement.content
}
}
}
else if (element.multiForwardMsgElement) {
messageSegment = {
type: OB11MessageDataType.forward,
type: OB11MessageDataType.Forward,
data: {
id: msg.msgId
}
@@ -424,6 +423,8 @@ export namespace OB11Entities {
for (const element of msg.elements) {
const grayTipElement = element.grayTipElement
const groupElement = grayTipElement?.groupElement
const xmlElement = grayTipElement?.xmlElement
if (groupElement) {
if (groupElement.type === TipGroupElementType.Ban) {
ctx.logger.info('收到群成员禁言提示', groupElement)
@@ -477,6 +478,13 @@ export namespace OB11Entities {
)
}
}
else if (groupElement.type === TipGroupElementType.MemberIncrease) {
const { memberUid, adminUid } = groupElement
if (memberUid !== selfInfo.uid) return
ctx.logger.info('收到群成员增加消息', groupElement)
const adminUin = adminUid ? await ctx.ntUserApi.getUinByUid(adminUid) : selfInfo.uin
return new OB11GroupIncreaseEvent(+msg.peerUid, +selfInfo.uin, +adminUin)
}
}
else if (element.fileElement) {
return new OB11GroupUploadNoticeEvent(+msg.peerUid, +msg.senderUin!, {
@@ -486,65 +494,47 @@ export namespace OB11Entities {
busid: element.fileElement.fileBizId || 0,
})
}
if (grayTipElement) {
const xmlElement = grayTipElement.xmlElement
if (xmlElement?.templId === '10382') {
const emojiLikeData = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: '',
}).parse(xmlElement.content)
ctx.logger.info('收到表情回应我的消息', emojiLikeData)
else if (xmlElement) {
if (xmlElement.templId === '10382') {
ctx.logger.info('收到表情回应我的消息', xmlElement.templParam)
try {
const senderUin: string = emojiLikeData.gtip.qq.jp
const msgSeq: string = emojiLikeData.gtip.url.msgseq
const emojiId: string = emojiLikeData.gtip.face.id
const senderUin = xmlElement.templParam.get('jp_uin')
const msgSeq = xmlElement.templParam.get('msg_seq')
const emojiId = xmlElement.templParam.get('face_id')
const peer = {
chatType: ChatType.Group,
guildId: '',
peerUid: msg.peerUid,
}
const replyMsgList = (await ctx.ntMsgApi.queryFirstMsgBySeq(peer, msgSeq)).msgList
const replyMsgList = (await ctx.ntMsgApi.queryFirstMsgBySeq(peer, msgSeq!)).msgList
if (!replyMsgList?.length) {
return
}
const shortId = ctx.store.createMsgShortId(peer, replyMsgList[0].msgId)
return new OB11GroupMsgEmojiLikeEvent(
parseInt(msg.peerUid),
parseInt(senderUin),
parseInt(senderUin!),
shortId,
[{
emoji_id: emojiId,
emoji_id: emojiId!,
count: 1,
}]
)
} catch (e) {
ctx.logger.error('解析表情回应消息失败', (e as Error).stack)
}
}
if (
grayTipElement.subElementType == GrayTipElementSubType.XmlMsg &&
xmlElement?.templId == '10179'
) {
ctx.logger.info('收到新人被邀请进群消息', grayTipElement)
if (xmlElement?.content) {
const regex = /jp="(\d+)"/g
const matches: string[] = []
let match: RegExpExecArray | null = null
while ((match = regex.exec(xmlElement.content)) !== null) {
matches.push(match[1])
}
if (matches.length === 2) {
const [invitor, invitee] = matches
return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite')
}
} else if (xmlElement.templId == '10179') {
ctx.logger.info('收到新人被邀请进群消息', xmlElement)
const invitor = xmlElement.templParam.get('invitor')
const invitee = xmlElement.templParam.get('invitee')
if (invitor && invitee) {
return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite')
}
}
else if (grayTipElement.subElementType == GrayTipElementSubType.JSON) {
}
if (grayTipElement) {
if (grayTipElement.subElementType == GrayTipElementSubType.JSON) {
const json = JSON.parse(grayTipElement.jsonGrayTipElement!.jsonStr)
if (grayTipElement.jsonGrayTipElement?.busiId === '1061') {
const param = grayTipElement.jsonGrayTipElement.xmlToJsonParam
@@ -665,9 +655,10 @@ export namespace OB11Entities {
export function sex(sex: Sex): OB11UserSex {
const sexMap = {
[Sex.male]: OB11UserSex.Male,
[Sex.female]: OB11UserSex.Female,
[Sex.unknown]: OB11UserSex.Unknown,
[Sex.Unknown]: OB11UserSex.Unknown,
[Sex.Male]: OB11UserSex.Male,
[Sex.Female]: OB11UserSex.Female,
[Sex.Hidden]: OB11UserSex.Unknown
}
return sexMap[sex] ?? OB11UserSex.Unknown
}
@@ -697,19 +688,6 @@ export namespace OB11Entities {
}
}
export function stranger(user: User): OB11User {
return {
...user,
user_id: parseInt(user.uin),
nickname: user.nick,
sex: sex(user.sex!),
age: 0,
qid: user.qid,
login_days: 0,
level: (user.qqLevel && calcQQLevel(user.qqLevel)) || 0,
}
}
export function group(group: Group): OB11Group {
return {
group_id: parseInt(group.groupCode),

View File

@@ -9,6 +9,7 @@ export enum EventType {
}
export abstract class OB11BaseEvent {
[index: string]: any
time = Math.floor(Date.now() / 1000)
self_id = parseInt(selfInfo.uin)
abstract post_type: EventType

View File

@@ -12,7 +12,7 @@ export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = 'leave') {
super()
this.group_id = groupId
this.operator_id = operatorId // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
this.operator_id = operatorId
this.user_id = userId
this.sub_type = subType
}

View File

@@ -33,14 +33,14 @@ export async function createSendElements(
continue
}
switch (sendMsg.type) {
case OB11MessageDataType.text: {
case OB11MessageDataType.Text: {
const text = sendMsg.data?.text
if (text) {
sendElements.push(SendElement.text(sendMsg.data!.text))
}
}
break
case OB11MessageDataType.at: {
case OB11MessageDataType.At: {
if (!peer) {
continue
}
@@ -76,7 +76,7 @@ export async function createSendElements(
}
}
break
case OB11MessageDataType.reply: {
case OB11MessageDataType.Reply: {
if (sendMsg.data?.id) {
const info = await ctx.store.getMsgInfoByShortId(+sendMsg.data.id)
if (!info) {
@@ -90,14 +90,14 @@ export async function createSendElements(
}
}
break
case OB11MessageDataType.face: {
case OB11MessageDataType.Face: {
const faceId = sendMsg.data?.id
if (faceId) {
sendElements.push(SendElement.face(parseInt(faceId)))
}
}
break
case OB11MessageDataType.mface: {
case OB11MessageDataType.Mface: {
sendElements.push(
SendElement.mface(
+sendMsg.data.emoji_package_id,
@@ -108,10 +108,10 @@ export async function createSendElements(
)
}
break
case OB11MessageDataType.image: {
case OB11MessageDataType.Image: {
const res = await SendElement.pic(
ctx,
(await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles })).path,
(await handleOb11RichMedia(ctx, sendMsg, deleteAfterSentFiles)).path,
sendMsg.data.summary || '',
sendMsg.data.subType || 0,
sendMsg.data.type === 'flash'
@@ -120,13 +120,13 @@ export async function createSendElements(
sendElements.push(res)
}
break
case OB11MessageDataType.file: {
const { path, fileName } = await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles })
case OB11MessageDataType.File: {
const { path, fileName } = await handleOb11RichMedia(ctx, sendMsg, deleteAfterSentFiles)
sendElements.push(await SendElement.file(ctx, path, fileName))
}
break
case OB11MessageDataType.video: {
const { path, fileName } = await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles })
case OB11MessageDataType.Video: {
const { path, fileName } = await handleOb11RichMedia(ctx, sendMsg, deleteAfterSentFiles)
let thumb = sendMsg.data.thumb
if (thumb) {
const uri2LocalRes = await uri2local(ctx, thumb)
@@ -137,32 +137,32 @@ export async function createSendElements(
sendElements.push(res)
}
break
case OB11MessageDataType.voice: {
const { path } = await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles })
case OB11MessageDataType.Record: {
const { path } = await handleOb11RichMedia(ctx, sendMsg, deleteAfterSentFiles)
sendElements.push(await SendElement.ptt(ctx, path))
}
break
case OB11MessageDataType.json: {
case OB11MessageDataType.Json: {
sendElements.push(SendElement.ark(sendMsg.data.data))
}
break
case OB11MessageDataType.dice: {
case OB11MessageDataType.Dice: {
const resultId = sendMsg.data?.result
sendElements.push(SendElement.dice(resultId))
}
break
case OB11MessageDataType.RPS: {
case OB11MessageDataType.Rps: {
const resultId = sendMsg.data?.result
sendElements.push(SendElement.rps(resultId))
}
break
case OB11MessageDataType.contact: {
case OB11MessageDataType.Contact: {
const { type, id } = sendMsg.data
const data = type === 'qq' ? ctx.ntFriendApi.getBuddyRecommendContact(id) : ctx.ntGroupApi.getGroupRecommendContact(id)
sendElements.push(SendElement.ark(await data))
}
break
case OB11MessageDataType.shake: {
case OB11MessageDataType.Shake: {
sendElements.push(SendElement.shake())
}
break
@@ -175,51 +175,22 @@ export async function createSendElements(
}
}
// forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/msg/SendMsg/create-send-elements.ts#L26
async function handleOb11FileLikeMessage(
ctx: Context,
{ data: inputdata }: OB11MessageFileBase,
{ deleteAfterSentFiles }: { deleteAfterSentFiles: string[] },
) {
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
const {
path,
isLocal,
fileName,
errMsg,
success,
} = (await uri2local(ctx, inputdata.url || inputdata.file))
if (!success) {
ctx.logger.error(errMsg)
throw Error(errMsg)
}
if (!isLocal) { // 只删除http和base64转过来的文件
deleteAfterSentFiles.push(path)
}
return { path, fileName: inputdata.name || fileName }
}
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
export function message2List(message: OB11MessageMixType, autoEscape = false) {
if (typeof message === 'string') {
if (autoEscape === true) {
message = [
return [
{
type: OB11MessageDataType.text,
type: OB11MessageDataType.Text,
data: {
text: message,
},
},
]
] as OB11MessageData[]
} else {
return decodeCQCode(message)
}
else {
message = decodeCQCode(message.toString())
}
}
else if (!Array.isArray(message)) {
message = [message]
} else if (!Array.isArray(message)) {
return [message]
}
return message
}
@@ -301,3 +272,18 @@ export async function createPeer(ctx: Context, payload: CreatePeerPayload, mode
}
throw new Error('请指定 group_id 或 user_id')
}
export async function handleOb11RichMedia(ctx: Context, segment: OB11MessageFileBase, deleteAfterSentFiles: string[]) {
const res = await uri2local(ctx, segment.data.url || segment.data.file)
if (!res.success) {
ctx.logger.error(res.errMsg)
throw Error(res.errMsg)
}
if (!res.isLocal) {
deleteAfterSentFiles.push(res.path)
}
return { path: res.path, fileName: segment.data.name || res.fileName }
}

View File

@@ -0,0 +1,239 @@
import { Context } from 'cordis'
import { OB11MessageData, OB11MessageDataType } from '../types'
import { Msg, RichMedia } from '@/ntqqapi/proto/compiled'
import { handleOb11RichMedia } from './createMessage'
import { selfInfo } from '@/common/globalVars'
import { Peer, RichMediaUploadCompleteNotify } from '@/ntqqapi/types'
import { deflateSync } from 'node:zlib'
import faceConfig from '@/ntqqapi/helper/face_config.json'
export class MessageEncoder {
static support = ['text', 'face', 'image', 'markdown', 'forward']
results: Msg.Message[]
children: Msg.Elem[]
deleteAfterSentFiles: string[]
isGroup: boolean
seq: number
tsum: number
preview: string
news: { text: string }[]
name?: string
uin?: number
constructor(private ctx: Context, private peer: Peer) {
this.results = []
this.children = []
this.deleteAfterSentFiles = []
this.isGroup = peer.chatType === 2
this.seq = Math.trunc(Math.random() * 65430)
this.tsum = 0
this.preview = ''
this.news = []
}
async flush() {
if (this.children.length === 0) return
const nick = this.name || selfInfo.nick || 'QQ用户'
if (this.news.length < 4) {
this.news.push({
text: `${nick}: ${this.preview}`
})
}
this.results.push({
routingHead: {
fromUin: this.uin ?? +selfInfo.uin ?? 1094950020,
c2c: this.isGroup ? undefined : {
friendName: nick
},
group: this.isGroup ? {
groupCode: 284840486,
groupCard: nick
} : undefined
},
contentHead: {
msgType: this.isGroup ? 82 : 9,
random: Math.floor(Math.random() * 4294967290),
msgSeq: this.seq,
msgTime: Math.trunc(Date.now() / 1000),
pkgNum: 1,
pkgIndex: 0,
divSeq: 0,
field15: {
field1: 0,
field2: 0,
field3: 0,
field4: '',
field5: ''
}
},
body: {
richText: {
elems: this.children
}
}
})
this.seq++
this.tsum++
this.children = []
this.preview = ''
}
async packImage(data: RichMediaUploadCompleteNotify, busiType: number) {
const imageSize = await this.ctx.ntFileApi.getImageSize(data.filePath)
return {
commonElem: {
serviceType: 48,
pbElem: RichMedia.MsgInfo.encode({
msgInfoBody: [{
index: {
info: {
fileSize: +data.commonFileInfo.fileSize,
md5HexStr: data.commonFileInfo.md5,
sha1HexStr: data.commonFileInfo.sha,
fileName: data.commonFileInfo.fileName,
fileType: {
type: 1,
picFormat: imageSize.type === 'gif' ? 2000 : 1000
},
width: imageSize.width,
height: imageSize.height,
time: 0,
original: 1
},
fileUuid: data.fileId,
storeID: 1,
expire: 2678400
},
pic: {
urlPath: `/download?appid=${this.isGroup ? 1407 : 1406}&fileid=${data.fileId}`,
ext: {
originalParam: '&spec=0',
bigParam: '&spec=720',
thumbParam: '&spec=198'
},
domain: 'multimedia.nt.qq.com.cn'
},
fileExist: true
}],
extBizInfo: {
pic: {
bizType: 0,
summary: ''
},
busiType
}
}).finish(),
businessType: this.isGroup ? 20 : 10
}
}
}
packForwardMessage(resid: string) {
const uuid = crypto.randomUUID()
const content = JSON.stringify({
app: 'com.tencent.multimsg',
config: {
autosize: 1,
forward: 1,
round: 1,
type: 'normal',
width: 300
},
desc: '[聊天记录]',
extra: JSON.stringify({
filename: uuid,
tsum: 0,
}),
meta: {
detail: {
news: [{
text: '查看转发消息'
}],
resid,
source: '聊天记录',
summary: '查看转发消息',
uniseq: uuid,
}
},
prompt: '[聊天记录]',
ver: '0.0.0.5',
view: 'contact'
})
return {
lightApp: {
data: Buffer.concat([Buffer.from([1]), deflateSync(Buffer.from(content, 'utf-8'))])
}
}
}
async visit(segment: OB11MessageData) {
const { type, data } = segment
if (type === OB11MessageDataType.Node) {
await this.render(data.content as OB11MessageData[])
const id = data.uin ?? data.user_id
this.uin = id ? +id : undefined
this.name = data.name ?? data.nickname
await this.flush()
} else if (type === OB11MessageDataType.Text) {
this.children.push({
text: {
str: data.text
}
})
this.preview += data.text
} else if (type === OB11MessageDataType.Face) {
this.children.push({
face: {
index: +data.id
}
})
const face = faceConfig.sysface.find(e => e.QSid === String(data.id))
if (face) {
this.preview += face.QDes
}
} else if (type === OB11MessageDataType.Image) {
const { path } = await handleOb11RichMedia(this.ctx, segment, this.deleteAfterSentFiles)
const data = await this.ctx.ntFileApi.uploadRMFileWithoutMsg(path, this.isGroup ? 4 : 3, this.peer.peerUid)
const busiType = Number(segment.data.subType) || 0
this.children.push(await this.packImage(data, busiType))
this.preview += busiType === 1 ? '[动画表情]' : '[图片]'
} else if (type === OB11MessageDataType.Markdown) {
this.children.push({
commonElem: {
serviceType: 45,
pbElem: Msg.MarkdownElem.encode(data).finish(),
businessType: 1
}
})
} else if (type === OB11MessageDataType.Forward) {
this.children.push(this.packForwardMessage(data.id))
this.preview += '[聊天记录]'
}
}
async render(segments: OB11MessageData[]) {
for (const segment of segments) {
await this.visit(segment)
}
}
async generate(content: OB11MessageData[]) {
await this.render(content)
return {
multiMsgItems: [{
fileName: 'MultiMsg',
buffer: {
msg: this.results
}
}],
tsum: this.tsum,
source: this.isGroup ? '群聊的聊天记录' : '聊天记录',
summary: `查看${this.tsum}条转发消息`,
news: this.news
}
}
}

View File

@@ -2,7 +2,7 @@ import { OB11Message, OB11MessageData, OB11MessageDataType } from '../types'
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
import { GroupRequestOperateTypes } from '@/ntqqapi/types'
import { convertMessage2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../helper/createMessage'
import { message2List, createSendElements, sendMsg, createPeer, CreatePeerMode } from '../helper/createMessage'
import { isNullable } from 'cosmokit'
import { Context } from 'cordis'
@@ -65,7 +65,7 @@ async function handleMsg(ctx: Context, msg: OB11Message, quickAction: QuickOpera
if (reply) {
let replyMessage: OB11MessageData[] = []
replyMessage.push({
type: OB11MessageDataType.reply,
type: OB11MessageDataType.Reply,
data: {
id: msg.message_id.toString(),
},
@@ -74,14 +74,14 @@ async function handleMsg(ctx: Context, msg: OB11Message, quickAction: QuickOpera
if (msg.message_type == 'group') {
if ((quickAction as QuickOperationGroupMessage).at_sender) {
replyMessage.push({
type: OB11MessageDataType.at,
type: OB11MessageDataType.At,
data: {
qq: msg.user_id.toString(),
},
})
}
}
replyMessage = replyMessage.concat(convertMessage2List(reply, quickAction.auto_escape))
replyMessage = replyMessage.concat(message2List(reply, quickAction.auto_escape))
const { sendElements, deleteAfterSentFiles } = await createSendElements(ctx, replyMessage, peer)
sendMsg(ctx, peer, sendElements, deleteAfterSentFiles).catch(e => ctx.logger.error(e))
}

View File

@@ -77,7 +77,7 @@ export enum OB11MessageType {
export interface OB11Message {
target_id?: number // 自己发送的消息才有此字段
self_id?: number
self_id: number
time: number
message_id: number
message_seq: number // go-cqhttp字段实际上是message_id
@@ -91,7 +91,7 @@ export interface OB11Message {
message_format: 'array' | 'string'
raw_message: string
font: number
post_type?: EventType
post_type: EventType
raw?: RawMessage
temp_source?: 0 | 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9
}
@@ -117,30 +117,30 @@ export interface OB11Return<DataType> {
}
export enum OB11MessageDataType {
text = 'text',
image = 'image',
music = 'music',
video = 'video',
voice = 'record',
file = 'file',
at = 'at',
reply = 'reply',
json = 'json',
face = 'face',
mface = 'mface', // 商城表情
markdown = 'markdown',
node = 'node', // 合并转发消息节点
forward = 'forward', // 合并转发消息,用于上报
xml = 'xml',
poke = 'poke',
dice = 'dice',
RPS = 'rps',
contact = 'contact',
shake = 'shake',
Text = 'text',
Image = 'image',
Music = 'music',
Video = 'video',
Record = 'record',
File = 'file',
At = 'at',
Reply = 'reply',
Json = 'json',
Face = 'face',
Mface = 'mface', // 商城表情
Markdown = 'markdown',
Node = 'node', // 合并转发消息节点
Forward = 'forward', // 合并转发消息,用于上报
Xml = 'xml',
Poke = 'poke',
Dice = 'dice',
Rps = 'rps',
Contact = 'contact',
Shake = 'shake',
}
export interface OB11MessageMFace {
type: OB11MessageDataType.mface
type: OB11MessageDataType.Mface
data: {
emoji_package_id: number
emoji_id: string
@@ -151,27 +151,27 @@ export interface OB11MessageMFace {
}
export interface OB11MessageDice {
type: OB11MessageDataType.dice
type: OB11MessageDataType.Dice
data: {
result: number /* intended */ | string /* in fact */
}
}
export interface OB11MessageRPS {
type: OB11MessageDataType.RPS
type: OB11MessageDataType.Rps
data: {
result: number | string
}
}
export interface OB11MessageText {
type: OB11MessageDataType.text
type: OB11MessageDataType.Text
data: {
text: string // 纯文本
}
}
export interface OB11MessagePoke {
type: OB11MessageDataType.poke
type: OB11MessageDataType.Poke
data: {
qq?: number
id?: number
@@ -189,7 +189,7 @@ export interface OB11MessageFileBase {
}
export interface OB11MessageImage extends OB11MessageFileBase {
type: OB11MessageDataType.image
type: OB11MessageDataType.Image
data: OB11MessageFileBase['data'] & {
summary?: string // 图片摘要
subType?: PicSubType
@@ -198,14 +198,14 @@ export interface OB11MessageImage extends OB11MessageFileBase {
}
export interface OB11MessageRecord extends OB11MessageFileBase {
type: OB11MessageDataType.voice
type: OB11MessageDataType.Record
data: OB11MessageFileBase['data'] & {
path?: string //扩展
}
}
export interface OB11MessageFile extends OB11MessageFileBase {
type: OB11MessageDataType.file
type: OB11MessageDataType.File
data: OB11MessageFileBase['data'] & {
file_id?: string
path?: string
@@ -213,14 +213,14 @@ export interface OB11MessageFile extends OB11MessageFileBase {
}
export interface OB11MessageVideo extends OB11MessageFileBase {
type: OB11MessageDataType.video
type: OB11MessageDataType.Video
data: OB11MessageFileBase['data'] & {
path?: string //扩展
}
}
export interface OB11MessageAt {
type: OB11MessageDataType.at
type: OB11MessageDataType.At
data: {
qq: string | 'all'
name?: string
@@ -228,14 +228,14 @@ export interface OB11MessageAt {
}
export interface OB11MessageReply {
type: OB11MessageDataType.reply
type: OB11MessageDataType.Reply
data: {
id: string
}
}
export interface OB11MessageFace {
type: OB11MessageDataType.face
type: OB11MessageDataType.Face
data: {
id: string
}
@@ -244,48 +244,50 @@ export interface OB11MessageFace {
export type OB11MessageMixType = OB11MessageData[] | string | OB11MessageData
export interface OB11MessageNode {
type: OB11MessageDataType.node
type: OB11MessageDataType.Node
data: {
id?: string
user_id?: number
nickname: string
content: OB11MessageMixType
id?: number | string
content?: OB11MessageMixType
user_id?: number // ob11
nickname?: string // ob11
name?: string // gocq
uin?: number | string // gocq
}
}
export interface OB11MessageIdMusic {
type: OB11MessageDataType.music
type: OB11MessageDataType.Music
data: IdMusicSignPostData
}
export interface OB11MessageCustomMusic {
type: OB11MessageDataType.music
type: OB11MessageDataType.Music
data: Omit<CustomMusicSignPostData, 'singer'> & { content?: string }
}
export type OB11MessageMusic = OB11MessageIdMusic | OB11MessageCustomMusic
export interface OB11MessageJson {
type: OB11MessageDataType.json
type: OB11MessageDataType.Json
data: { data: string /* , config: { token: string } */ }
}
export interface OB11MessageMarkdown {
type: OB11MessageDataType.markdown
type: OB11MessageDataType.Markdown
data: {
data: string
content: string
}
}
export interface OB11MessageForward {
type: OB11MessageDataType.forward
type: OB11MessageDataType.Forward
data: {
id: string
}
}
export interface OB11MessageContact {
type: OB11MessageDataType.contact
type: OB11MessageDataType.Contact
data: {
type: 'qq' | 'group'
id: string
@@ -293,7 +295,7 @@ export interface OB11MessageContact {
}
export interface OB11MessageShake {
type: OB11MessageDataType.shake
type: OB11MessageDataType.Shake
data: Record<string, never>
}

View File

@@ -11,6 +11,10 @@ function isEmpty(value: unknown) {
}
async function onSettingWindowCreated(view: Element) {
console.log(view)
if (!view){
return
}
const config = await window.llonebot.getConfig()
const ob11Config = { ...config.ob11 }
@@ -43,6 +47,13 @@ async function onSettingWindowCreated(view: Element) {
SettingButton('请稍候', 'llonebot-update-button', 'secondary'),
),
]),
SettingList([
SettingItem(
'是否启用 LLOneBot重启 QQ 后生效',
null,
SettingSwitch('enableLLOB', config.enableLLOB, { 'control-display-id': 'config-enableLLOB' }),
)
]),
SettingList([
SettingItem(
'是否启用 Satori 协议',
@@ -240,7 +251,9 @@ async function onSettingWindowCreated(view: Element) {
} else {
errDom?.classList.add('show')
}
errCodeDom!.innerHTML = errMsg
if (errCodeDom) {
errCodeDom.innerHTML = errMsg
}
}
showError().then()
@@ -449,9 +462,11 @@ async function onSettingWindowCreated(view: Element) {
}
window.llonebot.checkVersion().then(checkVersionFunc)
window.addEventListener('beforeunload', () => {
if (JSON.stringify(ob11Config) === JSON.stringify(config.ob11)) return
config.ob11 = ob11Config
window.llonebot.setConfig(true, config)
window.llonebot.getConfig().then(oldConfig => {
if (JSON.stringify(oldConfig) !== JSON.stringify(config)) {
window.llonebot.setConfig(true, config)
}
})
})
}

View File

@@ -91,7 +91,7 @@ class SatoriAdapter extends Service {
input.subMsgType === 12 &&
input.elements[0]?.grayTipElement?.xmlElement?.templId === '10382'
) {
// 机器人被表情回应
}
else {
// 普通的消息
@@ -99,7 +99,7 @@ class SatoriAdapter extends Service {
}
}
async handleGroupNotify(input: NT.GroupNotify) {
async handleGroupNotify(input: NT.GroupNotify, doubt: boolean) {
if (
input.type === NT.GroupNotifyType.InvitedByMember &&
input.status === NT.GroupNotifyStatus.Unhandle
@@ -119,14 +119,14 @@ class SatoriAdapter extends Service {
input.status === NT.GroupNotifyStatus.Unhandle
) {
// 他人主动申请,需管理员同意
return await parseGuildMemberRequest(this, input)
return await parseGuildMemberRequest(this, input, doubt)
}
else if (
input.type === NT.GroupNotifyType.InvitedNeedAdminiStratorPass &&
input.status === NT.GroupNotifyStatus.Unhandle
) {
// 他人被邀请,需管理员同意
return await parseGuildMemberRequest(this, input)
return await parseGuildMemberRequest(this, input, doubt)
}
}
@@ -140,7 +140,8 @@ class SatoriAdapter extends Service {
})
this.ctx.on('nt/group-notify', async input => {
const event = await this.handleGroupNotify(input)
const { doubt, notify } = input
const event = await this.handleGroupNotify(notify, doubt)
.catch(e => this.ctx.logger.error(e))
event && this.server.dispatch(event)
})

View File

@@ -46,9 +46,9 @@ export async function parseGuildMemberRemoved(bot: SatoriAdapter, input: GroupNo
})
}
export async function parseGuildMemberRequest(bot: SatoriAdapter, input: GroupNotify) {
export async function parseGuildMemberRequest(bot: SatoriAdapter, input: GroupNotify, doubt: boolean) {
const groupCode = input.group.groupCode
const flag = groupCode + '|' + input.seq + '|' + input.type
const flag = `${groupCode}|${input.seq}|${input.type}|${doubt === true ? '1' : '0'}`
return bot.event('guild-member-request', {
guild: decodeGuild(input.group),

View File

@@ -1 +1 @@
export const version = '4.0.12'
export const version = '4.3.2'