mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
85 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
52a065542e | ||
![]() |
fd10469685 | ||
![]() |
a2ee75b113 | ||
![]() |
0f7f243b98 | ||
![]() |
97d7996a50 | ||
![]() |
b658d164f9 | ||
![]() |
f150ae478b | ||
![]() |
d1f68553f1 | ||
![]() |
f47f0800de | ||
![]() |
b7ddefc950 | ||
![]() |
25b3325a44 | ||
![]() |
c281b87bab | ||
![]() |
c0946ddda2 | ||
![]() |
1128cf679c | ||
![]() |
ff65a42350 | ||
![]() |
c459587dcd | ||
![]() |
6f8ea9677f | ||
![]() |
38197527fa | ||
![]() |
21b2bd2c8e | ||
![]() |
25158eee55 | ||
![]() |
1aa804f255 | ||
![]() |
fbe101339d | ||
![]() |
a4aeb8171d | ||
![]() |
27f98a459c | ||
![]() |
e6b0eaa46d | ||
![]() |
f336317a33 | ||
![]() |
17b44cc0fa | ||
![]() |
debe3a8597 | ||
![]() |
f36c5e849f | ||
![]() |
abbd6797c4 | ||
![]() |
fdb7784a7d | ||
![]() |
92b49015b0 | ||
![]() |
1765ffff7b | ||
![]() |
3024316b5b | ||
![]() |
9a0d89bfbf | ||
![]() |
807ef3b700 | ||
![]() |
948f10d4e3 | ||
![]() |
0f99b5cb87 | ||
![]() |
6413b0ff82 | ||
![]() |
39713d8e11 | ||
![]() |
739a497af6 | ||
![]() |
de2fe9b0aa | ||
![]() |
44448895a0 | ||
![]() |
cfd9097769 | ||
![]() |
627042fd25 | ||
![]() |
b51ce24d0c | ||
![]() |
fc0881eccc | ||
![]() |
6b8509d2b2 | ||
![]() |
cf1d67a5cf | ||
![]() |
473ebd25b8 | ||
![]() |
d4427cfff4 | ||
![]() |
9d2e9786cc | ||
![]() |
9968f714c7 | ||
![]() |
bd212c4bf3 | ||
![]() |
32c7f904db | ||
![]() |
2ef017282f | ||
![]() |
9672f67a23 | ||
![]() |
6e5cfd827c | ||
![]() |
5402bef4a9 | ||
![]() |
4194512cce | ||
![]() |
b3aad8b0d9 | ||
![]() |
1489c6df25 | ||
![]() |
2e225045e6 | ||
![]() |
11ed06148c | ||
![]() |
a3fc018186 | ||
![]() |
9692bf6ec6 | ||
![]() |
9b3916307a | ||
![]() |
fdf96b479c | ||
![]() |
25c7a6096d | ||
![]() |
627955e7fd | ||
![]() |
43e9b070a9 | ||
![]() |
78bb36a2bb | ||
![]() |
58e6e3cbda | ||
![]() |
1da086ce0a | ||
![]() |
e9d43a9449 | ||
![]() |
ce31052661 | ||
![]() |
3fd9b0a183 | ||
![]() |
7e1dee8e07 | ||
![]() |
f2854fdf00 | ||
![]() |
1fad95a55b | ||
![]() |
5342e1521c | ||
![]() |
c0bb7def20 | ||
![]() |
3c532526df | ||
![]() |
05c6cae86f | ||
![]() |
24a49f035e |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,4 +3,4 @@ package-lock.json
|
|||||||
dist/
|
dist/
|
||||||
out/
|
out/
|
||||||
.idea/
|
.idea/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# LLOneBot API
|
# LLOneBot
|
||||||
|
|
||||||
LiteLoaderQQNT插件,使你的NTQQ支持OneBot11协议进行QQ机器人开发
|
LiteLoaderQQNT插件,使你的NTQQ支持OneBot11协议进行QQ机器人开发
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import cp from 'vite-plugin-cp'
|
import cp from 'vite-plugin-cp'
|
||||||
import './scripts/gen-version'
|
import './scripts/gen-version'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
const external = [
|
const external = [
|
||||||
'silk-wasm',
|
'silk-wasm',
|
||||||
@@ -34,6 +35,7 @@ let config = {
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
'@': path.resolve(__dirname, './src'),
|
||||||
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
|
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -43,9 +45,9 @@ let config = {
|
|||||||
...external.map(genCpModule),
|
...external.map(genCpModule),
|
||||||
{ src: './manifest.json', dest: 'dist' },
|
{ src: './manifest.json', dest: 'dist' },
|
||||||
{ src: './icon.jpg', dest: 'dist' },
|
{ src: './icon.jpg', dest: 'dist' },
|
||||||
{ src: './src/ntqqapi/external/crychic/crychic-win32-x64.node', dest: 'dist/main/' },
|
{ src: './src/ntqqapi/native/crychic/crychic-win32-x64.node', dest: 'dist/main/' },
|
||||||
{ src: './src/ntqqapi/external/moehook/MoeHoo-win32-x64.node', dest: 'dist/main/' },
|
// { src: './src/ntqqapi/native/moehook/MoeHoo-win32-x64.node', dest: 'dist/main/' },
|
||||||
{ src: './src/ntqqapi/external/moehook/MoeHoo-linux-x64.node', dest: 'dist/main/' },
|
// { src: './src/ntqqapi/native/moehook/MoeHoo-linux-x64.node', dest: 'dist/main/' },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.24.0",
|
"name": "LLOneBot v3.26.6",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
||||||
"version": "3.24.0",
|
"version": "3.26.6",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -10,7 +10,8 @@
|
|||||||
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOneBot/",
|
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOneBot/",
|
||||||
"build-win": "npm run build && npm run deploy-win",
|
"build-win": "npm run build && npm run deploy-win",
|
||||||
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOneBot\\\"",
|
"deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOneBot\\\"",
|
||||||
"format": "prettier -cw ."
|
"format": "prettier -cw .",
|
||||||
|
"check": "tsc"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -40,6 +40,7 @@ export class ConfigUtil {
|
|||||||
enableWsReverse: false,
|
enableWsReverse: false,
|
||||||
messagePostFormat: 'array',
|
messagePostFormat: 'array',
|
||||||
enableHttpHeart: false,
|
enableHttpHeart: false,
|
||||||
|
enableQOAutoQuote: false
|
||||||
}
|
}
|
||||||
let defaultConfig: Config = {
|
let defaultConfig: Config = {
|
||||||
ob11: ob11Default,
|
ob11: ob11Default,
|
||||||
@@ -82,9 +83,12 @@ export class ConfigUtil {
|
|||||||
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), 'utf-8')
|
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), 'utf-8')
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkOldConfig(currentConfig: Config | OB11Config,
|
private checkOldConfig(
|
||||||
oldConfig: Config | OB11Config,
|
currentConfig: Config | OB11Config,
|
||||||
currentKey: string, oldKey: string) {
|
oldConfig: Config | OB11Config,
|
||||||
|
currentKey: string,
|
||||||
|
oldKey: string,
|
||||||
|
) {
|
||||||
// 迁移旧的配置到新配置,避免用户重新填写配置
|
// 迁移旧的配置到新配置,避免用户重新填写配置
|
||||||
const oldValue = oldConfig[oldKey]
|
const oldValue = oldConfig[oldKey]
|
||||||
if (oldValue) {
|
if (oldValue) {
|
||||||
|
@@ -1,9 +1,18 @@
|
|||||||
import { type Friend, type FriendRequest, type Group, type GroupMember, type SelfInfo } from '../ntqqapi/types'
|
import {
|
||||||
|
CategoryFriend,
|
||||||
|
type Friend,
|
||||||
|
type FriendRequest,
|
||||||
|
type Group,
|
||||||
|
type GroupMember,
|
||||||
|
type SelfInfo,
|
||||||
|
User,
|
||||||
|
} from '../ntqqapi/types'
|
||||||
import { type FileCache, type LLOneBotError } from './types'
|
import { type FileCache, type LLOneBotError } from './types'
|
||||||
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
||||||
import { log } from './utils/log'
|
import { log } from './utils/log'
|
||||||
import { isNumeric } from './utils/helper'
|
import { isNumeric } from './utils/helper'
|
||||||
import { NTQQFriendApi } from '../ntqqapi/api'
|
import { NTQQFriendApi } from '../ntqqapi/api'
|
||||||
|
import { WebApiGroupMember } from '@/ntqqapi/api/webapi'
|
||||||
|
|
||||||
export const selfInfo: SelfInfo = {
|
export const selfInfo: SelfInfo = {
|
||||||
uid: '',
|
uid: '',
|
||||||
@@ -11,6 +20,10 @@ export const selfInfo: SelfInfo = {
|
|||||||
nick: '',
|
nick: '',
|
||||||
online: true,
|
online: true,
|
||||||
}
|
}
|
||||||
|
export const WebGroupData = {
|
||||||
|
GroupData: new Map<string, Array<WebApiGroupMember>>(),
|
||||||
|
GroupTime: new Map<string, number>(),
|
||||||
|
}
|
||||||
export let groups: Group[] = []
|
export let groups: Group[] = []
|
||||||
export let friends: Friend[] = []
|
export let friends: Friend[] = []
|
||||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
|
||||||
@@ -27,13 +40,13 @@ export async function getFriend(uinOrUid: string): Promise<Friend | undefined> {
|
|||||||
let friend = friends.find((friend) => friend[filterKey] === filterValue.toString())
|
let friend = friends.find((friend) => friend[filterKey] === filterValue.toString())
|
||||||
if (!friend) {
|
if (!friend) {
|
||||||
try {
|
try {
|
||||||
const _friends = (await NTQQFriendApi.getFriends(true))
|
const _friends = await NTQQFriendApi.getFriends(true)
|
||||||
friend = _friends.find(friend => friend[filterKey] === filterValue.toString())
|
friend = _friends.find((friend) => friend[filterKey] === filterValue.toString())
|
||||||
if (friend){
|
if (friend) {
|
||||||
friends.push(friend)
|
friends.push(friend)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("刷新好友列表失败", e.stack.toString())
|
log('刷新好友列表失败', e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return friend
|
return friend
|
||||||
@@ -107,3 +120,5 @@ export function getUidByUin(uin: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export let tempGroupCodeMap: Record<string, string> = {} // peerUid => 群号
|
export let tempGroupCodeMap: Record<string, string> = {} // peerUid => 群号
|
||||||
|
|
||||||
|
export let rawFriends: CategoryFriend[] = []
|
@@ -49,7 +49,7 @@ class DBUtil {
|
|||||||
setTimeout(initDB, 300)
|
setTimeout(initDB, 300)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initDB()
|
setTimeout(initDB)
|
||||||
}).then()
|
}).then()
|
||||||
|
|
||||||
const expiredMilliSecond = 1000 * 60 * 60
|
const expiredMilliSecond = 1000 * 60 * 60
|
||||||
@@ -154,12 +154,12 @@ class DBUtil {
|
|||||||
this.updateMsg(msg).then()
|
this.updateMsg(msg).then()
|
||||||
return existMsg.msgShortId
|
return existMsg.msgShortId
|
||||||
}
|
}
|
||||||
this.addCache(msg)
|
|
||||||
|
|
||||||
const shortMsgId = await this.genMsgShortId()
|
const shortMsgId = await this.genMsgShortId()
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId
|
||||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq
|
||||||
msg.msgShortId = shortMsgId
|
msg.msgShortId = shortMsgId
|
||||||
|
this.addCache(msg)
|
||||||
// log("新增消息记录", msg.msgId)
|
// log("新增消息记录", msg.msgId)
|
||||||
this.db.put(shortIdKey, msg.msgId).then().catch()
|
this.db.put(shortIdKey, msg.msgId).then().catch()
|
||||||
this.db.put(longIdKey, JSON.stringify(msg)).then().catch()
|
this.db.put(longIdKey, JSON.stringify(msg)).then().catch()
|
||||||
|
@@ -10,9 +10,10 @@ export interface OB11Config {
|
|||||||
enableWsReverse?: boolean
|
enableWsReverse?: boolean
|
||||||
messagePostFormat?: 'array' | 'string'
|
messagePostFormat?: 'array' | 'string'
|
||||||
enableHttpHeart?: boolean
|
enableHttpHeart?: boolean
|
||||||
|
enableQOAutoQuote: boolean // 快速操作回复自动引用原消息
|
||||||
}
|
}
|
||||||
export interface CheckVersion {
|
export interface CheckVersion {
|
||||||
result: boolean,
|
result: boolean
|
||||||
version: string
|
version: string
|
||||||
}
|
}
|
||||||
export interface Config {
|
export interface Config {
|
||||||
@@ -45,5 +46,6 @@ export interface FileCache {
|
|||||||
fileUuid?: string
|
fileUuid?: string
|
||||||
url?: string
|
url?: string
|
||||||
msgId?: string
|
msgId?: string
|
||||||
|
elementId: string
|
||||||
downloadFunc?: () => Promise<void>
|
downloadFunc?: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
83
src/common/utils/QQBasicInfo.ts
Normal file
83
src/common/utils/QQBasicInfo.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import path from 'node:path'
|
||||||
|
import fs from 'node:fs'
|
||||||
|
import os from 'node:os'
|
||||||
|
import { systemPlatform } from './system'
|
||||||
|
|
||||||
|
export const exePath = process.execPath
|
||||||
|
|
||||||
|
function getPKGPath() {
|
||||||
|
let p = path.join(path.dirname(exePath), 'resources', 'app', 'package.json')
|
||||||
|
if (systemPlatform === 'darwin') {
|
||||||
|
p = path.join(path.dirname(path.dirname(exePath)), 'Resources', 'app', 'package.json')
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pkgInfoPath = getPKGPath()
|
||||||
|
let configVersionInfoPath: string
|
||||||
|
|
||||||
|
|
||||||
|
if (os.platform() !== 'linux') {
|
||||||
|
configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const userPath = os.homedir()
|
||||||
|
const appDataPath = path.resolve(userPath, './.config/QQ')
|
||||||
|
configVersionInfoPath = path.resolve(appDataPath, './versions/config.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof configVersionInfoPath !== 'string') {
|
||||||
|
throw new Error('Something went wrong when load QQ info path')
|
||||||
|
}
|
||||||
|
|
||||||
|
export { configVersionInfoPath }
|
||||||
|
|
||||||
|
type QQPkgInfo = {
|
||||||
|
version: string;
|
||||||
|
buildVersion: string;
|
||||||
|
platform: string;
|
||||||
|
eleArch: string;
|
||||||
|
}
|
||||||
|
type QQVersionConfigInfo = {
|
||||||
|
baseVersion: string;
|
||||||
|
curVersion: string;
|
||||||
|
prevVersion: string;
|
||||||
|
onErrorVersions: Array<any>;
|
||||||
|
buildId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _qqVersionConfigInfo: QQVersionConfigInfo = {
|
||||||
|
'baseVersion': '9.9.9-23361',
|
||||||
|
'curVersion': '9.9.9-23361',
|
||||||
|
'prevVersion': '',
|
||||||
|
'onErrorVersions': [],
|
||||||
|
'buildId': '23361',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(configVersionInfoPath)) {
|
||||||
|
try {
|
||||||
|
const _ = JSON.parse(fs.readFileSync(configVersionInfoPath).toString())
|
||||||
|
_qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Load QQ version config info failed, Use default version', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo
|
||||||
|
|
||||||
|
export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath)
|
||||||
|
// platform_type: 3,
|
||||||
|
// app_type: 4,
|
||||||
|
// app_version: '9.9.9-23159',
|
||||||
|
// qua: 'V1_WIN_NQ_9.9.9_23159_GW_B',
|
||||||
|
// appid: '537213764',
|
||||||
|
// platVer: '10.0.26100',
|
||||||
|
// clientVer: '9.9.9-23159',
|
||||||
|
|
||||||
|
let _appid: string = '537213803' // 默认为 Windows 平台的 appid
|
||||||
|
if (systemPlatform === 'linux') {
|
||||||
|
_appid = '537213827'
|
||||||
|
}
|
||||||
|
// todo: mac 平台的 appid
|
||||||
|
export const appid = _appid
|
||||||
|
export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106'
|
@@ -109,7 +109,7 @@ export async function httpDownload(options: string | HttpDownloadOptions): Promi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fetchRes = await net.fetch(url, headers)
|
const fetchRes = await net.fetch(url, {headers})
|
||||||
if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`)
|
if (!fetchRes.ok) throw new Error(`下载文件失败: ${fetchRes.statusText}`)
|
||||||
|
|
||||||
const blob = await fetchRes.blob()
|
const blob = await fetchRes.blob()
|
||||||
@@ -176,6 +176,7 @@ export async function uri2local(uri: string, fileName: string = null): Promise<U
|
|||||||
// res.ext = pathInfo.ext
|
// res.ext = pathInfo.ext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fileName = fileName.replace(/[/\\:*?"<>|]/g, '_')
|
||||||
res.fileName = fileName
|
res.fileName = fileName
|
||||||
filePath = path.join(TEMP_DIR, uuidv4() + fileName)
|
filePath = path.join(TEMP_DIR, uuidv4() + fileName)
|
||||||
fs.writeFileSync(filePath, buffer)
|
fs.writeFileSync(filePath, buffer)
|
||||||
|
@@ -65,3 +65,33 @@ export function wrapText(str: string, maxLength: number): string {
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函数缓存装饰器,根据方法名、参数、自定义key生成缓存键,在一定时间内返回缓存结果
|
||||||
|
* @param ttl 超时时间,单位毫秒
|
||||||
|
* @param customKey 自定义缓存键前缀,可为空,防止方法名参数名一致时导致缓存键冲突
|
||||||
|
* @returns 处理后缓存或调用原方法的结果
|
||||||
|
*/
|
||||||
|
export function cacheFunc(ttl: number, customKey: string='') {
|
||||||
|
const cache = new Map<string, { expiry: number; value: any }>();
|
||||||
|
|
||||||
|
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor {
|
||||||
|
const originalMethod = descriptor.value;
|
||||||
|
const className = target.constructor.name; // 获取类名
|
||||||
|
const methodName = propertyKey; // 获取方法名
|
||||||
|
descriptor.value = async function (...args: any[]){
|
||||||
|
const cacheKey = `${customKey}${className}.${methodName}:${JSON.stringify(args)}`;
|
||||||
|
const cached = cache.get(cacheKey);
|
||||||
|
if (cached && cached.expiry > Date.now()) {
|
||||||
|
return cached.value;
|
||||||
|
} else {
|
||||||
|
const result = await originalMethod.apply(this, args);
|
||||||
|
cache.set(cacheKey, { value: result, expiry: Date.now() + ttl });
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return descriptor;
|
||||||
|
};
|
||||||
|
}
|
@@ -5,7 +5,7 @@ export * from './file'
|
|||||||
export * from './helper'
|
export * from './helper'
|
||||||
export * from './log'
|
export * from './log'
|
||||||
export * from './qqlevel'
|
export * from './qqlevel'
|
||||||
export * from './qqpkg'
|
export * from './QQBasicInfo'
|
||||||
export * from './upgrade'
|
export * from './upgrade'
|
||||||
export const DATA_DIR = global.LiteLoader.plugins['LLOneBot'].path.data
|
export const DATA_DIR = global.LiteLoader.plugins['LLOneBot'].path.data
|
||||||
export const TEMP_DIR = path.join(DATA_DIR, 'temp')
|
export const TEMP_DIR = path.join(DATA_DIR, 'temp')
|
||||||
@@ -16,3 +16,4 @@ if (!fs.existsSync(TEMP_DIR)) {
|
|||||||
export { getVideoInfo } from './video'
|
export { getVideoInfo } from './video'
|
||||||
export { checkFfmpeg } from './video'
|
export { checkFfmpeg } from './video'
|
||||||
export { encodeSilk } from './audio'
|
export { encodeSilk } from './audio'
|
||||||
|
export { isQQ998 } from './QQBasicInfo'
|
@@ -1,12 +0,0 @@
|
|||||||
import path from 'path'
|
|
||||||
|
|
||||||
type QQPkgInfo = {
|
|
||||||
version: string
|
|
||||||
buildVersion: string
|
|
||||||
platform: string
|
|
||||||
eleArch: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, 'app/package.json'))
|
|
||||||
|
|
||||||
export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106'
|
|
107
src/common/utils/request.ts
Normal file
107
src/common/utils/request.ts
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
import https from 'node:https';
|
||||||
|
import http from 'node:http';
|
||||||
|
import { log } from '@/common/utils/log'
|
||||||
|
|
||||||
|
export class RequestUtil {
|
||||||
|
// 适用于获取服务器下发cookies时获取,仅GET
|
||||||
|
static async HttpsGetCookies(url: string): Promise<{ [key: string]: string }> {
|
||||||
|
const client = url.startsWith('https') ? https : http;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
client.get(url, (res) => {
|
||||||
|
let cookies: { [key: string]: string } = {};
|
||||||
|
const handleRedirect = (res: http.IncomingMessage) => {
|
||||||
|
//console.log(res.headers.location);
|
||||||
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
|
if (res.headers.location) {
|
||||||
|
const redirectUrl = new URL(res.headers.location, url);
|
||||||
|
RequestUtil.HttpsGetCookies(redirectUrl.href).then((redirectCookies) => {
|
||||||
|
// 合并重定向过程中的cookies
|
||||||
|
log('redirectCookies', redirectCookies)
|
||||||
|
cookies = { ...cookies, ...redirectCookies };
|
||||||
|
resolve(cookies);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(cookies);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resolve(cookies);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
res.on('data', () => { }); // Necessary to consume the stream
|
||||||
|
res.on('end', () => {
|
||||||
|
handleRedirect(res);
|
||||||
|
});
|
||||||
|
if (res.headers['set-cookie']) {
|
||||||
|
// console.log(res.headers['set-cookie']);
|
||||||
|
log('set-cookie', url, res.headers['set-cookie']);
|
||||||
|
res.headers['set-cookie'].forEach((cookie) => {
|
||||||
|
const parts = cookie.split(';')[0].split('=');
|
||||||
|
const key = parts[0];
|
||||||
|
const value = parts[1];
|
||||||
|
if (key && value && key.length > 0 && value.length > 0) {
|
||||||
|
cookies[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求和回复都是JSON data传原始内容 自动编码json
|
||||||
|
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}, isJsonRet: boolean = true, isArgJson: boolean = true): Promise<T> {
|
||||||
|
let option = new URL(url);
|
||||||
|
const protocol = url.startsWith('https://') ? https : http;
|
||||||
|
const options = {
|
||||||
|
hostname: option.hostname,
|
||||||
|
port: option.port,
|
||||||
|
path: option.href,
|
||||||
|
method: method,
|
||||||
|
headers: headers
|
||||||
|
};
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = protocol.request(options, (res: any) => {
|
||||||
|
let responseBody = '';
|
||||||
|
res.on('data', (chunk: string | Buffer) => {
|
||||||
|
responseBody += chunk.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
try {
|
||||||
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
||||||
|
if (isJsonRet) {
|
||||||
|
const responseJson = JSON.parse(responseBody);
|
||||||
|
resolve(responseJson as T);
|
||||||
|
} else {
|
||||||
|
resolve(responseBody as T);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(new Error(`Unexpected status code: ${res.statusCode}`));
|
||||||
|
}
|
||||||
|
} catch (parseError) {
|
||||||
|
reject(parseError);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', (error: any) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
|
||||||
|
if (isArgJson) {
|
||||||
|
req.write(JSON.stringify(data));
|
||||||
|
} else {
|
||||||
|
req.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求返回都是原始内容
|
||||||
|
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}) {
|
||||||
|
return this.HttpGetJson<string>(url, method, data, headers, false, false);
|
||||||
|
}
|
||||||
|
}
|
10
src/common/utils/system.ts
Normal file
10
src/common/utils/system.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
export const systemPlatform = os.platform();
|
||||||
|
export const cpuArch = os.arch();
|
||||||
|
export const systemVersion = os.release();
|
||||||
|
// export const hostname = os.hostname(); // win7不支持
|
||||||
|
const homeDir = os.homedir();
|
||||||
|
export const downloadsPath = path.join(homeDir, 'Downloads');
|
||||||
|
export const systemName = os.type();
|
@@ -5,7 +5,7 @@ import { copyFolder, httpDownload, log, PLUGIN_DIR, TEMP_DIR } from '.'
|
|||||||
import compressing from 'compressing'
|
import compressing from 'compressing'
|
||||||
|
|
||||||
const downloadMirrorHosts = ['https://mirror.ghproxy.com/']
|
const downloadMirrorHosts = ['https://mirror.ghproxy.com/']
|
||||||
const checkVersionMirrorHosts = ['https://521github.com']
|
const checkVersionMirrorHosts = ['https://kkgithub.com']
|
||||||
|
|
||||||
export async function checkNewVersion() {
|
export async function checkNewVersion() {
|
||||||
const latestVersionText = await getRemoteVersion()
|
const latestVersionText = await getRemoteVersion()
|
||||||
|
168
src/main/main.ts
168
src/main/main.ts
@@ -25,7 +25,7 @@ import {
|
|||||||
selfInfo,
|
selfInfo,
|
||||||
uidMaps,
|
uidMaps,
|
||||||
} from '../common/data'
|
} from '../common/data'
|
||||||
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook } from '../ntqqapi/hook'
|
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook, startHook } from '../ntqqapi/hook'
|
||||||
import { OB11Constructor } from '../onebot11/constructor'
|
import { OB11Constructor } from '../onebot11/constructor'
|
||||||
import {
|
import {
|
||||||
ChatType,
|
ChatType,
|
||||||
@@ -38,7 +38,7 @@ import {
|
|||||||
import { httpHeart, ob11HTTPServer } from '../onebot11/server/http'
|
import { httpHeart, ob11HTTPServer } from '../onebot11/server/http'
|
||||||
import { OB11FriendRecallNoticeEvent } from '../onebot11/event/notice/OB11FriendRecallNoticeEvent'
|
import { OB11FriendRecallNoticeEvent } from '../onebot11/event/notice/OB11FriendRecallNoticeEvent'
|
||||||
import { OB11GroupRecallNoticeEvent } from '../onebot11/event/notice/OB11GroupRecallNoticeEvent'
|
import { OB11GroupRecallNoticeEvent } from '../onebot11/event/notice/OB11GroupRecallNoticeEvent'
|
||||||
import { postOB11Event } from '../onebot11/server/postOB11Event'
|
import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
||||||
import { ob11ReverseWebsockets } from '../onebot11/server/ws/ReverseWebsocket'
|
import { ob11ReverseWebsockets } from '../onebot11/server/ws/ReverseWebsocket'
|
||||||
import { OB11GroupAdminNoticeEvent } from '../onebot11/event/notice/OB11GroupAdminNoticeEvent'
|
import { OB11GroupAdminNoticeEvent } from '../onebot11/event/notice/OB11GroupAdminNoticeEvent'
|
||||||
import { OB11GroupRequestEvent } from '../onebot11/event/request/OB11GroupRequest'
|
import { OB11GroupRequestEvent } from '../onebot11/event/request/OB11GroupRequest'
|
||||||
@@ -48,13 +48,15 @@ import { dbUtil } from '../common/db'
|
|||||||
import { setConfig } from './setConfig'
|
import { setConfig } from './setConfig'
|
||||||
import { NTQQUserApi } from '../ntqqapi/api/user'
|
import { NTQQUserApi } from '../ntqqapi/api/user'
|
||||||
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
import { NTQQGroupApi } from '../ntqqapi/api/group'
|
||||||
import { crychic } from '../ntqqapi/external/crychic'
|
import { crychic } from '../ntqqapi/native/crychic'
|
||||||
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from '../onebot11/event/notice/OB11PokeEvent'
|
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from '../onebot11/event/notice/OB11PokeEvent'
|
||||||
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade'
|
||||||
import { log } from '../common/utils/log'
|
import { log } from '../common/utils/log'
|
||||||
import { getConfigUtil } from '../common/config'
|
import { getConfigUtil } from '../common/config'
|
||||||
import { checkFfmpeg } from '../common/utils/video'
|
import { checkFfmpeg } from '../common/utils/video'
|
||||||
import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
||||||
|
import '../ntqqapi/native/wrapper'
|
||||||
|
import { sentMessages } from '@/ntqqapi/api'
|
||||||
|
|
||||||
let running = false
|
let running = false
|
||||||
|
|
||||||
@@ -141,7 +143,8 @@ function onLoad() {
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
log('保存设置失败', e.stack)
|
log('保存设置失败', e.stack)
|
||||||
})
|
})
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -168,12 +171,8 @@ function onLoad() {
|
|||||||
|
|
||||||
OB11Constructor.message(message)
|
OB11Constructor.message(message)
|
||||||
.then((msg) => {
|
.then((msg) => {
|
||||||
if (debug) {
|
if (!debug && msg.message.length === 0) {
|
||||||
msg.raw = message
|
return
|
||||||
} else {
|
|
||||||
if (msg.message.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
||||||
if (isSelfMsg && !reportSelfMessage) {
|
if (isSelfMsg && !reportSelfMessage) {
|
||||||
@@ -182,26 +181,27 @@ function onLoad() {
|
|||||||
if (isSelfMsg) {
|
if (isSelfMsg) {
|
||||||
msg.target_id = parseInt(message.peerUin)
|
msg.target_id = parseInt(message.peerUin)
|
||||||
}
|
}
|
||||||
postOB11Event(msg)
|
postOb11Event(msg)
|
||||||
// log("post msg", msg)
|
// log("post msg", msg)
|
||||||
})
|
})
|
||||||
.catch((e) => log('constructMessage error: ', e.stack.toString()))
|
.catch((e) => log('constructMessage error: ', e.stack.toString()))
|
||||||
OB11Constructor.GroupEvent(message).then((groupEvent) => {
|
OB11Constructor.GroupEvent(message).then((groupEvent) => {
|
||||||
if (groupEvent) {
|
if (groupEvent) {
|
||||||
// log("post group event", groupEvent);
|
// log("post group event", groupEvent);
|
||||||
postOB11Event(groupEvent)
|
postOb11Event(groupEvent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
OB11Constructor.FriendAddEvent(message).then((friendAddEvent) => {
|
OB11Constructor.FriendAddEvent(message).then((friendAddEvent) => {
|
||||||
if (friendAddEvent) {
|
if (friendAddEvent) {
|
||||||
// log("post friend add event", friendAddEvent);
|
// log("post friend add event", friendAddEvent);
|
||||||
postOB11Event(friendAddEvent)
|
postOb11Event(friendAddEvent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startReceiveHook() {
|
async function startReceiveHook() {
|
||||||
|
startHook().then()
|
||||||
if (getConfigUtil().getConfig().enablePoke) {
|
if (getConfigUtil().getConfig().enablePoke) {
|
||||||
crychic.loadNode()
|
crychic.loadNode()
|
||||||
crychic.registerPokeHandler((id, isGroup) => {
|
crychic.registerPokeHandler((id, isGroup) => {
|
||||||
@@ -209,10 +209,11 @@ function onLoad() {
|
|||||||
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent
|
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
pokeEvent = new OB11GroupPokeEvent(parseInt(id))
|
pokeEvent = new OB11GroupPokeEvent(parseInt(id))
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
pokeEvent = new OB11FriendPokeEvent(parseInt(id))
|
pokeEvent = new OB11FriendPokeEvent(parseInt(id))
|
||||||
}
|
}
|
||||||
postOB11Event(pokeEvent)
|
postOb11Event(pokeEvent)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
registerReceiveHook<{
|
registerReceiveHook<{
|
||||||
@@ -224,39 +225,32 @@ function onLoad() {
|
|||||||
log('report message error: ', e.stack.toString())
|
log('report message error: ', e.stack.toString())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
const recallMsgIds: string[] = [] // 避免重复上报
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("message update", message)
|
const sentMessage = sentMessages[message.msgId]
|
||||||
|
if (sentMessage){
|
||||||
|
Object.assign(sentMessage, message)
|
||||||
|
}
|
||||||
|
log('message update', message.msgId, message)
|
||||||
if (message.recallTime != '0') {
|
if (message.recallTime != '0') {
|
||||||
//todo: 这个判断方法不太好,应该使用灰色消息元素来判断
|
if (recallMsgIds.includes(message.msgId)) {
|
||||||
// 撤回消息上报
|
continue
|
||||||
|
}
|
||||||
|
recallMsgIds.push(message.msgId)
|
||||||
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
const oriMessage = await dbUtil.getMsgByLongId(message.msgId)
|
||||||
if (!oriMessage) {
|
if (!oriMessage) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
oriMessage.recallTime = message.recallTime
|
oriMessage.recallTime = message.recallTime
|
||||||
dbUtil.updateMsg(oriMessage).then()
|
dbUtil.updateMsg(oriMessage).then()
|
||||||
if (message.chatType == ChatType.friend) {
|
message.msgShortId = oriMessage.msgShortId
|
||||||
const friendRecallEvent = new OB11FriendRecallNoticeEvent(
|
OB11Constructor.RecallEvent(message).then((recallEvent) => {
|
||||||
parseInt(message.senderUin),
|
if (recallEvent) {
|
||||||
oriMessage.msgShortId,
|
log('post recall event', recallEvent)
|
||||||
)
|
postOb11Event(recallEvent)
|
||||||
postOB11Event(friendRecallEvent)
|
|
||||||
} else if (message.chatType == ChatType.group) {
|
|
||||||
let operatorId = message.senderUin
|
|
||||||
for (const element of message.elements) {
|
|
||||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid
|
|
||||||
const operator = await getGroupMember(message.peerUin, operatorUid)
|
|
||||||
operatorId = operator.uin
|
|
||||||
}
|
}
|
||||||
const groupRecallEvent = new OB11GroupRecallNoticeEvent(
|
})
|
||||||
parseInt(message.peerUin),
|
|
||||||
parseInt(message.senderUin),
|
|
||||||
parseInt(operatorId),
|
|
||||||
oriMessage.msgShortId,
|
|
||||||
)
|
|
||||||
postOB11Event(groupRecallEvent)
|
|
||||||
}
|
|
||||||
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
// 不让入库覆盖原来消息,不然就获取不到撤回的消息内容了
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -311,7 +305,11 @@ function onLoad() {
|
|||||||
// if (notify.user2.uid) {
|
// if (notify.user2.uid) {
|
||||||
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
// member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
|
||||||
// }
|
// }
|
||||||
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET_OTHER].includes(notify.type)) {
|
if (
|
||||||
|
[GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET_OTHER].includes(
|
||||||
|
notify.type,
|
||||||
|
)
|
||||||
|
) {
|
||||||
const member1 = await getGroupMember(notify.group.groupCode, notify.user1.uid)
|
const member1 = await getGroupMember(notify.group.groupCode, notify.user1.uid)
|
||||||
log('有管理员变动通知')
|
log('有管理员变动通知')
|
||||||
refreshGroupMembers(notify.group.groupCode).then()
|
refreshGroupMembers(notify.group.groupCode).then()
|
||||||
@@ -321,13 +319,20 @@ function onLoad() {
|
|||||||
if (member1) {
|
if (member1) {
|
||||||
log('变动管理员获取成功')
|
log('变动管理员获取成功')
|
||||||
groupAdminNoticeEvent.user_id = parseInt(member1.uin)
|
groupAdminNoticeEvent.user_id = parseInt(member1.uin)
|
||||||
groupAdminNoticeEvent.sub_type = [GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET_OTHER].includes(notify.type) ? 'unset' : 'set'
|
groupAdminNoticeEvent.sub_type = [
|
||||||
|
GroupNotifyTypes.ADMIN_UNSET,
|
||||||
|
GroupNotifyTypes.ADMIN_UNSET_OTHER,
|
||||||
|
].includes(notify.type)
|
||||||
|
? 'unset'
|
||||||
|
: 'set'
|
||||||
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
// member1.role = notify.type == GroupNotifyTypes.ADMIN_SET ? GroupMemberRole.admin : GroupMemberRole.normal;
|
||||||
postOB11Event(groupAdminNoticeEvent, true)
|
postOb11Event(groupAdminNoticeEvent, true)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
log('获取群通知的成员信息失败', notify, getGroup(notify.group.groupCode))
|
log('获取群通知的成员信息失败', notify, getGroup(notify.group.groupCode))
|
||||||
}
|
}
|
||||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
}
|
||||||
|
else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
||||||
log('有成员退出通知', notify)
|
log('有成员退出通知', notify)
|
||||||
try {
|
try {
|
||||||
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid)
|
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid)
|
||||||
@@ -345,43 +350,62 @@ function onLoad() {
|
|||||||
parseInt(operatorId),
|
parseInt(operatorId),
|
||||||
subType,
|
subType,
|
||||||
)
|
)
|
||||||
postOB11Event(groupDecreaseEvent, true)
|
postOb11Event(groupDecreaseEvent, true)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('获取群通知的成员信息失败', notify, e.stack.toString())
|
log('获取群通知的成员信息失败', notify, e.stack.toString())
|
||||||
}
|
}
|
||||||
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
|
}
|
||||||
|
else if ([GroupNotifyTypes.JOIN_REQUEST, GroupNotifyTypes.JOIN_REQUEST_BY_INVITED].includes(notify.type)) {
|
||||||
log('有加群请求')
|
log('有加群请求')
|
||||||
let groupRequestEvent = new OB11GroupRequestEvent()
|
let groupRequestEvent = new OB11GroupRequestEvent()
|
||||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode)
|
groupRequestEvent.group_id = parseInt(notify.group.groupCode)
|
||||||
let requestQQ = ''
|
let requestQQ = uidMaps[notify.user1.uid]
|
||||||
try {
|
if (!requestQQ) {
|
||||||
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin
|
try {
|
||||||
} catch (e) {
|
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin
|
||||||
log('获取加群人QQ号失败', e)
|
} catch (e) {
|
||||||
|
log('获取加群人QQ号失败', e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
groupRequestEvent.user_id = parseInt(requestQQ) || 0
|
groupRequestEvent.user_id = parseInt(requestQQ) || 0
|
||||||
groupRequestEvent.sub_type = 'add'
|
groupRequestEvent.sub_type = 'add'
|
||||||
groupRequestEvent.comment = notify.postscript
|
groupRequestEvent.comment = notify.postscript
|
||||||
groupRequestEvent.flag = notify.seq
|
groupRequestEvent.flag = notify.seq
|
||||||
postOB11Event(groupRequestEvent)
|
if (notify.type == GroupNotifyTypes.JOIN_REQUEST_BY_INVITED) {
|
||||||
} else if (notify.type == GroupNotifyTypes.INVITE_ME) {
|
// groupRequestEvent.sub_type = 'invite'
|
||||||
|
let invitorQQ = uidMaps[notify.user2.uid]
|
||||||
|
if (!invitorQQ) {
|
||||||
|
try {
|
||||||
|
let invitor = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))
|
||||||
|
groupRequestEvent.invitor_id = parseInt(invitor.uin)
|
||||||
|
} catch (e) {
|
||||||
|
groupRequestEvent.invitor_id = 0
|
||||||
|
log('获取邀请人QQ号失败', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
postOb11Event(groupRequestEvent)
|
||||||
|
}
|
||||||
|
else if (notify.type == GroupNotifyTypes.INVITE_ME) {
|
||||||
log('收到邀请我加群通知')
|
log('收到邀请我加群通知')
|
||||||
let groupInviteEvent = new OB11GroupRequestEvent()
|
let groupInviteEvent = new OB11GroupRequestEvent()
|
||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode)
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode)
|
||||||
let user_id = (await getFriend(notify.user2.uid))?.uin
|
let user_id = uidMaps[notify.user2.uid]
|
||||||
if (!user_id) {
|
if (!user_id) {
|
||||||
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||||
}
|
}
|
||||||
groupInviteEvent.user_id = parseInt(user_id)
|
groupInviteEvent.user_id = parseInt(user_id)
|
||||||
groupInviteEvent.sub_type = 'invite'
|
groupInviteEvent.sub_type = 'invite'
|
||||||
|
// groupInviteEvent.invitor_id = parseInt(user_id)
|
||||||
groupInviteEvent.flag = notify.seq
|
groupInviteEvent.flag = notify.seq
|
||||||
postOB11Event(groupInviteEvent)
|
postOb11Event(groupInviteEvent)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('解析群通知失败', e.stack.toString())
|
log('解析群通知失败', e.stack.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (payload.doubt) {
|
}
|
||||||
|
else if (payload.doubt) {
|
||||||
// 可能有群管理员变动
|
// 可能有群管理员变动
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -401,7 +425,7 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
friendRequestEvent.flag = flag
|
friendRequestEvent.flag = flag
|
||||||
friendRequestEvent.comment = req.extWords
|
friendRequestEvent.comment = req.extWords
|
||||||
postOB11Event(friendRequestEvent)
|
postOb11Event(friendRequestEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -418,8 +442,33 @@ function onLoad() {
|
|||||||
uidMaps[value] = key
|
uidMaps[value] = key
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
startReceiveHook().then()
|
try{
|
||||||
NTQQGroupApi.getGroups(true).then()
|
log('start get groups')
|
||||||
|
const _groups = await NTQQGroupApi.getGroups()
|
||||||
|
log('_groups', _groups)
|
||||||
|
await Promise.all(
|
||||||
|
_groups.map(async (group) => {
|
||||||
|
try {
|
||||||
|
const members = await NTQQGroupApi.getGroupMembers(group.groupCode)
|
||||||
|
group.members = members
|
||||||
|
groups.push(group)
|
||||||
|
} catch (e) {
|
||||||
|
log('获取群成员失败', e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
log('获取群列表失败', e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
log('start activate group member info')
|
||||||
|
NTQQGroupApi.activateMemberInfoChange().then().catch(log)
|
||||||
|
NTQQGroupApi.activateMemberListChange().then().catch(log)
|
||||||
|
startReceiveHook().then()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
if (config.ob11.enableHttp) {
|
if (config.ob11.enableHttp) {
|
||||||
ob11HTTPServer.start(config.ob11.httpPort)
|
ob11HTTPServer.start(config.ob11.httpPort)
|
||||||
@@ -474,7 +523,8 @@ function onLoad() {
|
|||||||
|
|
||||||
getUserNick().then()
|
getUserNick().then()
|
||||||
start().then()
|
start().then()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
setTimeout(init, 1000)
|
setTimeout(init, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,26 +7,31 @@ import {
|
|||||||
ChatCacheList,
|
ChatCacheList,
|
||||||
ChatCacheListItemBasic,
|
ChatCacheListItemBasic,
|
||||||
ChatType,
|
ChatType,
|
||||||
ElementType, IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT, RawMessage,
|
ElementType,
|
||||||
|
IMAGE_HTTP_HOST,
|
||||||
|
IMAGE_HTTP_HOST_NT, PicElement,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { ReceiveCmdS } from '../hook'
|
import { ReceiveCmdS } from '../hook'
|
||||||
import { log } from '../../common/utils'
|
import { log } from '@/common/utils'
|
||||||
import https from 'https'
|
import { rkeyManager } from '@/ntqqapi/api/rkey'
|
||||||
import { sleep } from '../../common/utils'
|
import { wrapperApi } from '@/ntqqapi/native/wrapper'
|
||||||
import { hookApi } from '../external/moehook/hook'
|
import { Peer } from '@/ntqqapi/api/msg'
|
||||||
|
|
||||||
let privateImageRKey = ''
|
|
||||||
let groupImageRKey = ''
|
|
||||||
let lastGetPrivateRKeyTime = 0
|
|
||||||
let lastGetGroupRKeyTime = 0
|
|
||||||
const rkeyExpireTime = 1000 * 60 * 30
|
|
||||||
|
|
||||||
export class NTQQFileApi {
|
export class NTQQFileApi {
|
||||||
|
static async getVideoUrl(peer: Peer, msgId: string, elementId: string): Promise<string> {
|
||||||
|
return (await wrapperApi.NodeIQQNTWrapperSession.getRichMediaService().getVideoPlayUrlV2(peer,
|
||||||
|
msgId,
|
||||||
|
elementId,
|
||||||
|
0,
|
||||||
|
{ downSourceType: 1, triggerType: 1 })).urlResult?.domainUrl[0]?.url;
|
||||||
|
}
|
||||||
static async getFileType(filePath: string) {
|
static async getFileType(filePath: string) {
|
||||||
return await callNTQQApi<{ ext: string }>({
|
return await callNTQQApi<{ ext: string }>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath],
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_TYPE,
|
||||||
|
args: [filePath],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,16 +47,20 @@ export class NTQQFileApi {
|
|||||||
return await callNTQQApi<string>({
|
return await callNTQQApi<string>({
|
||||||
className: NTQQApiClass.FS_API,
|
className: NTQQApiClass.FS_API,
|
||||||
methodName: NTQQApiMethod.FILE_COPY,
|
methodName: NTQQApiMethod.FILE_COPY,
|
||||||
args: [{
|
args: [
|
||||||
fromPath: filePath,
|
{
|
||||||
toPath: destPath,
|
fromPath: filePath,
|
||||||
}],
|
toPath: destPath,
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getFileSize(filePath: string) {
|
static async getFileSize(filePath: string) {
|
||||||
return await callNTQQApi<number>({
|
return await callNTQQApi<number>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath],
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_SIZE,
|
||||||
|
args: [filePath],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,18 +79,20 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
const mediaPath = await callNTQQApi<string>({
|
const mediaPath = await callNTQQApi<string>({
|
||||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||||
args: [{
|
args: [
|
||||||
path_info: {
|
{
|
||||||
md5HexStr: md5,
|
path_info: {
|
||||||
fileName: fileName,
|
md5HexStr: md5,
|
||||||
elementType: elementType,
|
fileName: fileName,
|
||||||
elementSubType,
|
elementType: elementType,
|
||||||
thumbSize: 0,
|
elementSubType,
|
||||||
needCreate: true,
|
thumbSize: 0,
|
||||||
downloadType: 1,
|
needCreate: true,
|
||||||
file_uuid: '',
|
downloadType: 1,
|
||||||
|
file_uuid: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}],
|
],
|
||||||
})
|
})
|
||||||
log('media path', mediaPath)
|
log('media path', mediaPath)
|
||||||
await NTQQFileApi.copyFile(filePath, mediaPath)
|
await NTQQFileApi.copyFile(filePath, mediaPath)
|
||||||
@@ -95,7 +106,15 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string, force: boolean = false) {
|
static async downloadMedia(
|
||||||
|
msgId: string,
|
||||||
|
chatType: ChatType,
|
||||||
|
peerUid: string,
|
||||||
|
elementId: string,
|
||||||
|
thumbPath: string,
|
||||||
|
sourcePath: string,
|
||||||
|
force: boolean = false,
|
||||||
|
) {
|
||||||
// 用于下载收到的消息中的图片等
|
// 用于下载收到的消息中的图片等
|
||||||
if (sourcePath && fs.existsSync(sourcePath)) {
|
if (sourcePath && fs.existsSync(sourcePath)) {
|
||||||
if (force) {
|
if (force) {
|
||||||
@@ -126,7 +145,7 @@ export class NTQQFileApi {
|
|||||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||||
args: apiParams,
|
args: apiParams,
|
||||||
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
||||||
cmdCB: (payload: { notifyInfo: { filePath: string, msgId: string } }) => {
|
cmdCB: (payload: { notifyInfo: { filePath: string; msgId: string } }) => {
|
||||||
log('media 下载完成判断', payload.notifyInfo.msgId, msgId)
|
log('media 下载完成判断', payload.notifyInfo.msgId, msgId)
|
||||||
return payload.notifyInfo.msgId == msgId
|
return payload.notifyInfo.msgId == msgId
|
||||||
},
|
},
|
||||||
@@ -135,21 +154,19 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getImageSize(filePath: string) {
|
static async getImageSize(filePath: string) {
|
||||||
return await callNTQQApi<{ width: number, height: number }>({
|
return await callNTQQApi<{ width: number; height: number }>({
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath],
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.IMAGE_SIZE,
|
||||||
|
args: [filePath],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getImageUrl(msg: RawMessage) {
|
static async getImageUrl(picElement: PicElement, chatType: ChatType) {
|
||||||
const isPrivateImage = msg.chatType !== ChatType.group
|
const isPrivateImage = chatType !== ChatType.group
|
||||||
const msgElement = msg.elements.find(e => !!e.picElement)
|
const url = picElement.originImageUrl // 没有域名
|
||||||
if (!msgElement) {
|
const md5HexStr = picElement.md5HexStr
|
||||||
return ''
|
const fileMd5 = picElement.md5HexStr
|
||||||
}
|
const fileUuid = picElement.fileUuid
|
||||||
const url = msgElement.picElement.originImageUrl // 没有域名
|
|
||||||
const md5HexStr = msgElement.picElement.md5HexStr
|
|
||||||
const fileMd5 = msgElement.picElement.md5HexStr
|
|
||||||
const fileUuid = msgElement.picElement.fileUuid
|
|
||||||
if (url) {
|
if (url) {
|
||||||
if (url.startsWith('/download')) {
|
if (url.startsWith('/download')) {
|
||||||
// console.log('rkey', rkey);
|
// console.log('rkey', rkey);
|
||||||
@@ -157,70 +174,9 @@ export class NTQQFileApi {
|
|||||||
return IMAGE_HTTP_HOST_NT + url
|
return IMAGE_HTTP_HOST_NT + url
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hookApi.isAvailable()) {
|
const rkeyData = await rkeyManager.getRkey();
|
||||||
log('hookApi is not available')
|
const existsRKey = isPrivateImage ? rkeyData.private_rkey : rkeyData.group_rkey;
|
||||||
return ''
|
return IMAGE_HTTP_HOST_NT + url + `${existsRKey}`
|
||||||
}
|
|
||||||
|
|
||||||
const saveRKey = (rkey: string) => {
|
|
||||||
if (isPrivateImage) {
|
|
||||||
privateImageRKey = rkey
|
|
||||||
lastGetPrivateRKeyTime = Date.now()
|
|
||||||
} else {
|
|
||||||
groupImageRKey = rkey
|
|
||||||
lastGetGroupRKeyTime = Date.now()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const refreshRKey = async () => {
|
|
||||||
log('获取图片rkey...')
|
|
||||||
NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, msgElement.elementId, '', msgElement.picElement.sourcePath, false).then().catch(() => {
|
|
||||||
})
|
|
||||||
await sleep(1000)
|
|
||||||
const _rkey = hookApi.getRKey()
|
|
||||||
if (_rkey) {
|
|
||||||
const imageUrl = IMAGE_HTTP_HOST_NT + url + _rkey
|
|
||||||
// 验证_rkey是否有效
|
|
||||||
try {
|
|
||||||
await new Promise((res, rej) => {
|
|
||||||
https.get(imageUrl, response => {
|
|
||||||
if (response.statusCode !== 200) {
|
|
||||||
rej('图片rkey获取失败')
|
|
||||||
} else {
|
|
||||||
res(response)
|
|
||||||
}
|
|
||||||
}).on('error', e => {
|
|
||||||
rej(e)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
log('图片rkey获取成功', _rkey)
|
|
||||||
saveRKey(_rkey)
|
|
||||||
return _rkey
|
|
||||||
}catch (e) {
|
|
||||||
log('图片rkey有误', imageUrl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const existsRKey = isPrivateImage ? privateImageRKey : groupImageRKey
|
|
||||||
const lastGetRKeyTime = isPrivateImage ? lastGetPrivateRKeyTime : lastGetGroupRKeyTime
|
|
||||||
if ((Date.now() - lastGetRKeyTime > rkeyExpireTime)) {
|
|
||||||
// rkey过期
|
|
||||||
const newRKey = await refreshRKey()
|
|
||||||
if (newRKey) {
|
|
||||||
return IMAGE_HTTP_HOST_NT + url + `${newRKey}`
|
|
||||||
} else {
|
|
||||||
log('图片rkey获取失败', url)
|
|
||||||
if(existsRKey){
|
|
||||||
return IMAGE_HTTP_HOST_NT + url + `${existsRKey}`
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 使用未过期的rkey
|
|
||||||
if (existsRKey) {
|
|
||||||
return IMAGE_HTTP_HOST_NT + url + `${existsRKey}`
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 老的图片url,不需要rkey
|
// 老的图片url,不需要rkey
|
||||||
return IMAGE_HTTP_HOST + url
|
return IMAGE_HTTP_HOST + url
|
||||||
@@ -229,47 +185,58 @@ export class NTQQFileApi {
|
|||||||
// 没有url,需要自己拼接
|
// 没有url,需要自己拼接
|
||||||
return `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${(fileMd5 || md5HexStr)!.toUpperCase()}/0`
|
return `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${(fileMd5 || md5HexStr)!.toUpperCase()}/0`
|
||||||
}
|
}
|
||||||
log('图片url获取失败', msg)
|
log('图片url获取失败', picElement)
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQFileCacheApi {
|
export class NTQQFileCacheApi {
|
||||||
static async setCacheSilentScan(isSilent: boolean = true) {
|
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||||
args: [{
|
args: [
|
||||||
isSilent,
|
{
|
||||||
}, null],
|
isSilent,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static getCacheSessionPathList() {
|
static getCacheSessionPathList() {
|
||||||
return callNTQQApi<{
|
return callNTQQApi<
|
||||||
key: string,
|
{
|
||||||
value: string
|
key: string
|
||||||
}[]>({
|
value: string
|
||||||
|
}[]
|
||||||
|
>({
|
||||||
className: NTQQApiClass.OS_API,
|
className: NTQQApiClass.OS_API,
|
||||||
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||||
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
return callNTQQApi<any>({
|
||||||
|
// TODO: 目前还不知道真正的返回值是什么
|
||||||
methodName: NTQQApiMethod.CACHE_CLEAR,
|
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||||
args: [{
|
args: [
|
||||||
keys: cacheKeys,
|
{
|
||||||
}, null],
|
keys: cacheKeys,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static addCacheScannedPaths(pathMap: object = {}) {
|
static addCacheScannedPaths(pathMap: object = {}) {
|
||||||
return callNTQQApi<GeneralCallResult>({
|
return callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||||
args: [{
|
args: [
|
||||||
pathMap: { ...pathMap },
|
{
|
||||||
}, null],
|
pathMap: { ...pathMap },
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,14 +270,18 @@ export class NTQQFileCacheApi {
|
|||||||
return new Promise<ChatCacheList>((res, rej) => {
|
return new Promise<ChatCacheList>((res, rej) => {
|
||||||
callNTQQApi<ChatCacheList>({
|
callNTQQApi<ChatCacheList>({
|
||||||
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
||||||
args: [{
|
args: [
|
||||||
chatType: type,
|
{
|
||||||
pageSize,
|
chatType: type,
|
||||||
order: 1,
|
pageSize,
|
||||||
pageIndex,
|
order: 1,
|
||||||
}, null],
|
pageIndex,
|
||||||
}).then(list => res(list))
|
},
|
||||||
.catch(e => rej(e))
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((list) => res(list))
|
||||||
|
.catch((e) => rej(e))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,24 +290,29 @@ export class NTQQFileCacheApi {
|
|||||||
|
|
||||||
return callNTQQApi<CacheFileList>({
|
return callNTQQApi<CacheFileList>({
|
||||||
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
||||||
args: [{
|
args: [
|
||||||
fileType: fileType,
|
{
|
||||||
restart: true,
|
fileType: fileType,
|
||||||
pageSize: pageSize,
|
restart: true,
|
||||||
order: 1,
|
pageSize: pageSize,
|
||||||
lastRecord: _lastRecord,
|
order: 1,
|
||||||
}, null],
|
lastRecord: _lastRecord,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||||
args: [{
|
args: [
|
||||||
chats,
|
{
|
||||||
fileKeys,
|
chats,
|
||||||
}, null],
|
fileKeys,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,15 +7,48 @@ import { log } from '../../common/utils/log'
|
|||||||
import { NTQQWindowApi, NTQQWindows } from './window'
|
import { NTQQWindowApi, NTQQWindows } from './window'
|
||||||
|
|
||||||
export class NTQQGroupApi {
|
export class NTQQGroupApi {
|
||||||
|
|
||||||
|
static async activateMemberListChange(){
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.ACTIVATE_MEMBER_LIST_CHANGE,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
args: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async activateMemberInfoChange(){
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.ACTIVATE_MEMBER_INFO_CHANGE,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
args: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getGroupAllInfo(groupCode: string, source: number=4){
|
||||||
|
return await callNTQQApi<GeneralCallResult & Group>({
|
||||||
|
methodName: NTQQApiMethod.GET_GROUP_ALL_INFO,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode,
|
||||||
|
source
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
static async getGroups(forced = false) {
|
static async getGroups(forced = false) {
|
||||||
let cbCmd = ReceiveCmdS.GROUPS
|
// let cbCmd = ReceiveCmdS.GROUPS
|
||||||
if (process.platform != 'win32') {
|
// if (process.platform != 'win32') {
|
||||||
cbCmd = ReceiveCmdS.GROUPS_STORE
|
// cbCmd = ReceiveCmdS.GROUPS_STORE
|
||||||
}
|
// }
|
||||||
const result = await callNTQQApi<{
|
const result = await callNTQQApi<{
|
||||||
updateType: number
|
updateType: number
|
||||||
groupList: Group[]
|
groupList: Group[]
|
||||||
}>({ methodName: NTQQApiMethod.GROUPS, args: [{ force_update: forced }, undefined], cbCmd })
|
}>({
|
||||||
|
methodName: NTQQApiMethod.GROUPS,
|
||||||
|
args: [{ force_update: forced }, undefined],
|
||||||
|
cbCmd: [ReceiveCmdS.GROUPS, ReceiveCmdS.GROUPS_STORE],
|
||||||
|
afterFirstCmd: false,
|
||||||
|
})
|
||||||
|
log('get groups result', result)
|
||||||
return result.groupList
|
return result.groupList
|
||||||
}
|
}
|
||||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
||||||
@@ -58,6 +91,19 @@ export class NTQQGroupApi {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static async getGroupMembersInfo(groupCode: string, uids: string[], forceUpdate: boolean=false) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.GROUP_MEMBERS_INFO,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
forceUpdate,
|
||||||
|
groupCode,
|
||||||
|
uids
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
static async getGroupNotifies() {
|
static async getGroupNotifies() {
|
||||||
// 获取管理员变更
|
// 获取管理员变更
|
||||||
// 加群通知,退出通知,需要管理员权限
|
// 加群通知,退出通知,需要管理员权限
|
||||||
@@ -74,7 +120,11 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
static async getGroupIgnoreNotifies() {
|
static async getGroupIgnoreNotifies() {
|
||||||
await NTQQGroupApi.getGroupNotifies()
|
await NTQQGroupApi.getGroupNotifies()
|
||||||
return await NTQQWindowApi.openWindow(NTQQWindows.GroupNotifyFilterWindow, [], ReceiveCmdS.GROUP_NOTIFY)
|
return await NTQQWindowApi.openWindow<GeneralCallResult & GroupNotifies>(
|
||||||
|
NTQQWindows.GroupNotifyFilterWindow,
|
||||||
|
[],
|
||||||
|
ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
@@ -154,7 +204,8 @@ export class NTQQGroupApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
NTQQGroupApi.activateMemberListChange().then().catch(log)
|
||||||
|
const res = await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@@ -165,6 +216,8 @@ export class NTQQGroupApi {
|
|||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
NTQQGroupApi.getGroupMembersInfo(groupQQ, [memberUid], true).then().catch(log)
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
@@ -7,7 +7,9 @@ import { log } from '../../common/utils/log'
|
|||||||
import { sleep } from '../../common/utils/helper'
|
import { sleep } from '../../common/utils/helper'
|
||||||
import { isQQ998 } from '../../common/utils'
|
import { isQQ998 } from '../../common/utils'
|
||||||
|
|
||||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {} // peerUid: callbackFunnc
|
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {} // peerUid: callbackFunc
|
||||||
|
|
||||||
|
export let sentMessages: Record<string, RawMessage> = {} // msgId: RawMessage
|
||||||
|
|
||||||
export interface Peer {
|
export interface Peer {
|
||||||
chatType: ChatType
|
chatType: ChatType
|
||||||
@@ -15,11 +17,83 @@ export interface Peer {
|
|||||||
guildId?: ''
|
guildId?: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 10000) {
|
||||||
|
// 等待上一个相同的peer发送完
|
||||||
|
const peerUid = peer.peerUid
|
||||||
|
let checkLastSendUsingTime = 0
|
||||||
|
const waitLastSend = async () => {
|
||||||
|
if (checkLastSendUsingTime > timeout) {
|
||||||
|
throw '发送超时'
|
||||||
|
}
|
||||||
|
let lastSending = sendMessagePool[peer.peerUid]
|
||||||
|
if (lastSending) {
|
||||||
|
// log("有正在发送的消息,等待中...")
|
||||||
|
await sleep(500)
|
||||||
|
checkLastSendUsingTime += 500
|
||||||
|
return await waitLastSend()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await waitLastSend()
|
||||||
|
|
||||||
|
let sentMessage: RawMessage = null
|
||||||
|
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||||
|
delete sendMessagePool[peerUid]
|
||||||
|
sentMessage = rawMessage
|
||||||
|
sentMessages[rawMessage.msgId] = rawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkSendCompleteUsingTime = 0
|
||||||
|
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||||
|
if (sentMessage) {
|
||||||
|
if (waitComplete) {
|
||||||
|
if (sentMessage.sendStatus == 2) {
|
||||||
|
delete sentMessages[sentMessage.msgId]
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
delete sentMessages[sentMessage.msgId]
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
// log(`给${peerUid}发送消息成功`)
|
||||||
|
}
|
||||||
|
checkSendCompleteUsingTime += 500
|
||||||
|
if (checkSendCompleteUsingTime > timeout) {
|
||||||
|
throw '发送超时'
|
||||||
|
}
|
||||||
|
await sleep(500)
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
return checkSendComplete()
|
||||||
|
}
|
||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
|
static enterOrExitAIO(peer: Peer, enter: boolean) {
|
||||||
|
return callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.ENTER_OR_EXIT_AIO,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
"info_list": [
|
||||||
|
{
|
||||||
|
peer,
|
||||||
|
"option": enter ? 1 : 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"send": true
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) {
|
||||||
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
// nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览
|
||||||
// nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid
|
// nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid
|
||||||
// 其实以官方文档为准是最好的,https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
|
// 其实以官方文档为准是最好的,https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
|
||||||
|
emojiId = emojiId.toString()
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.EMOJI_LIKE,
|
methodName: NTQQApiMethod.EMOJI_LIKE,
|
||||||
args: [
|
args: [
|
||||||
@@ -34,6 +108,7 @@ export class NTQQMsgApi {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) {
|
static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) {
|
||||||
return await callNTQQApi<GeneralCallResult & { msgList: RawMessage[] }>({
|
return await callNTQQApi<GeneralCallResult & { msgList: RawMessage[] }>({
|
||||||
methodName: NTQQApiMethod.GET_MULTI_MSG,
|
methodName: NTQQApiMethod.GET_MULTI_MSG,
|
||||||
@@ -48,6 +123,20 @@ export class NTQQMsgApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getMsgBoxInfo(peer: Peer) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.GET_MSG_BOX_INFO,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
contacts: [
|
||||||
|
peer
|
||||||
|
],
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
static async activateChat(peer: Peer) {
|
static async activateChat(peer: Peer) {
|
||||||
// await this.fetchRecentContact();
|
// await this.fetchRecentContact();
|
||||||
// await sleep(500);
|
// await sleep(500);
|
||||||
@@ -56,6 +145,7 @@ export class NTQQMsgApi {
|
|||||||
args: [{ peer, cnt: 20 }, null],
|
args: [{ peer, cnt: 20 }, null],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async activateChatAndGetHistory(peer: Peer) {
|
static async activateChatAndGetHistory(peer: Peer) {
|
||||||
// await this.fetchRecentContact();
|
// await this.fetchRecentContact();
|
||||||
// await sleep(500);
|
// await sleep(500);
|
||||||
@@ -65,6 +155,7 @@ export class NTQQMsgApi {
|
|||||||
args: [{ peer, cnt: 20 }, null],
|
args: [{ peer, cnt: 20 }, null],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
static async getMsgHistory(peer: Peer, msgId: string, count: number) {
|
||||||
// 消息时间从旧到新
|
// 消息时间从旧到新
|
||||||
return await callNTQQApi<GeneralCallResult & { msgList: RawMessage[] }>({
|
return await callNTQQApi<GeneralCallResult & { msgList: RawMessage[] }>({
|
||||||
@@ -80,6 +171,7 @@ export class NTQQMsgApi {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fetchRecentContact() {
|
static async fetchRecentContact() {
|
||||||
await callNTQQApi({
|
await callNTQQApi({
|
||||||
methodName: NTQQApiMethod.RECENT_CONTACT,
|
methodName: NTQQApiMethod.RECENT_CONTACT,
|
||||||
@@ -115,52 +207,7 @@ export class NTQQMsgApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||||
const peerUid = peer.peerUid
|
const waiter = sendWaiter(peer, waitComplete, timeout)
|
||||||
|
|
||||||
// 等待上一个相同的peer发送完
|
|
||||||
let checkLastSendUsingTime = 0
|
|
||||||
const waitLastSend = async () => {
|
|
||||||
if (checkLastSendUsingTime > timeout) {
|
|
||||||
throw '发送超时'
|
|
||||||
}
|
|
||||||
let lastSending = sendMessagePool[peer.peerUid]
|
|
||||||
if (lastSending) {
|
|
||||||
// log("有正在发送的消息,等待中...")
|
|
||||||
await sleep(500)
|
|
||||||
checkLastSendUsingTime += 500
|
|
||||||
return await waitLastSend()
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await waitLastSend()
|
|
||||||
|
|
||||||
let sentMessage: RawMessage = null
|
|
||||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
|
||||||
delete sendMessagePool[peerUid]
|
|
||||||
sentMessage = rawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkSendCompleteUsingTime = 0
|
|
||||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
|
||||||
if (sentMessage) {
|
|
||||||
if (waitComplete) {
|
|
||||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
// log(`给${peerUid}发送消息成功`)
|
|
||||||
}
|
|
||||||
checkSendCompleteUsingTime += 500
|
|
||||||
if (checkSendCompleteUsingTime > timeout) {
|
|
||||||
throw '发送超时'
|
|
||||||
}
|
|
||||||
await sleep(500)
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
callNTQQApi({
|
callNTQQApi({
|
||||||
methodName: NTQQApiMethod.SEND_MSG,
|
methodName: NTQQApiMethod.SEND_MSG,
|
||||||
args: [
|
args: [
|
||||||
@@ -173,11 +220,12 @@ export class NTQQMsgApi {
|
|||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
}).then()
|
}).then()
|
||||||
return await checkSendComplete()
|
return await waiter
|
||||||
}
|
}
|
||||||
|
|
||||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
const waiter = sendWaiter(destPeer, true, 10000)
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
@@ -189,7 +237,8 @@ export class NTQQMsgApi {
|
|||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
})
|
}).then().catch(log)
|
||||||
|
return await waiter
|
||||||
}
|
}
|
||||||
|
|
||||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
59
src/ntqqapi/api/rkey.ts
Normal file
59
src/ntqqapi/api/rkey.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
//远端rkey获取
|
||||||
|
|
||||||
|
import { log } from '@/common/utils'
|
||||||
|
|
||||||
|
interface ServerRkeyData{
|
||||||
|
group_rkey: string;
|
||||||
|
private_rkey: string;
|
||||||
|
expired_time: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RkeyManager {
|
||||||
|
serverUrl: string = '';
|
||||||
|
private rkeyData: ServerRkeyData = {
|
||||||
|
group_rkey: '',
|
||||||
|
private_rkey: '',
|
||||||
|
expired_time: 0
|
||||||
|
};
|
||||||
|
constructor(serverUrl: string) {
|
||||||
|
this.serverUrl = serverUrl;
|
||||||
|
}
|
||||||
|
async getRkey(){
|
||||||
|
if (this.isExpired()) {
|
||||||
|
try {
|
||||||
|
await this.refreshRkey();
|
||||||
|
} catch (e) {
|
||||||
|
log('获取rkey失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.rkeyData;
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpired(): boolean {
|
||||||
|
const now = new Date().getTime() / 1000;
|
||||||
|
// console.log(`now: ${now}, expired_time: ${this.rkeyData.expired_time}`);
|
||||||
|
return now > this.rkeyData.expired_time;
|
||||||
|
}
|
||||||
|
async refreshRkey(): Promise<any> {
|
||||||
|
//刷新rkey
|
||||||
|
this.rkeyData = await this.fetchServerRkey();
|
||||||
|
}
|
||||||
|
async fetchServerRkey(){
|
||||||
|
return new Promise<ServerRkeyData>((resolve, reject) => {
|
||||||
|
fetch(this.serverUrl)
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
return reject(response.statusText); // 请求失败,返回错误信息
|
||||||
|
}
|
||||||
|
return response.json(); // 解析 JSON 格式的响应体
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
resolve(data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const rkeyManager = new RkeyManager('http://napcat-sign.wumiao.wang:2082/rkey');
|
@@ -3,10 +3,20 @@ import { Group, SelfInfo, User } from '../types'
|
|||||||
import { ReceiveCmdS } from '../hook'
|
import { ReceiveCmdS } from '../hook'
|
||||||
import { selfInfo, uidMaps } from '../../common/data'
|
import { selfInfo, uidMaps } from '../../common/data'
|
||||||
import { NTQQWindowApi, NTQQWindows } from './window'
|
import { NTQQWindowApi, NTQQWindows } from './window'
|
||||||
import { isQQ998, log, sleep } from '../../common/utils'
|
import { cacheFunc, isQQ998, log, sleep } from '../../common/utils'
|
||||||
|
import { wrapperApi } from '@/ntqqapi/native/wrapper'
|
||||||
|
import * as https from 'https'
|
||||||
|
import { RequestUtil } from '@/common/utils/request'
|
||||||
|
|
||||||
let userInfoCache: Record<string, User> = {} // uid: User
|
let userInfoCache: Record<string, User> = {} // uid: User
|
||||||
|
|
||||||
|
export interface ClientKeyData extends GeneralCallResult {
|
||||||
|
url: string;
|
||||||
|
keyIndex: string;
|
||||||
|
clientKey: string;
|
||||||
|
expireTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class NTQQUserApi {
|
export class NTQQUserApi {
|
||||||
static async setQQAvatar(filePath: string) {
|
static async setQQAvatar(filePath: string) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
@@ -28,6 +38,7 @@ export class NTQQUserApi {
|
|||||||
timeoutSecond: 2,
|
timeoutSecond: 2,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getUserInfo(uid: string) {
|
static async getUserInfo(uid: string) {
|
||||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
||||||
methodName: NTQQApiMethod.USER_INFO,
|
methodName: NTQQApiMethod.USER_INFO,
|
||||||
@@ -36,9 +47,13 @@ export class NTQQUserApi {
|
|||||||
})
|
})
|
||||||
return result.profiles.get(uid)
|
return result.profiles.get(uid)
|
||||||
}
|
}
|
||||||
static async getUserDetailInfo(uid: string, getLevel = false) {
|
|
||||||
|
static async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) {
|
||||||
// this.getUserInfo(uid);
|
// this.getUserInfo(uid);
|
||||||
let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
|
let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
|
||||||
|
if (!withBizInfo) {
|
||||||
|
methodName = NTQQApiMethod.USER_DETAIL_INFO
|
||||||
|
}
|
||||||
const fetchInfo = async () => {
|
const fetchInfo = async () => {
|
||||||
const result = await callNTQQApi<{ info: User }>({
|
const result = await callNTQQApi<{ info: User }>({
|
||||||
methodName,
|
methodName,
|
||||||
@@ -84,64 +99,42 @@ export class NTQQUserApi {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
static async getSkey(groupName: string, groupCode: string): Promise<{ data: string }> {
|
static async getQzoneCookies() {
|
||||||
return await NTQQWindowApi.openWindow<{ data: string }>(
|
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + (await this.getClientKey()).clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27'
|
||||||
NTQQWindows.GroupHomeWorkWindow,
|
let cookies: { [key: string]: string; } = {};
|
||||||
[
|
try {
|
||||||
{
|
cookies = await RequestUtil.HttpsGetCookies(requestUrl);
|
||||||
groupName,
|
} catch (e: any) {
|
||||||
groupCode,
|
log('获取QZone Cookies失败', e)
|
||||||
source: 'funcbar',
|
cookies = {}
|
||||||
},
|
}
|
||||||
],
|
return cookies;
|
||||||
ReceiveCmdS.SKEY_UPDATE,
|
}
|
||||||
1,
|
static async getSkey(): Promise<string> {
|
||||||
)
|
const clientKeyData = await this.getClientKey()
|
||||||
// return await callNTQQApi<string>({
|
if (clientKeyData.result !== 0) {
|
||||||
// className: NTQQApiClass.GROUP_HOME_WORK,
|
throw new Error('获取clientKey失败')
|
||||||
// methodName: NTQQApiMethod.UPDATE_SKEY,
|
}
|
||||||
// args: [
|
const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin
|
||||||
// {
|
+ '&clientkey=' + clientKeyData.clientKey
|
||||||
// domain: "qun.qq.com"
|
+ '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex;
|
||||||
// }
|
return (await RequestUtil.HttpsGetCookies(url))?.skey;
|
||||||
// ]
|
|
||||||
// })
|
|
||||||
// return await callNTQQApi<GeneralCallResult>({
|
|
||||||
// methodName: NTQQApiMethod.GET_SKEY,
|
|
||||||
// args: [
|
|
||||||
// {
|
|
||||||
// "domains": [
|
|
||||||
// "qzone.qq.com",
|
|
||||||
// "qlive.qq.com",
|
|
||||||
// "qun.qq.com",
|
|
||||||
// "gamecenter.qq.com",
|
|
||||||
// "vip.qq.com",
|
|
||||||
// "qianbao.qq.com",
|
|
||||||
// "qidian.qq.com"
|
|
||||||
// ],
|
|
||||||
// "isForNewPCQQ": false
|
|
||||||
// },
|
|
||||||
// null
|
|
||||||
// ]
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getCookie(group: Group) {
|
@cacheFunc(60 * 30 * 1000)
|
||||||
let cookies = await this.getCookieWithoutSkey()
|
static async getCookies(domain: string) {
|
||||||
let skey = ''
|
if (domain.endsWith("qzone.qq.com")) {
|
||||||
for (let i = 0; i < 2; i++) {
|
let data = (await NTQQUserApi.getQzoneCookies());
|
||||||
skey = (await this.getSkey(group.groupName, group.groupCode)).data
|
const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
|
||||||
skey = skey.trim()
|
return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue };
|
||||||
if (skey) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
await sleep(1000)
|
|
||||||
}
|
}
|
||||||
if (!skey) {
|
const skey = await this.getSkey();
|
||||||
throw new Error('获取skey失败')
|
const pskey = (await this.getPSkey([domain])).get(domain);
|
||||||
|
if (!pskey || !skey) {
|
||||||
|
throw new Error('获取Cookies失败')
|
||||||
}
|
}
|
||||||
const bkn = NTQQUserApi.genBkn(skey)
|
const bkn = NTQQUserApi.genBkn(skey)
|
||||||
cookies = cookies.replace('skey=;', `skey=${skey};`)
|
const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
|
||||||
return { cookies, bkn }
|
return { cookies, bkn }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,4 +149,17 @@ export class NTQQUserApi {
|
|||||||
|
|
||||||
return (hash & 0x7fffffff).toString()
|
return (hash & 0x7fffffff).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getPSkey(domains: string[]): Promise<Map<string, string>> {
|
||||||
|
const res = await wrapperApi.NodeIQQNTWrapperSession.getTipOffService().getPskey(domains, true)
|
||||||
|
if (res.result !== 0) {
|
||||||
|
throw new Error(`获取Pskey失败: ${res.errMsg}`)
|
||||||
|
}
|
||||||
|
return res.domainPskeyMap
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getClientKey(): Promise<ClientKeyData> {
|
||||||
|
return await wrapperApi.NodeIQQNTWrapperSession.getTicketService().forceFetchClientKey('')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,76 +1,366 @@
|
|||||||
import { groups } from '../../common/data'
|
import { WebGroupData, groups, selfInfo } from '@/common/data';
|
||||||
import { log } from '../../common/utils'
|
import { log } from '@/common/utils/log';
|
||||||
import { NTQQUserApi } from './user'
|
import { NTQQUserApi } from './user';
|
||||||
|
import { RequestUtil } from '@/common/utils/request';
|
||||||
export class WebApi {
|
export enum WebHonorType {
|
||||||
private static bkn: string
|
ALL = 'all',
|
||||||
private static skey: string
|
TALKACTIVE = 'talkative',
|
||||||
private static pskey: string
|
PERFROMER = 'performer',
|
||||||
private static cookie: string
|
LEGEND = 'legend',
|
||||||
private defaultHeaders: Record<string, string> = {
|
STORONGE_NEWBI = 'strong_newbie',
|
||||||
'User-Agent': 'QQ/8.9.28.635 CFNetwork/1312 Darwin/21.0.0',
|
EMOTION = 'emotion'
|
||||||
|
}
|
||||||
|
export interface WebApiGroupMember {
|
||||||
|
uin: number
|
||||||
|
role: number
|
||||||
|
g: number
|
||||||
|
join_time: number
|
||||||
|
last_speak_time: number
|
||||||
|
lv: {
|
||||||
|
point: number
|
||||||
|
level: number
|
||||||
}
|
}
|
||||||
|
card: string
|
||||||
constructor() {}
|
tags: string
|
||||||
|
flag: number
|
||||||
public async addGroupDigest(groupCode: string, msgSeq: string) {
|
nick: string
|
||||||
const url = `https://qun.qq.com/cgi-bin/group_digest/cancel_digest?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&msg_seq=${msgSeq}&msg_random=444021292`
|
qage: number
|
||||||
const res = await this.request(url)
|
rm: number
|
||||||
return await res.json()
|
}
|
||||||
|
interface WebApiGroupMemberRet {
|
||||||
|
ec: number
|
||||||
|
errcode: number
|
||||||
|
em: string
|
||||||
|
cache: number
|
||||||
|
adm_num: number
|
||||||
|
levelname: any
|
||||||
|
mems: WebApiGroupMember[]
|
||||||
|
count: number
|
||||||
|
svr_time: number
|
||||||
|
max_count: number
|
||||||
|
search_count: number
|
||||||
|
extmode: number
|
||||||
|
}
|
||||||
|
export interface WebApiGroupNoticeFeed {
|
||||||
|
u: number//发送者
|
||||||
|
fid: string//fid
|
||||||
|
pubt: number//时间
|
||||||
|
msg: {
|
||||||
|
text: string
|
||||||
|
text_face: string
|
||||||
|
title: string,
|
||||||
|
pics?: {
|
||||||
|
id: string,
|
||||||
|
w: string,
|
||||||
|
h: string
|
||||||
|
}[]
|
||||||
}
|
}
|
||||||
|
type: number
|
||||||
public async getGroupDigest(groupCode: string) {
|
fn: number
|
||||||
const url = `https://qun.qq.com/cgi-bin/group_digest/digest_list?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&page_start=0&page_limit=20`
|
cn: number
|
||||||
const res = await this.request(url)
|
vn: number
|
||||||
log(res.headers)
|
settings: {
|
||||||
return await res.json()
|
is_show_edit_card: number
|
||||||
|
remind_ts: number
|
||||||
|
tip_window_type: number
|
||||||
|
confirm_required: number
|
||||||
}
|
}
|
||||||
|
read_num: number
|
||||||
private genBkn(sKey: string) {
|
is_read: number
|
||||||
return NTQQUserApi.genBkn(sKey)
|
is_all_confirm: number
|
||||||
|
}
|
||||||
|
export interface WebApiGroupNoticeRet {
|
||||||
|
ec: number
|
||||||
|
em: string
|
||||||
|
ltsm: number
|
||||||
|
srv_code: number
|
||||||
|
read_only: number
|
||||||
|
role: number
|
||||||
|
feeds: WebApiGroupNoticeFeed[]
|
||||||
|
group: {
|
||||||
|
group_id: number
|
||||||
|
class_ext: number
|
||||||
}
|
}
|
||||||
private async init() {
|
sta: number,
|
||||||
if (!WebApi.bkn) {
|
gln: number
|
||||||
const group = groups[0]
|
tst: number,
|
||||||
WebApi.skey = (await NTQQUserApi.getSkey(group.groupName, group.groupCode)).data
|
ui: any
|
||||||
WebApi.bkn = this.genBkn(WebApi.skey)
|
server_time: number
|
||||||
let cookie = await NTQQUserApi.getCookieWithoutSkey()
|
svrt: number
|
||||||
const pskeyRegex = /p_skey=([^;]+)/
|
ad: number
|
||||||
const match = cookie.match(pskeyRegex)
|
}
|
||||||
const pskeyValue = match ? match[1] : null
|
interface GroupEssenceMsg {
|
||||||
WebApi.pskey = pskeyValue
|
group_code: string
|
||||||
if (cookie.indexOf('skey=;') !== -1) {
|
msg_seq: number
|
||||||
cookie = cookie.replace('skey=;', `skey=${WebApi.skey};`)
|
msg_random: number
|
||||||
}
|
sender_uin: string
|
||||||
WebApi.cookie = cookie
|
sender_nick: string
|
||||||
// for(const kv of WebApi.cookie.split(";")){
|
sender_time: number
|
||||||
// const [key, value] = kv.split("=");
|
add_digest_uin: string
|
||||||
// }
|
add_digest_nick: string
|
||||||
// log("set cookie", key, value)
|
add_digest_time: number
|
||||||
// await session.defaultSession.cookies.set({
|
msg_content: any[]
|
||||||
// url: 'https://qun.qq.com', // 你要请求的域名
|
can_be_removed: true
|
||||||
// name: key.trim(),
|
}
|
||||||
// value: value.trim(),
|
export interface GroupEssenceMsgRet {
|
||||||
// expirationDate: Date.now() / 1000 + 300000, // Cookie 过期时间,例如设置为当前时间之后的300秒
|
retcode: number
|
||||||
// });
|
retmsg: string
|
||||||
// }
|
data: {
|
||||||
}
|
msg_list: GroupEssenceMsg[]
|
||||||
}
|
is_end: boolean
|
||||||
|
group_role: number
|
||||||
private async request(url: string, method: 'GET' | 'POST' = 'GET', headers: Record<string, string> = {}) {
|
config_page_url: string
|
||||||
await this.init()
|
}
|
||||||
url += '&bkn=' + WebApi.bkn
|
}
|
||||||
let _headers: Record<string, string> = {
|
export class WebApi {
|
||||||
...this.defaultHeaders,
|
static async getGroupEssenceMsg(GroupCode: string, page_start: string): Promise<GroupEssenceMsgRet> {
|
||||||
...headers,
|
const {cookies: CookieValue, bkn: Bkn} = (await NTQQUserApi.getCookies('qun.qq.com'))
|
||||||
Cookie: WebApi.cookie,
|
const url = 'https://qun.qq.com/cgi-bin/group_digest/digest_list?bkn=' + Bkn + '&group_code=' + GroupCode + '&page_start=' + page_start + '&page_limit=20';
|
||||||
credentials: 'include',
|
let ret;
|
||||||
}
|
try {
|
||||||
log('request', url, _headers)
|
ret = await RequestUtil.HttpGetJson<GroupEssenceMsgRet>(url, 'GET', '', { 'Cookie': CookieValue });
|
||||||
const options = {
|
} catch {
|
||||||
method: method,
|
return undefined;
|
||||||
headers: _headers,
|
}
|
||||||
}
|
//console.log(url, CookieValue);
|
||||||
return fetch(url, options)
|
if (ret.retcode !== 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
static async getGroupMembers(GroupCode: string, cached: boolean = true): Promise<WebApiGroupMember[]> {
|
||||||
|
log('webapi 获取群成员', GroupCode);
|
||||||
|
let MemberData: Array<WebApiGroupMember> = new Array<WebApiGroupMember>();
|
||||||
|
try {
|
||||||
|
let cachedData = WebGroupData.GroupData.get(GroupCode);
|
||||||
|
let cachedTime = WebGroupData.GroupTime.get(GroupCode);
|
||||||
|
|
||||||
|
if (!cachedTime || Date.now() - cachedTime > 1800 * 1000 || !cached) {
|
||||||
|
const _Pskey = (await NTQQUserApi.getPSkey(['qun.qq.com']))['qun.qq.com'];
|
||||||
|
const _Skey = await NTQQUserApi.getSkey();
|
||||||
|
const CookieValue = 'p_skey=' + _Pskey + '; skey=' + _Skey + '; p_uin=o' + selfInfo.uin;
|
||||||
|
if (!_Skey || !_Pskey) {
|
||||||
|
return MemberData;
|
||||||
|
}
|
||||||
|
const Bkn = WebApi.genBkn(_Skey);
|
||||||
|
const retList: Promise<WebApiGroupMemberRet>[] = [];
|
||||||
|
const fastRet = await RequestUtil.HttpGetJson<WebApiGroupMemberRet>('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=0&end=40&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue });
|
||||||
|
if (!fastRet?.count || fastRet?.errcode !== 0 || !fastRet?.mems) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
for (const key in fastRet.mems) {
|
||||||
|
MemberData.push(fastRet.mems[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//初始化获取PageNum
|
||||||
|
const PageNum = Math.ceil(fastRet.count / 40);
|
||||||
|
//遍历批量请求
|
||||||
|
for (let i = 2; i <= PageNum; i++) {
|
||||||
|
const ret: Promise<WebApiGroupMemberRet> = RequestUtil.HttpGetJson<WebApiGroupMemberRet>('https://qun.qq.com/cgi-bin/qun_mgr/search_group_members?st=' + (i - 1) * 40 + '&end=' + i * 40 + '&sort=1&gc=' + GroupCode + '&bkn=' + Bkn, 'POST', '', { 'Cookie': CookieValue });
|
||||||
|
retList.push(ret);
|
||||||
|
}
|
||||||
|
//批量等待
|
||||||
|
for (let i = 1; i <= PageNum; i++) {
|
||||||
|
const ret = await (retList[i]);
|
||||||
|
if (!ret?.count || ret?.errcode !== 0 || !ret?.mems) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const key in ret.mems) {
|
||||||
|
MemberData.push(ret.mems[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WebGroupData.GroupData.set(GroupCode, MemberData);
|
||||||
|
WebGroupData.GroupTime.set(GroupCode, Date.now());
|
||||||
|
} else {
|
||||||
|
MemberData = cachedData as Array<WebApiGroupMember>;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return MemberData;
|
||||||
|
}
|
||||||
|
return MemberData;
|
||||||
|
}
|
||||||
|
// public static async addGroupDigest(groupCode: string, msgSeq: string) {
|
||||||
|
// const url = `https://qun.qq.com/cgi-bin/group_digest/cancel_digest?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&msg_seq=${msgSeq}&msg_random=444021292`;
|
||||||
|
// const res = await this.request(url);
|
||||||
|
// return await res.json();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public async getGroupDigest(groupCode: string) {
|
||||||
|
// const url = `https://qun.qq.com/cgi-bin/group_digest/digest_list?random=665&X-CROSS-ORIGIN=fetch&group_code=${groupCode}&page_start=0&page_limit=20`;
|
||||||
|
// const res = await this.request(url);
|
||||||
|
// return await res.json();
|
||||||
|
// }
|
||||||
|
static async setGroupNotice(GroupCode: string, Content: string = '') {
|
||||||
|
//https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=${bkn}
|
||||||
|
//qid=${群号}&bkn=${bkn}&text=${内容}&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}
|
||||||
|
const _Pskey = (await NTQQUserApi.getPSkey(['qun.qq.com']))['qun.qq.com'];
|
||||||
|
const _Skey = await NTQQUserApi.getSkey();
|
||||||
|
const CookieValue = 'p_skey=' + _Pskey + '; skey=' + _Skey + '; p_uin=o' + selfInfo.uin;
|
||||||
|
let ret: any = undefined;
|
||||||
|
//console.log(CookieValue);
|
||||||
|
if (!_Skey || !_Pskey) {
|
||||||
|
//获取Cookies失败
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const Bkn = WebApi.genBkn(_Skey);
|
||||||
|
const data = 'qid=' + GroupCode + '&bkn=' + Bkn + '&text=' + Content + '&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}';
|
||||||
|
const url = 'https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=' + Bkn;
|
||||||
|
try {
|
||||||
|
ret = await RequestUtil.HttpGetJson<any>(url, 'GET', '', { 'Cookie': CookieValue });
|
||||||
|
return ret;
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
static async getGrouptNotice(GroupCode: string): Promise<undefined | WebApiGroupNoticeRet> {
|
||||||
|
const _Pskey = (await NTQQUserApi.getPSkey(['qun.qq.com']))['qun.qq.com'];
|
||||||
|
const _Skey = await NTQQUserApi.getSkey();
|
||||||
|
const CookieValue = 'p_skey=' + _Pskey + '; skey=' + _Skey + '; p_uin=o' + selfInfo.uin;
|
||||||
|
let ret: WebApiGroupNoticeRet | undefined = undefined;
|
||||||
|
//console.log(CookieValue);
|
||||||
|
if (!_Skey || !_Pskey) {
|
||||||
|
//获取Cookies失败
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const Bkn = WebApi.genBkn(_Skey);
|
||||||
|
const url = 'https://web.qun.qq.com/cgi-bin/announce/get_t_list?bkn=' + Bkn + '&qid=' + GroupCode + '&ft=23&ni=1&n=1&i=1&log_read=1&platform=1&s=-1&n=20';
|
||||||
|
try {
|
||||||
|
ret = await RequestUtil.HttpGetJson<WebApiGroupNoticeRet>(url, 'GET', '', { 'Cookie': CookieValue });
|
||||||
|
if (ret?.ec !== 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
static genBkn(sKey: string) {
|
||||||
|
sKey = sKey || '';
|
||||||
|
let hash = 5381;
|
||||||
|
|
||||||
|
for (let i = 0; i < sKey.length; i++) {
|
||||||
|
const code = sKey.charCodeAt(i);
|
||||||
|
hash = hash + (hash << 5) + code;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (hash & 0x7FFFFFFF).toString();
|
||||||
|
}
|
||||||
|
//实现未缓存 考虑2h缓存
|
||||||
|
static async getGroupHonorInfo(groupCode: string, getType: WebHonorType) {
|
||||||
|
async function getDataInternal(Internal_groupCode: string, Internal_type: number) {
|
||||||
|
let url = 'https://qun.qq.com/interactive/honorlist?gc=' + Internal_groupCode + '&type=' + Internal_type.toString();
|
||||||
|
let res = '';
|
||||||
|
let resJson;
|
||||||
|
try {
|
||||||
|
res = await RequestUtil.HttpGetText(url, 'GET', '', { 'Cookie': CookieValue });
|
||||||
|
const match = res.match(/window\.__INITIAL_STATE__=(.*?);/);
|
||||||
|
if (match) {
|
||||||
|
resJson = JSON.parse(match[1].trim());
|
||||||
|
}
|
||||||
|
if (Internal_type === 1) {
|
||||||
|
return resJson?.talkativeList;
|
||||||
|
} else {
|
||||||
|
return resJson?.actorList;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log('获取当前群荣耀失败', url, e);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let HonorInfo: any = { group_id: groupCode };
|
||||||
|
const CookieValue = (await NTQQUserApi.getCookies('qun.qq.com')).cookies;
|
||||||
|
|
||||||
|
if (getType === WebHonorType.TALKACTIVE || getType === WebHonorType.ALL) {
|
||||||
|
try {
|
||||||
|
let RetInternal = await getDataInternal(groupCode, 1);
|
||||||
|
if (!RetInternal) {
|
||||||
|
throw new Error('获取龙王信息失败');
|
||||||
|
}
|
||||||
|
HonorInfo.current_talkative = {
|
||||||
|
user_id: RetInternal[0]?.uin,
|
||||||
|
avatar: RetInternal[0]?.avatar,
|
||||||
|
nickname: RetInternal[0]?.name,
|
||||||
|
day_count: 0,
|
||||||
|
description: RetInternal[0]?.desc
|
||||||
|
}
|
||||||
|
HonorInfo.talkative_list = [];
|
||||||
|
for (const talkative_ele of RetInternal) {
|
||||||
|
HonorInfo.talkative_list.push({
|
||||||
|
user_id: talkative_ele?.uin,
|
||||||
|
avatar: talkative_ele?.avatar,
|
||||||
|
description: talkative_ele?.desc,
|
||||||
|
day_count: 0,
|
||||||
|
nickname: talkative_ele?.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getType === WebHonorType.PERFROMER || getType === WebHonorType.ALL) {
|
||||||
|
try {
|
||||||
|
let RetInternal = await getDataInternal(groupCode, 2);
|
||||||
|
if (!RetInternal) {
|
||||||
|
throw new Error('获取群聊之火失败');
|
||||||
|
}
|
||||||
|
HonorInfo.performer_list = [];
|
||||||
|
for (const performer_ele of RetInternal) {
|
||||||
|
HonorInfo.performer_list.push({
|
||||||
|
user_id: performer_ele?.uin,
|
||||||
|
nickname: performer_ele?.name,
|
||||||
|
avatar: performer_ele?.avatar,
|
||||||
|
description: performer_ele?.desc
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getType === WebHonorType.PERFROMER || getType === WebHonorType.ALL) {
|
||||||
|
try {
|
||||||
|
let RetInternal = await getDataInternal(groupCode, 3);
|
||||||
|
if (!RetInternal) {
|
||||||
|
throw new Error('获取群聊炽焰失败');
|
||||||
|
}
|
||||||
|
HonorInfo.legend_list = [];
|
||||||
|
for (const legend_ele of RetInternal) {
|
||||||
|
HonorInfo.legend_list.push({
|
||||||
|
user_id: legend_ele?.uin,
|
||||||
|
nickname: legend_ele?.name,
|
||||||
|
avatar: legend_ele?.avatar,
|
||||||
|
desc: legend_ele?.description
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log('获取群聊炽焰失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
|
||||||
|
try {
|
||||||
|
let RetInternal = await getDataInternal(groupCode, 6);
|
||||||
|
if (!RetInternal) {
|
||||||
|
throw new Error('获取快乐源泉失败');
|
||||||
|
}
|
||||||
|
HonorInfo.emotion_list = [];
|
||||||
|
for (const emotion_ele of RetInternal) {
|
||||||
|
HonorInfo.emotion_list.push({
|
||||||
|
user_id: emotion_ele?.uin,
|
||||||
|
nickname: emotion_ele?.name,
|
||||||
|
avatar: emotion_ele?.avatar,
|
||||||
|
desc: emotion_ele?.description
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log('获取快乐源泉失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//冒尖小春笋好像已经被tx扬了
|
||||||
|
if (getType === WebHonorType.EMOTION || getType === WebHonorType.ALL) {
|
||||||
|
HonorInfo.strong_newbie_list = [];
|
||||||
|
}
|
||||||
|
return HonorInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ import {
|
|||||||
AtType,
|
AtType,
|
||||||
ElementType,
|
ElementType,
|
||||||
FaceIndex,
|
FaceIndex,
|
||||||
FaceType,
|
|
||||||
PicType,
|
PicType,
|
||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendFaceElement,
|
SendFaceElement,
|
||||||
@@ -22,8 +21,9 @@ import { log } from '../common/utils/log'
|
|||||||
import { defaultVideoThumb, getVideoInfo } from '../common/utils/video'
|
import { defaultVideoThumb, getVideoInfo } from '../common/utils/video'
|
||||||
import { encodeSilk } from '../common/utils/audio'
|
import { encodeSilk } from '../common/utils/audio'
|
||||||
import { isNull } from '../common/utils'
|
import { isNull } from '../common/utils'
|
||||||
|
import faceConfig from './face_config.json';
|
||||||
|
|
||||||
export const mFaceCache = new Map<string, string>(); // emojiId -> faceName
|
export const mFaceCache = new Map<string, string>() // emojiId -> faceName
|
||||||
|
|
||||||
export class SendMsgElementConstructor {
|
export class SendMsgElementConstructor {
|
||||||
static poke(groupCode: string, uin: string) {
|
static poke(groupCode: string, uin: string) {
|
||||||
@@ -76,6 +76,10 @@ export class SendMsgElementConstructor {
|
|||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw '文件异常,大小为0'
|
throw '文件异常,大小为0'
|
||||||
}
|
}
|
||||||
|
const maxMB = 30;
|
||||||
|
if (fileSize > 1024 * 1024 * 30){
|
||||||
|
throw `图片过大,最大支持${maxMB}MB,当前文件大小${fileSize}B`
|
||||||
|
}
|
||||||
const imageSize = await NTQQFileApi.getImageSize(picPath)
|
const imageSize = await NTQQFileApi.getImageSize(picPath)
|
||||||
const picElement = {
|
const picElement = {
|
||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
@@ -119,18 +123,22 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async video(filePath: string, fileName: string = '', diyThumbPath: string = ''): Promise<SendVideoElement> {
|
static async video(filePath: string, fileName: string = '', diyThumbPath: string = ''): Promise<SendVideoElement> {
|
||||||
try{
|
try {
|
||||||
await fs.stat(filePath)
|
await fs.stat(filePath)
|
||||||
}catch (e) {
|
} catch (e) {
|
||||||
throw `文件${filePath}异常,不存在`
|
throw `文件${filePath}异常,不存在`
|
||||||
}
|
}
|
||||||
log("复制视频到QQ目录", filePath)
|
log('复制视频到QQ目录', filePath)
|
||||||
let { fileName: _fileName, path, fileSize, md5 } = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO)
|
let { fileName: _fileName, path, fileSize, md5 } = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO)
|
||||||
|
|
||||||
log("复制视频到QQ目录完成", path)
|
log('复制视频到QQ目录完成', path)
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw '文件异常,大小为0'
|
throw '文件异常,大小为0'
|
||||||
}
|
}
|
||||||
|
const maxMB = 100;
|
||||||
|
if (fileSize > 1024 * 1024 * maxMB) {
|
||||||
|
throw `视频过大,最大支持${maxMB}MB,当前文件大小${fileSize}B`
|
||||||
|
}
|
||||||
const pathLib = require('path')
|
const pathLib = require('path')
|
||||||
let thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
let thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
|
||||||
thumbDir = pathLib.dirname(thumbDir)
|
thumbDir = pathLib.dirname(thumbDir)
|
||||||
@@ -265,13 +273,30 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static face(faceId: number): SendFaceElement {
|
static face(faceId: number): SendFaceElement {
|
||||||
|
// 从face_config.json中获取表情名称
|
||||||
|
const sysFaces = faceConfig.sysface
|
||||||
|
const emojiFaces = faceConfig.emoji
|
||||||
|
const face = sysFaces.find((face) => face.QSid === faceId.toString())
|
||||||
faceId = parseInt(faceId.toString())
|
faceId = parseInt(faceId.toString())
|
||||||
|
// let faceType = parseInt(faceId.toString().substring(0, 1));
|
||||||
|
let faceType = 1
|
||||||
|
if (faceId >= 222){
|
||||||
|
faceType = 2
|
||||||
|
}
|
||||||
|
if (face.AniStickerType){
|
||||||
|
faceType = 3;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
elementType: ElementType.FACE,
|
elementType: ElementType.FACE,
|
||||||
elementId: '',
|
elementId: '',
|
||||||
faceElement: {
|
faceElement: {
|
||||||
faceIndex: faceId,
|
faceIndex: faceId,
|
||||||
faceType: faceId < 222 ? FaceType.normal : FaceType.normal2,
|
faceType,
|
||||||
|
faceText: face.QDes,
|
||||||
|
stickerId: face.AniStickerId,
|
||||||
|
stickerType: face.AniStickerType,
|
||||||
|
packId: face.AniStickerPackId,
|
||||||
|
sourceType: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +323,7 @@ export class SendMsgElementConstructor {
|
|||||||
elementId: '',
|
elementId: '',
|
||||||
faceElement: {
|
faceElement: {
|
||||||
faceIndex: FaceIndex.dice,
|
faceIndex: FaceIndex.dice,
|
||||||
faceType: FaceType.dice,
|
faceType: 3,
|
||||||
faceText: '[骰子]',
|
faceText: '[骰子]',
|
||||||
packId: '1',
|
packId: '1',
|
||||||
stickerId: '33',
|
stickerId: '33',
|
||||||
|
54
src/ntqqapi/external/crychic/index.ts
vendored
54
src/ntqqapi/external/crychic/index.ts
vendored
@@ -1,54 +0,0 @@
|
|||||||
import {log} from "../../../common/utils";
|
|
||||||
import {NTQQApi} from "../../ntcall";
|
|
||||||
import {cpModule} from "../cpmodule";
|
|
||||||
|
|
||||||
type PokeHandler = (id: string, isGroup: boolean) => void
|
|
||||||
type CrychicHandler = (event: string, id: string, isGroup: boolean) => void
|
|
||||||
|
|
||||||
let pokeRecords: Record<string, number> = {}
|
|
||||||
|
|
||||||
class Crychic{
|
|
||||||
private crychic: any = undefined
|
|
||||||
|
|
||||||
loadNode(){
|
|
||||||
if (!this.crychic){
|
|
||||||
try {
|
|
||||||
cpModule('crychic');
|
|
||||||
this.crychic = require("./crychic.node")
|
|
||||||
this.crychic.init()
|
|
||||||
}catch (e) {
|
|
||||||
log("crychic加载失败", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
registerPokeHandler(fn: PokeHandler){
|
|
||||||
this.registerHandler((event, id, isGroup)=>{
|
|
||||||
if (event === "poke"){
|
|
||||||
let existTime = pokeRecords[id]
|
|
||||||
if (existTime) {
|
|
||||||
if (Date.now() - existTime < 1500) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pokeRecords[id] = Date.now()
|
|
||||||
fn(id, isGroup);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
registerHandler(fn: CrychicHandler){
|
|
||||||
if (!this.crychic) return;
|
|
||||||
this.crychic.setCryHandler(fn)
|
|
||||||
}
|
|
||||||
sendFriendPoke(friendUid: string){
|
|
||||||
if (!this.crychic) return;
|
|
||||||
this.crychic.sendFriendPoke(parseInt(friendUid))
|
|
||||||
NTQQApi.fetchUnitedCommendConfig().then()
|
|
||||||
}
|
|
||||||
sendGroupPoke(groupCode: string, memberUin: string){
|
|
||||||
if (!this.crychic) return;
|
|
||||||
this.crychic.sendGroupPoke(parseInt(memberUin), parseInt(groupCode))
|
|
||||||
NTQQApi.fetchUnitedCommendConfig().then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const crychic = new Crychic()
|
|
BIN
src/ntqqapi/external/moehook/MoeHoo-linux-x64.node
vendored
BIN
src/ntqqapi/external/moehook/MoeHoo-linux-x64.node
vendored
Binary file not shown.
BIN
src/ntqqapi/external/moehook/MoeHoo-win32-x64.node
vendored
BIN
src/ntqqapi/external/moehook/MoeHoo-win32-x64.node
vendored
Binary file not shown.
3665
src/ntqqapi/face_config.json
Normal file
3665
src/ntqqapi/face_config.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,28 @@
|
|||||||
import { BrowserWindow } from 'electron'
|
import { BrowserWindow } from 'electron'
|
||||||
import { NTQQApiClass, NTQQApiMethod } from './ntcall'
|
import { NTQQApiClass, NTQQApiMethod } from './ntcall'
|
||||||
import { NTQQMsgApi, sendMessagePool } from './api/msg'
|
import { NTQQMsgApi, sendMessagePool } from './api/msg'
|
||||||
import { ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User } from './types'
|
import { CategoryFriend, ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User } from './types'
|
||||||
import {
|
import {
|
||||||
deleteGroup,
|
deleteGroup,
|
||||||
friends,
|
friends,
|
||||||
getFriend,
|
getFriend,
|
||||||
getGroupMember,
|
getGroupMember,
|
||||||
groups,
|
groups, rawFriends,
|
||||||
selfInfo,
|
selfInfo,
|
||||||
tempGroupCodeMap,
|
tempGroupCodeMap,
|
||||||
uidMaps,
|
uidMaps,
|
||||||
} from '../common/data'
|
} from '@/common/data'
|
||||||
import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
import { OB11GroupDecreaseEvent } from '../onebot11/event/notice/OB11GroupDecreaseEvent'
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { postOB11Event } from '../onebot11/server/postOB11Event'
|
import { postOb11Event } from '../onebot11/server/post-ob11-event'
|
||||||
import { getConfigUtil, HOOK_LOG } from '../common/config'
|
import { getConfigUtil, HOOK_LOG } from '@/common/config'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { dbUtil } from '../common/db'
|
import { dbUtil } from '@/common/db'
|
||||||
import { NTQQGroupApi } from './api/group'
|
import { NTQQGroupApi } from './api/group'
|
||||||
import { log } from '../common/utils/log'
|
import { log } from '@/common/utils'
|
||||||
import { isNumeric, sleep } from '../common/utils/helper'
|
import { isNumeric, sleep } from '@/common/utils'
|
||||||
import { OB11Constructor } from '../onebot11/constructor'
|
import { OB11Constructor } from '../onebot11/constructor'
|
||||||
|
import { OB11GroupCardEvent } from '../onebot11/event/notice/OB11GroupCardEvent'
|
||||||
|
|
||||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||||
|
|
||||||
@@ -299,7 +300,7 @@ async function processGroupEvent(payload: { groupList: Group[] }) {
|
|||||||
}
|
}
|
||||||
for (const member of oldMembers) {
|
for (const member of oldMembers) {
|
||||||
if (!newMembersSet.has(member.uin) && member.uin != selfInfo.uin) {
|
if (!newMembersSet.has(member.uin) && member.uin != selfInfo.uin) {
|
||||||
postOB11Event(
|
postOb11Event(
|
||||||
new OB11GroupDecreaseEvent(
|
new OB11GroupDecreaseEvent(
|
||||||
parseInt(group.groupCode),
|
parseInt(group.groupCode),
|
||||||
parseInt(member.uin),
|
parseInt(member.uin),
|
||||||
@@ -324,205 +325,222 @@ async function processGroupEvent(payload: { groupList: Group[] }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 群列表变动
|
export async function startHook() {
|
||||||
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
|
||||||
// updateType 3是群列表变动,2是群成员变动
|
|
||||||
// log("群列表变动", payload.updateType, payload.groupList)
|
|
||||||
if (payload.updateType != 2) {
|
|
||||||
updateGroups(payload.groupList).then()
|
|
||||||
} else {
|
|
||||||
if (process.platform == 'win32') {
|
|
||||||
processGroupEvent(payload).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
|
||||||
// updateType 3是群列表变动,2是群成员变动
|
|
||||||
// log("群列表变动", payload.updateType, payload.groupList)
|
|
||||||
if (payload.updateType != 2) {
|
|
||||||
updateGroups(payload.groupList).then()
|
|
||||||
} else {
|
|
||||||
if (process.platform != 'win32') {
|
|
||||||
processGroupEvent(payload).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerReceiveHook<{
|
// 群列表变动
|
||||||
groupCode: string
|
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
||||||
dataSource: number
|
// updateType 3是群列表变动,2是群成员变动
|
||||||
members: Set<GroupMember>
|
// log("群列表变动", payload.updateType, payload.groupList)
|
||||||
}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, async (payload) => {
|
if (payload.updateType != 2) {
|
||||||
const groupCode = payload.groupCode
|
updateGroups(payload.groupList).then()
|
||||||
const members = Array.from(payload.members.values())
|
|
||||||
// log("群成员信息变动", groupCode, members)
|
|
||||||
for (const member of members) {
|
|
||||||
const existMember = await getGroupMember(groupCode, member.uin)
|
|
||||||
if (existMember) {
|
|
||||||
Object.assign(existMember, member)
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
if (process.platform == 'win32') {
|
||||||
// if (existGroup) {
|
processGroupEvent(payload).then()
|
||||||
// log("对比群成员", existGroup.members, members)
|
}
|
||||||
// for (const member of members) {
|
}
|
||||||
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
})
|
||||||
// if (existMember) {
|
registerReceiveHook<{ groupList: Group[]; updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
||||||
// log("对比群名片", existMember.cardName, member.cardName)
|
// updateType 3是群列表变动,2是群成员变动
|
||||||
// if (existMember.cardName != member.cardName) {
|
// log("群列表变动", payload.updateType, payload.groupList)
|
||||||
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
if (payload.updateType != 2) {
|
||||||
// }
|
updateGroups(payload.groupList).then()
|
||||||
// Object.assign(existMember, member);
|
}
|
||||||
// }
|
else {
|
||||||
// }
|
if (process.platform != 'win32') {
|
||||||
// }
|
processGroupEvent(payload).then()
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerReceiveHook<{
|
||||||
|
groupCode: string
|
||||||
|
dataSource: number
|
||||||
|
members: Set<GroupMember>
|
||||||
|
}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, async (payload) => {
|
||||||
|
const groupCode = payload.groupCode
|
||||||
|
const members = Array.from(payload.members.values())
|
||||||
|
// log("群成员信息变动", groupCode, members)
|
||||||
|
for (const member of members) {
|
||||||
|
const existMember = await getGroupMember(groupCode, member.uin)
|
||||||
|
if (existMember) {
|
||||||
|
if (member.cardName != existMember.cardName) {
|
||||||
|
log('群成员名片变动', `${groupCode}: ${existMember.uin}`, existMember.cardName, '->', member.cardName)
|
||||||
|
postOb11Event(
|
||||||
|
new OB11GroupCardEvent(parseInt(groupCode), parseInt(member.uin), member.cardName, existMember.cardName),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Object.assign(existMember, member)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// const existGroup = groups.find(g => g.groupCode == groupCode);
|
||||||
|
// if (existGroup) {
|
||||||
|
// log("对比群成员", existGroup.members, members)
|
||||||
|
// for (const member of members) {
|
||||||
|
// const existMember = existGroup.members.find(m => m.uin == member.uin);
|
||||||
|
// if (existMember) {
|
||||||
|
// log("对比群名片", existMember.cardName, member.cardName)
|
||||||
|
// if (existMember.cardName != member.cardName) {
|
||||||
|
// postOB11Event(new OB11GroupCardEvent(parseInt(existGroup.groupCode), parseInt(member.uin), member.cardName, existMember.cardName));
|
||||||
|
// }
|
||||||
|
// Object.assign(existMember, member);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
|
||||||
// 好友列表变动
|
// 好友列表变动
|
||||||
registerReceiveHook<{
|
registerReceiveHook<{
|
||||||
data: { categoryId: number; categroyName: string; categroyMbCount: number; buddyList: User[] }[]
|
data: CategoryFriend[]
|
||||||
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
}>(ReceiveCmdS.FRIENDS, (payload) => {
|
||||||
for (const fData of payload.data) {
|
rawFriends.length = 0;
|
||||||
const _friends = fData.buddyList
|
rawFriends.push(...payload.data);
|
||||||
for (let friend of _friends) {
|
for (const fData of payload.data) {
|
||||||
NTQQMsgApi.activateChat({ peerUid: friend.uid, chatType: ChatType.friend }).then()
|
const _friends = fData.buddyList
|
||||||
let existFriend = friends.find((f) => f.uin == friend.uin)
|
for (let friend of _friends) {
|
||||||
if (!existFriend) {
|
NTQQMsgApi.activateChat({ peerUid: friend.uid, chatType: ChatType.friend }).then()
|
||||||
friends.push(friend)
|
let existFriend = friends.find((f) => f.uin == friend.uin)
|
||||||
} else {
|
if (!existFriend) {
|
||||||
Object.assign(existFriend, friend)
|
friends.push(friend)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object.assign(existFriend, friend)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
||||||
// 保存一下uid
|
// 保存一下uid
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
const uid = message.senderUid
|
const uid = message.senderUid
|
||||||
const uin = message.senderUin
|
const uin = message.senderUin
|
||||||
if (uid && uin) {
|
if (uid && uin) {
|
||||||
if (message.chatType === ChatType.temp) {
|
if (message.chatType === ChatType.temp) {
|
||||||
dbUtil.getReceivedTempUinMap().then((receivedTempUinMap) => {
|
dbUtil.getReceivedTempUinMap().then((receivedTempUinMap) => {
|
||||||
if (!receivedTempUinMap[uin]) {
|
if (!receivedTempUinMap[uin]) {
|
||||||
receivedTempUinMap[uin] = uid
|
receivedTempUinMap[uin] = uid
|
||||||
dbUtil.setReceivedTempUinMap(receivedTempUinMap)
|
dbUtil.setReceivedTempUinMap(receivedTempUinMap)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
uidMaps[uid] = uin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 自动清理新消息文件
|
|
||||||
const { autoDeleteFile } = getConfigUtil().getConfig()
|
|
||||||
if (!autoDeleteFile) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for (const message of payload.msgList) {
|
|
||||||
// log("收到新消息,push到历史记录", message.msgId)
|
|
||||||
// dbUtil.addMsg(message).then()
|
|
||||||
// 清理文件
|
|
||||||
|
|
||||||
for (const msgElement of message.elements) {
|
|
||||||
setTimeout(() => {
|
|
||||||
const picPath = msgElement.picElement?.sourcePath
|
|
||||||
const picThumbPath = [...msgElement.picElement?.thumbPath.values()]
|
|
||||||
const pttPath = msgElement.pttElement?.filePath
|
|
||||||
const filePath = msgElement.fileElement?.filePath
|
|
||||||
const videoPath = msgElement.videoElement?.filePath
|
|
||||||
const videoThumbPath: string[] = [...msgElement.videoElement?.thumbPath.values()]
|
|
||||||
const pathList = [picPath, ...picThumbPath, pttPath, filePath, videoPath, ...videoThumbPath]
|
|
||||||
if (msgElement.picElement) {
|
|
||||||
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
|
||||||
}
|
|
||||||
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
|
||||||
if (aioOpGrayTipElement) {
|
|
||||||
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat
|
|
||||||
}
|
|
||||||
|
|
||||||
// log("需要清理的文件", pathList);
|
|
||||||
for (const path of pathList) {
|
|
||||||
if (path) {
|
|
||||||
fs.unlink(picPath, () => {
|
|
||||||
log('删除文件成功', path)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, getConfigUtil().getConfig().autoDeleteFileSecond * 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({ msgRecord }) => {
|
|
||||||
const message = msgRecord
|
|
||||||
const peerUid = message.peerUid
|
|
||||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
|
||||||
// log("收到自己发送成功的消息", message.msgId, message.msgSeq);
|
|
||||||
dbUtil.addMsg(message).then()
|
|
||||||
const sendCallback = sendMessagePool[peerUid]
|
|
||||||
if (sendCallback) {
|
|
||||||
try {
|
|
||||||
sendCallback(message)
|
|
||||||
} catch (e) {
|
|
||||||
log('receive self msg error', e.stack)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
|
||||||
selfInfo.online = info.info.status !== 20
|
|
||||||
})
|
|
||||||
|
|
||||||
let activatedPeerUids: string[] = []
|
|
||||||
registerReceiveHook<{
|
|
||||||
changedRecentContactLists: {
|
|
||||||
listType: number
|
|
||||||
sortedContactList: string[]
|
|
||||||
changedList: {
|
|
||||||
id: string // peerUid
|
|
||||||
chatType: ChatType
|
|
||||||
}[]
|
|
||||||
}[]
|
|
||||||
}>(ReceiveCmdS.RECENT_CONTACT, async (payload) => {
|
|
||||||
for (const recentContact of payload.changedRecentContactLists) {
|
|
||||||
for (const changedContact of recentContact.changedList) {
|
|
||||||
if (activatedPeerUids.includes(changedContact.id)) continue
|
|
||||||
activatedPeerUids.push(changedContact.id)
|
|
||||||
const peer = { peerUid: changedContact.id, chatType: changedContact.chatType }
|
|
||||||
if (changedContact.chatType === ChatType.temp) {
|
|
||||||
log('收到临时会话消息', peer)
|
|
||||||
NTQQMsgApi.activateChatAndGetHistory(peer).then(() => {
|
|
||||||
NTQQMsgApi.getMsgHistory(peer, '', 20).then(({ msgList }) => {
|
|
||||||
let lastTempMsg = msgList.pop()
|
|
||||||
log('激活窗口之前的第一条临时会话消息:', lastTempMsg)
|
|
||||||
if (Date.now() / 1000 - parseInt(lastTempMsg.msgTime) < 5) {
|
|
||||||
OB11Constructor.message(lastTempMsg).then((r) => postOB11Event(r))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
} else {
|
uidMaps[uid] = uin
|
||||||
NTQQMsgApi.activateChat(peer).then()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerCallHook(NTQQApiMethod.DELETE_ACTIVE_CHAT, async (payload) => {
|
// 自动清理新消息文件
|
||||||
const peerUid = payload[0] as string
|
const { autoDeleteFile } = getConfigUtil().getConfig()
|
||||||
log('激活的聊天窗口被删除,准备重新激活', peerUid)
|
if (!autoDeleteFile) {
|
||||||
let chatType = ChatType.friend
|
return
|
||||||
if (isNumeric(peerUid)) {
|
}
|
||||||
chatType = ChatType.group
|
for (const message of payload.msgList) {
|
||||||
} else {
|
// log("收到新消息,push到历史记录", message.msgId)
|
||||||
// 检查是否好友
|
// dbUtil.addMsg(message).then()
|
||||||
if (!(await getFriend(peerUid))) {
|
// 清理文件
|
||||||
chatType = ChatType.temp
|
|
||||||
|
for (const msgElement of message.elements) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const picPath = msgElement.picElement?.sourcePath
|
||||||
|
const picThumbPath = [...msgElement.picElement?.thumbPath.values()]
|
||||||
|
const pttPath = msgElement.pttElement?.filePath
|
||||||
|
const filePath = msgElement.fileElement?.filePath
|
||||||
|
const videoPath = msgElement.videoElement?.filePath
|
||||||
|
const videoThumbPath: string[] = [...msgElement.videoElement?.thumbPath.values()]
|
||||||
|
const pathList = [picPath, ...picThumbPath, pttPath, filePath, videoPath, ...videoThumbPath]
|
||||||
|
if (msgElement.picElement) {
|
||||||
|
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
||||||
|
}
|
||||||
|
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
||||||
|
if (aioOpGrayTipElement) {
|
||||||
|
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat
|
||||||
|
}
|
||||||
|
|
||||||
|
// log("需要清理的文件", pathList);
|
||||||
|
for (const path of pathList) {
|
||||||
|
if (path) {
|
||||||
|
fs.unlink(picPath, () => {
|
||||||
|
log('删除文件成功', path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, getConfigUtil().getConfig().autoDeleteFileSecond * 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const peer = { peerUid, chatType }
|
|
||||||
await sleep(1000)
|
|
||||||
NTQQMsgApi.activateChat(peer).then((r) => {
|
|
||||||
log('重新激活聊天窗口', peer, { result: r.result, errMsg: r.errMsg })
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({ msgRecord }) => {
|
||||||
|
const message = msgRecord
|
||||||
|
const peerUid = message.peerUid
|
||||||
|
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||||
|
// log("收到自己发送成功的消息", message.msgId, message.msgSeq);
|
||||||
|
dbUtil.addMsg(message).then()
|
||||||
|
const sendCallback = sendMessagePool[peerUid]
|
||||||
|
if (sendCallback) {
|
||||||
|
try {
|
||||||
|
sendCallback(message)
|
||||||
|
} catch (e) {
|
||||||
|
log('receive self msg error', e.stack)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
||||||
|
selfInfo.online = info.info.status !== 20
|
||||||
|
})
|
||||||
|
|
||||||
|
let activatedPeerUids: string[] = []
|
||||||
|
registerReceiveHook<{
|
||||||
|
changedRecentContactLists: {
|
||||||
|
listType: number
|
||||||
|
sortedContactList: string[]
|
||||||
|
changedList: {
|
||||||
|
id: string // peerUid
|
||||||
|
chatType: ChatType
|
||||||
|
}[]
|
||||||
|
}[]
|
||||||
|
}>(ReceiveCmdS.RECENT_CONTACT, async (payload) => {
|
||||||
|
for (const recentContact of payload.changedRecentContactLists) {
|
||||||
|
for (const changedContact of recentContact.changedList) {
|
||||||
|
if (activatedPeerUids.includes(changedContact.id)) continue
|
||||||
|
activatedPeerUids.push(changedContact.id)
|
||||||
|
const peer = { peerUid: changedContact.id, chatType: changedContact.chatType }
|
||||||
|
if (changedContact.chatType === ChatType.temp) {
|
||||||
|
log('收到临时会话消息', peer)
|
||||||
|
NTQQMsgApi.activateChatAndGetHistory(peer).then(() => {
|
||||||
|
NTQQMsgApi.getMsgHistory(peer, '', 20).then(({ msgList }) => {
|
||||||
|
let lastTempMsg = msgList.pop()
|
||||||
|
log('激活窗口之前的第一条临时会话消息:', lastTempMsg)
|
||||||
|
if (Date.now() / 1000 - parseInt(lastTempMsg.msgTime) < 5) {
|
||||||
|
OB11Constructor.message(lastTempMsg).then((r) => postOb11Event(r))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NTQQMsgApi.activateChat(peer).then()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerCallHook(NTQQApiMethod.DELETE_ACTIVE_CHAT, async (payload) => {
|
||||||
|
const peerUid = payload[0] as string
|
||||||
|
log('激活的聊天窗口被删除,准备重新激活', peerUid)
|
||||||
|
let chatType = ChatType.friend
|
||||||
|
if (isNumeric(peerUid)) {
|
||||||
|
chatType = ChatType.group
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 检查是否好友
|
||||||
|
if (!(await getFriend(peerUid))) {
|
||||||
|
chatType = ChatType.temp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const peer = { peerUid, chatType }
|
||||||
|
await sleep(1000)
|
||||||
|
NTQQMsgApi.activateChat(peer).then((r) => {
|
||||||
|
log('重新激活聊天窗口', peer, { result: r.result, errMsg: r.errMsg })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
58
src/ntqqapi/native/crychic/index.ts
Normal file
58
src/ntqqapi/native/crychic/index.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { log } from '../../../common/utils'
|
||||||
|
import { NTQQApi } from '../../ntcall'
|
||||||
|
import { cpModule } from '../cpmodule'
|
||||||
|
|
||||||
|
type PokeHandler = (id: string, isGroup: boolean) => void
|
||||||
|
type CrychicHandler = (event: string, id: string, isGroup: boolean) => void
|
||||||
|
|
||||||
|
let pokeRecords: Record<string, number> = {}
|
||||||
|
|
||||||
|
class Crychic {
|
||||||
|
private crychic: any = undefined
|
||||||
|
|
||||||
|
loadNode() {
|
||||||
|
if (!this.crychic) {
|
||||||
|
try {
|
||||||
|
cpModule('crychic')
|
||||||
|
this.crychic = require('./crychic.node')
|
||||||
|
this.crychic.init()
|
||||||
|
} catch (e) {
|
||||||
|
log('crychic加载失败', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerPokeHandler(fn: PokeHandler) {
|
||||||
|
this.registerHandler((event, id, isGroup) => {
|
||||||
|
if (event === 'poke') {
|
||||||
|
let existTime = pokeRecords[id]
|
||||||
|
if (existTime) {
|
||||||
|
if (Date.now() - existTime < 1500) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pokeRecords[id] = Date.now()
|
||||||
|
fn(id, isGroup)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
registerHandler(fn: CrychicHandler) {
|
||||||
|
if (!this.crychic) return
|
||||||
|
this.crychic.setCryHandler(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendFriendPoke(friendUid: string) {
|
||||||
|
if (!this.crychic) return
|
||||||
|
this.crychic.sendFriendPoke(parseInt(friendUid))
|
||||||
|
NTQQApi.fetchUnitedCommendConfig().then()
|
||||||
|
}
|
||||||
|
|
||||||
|
sendGroupPoke(groupCode: string, memberUin: string) {
|
||||||
|
if (!this.crychic) return
|
||||||
|
this.crychic.sendGroupPoke(parseInt(memberUin), parseInt(groupCode))
|
||||||
|
NTQQApi.fetchUnitedCommendConfig().then()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const crychic = new Crychic()
|
@@ -1,11 +1,9 @@
|
|||||||
import * as os from "os";
|
|
||||||
import fs from "fs";
|
|
||||||
import path from "node:path";
|
|
||||||
import {cpModule} from "../cpmodule";
|
import {cpModule} from "../cpmodule";
|
||||||
|
import { qqPkgInfo } from '@/common/utils/QQBasicInfo'
|
||||||
|
|
||||||
interface MoeHook {
|
interface MoeHook {
|
||||||
GetRkey: () => string, // Return '&rkey=xxx'
|
GetRkey: () => string, // Return '&rkey=xxx'
|
||||||
HookRkey: () => string
|
HookRkey: (version: string) => string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -16,7 +14,8 @@ class HookApi {
|
|||||||
cpModule('MoeHoo');
|
cpModule('MoeHoo');
|
||||||
try {
|
try {
|
||||||
this.moeHook = require('./MoeHoo.node');
|
this.moeHook = require('./MoeHoo.node');
|
||||||
console.log("hook rkey地址", this.moeHook!.HookRkey());
|
console.log("hook rkey qq version", this.moeHook!.HookRkey(qqPkgInfo.version));
|
||||||
|
console.log("hook rkey地址", this.moeHook!.HookRkey(qqPkgInfo.version));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('加载 moehoo 失败', e);
|
console.log('加载 moehoo 失败', e);
|
||||||
}
|
}
|
||||||
@@ -31,4 +30,4 @@ class HookApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const hookApi = new HookApi();
|
// export const hookApi = new HookApi();
|
19
src/ntqqapi/native/wrapper.ts
Normal file
19
src/ntqqapi/native/wrapper.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
let Process = require('process')
|
||||||
|
let os = require('os')
|
||||||
|
Process.dlopenOrig = Process.dlopen
|
||||||
|
|
||||||
|
export const wrapperApi: any = {}
|
||||||
|
|
||||||
|
Process.dlopen = function(module, filename, flags = os.constants.dlopen.RTLD_LAZY) {
|
||||||
|
let dlopenRet = this.dlopenOrig(module, filename, flags)
|
||||||
|
for (let export_name in module.exports) {
|
||||||
|
module.exports[export_name] = new Proxy(module.exports[export_name], {
|
||||||
|
construct: (target, args, _newTarget) => {
|
||||||
|
let ret = new target(...args)
|
||||||
|
if (export_name === 'NodeIQQNTWrapperSession') wrapperApi.NodeIQQNTWrapperSession = ret
|
||||||
|
return ret
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return dlopenRet
|
||||||
|
}
|
@@ -4,7 +4,6 @@ import { hookApiCallbacks, ReceiveCmd, ReceiveCmdS, registerReceiveHook, removeR
|
|||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { log } from '../common/utils/log'
|
import { log } from '../common/utils/log'
|
||||||
import { NTQQWindow, NTQQWindowApi, NTQQWindows } from './api/window'
|
import { NTQQWindow, NTQQWindowApi, NTQQWindows } from './api/window'
|
||||||
import { WebApi } from './api/webapi'
|
|
||||||
import { HOOK_LOG } from '../common/config'
|
import { HOOK_LOG } from '../common/config'
|
||||||
|
|
||||||
export enum NTQQApiClass {
|
export enum NTQQApiClass {
|
||||||
@@ -21,19 +20,24 @@ export enum NTQQApiClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
|
TEST = 'NodeIKernelTipOffService/getPskey',
|
||||||
RECENT_CONTACT = 'nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact',
|
RECENT_CONTACT = 'nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact',
|
||||||
ACTIVE_CHAT_PREVIEW = 'nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回最新预览消息
|
ACTIVE_CHAT_PREVIEW = 'nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回最新预览消息
|
||||||
ACTIVE_CHAT_HISTORY = 'nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回历史消息
|
ACTIVE_CHAT_HISTORY = 'nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat', // 激活聊天窗口,有时候必须这样才能收到消息, 并返回历史消息
|
||||||
HISTORY_MSG = 'nodeIKernelMsgService/getMsgsIncludeSelf',
|
HISTORY_MSG = 'nodeIKernelMsgService/getMsgsIncludeSelf',
|
||||||
GET_MULTI_MSG = 'nodeIKernelMsgService/getMultiMsg',
|
GET_MULTI_MSG = 'nodeIKernelMsgService/getMultiMsg',
|
||||||
DELETE_ACTIVE_CHAT = 'nodeIKernelMsgService/deleteActiveChatByUid',
|
DELETE_ACTIVE_CHAT = 'nodeIKernelMsgService/deleteActiveChatByUid',
|
||||||
|
ENTER_OR_EXIT_AIO = 'nodeIKernelMsgService/enterOrExitAio',
|
||||||
|
|
||||||
LIKE_FRIEND = 'nodeIKernelProfileLikeService/setBuddyProfileLike',
|
LIKE_FRIEND = 'nodeIKernelProfileLikeService/setBuddyProfileLike',
|
||||||
SELF_INFO = 'fetchAuthData',
|
SELF_INFO = 'fetchAuthData',
|
||||||
FRIENDS = 'nodeIKernelBuddyService/getBuddyList',
|
FRIENDS = 'nodeIKernelBuddyService/getBuddyList',
|
||||||
|
|
||||||
GROUPS = 'nodeIKernelGroupService/getGroupList',
|
GROUPS = 'nodeIKernelGroupService/getGroupList',
|
||||||
GROUP_MEMBER_SCENE = 'nodeIKernelGroupService/createMemberListScene',
|
GROUP_MEMBER_SCENE = 'nodeIKernelGroupService/createMemberListScene',
|
||||||
GROUP_MEMBERS = 'nodeIKernelGroupService/getNextMemberList',
|
GROUP_MEMBERS = 'nodeIKernelGroupService/getNextMemberList',
|
||||||
|
GROUP_MEMBERS_INFO = 'nodeIKernelGroupService/getMemberInfo',
|
||||||
|
|
||||||
USER_INFO = 'nodeIKernelProfileService/getUserSimpleInfo',
|
USER_INFO = 'nodeIKernelProfileService/getUserSimpleInfo',
|
||||||
USER_DETAIL_INFO = 'nodeIKernelProfileService/getUserDetailInfo',
|
USER_DETAIL_INFO = 'nodeIKernelProfileService/getUserDetailInfo',
|
||||||
USER_DETAIL_INFO_WITH_BIZ_INFO = 'nodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
USER_DETAIL_INFO_WITH_BIZ_INFO = 'nodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
||||||
@@ -65,6 +69,10 @@ export enum NTQQApiMethod {
|
|||||||
PUBLISH_GROUP_BULLETIN = 'nodeIKernelGroupService/publishGroupBulletinBulletin',
|
PUBLISH_GROUP_BULLETIN = 'nodeIKernelGroupService/publishGroupBulletinBulletin',
|
||||||
SET_GROUP_NAME = 'nodeIKernelGroupService/modifyGroupName',
|
SET_GROUP_NAME = 'nodeIKernelGroupService/modifyGroupName',
|
||||||
SET_GROUP_TITLE = 'nodeIKernelGroupService/modifyMemberSpecialTitle',
|
SET_GROUP_TITLE = 'nodeIKernelGroupService/modifyMemberSpecialTitle',
|
||||||
|
ACTIVATE_MEMBER_LIST_CHANGE = 'nodeIKernelGroupListener/onMemberListChange',
|
||||||
|
ACTIVATE_MEMBER_INFO_CHANGE = 'nodeIKernelGroupListener/onMemberInfoChange',
|
||||||
|
GET_MSG_BOX_INFO = 'nodeIKernelMsgService/getABatchOfContactMsgBoxInfo',
|
||||||
|
GET_GROUP_ALL_INFO = 'nodeIKernelGroupService/getGroupAllInfo',
|
||||||
|
|
||||||
CACHE_SET_SILENCE = 'nodeIKernelStorageCleanService/setSilentScan',
|
CACHE_SET_SILENCE = 'nodeIKernelStorageCleanService/setSilentScan',
|
||||||
CACHE_ADD_SCANNED_PATH = 'nodeIKernelStorageCleanService/addCacheScanedPaths',
|
CACHE_ADD_SCANNED_PATH = 'nodeIKernelStorageCleanService/addCacheScanedPaths',
|
||||||
@@ -81,7 +89,7 @@ export enum NTQQApiMethod {
|
|||||||
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
||||||
|
|
||||||
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader',
|
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader',
|
||||||
GET_SKEY = 'nodeIKernelTipOffService/getPskey',
|
GET_PSKEY = 'nodeIKernelTipOffService/getPskey',
|
||||||
UPDATE_SKEY = 'updatePskey',
|
UPDATE_SKEY = 'updatePskey',
|
||||||
|
|
||||||
FETCH_UNITED_COMMEND_CONFIG = 'nodeIKernelUnitedConfigService/fetchUnitedCommendConfig', // 发包需要调用的
|
FETCH_UNITED_COMMEND_CONFIG = 'nodeIKernelUnitedConfigService/fetchUnitedCommendConfig', // 发包需要调用的
|
||||||
@@ -99,7 +107,7 @@ interface NTQQApiParams {
|
|||||||
channel?: NTQQApiChannel
|
channel?: NTQQApiChannel
|
||||||
classNameIsRegister?: boolean
|
classNameIsRegister?: boolean
|
||||||
args?: unknown[]
|
args?: unknown[]
|
||||||
cbCmd?: ReceiveCmd | null
|
cbCmd?: ReceiveCmd | ReceiveCmd[] | null
|
||||||
cmdCB?: (payload: any) => boolean
|
cmdCB?: (payload: any) => boolean
|
||||||
afterFirstCmd?: boolean // 是否在methodName调用完之后再去hook cbCmd
|
afterFirstCmd?: boolean // 是否在methodName调用完之后再去hook cbCmd
|
||||||
timeoutSecond?: number
|
timeoutSecond?: number
|
||||||
@@ -139,7 +147,8 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
success = true
|
success = true
|
||||||
resolve(r)
|
resolve(r)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
// 这里的callback比较特殊,QQ后端先返回是否调用成功,再返回一条结果数据
|
||||||
const secondCallback = () => {
|
const secondCallback = () => {
|
||||||
const hookId = registerReceiveHook<ReturnType>(cbCmd, (payload) => {
|
const hookId = registerReceiveHook<ReturnType>(cbCmd, (payload) => {
|
||||||
@@ -150,7 +159,8 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
success = true
|
success = true
|
||||||
resolve(payload)
|
resolve(payload)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
removeReceiveHook(hookId)
|
removeReceiveHook(hookId)
|
||||||
success = true
|
success = true
|
||||||
resolve(payload)
|
resolve(payload)
|
||||||
@@ -162,7 +172,8 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
log(`${methodName} callback`, result)
|
log(`${methodName} callback`, result)
|
||||||
if (result?.result == 0 || result === undefined) {
|
if (result?.result == 0 || result === undefined) {
|
||||||
afterFirstCmd && secondCallback()
|
afterFirstCmd && secondCallback()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
success = true
|
success = true
|
||||||
reject(`ntqq api call failed, ${result.errMsg}`)
|
reject(`ntqq api call failed, ${result.errMsg}`)
|
||||||
}
|
}
|
||||||
@@ -180,7 +191,8 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
channel,
|
channel,
|
||||||
{
|
{
|
||||||
sender: {
|
sender: {
|
||||||
send: (..._args: unknown[]) => {},
|
send: (..._args: unknown[]) => {
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ type: 'request', callbackId: uuid, eventName },
|
{ type: 'request', callbackId: uuid, eventName },
|
||||||
|
@@ -188,6 +188,7 @@ export const IMAGE_HTTP_HOST = 'https://gchat.qpic.cn'
|
|||||||
export const IMAGE_HTTP_HOST_NT = 'https://multimedia.nt.qq.com.cn'
|
export const IMAGE_HTTP_HOST_NT = 'https://multimedia.nt.qq.com.cn'
|
||||||
|
|
||||||
export interface PicElement {
|
export interface PicElement {
|
||||||
|
picType: PicType // 有这玩意儿吗
|
||||||
originImageUrl: string // http url, 没有host,host是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn
|
originImageUrl: string // http url, 没有host,host是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn
|
||||||
originImageMd5?: string
|
originImageMd5?: string
|
||||||
sourcePath: string // 图片本地路径
|
sourcePath: string // 图片本地路径
|
||||||
@@ -201,6 +202,7 @@ export interface PicElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum GrayTipElementSubType {
|
export enum GrayTipElementSubType {
|
||||||
|
RECALL = 1,
|
||||||
INVITE_NEW_MEMBER = 12,
|
INVITE_NEW_MEMBER = 12,
|
||||||
MEMBER_NEW_TITLE = 17,
|
MEMBER_NEW_TITLE = 17,
|
||||||
}
|
}
|
||||||
@@ -213,6 +215,8 @@ export interface GrayTipElement {
|
|||||||
operatorNick: string
|
operatorNick: string
|
||||||
operatorRemark: string
|
operatorRemark: string
|
||||||
operatorMemRemark?: string
|
operatorMemRemark?: string
|
||||||
|
origMsgSenderUid?: string
|
||||||
|
isSelfOperate?: boolean
|
||||||
wording: string // 自定义的撤回提示语
|
wording: string // 自定义的撤回提示语
|
||||||
}
|
}
|
||||||
aioOpGrayTipElement: TipAioOpGrayTipElement
|
aioOpGrayTipElement: TipAioOpGrayTipElement
|
||||||
@@ -226,11 +230,6 @@ export interface GrayTipElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum FaceType {
|
|
||||||
normal = 1, // 小黄脸
|
|
||||||
normal2 = 2, // 新小黄脸, 从faceIndex 222开始?
|
|
||||||
dice = 3, // 骰子
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum FaceIndex {
|
export enum FaceIndex {
|
||||||
dice = 358,
|
dice = 358,
|
||||||
@@ -239,7 +238,7 @@ export enum FaceIndex {
|
|||||||
|
|
||||||
export interface FaceElement {
|
export interface FaceElement {
|
||||||
faceIndex: number
|
faceIndex: number
|
||||||
faceType: FaceType
|
faceType: number
|
||||||
faceText?: string
|
faceText?: string
|
||||||
packId?: string
|
packId?: string
|
||||||
stickerId?: string
|
stickerId?: string
|
||||||
|
@@ -1,12 +1,13 @@
|
|||||||
export enum GroupNotifyTypes {
|
export enum GroupNotifyTypes {
|
||||||
INVITE_ME = 1,
|
INVITE_ME = 1,
|
||||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
INVITED_JOIN = 4, // 有人接受了邀请入群
|
||||||
|
JOIN_REQUEST_BY_INVITED = 5, // 有人邀请了别人入群
|
||||||
JOIN_REQUEST = 7,
|
JOIN_REQUEST = 7,
|
||||||
ADMIN_SET = 8,
|
ADMIN_SET = 8,
|
||||||
KICK_MEMBER = 9,
|
KICK_MEMBER = 9,
|
||||||
MEMBER_EXIT = 11, // 主动退出
|
MEMBER_EXIT = 11, // 主动退出
|
||||||
ADMIN_UNSET = 12, // 我被取消管理员
|
ADMIN_UNSET = 12, // 我被取消管理员
|
||||||
ADMIN_UNSET_OTHER = 13, // 其他人取消管理员
|
ADMIN_UNSET_OTHER = 13, // 其他人取消管理员
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GroupNotifies {
|
export interface GroupNotifies {
|
||||||
|
@@ -10,6 +10,7 @@ export interface QQLevel {
|
|||||||
moonNum: number
|
moonNum: number
|
||||||
starNum: number
|
starNum: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
uid: string // 加密的字符串
|
uid: string // 加密的字符串
|
||||||
uin: string // QQ号
|
uin: string // QQ号
|
||||||
@@ -72,4 +73,12 @@ export interface SelfInfo extends User {
|
|||||||
online?: boolean
|
online?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Friend extends User {}
|
export interface Friend extends User {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CategoryFriend {
|
||||||
|
categoryId: number;
|
||||||
|
categroyName: string;
|
||||||
|
categroyMbCount: number;
|
||||||
|
buddyList: User[]
|
||||||
|
}
|
@@ -1,12 +1,12 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import { dbUtil } from '../../../common/db'
|
import { dbUtil } from '@/common/db'
|
||||||
import { getConfigUtil } from '../../../common/config'
|
import { getConfigUtil } from '@/common/config'
|
||||||
import { log, sleep, uri2local } from '../../../common/utils'
|
import { log, sleep, uri2local } from '@/common/utils'
|
||||||
import { NTQQFileApi } from '../../../ntqqapi/api/file'
|
import { NTQQFileApi } from '@/ntqqapi/api'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { FileElement, RawMessage, VideoElement } from '../../../ntqqapi/types'
|
import { FileElement, RawMessage, VideoElement } from '@/ntqqapi/types'
|
||||||
import { FileCache } from '../../../common/types'
|
import { FileCache } from '@/common/types'
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名或者fileUuid
|
file: string // 文件名或者fileUuid
|
||||||
@@ -21,13 +21,12 @@ export interface GetFileResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||||
private getElement(msg: RawMessage): { id: string; element: VideoElement | FileElement } {
|
private getElement(msg: RawMessage, elementId: string): VideoElement | FileElement {
|
||||||
let element = msg.elements.find((e) => e.fileElement)
|
let element = msg.elements.find((e) => e.elementId === elementId)
|
||||||
if (!element) {
|
if (!element) {
|
||||||
element = msg.elements.find((e) => e.videoElement)
|
throw new Error('element not found')
|
||||||
return { id: element.elementId, element: element.videoElement }
|
|
||||||
}
|
}
|
||||||
return { id: element.elementId, element: element.fileElement }
|
return element.fileElement
|
||||||
}
|
}
|
||||||
private async download(cache: FileCache, file: string) {
|
private async download(cache: FileCache, file: string) {
|
||||||
log('需要调用 NTQQ 下载文件api')
|
log('需要调用 NTQQ 下载文件api')
|
||||||
@@ -35,14 +34,14 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
if (msg) {
|
if (msg) {
|
||||||
log('找到了文件 msg', msg)
|
log('找到了文件 msg', msg)
|
||||||
let element = this.getElement(msg)
|
let element = this.getElement(msg, cache.elementId)
|
||||||
log('找到了文件 element', element)
|
log('找到了文件 element', element)
|
||||||
// 构建下载函数
|
// 构建下载函数
|
||||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, element.id, '', '', true)
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, cache.elementId, '', '', true)
|
||||||
await sleep(1000)
|
await sleep(1000) // 这里延时是为何?
|
||||||
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||||
log('下载完成后的msg', msg)
|
log('下载完成后的msg', msg)
|
||||||
cache.filePath = this.getElement(msg).element.filePath
|
cache.filePath = this.getElement(msg, cache.elementId).filePath
|
||||||
dbUtil.addFileCache(file, cache).then()
|
dbUtil.addFileCache(file, cache).then()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,8 @@ import { OB11Constructor } from '../../constructor'
|
|||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: string // long msg id
|
message_id: string // long msg id,gocq
|
||||||
|
id?: string // long msg id, onebot11
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
@@ -16,7 +17,11 @@ interface Response {
|
|||||||
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
|
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
const rootMsg = await dbUtil.getMsgByLongId(payload.message_id)
|
const message_id = payload.id || payload.message_id
|
||||||
|
if (!message_id) {
|
||||||
|
throw Error('message_id不能为空')
|
||||||
|
}
|
||||||
|
const rootMsg = await dbUtil.getMsgByLongId(message_id)
|
||||||
if (!rootMsg) {
|
if (!rootMsg) {
|
||||||
throw Error('msg not found')
|
throw Error('msg not found')
|
||||||
}
|
}
|
||||||
|
17
src/onebot11/action/go-cqhttp/QuickOperation.ts
Normal file
17
src/onebot11/action/go-cqhttp/QuickOperation.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import BaseAction from '../BaseAction'
|
||||||
|
import { handleQuickOperation, QuickOperation, QuickOperationEvent } from '../quick-operation'
|
||||||
|
import { log } from '@/common/utils'
|
||||||
|
import { ActionName } from '../types'
|
||||||
|
|
||||||
|
interface Payload{
|
||||||
|
context: QuickOperationEvent,
|
||||||
|
operation: QuickOperation
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GoCQHTTHandleQuickOperation extends BaseAction<Payload, null>{
|
||||||
|
actionName = ActionName.GoCQHTTP_HandleQuickOperation
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
handleQuickOperation(payload.context, payload.operation).then().catch(log);
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
24
src/onebot11/action/group/GetGroupEssence.ts
Normal file
24
src/onebot11/action/group/GetGroupEssence.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { GroupEssenceMsgRet, WebApi } from "@/ntqqapi/api";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import { ActionName } from "../types";
|
||||||
|
|
||||||
|
interface PayloadType {
|
||||||
|
group_id: number;
|
||||||
|
pages?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetGroupEssence extends BaseAction<PayloadType, GroupEssenceMsgRet> {
|
||||||
|
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||||
|
|
||||||
|
protected async _handle(payload: PayloadType) {
|
||||||
|
throw '此 api 暂不支持'
|
||||||
|
const ret = await WebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages?.toString() || '0');
|
||||||
|
if (!ret) {
|
||||||
|
throw new Error('获取失败');
|
||||||
|
}
|
||||||
|
// ret.map((item) => {
|
||||||
|
//
|
||||||
|
// })
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
22
src/onebot11/action/group/GetGroupHonorInfo.ts
Normal file
22
src/onebot11/action/group/GetGroupHonorInfo.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { WebApi, WebHonorType } from "@/ntqqapi/api";
|
||||||
|
import { ActionName } from "../types";
|
||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
group_id: number,
|
||||||
|
type?: WebHonorType
|
||||||
|
}
|
||||||
|
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||||
|
actionName = ActionName.GetGroupHonorInfo;
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload) {
|
||||||
|
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||||
|
if (!payload.group_id) {
|
||||||
|
throw '缺少参数group_id';
|
||||||
|
}
|
||||||
|
if (!payload.type) {
|
||||||
|
payload.type = WebHonorType.ALL;
|
||||||
|
}
|
||||||
|
return await WebApi.getGroupHonorInfo(payload.group_id.toString(), payload.type);
|
||||||
|
}
|
||||||
|
}
|
@@ -14,13 +14,10 @@ class GetGroupList extends BaseAction<Payload, OB11Group[]> {
|
|||||||
actionName = ActionName.GetGroupList
|
actionName = ActionName.GetGroupList
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
if (
|
if (groups.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') {
|
||||||
groups.length === 0
|
|
||||||
|| payload?.no_cache === true || payload?.no_cache === 'true'
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
const groups = await NTQQGroupApi.getGroups(true)
|
const groups = await NTQQGroupApi.getGroups(true)
|
||||||
log("强制刷新群列表, 数量:", groups.length)
|
log('强制刷新群列表, 数量:', groups.length)
|
||||||
return OB11Constructor.groups(groups)
|
return OB11Constructor.groups(groups)
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ import { NTQQGroupApi } from '../../../ntqqapi/api/group'
|
|||||||
import { log } from '../../../common/utils'
|
import { log } from '../../../common/utils'
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
group_id: number,
|
group_id: number
|
||||||
no_cache: boolean | string
|
no_cache: boolean | string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import GetMsg from './msg/GetMsg'
|
import GetMsg from './msg/GetMsg'
|
||||||
import GetLoginInfo from './system/GetLoginInfo'
|
import GetLoginInfo from './system/GetLoginInfo'
|
||||||
import GetFriendList from './user/GetFriendList'
|
import { GetFriendList, GetFriendWithCategory} from './user/GetFriendList'
|
||||||
import GetGroupList from './group/GetGroupList'
|
import GetGroupList from './group/GetGroupList'
|
||||||
import GetGroupInfo from './group/GetGroupInfo'
|
import GetGroupInfo from './group/GetGroupInfo'
|
||||||
import GetGroupMemberList from './group/GetGroupMemberList'
|
import GetGroupMemberList from './group/GetGroupMemberList'
|
||||||
@@ -46,7 +46,10 @@ import GetFile from './file/GetFile'
|
|||||||
import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg'
|
import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg'
|
||||||
import { GetCookies } from './user/GetCookie'
|
import { GetCookies } from './user/GetCookie'
|
||||||
import { SetMsgEmojiLike } from './msg/SetMsgEmojiLike'
|
import { SetMsgEmojiLike } from './msg/SetMsgEmojiLike'
|
||||||
import { ForwardFriendSingleMsg, ForwardSingleGroupMsg } from './msg/ForwardSingleMsg'
|
import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from './msg/ForwardSingleMsg'
|
||||||
|
import { GetGroupEssence } from './group/GetGroupEssence'
|
||||||
|
import { GetGroupHonorInfo } from './group/GetGroupHonorInfo'
|
||||||
|
import { GoCQHTTHandleQuickOperation } from './go-cqhttp/QuickOperation'
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
@@ -55,6 +58,7 @@ export const actionHandlers = [
|
|||||||
new SetConfigAction(),
|
new SetConfigAction(),
|
||||||
new GetGroupAddRequest(),
|
new GetGroupAddRequest(),
|
||||||
new SetQQAvatar(),
|
new SetQQAvatar(),
|
||||||
|
new GetFriendWithCategory(),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(),
|
new SendLike(),
|
||||||
new GetMsg(),
|
new GetMsg(),
|
||||||
@@ -87,8 +91,10 @@ export const actionHandlers = [
|
|||||||
new GetCookies(),
|
new GetCookies(),
|
||||||
new SetMsgEmojiLike(),
|
new SetMsgEmojiLike(),
|
||||||
new ForwardFriendSingleMsg(),
|
new ForwardFriendSingleMsg(),
|
||||||
new ForwardSingleGroupMsg(),
|
new ForwardGroupSingleMsg(),
|
||||||
//以下为go-cqhttp api
|
//以下为go-cqhttp api
|
||||||
|
new GetGroupEssence(),
|
||||||
|
new GetGroupHonorInfo(),
|
||||||
new GoCQHTTPSendForwardMsg(),
|
new GoCQHTTPSendForwardMsg(),
|
||||||
new GoCQHTTPSendGroupForwardMsg(),
|
new GoCQHTTPSendGroupForwardMsg(),
|
||||||
new GoCQHTTPSendPrivateForwardMsg(),
|
new GoCQHTTPSendPrivateForwardMsg(),
|
||||||
@@ -100,6 +106,7 @@ export const actionHandlers = [
|
|||||||
new GoCQHTTPUploadPrivateFile(),
|
new GoCQHTTPUploadPrivateFile(),
|
||||||
new GoCQHTTPGetGroupMsgHistory(),
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
new GoCQHTTGetForwardMsgAction(),
|
new GoCQHTTGetForwardMsgAction(),
|
||||||
|
new GoCQHTTHandleQuickOperation()
|
||||||
]
|
]
|
||||||
|
|
||||||
function initActionMap() {
|
function initActionMap() {
|
||||||
|
@@ -11,7 +11,11 @@ interface Payload {
|
|||||||
user_id?: number
|
user_id?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
interface Response {
|
||||||
|
message_id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
class ForwardSingleMsg extends BaseAction<Payload, Response> {
|
||||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||||
if (payload.user_id) {
|
if (payload.user_id) {
|
||||||
return { chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString()) }
|
return { chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString()) }
|
||||||
@@ -19,10 +23,10 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
return { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
return { chatType: ChatType.group, peerUid: payload.group_id.toString() }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<Response> {
|
||||||
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
const msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||||
const peer = await this.getTargetPeer(payload)
|
const peer = await this.getTargetPeer(payload)
|
||||||
await NTQQMsgApi.forwardMsg(
|
const sentMsg = await NTQQMsgApi.forwardMsg(
|
||||||
{
|
{
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
@@ -30,7 +34,8 @@ class ForwardSingleMsg extends BaseAction<Payload, null> {
|
|||||||
peer,
|
peer,
|
||||||
[msg.msgId],
|
[msg.msgId],
|
||||||
)
|
)
|
||||||
return null
|
const ob11MsgId = await dbUtil.addMsg(sentMsg)
|
||||||
|
return {message_id: ob11MsgId}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +43,6 @@ export class ForwardFriendSingleMsg extends ForwardSingleMsg {
|
|||||||
actionName = ActionName.ForwardFriendSingleMsg
|
actionName = ActionName.ForwardFriendSingleMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ForwardSingleGroupMsg extends ForwardSingleMsg {
|
export class ForwardGroupSingleMsg extends ForwardSingleMsg {
|
||||||
actionName = ActionName.ForwardGroupSingleMsg
|
actionName = ActionName.ForwardGroupSingleMsg
|
||||||
}
|
}
|
||||||
|
@@ -14,11 +14,13 @@ import { friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo } f
|
|||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
OB11MessageDataType, OB11MessageFile,
|
OB11MessageDataType,
|
||||||
|
OB11MessageFile,
|
||||||
OB11MessageJson,
|
OB11MessageJson,
|
||||||
OB11MessageMixType,
|
OB11MessageMixType,
|
||||||
OB11MessageMusic,
|
OB11MessageMusic,
|
||||||
OB11MessageNode, OB11MessageVideo,
|
OB11MessageNode,
|
||||||
|
OB11MessageVideo,
|
||||||
OB11PostSendMsg,
|
OB11PostSendMsg,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { NTQQMsgApi, Peer } from '../../../ntqqapi/api/msg'
|
import { NTQQMsgApi, Peer } from '../../../ntqqapi/api/msg'
|
||||||
@@ -32,9 +34,9 @@ import { ALLOW_SEND_TEMP_MSG, getConfigUtil } from '../../../common/config'
|
|||||||
import { log } from '../../../common/utils/log'
|
import { log } from '../../../common/utils/log'
|
||||||
import { sleep } from '../../../common/utils/helper'
|
import { sleep } from '../../../common/utils/helper'
|
||||||
import { uri2local } from '../../../common/utils'
|
import { uri2local } from '../../../common/utils'
|
||||||
import { crychic } from '../../../ntqqapi/external/crychic'
|
import { crychic } from '../../../ntqqapi/native/crychic'
|
||||||
import { NTQQGroupApi } from '../../../ntqqapi/api'
|
import { NTQQGroupApi } from '../../../ntqqapi/api'
|
||||||
import { CustomMusicSignPostData, MusicSign, MusicSignPostData } from '../../../common/utils/sign'
|
import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '../../../common/utils/sign'
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
function checkUri(uri: string): boolean {
|
function checkUri(uri: string): boolean {
|
||||||
@@ -48,22 +50,28 @@ function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
|||||||
let data = msg['data']
|
let data = msg['data']
|
||||||
if (type === 'text' && !data['text']) {
|
if (type === 'text' && !data['text']) {
|
||||||
return 400
|
return 400
|
||||||
} else if (['image', 'voice', 'record'].includes(type)) {
|
}
|
||||||
|
else if (['image', 'voice', 'record'].includes(type)) {
|
||||||
if (!data['file']) {
|
if (!data['file']) {
|
||||||
return 400
|
return 400
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (checkUri(data['file'])) {
|
if (checkUri(data['file'])) {
|
||||||
return 200
|
return 200
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return 400
|
return 400
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type === 'at' && !data['qq']) {
|
}
|
||||||
return 400
|
else if (type === 'at' && !data['qq']) {
|
||||||
} else if (type === 'reply' && !data['id']) {
|
|
||||||
return 400
|
return 400
|
||||||
}
|
}
|
||||||
} else {
|
else if (type === 'reply' && !data['id']) {
|
||||||
|
return 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
return 400
|
return 400
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,10 +93,12 @@ export function convertMessage2List(message: OB11MessageMixType, autoEscape = fa
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
message = decodeCQCode(message.toString())
|
message = decodeCQCode(message.toString())
|
||||||
}
|
}
|
||||||
} else if (!Array.isArray(message)) {
|
}
|
||||||
|
else if (!Array.isArray(message)) {
|
||||||
message = [message]
|
message = [message]
|
||||||
}
|
}
|
||||||
return message
|
return message
|
||||||
@@ -106,172 +116,177 @@ export async function createSendElements(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch (sendMsg.type) {
|
switch (sendMsg.type) {
|
||||||
case OB11MessageDataType.text:
|
case OB11MessageDataType.text: {
|
||||||
{
|
const text = sendMsg.data?.text
|
||||||
const text = sendMsg.data?.text
|
if (text) {
|
||||||
if (text) {
|
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
||||||
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.at:
|
case OB11MessageDataType.at: {
|
||||||
{
|
if (!target) {
|
||||||
if (!target) {
|
continue
|
||||||
continue
|
}
|
||||||
|
let atQQ = sendMsg.data?.qq
|
||||||
|
if (atQQ) {
|
||||||
|
atQQ = atQQ.toString()
|
||||||
|
if (atQQ === 'all') {
|
||||||
|
// todo:查询剩余的at全体次数
|
||||||
|
const groupCode = (target as Group)?.groupCode
|
||||||
|
let remainAtAllCount = 1
|
||||||
|
let isAdmin: boolean = true
|
||||||
|
if (groupCode) {
|
||||||
|
try {
|
||||||
|
remainAtAllCount = (await NTQQGroupApi.getGroupAtAllRemainCount(groupCode)).atInfo
|
||||||
|
.RemainAtAllCountForUin
|
||||||
|
log(`群${groupCode}剩余at全体次数`, remainAtAllCount)
|
||||||
|
const self = await getGroupMember((target as Group)?.groupCode, selfInfo.uin)
|
||||||
|
isAdmin = self.role === GroupMemberRole.admin || self.role === GroupMemberRole.owner
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isAdmin && remainAtAllCount > 0) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let atQQ = sendMsg.data?.qq
|
else {
|
||||||
if (atQQ) {
|
// const atMember = group?.members.find(m => m.uin == atQQ)
|
||||||
atQQ = atQQ.toString()
|
const atMember = await getGroupMember((target as Group)?.groupCode, atQQ)
|
||||||
if (atQQ === 'all') {
|
if (atMember) {
|
||||||
// todo:查询剩余的at全体次数
|
sendElements.push(
|
||||||
const groupCode = (target as Group)?.groupCode
|
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick),
|
||||||
let remainAtAllCount = 1
|
)
|
||||||
let isAdmin: boolean = true
|
|
||||||
if (groupCode) {
|
|
||||||
try {
|
|
||||||
remainAtAllCount = (await NTQQGroupApi.getGroupAtAllRemainCount(groupCode)).atInfo
|
|
||||||
.RemainAtAllCountForUin
|
|
||||||
log(`群${groupCode}剩余at全体次数`, remainAtAllCount)
|
|
||||||
const self = await getGroupMember((target as Group)?.groupCode, selfInfo.uin)
|
|
||||||
isAdmin = self.role === GroupMemberRole.admin || self.role === GroupMemberRole.owner
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
if (isAdmin && remainAtAllCount > 0) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// const atMember = group?.members.find(m => m.uin == atQQ)
|
|
||||||
const atMember = await getGroupMember((target as Group)?.groupCode, atQQ)
|
|
||||||
if (atMember) {
|
|
||||||
sendElements.push(
|
|
||||||
SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.reply:
|
case OB11MessageDataType.reply: {
|
||||||
{
|
let replyMsgId = sendMsg.data.id
|
||||||
let replyMsgId = sendMsg.data.id
|
if (replyMsgId) {
|
||||||
if (replyMsgId) {
|
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
||||||
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId))
|
if (replyMsg) {
|
||||||
if (replyMsg) {
|
sendElements.push(
|
||||||
|
SendMsgElementConstructor.reply(
|
||||||
|
replyMsg.msgSeq,
|
||||||
|
replyMsg.msgId,
|
||||||
|
replyMsg.senderUin,
|
||||||
|
replyMsg.senderUin,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case OB11MessageDataType.face: {
|
||||||
|
const faceId = sendMsg.data?.id
|
||||||
|
if (faceId) {
|
||||||
|
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case OB11MessageDataType.mface: {
|
||||||
|
sendElements.push(
|
||||||
|
SendMsgElementConstructor.mface(
|
||||||
|
sendMsg.data.emoji_package_id,
|
||||||
|
sendMsg.data.emoji_id,
|
||||||
|
sendMsg.data.key,
|
||||||
|
sendMsg.data.summary,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case OB11MessageDataType.image:
|
||||||
|
case OB11MessageDataType.file:
|
||||||
|
case OB11MessageDataType.video:
|
||||||
|
case OB11MessageDataType.voice: {
|
||||||
|
const data = (sendMsg as OB11MessageFile).data
|
||||||
|
let file = data.file
|
||||||
|
const payloadFileName = data?.name
|
||||||
|
if (file) {
|
||||||
|
const cache = await dbUtil.getFileCache(file)
|
||||||
|
if (cache) {
|
||||||
|
if (fs.existsSync(cache.filePath)) {
|
||||||
|
file = 'file://' + cache.filePath
|
||||||
|
}
|
||||||
|
else if (cache.downloadFunc) {
|
||||||
|
await cache.downloadFunc()
|
||||||
|
file = cache.filePath
|
||||||
|
}
|
||||||
|
else if (cache.url) {
|
||||||
|
file = cache.url
|
||||||
|
}
|
||||||
|
log('找到文件缓存', file)
|
||||||
|
}
|
||||||
|
const { path, isLocal, fileName, errMsg } = await uri2local(file)
|
||||||
|
if (errMsg) {
|
||||||
|
throw errMsg
|
||||||
|
}
|
||||||
|
if (path) {
|
||||||
|
if (!isLocal) {
|
||||||
|
// 只删除http和base64转过来的文件
|
||||||
|
deleteAfterSentFiles.push(path)
|
||||||
|
}
|
||||||
|
if (sendMsg.type === OB11MessageDataType.file) {
|
||||||
|
log('发送文件', path, payloadFileName || fileName)
|
||||||
|
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName))
|
||||||
|
}
|
||||||
|
else if (sendMsg.type === OB11MessageDataType.video) {
|
||||||
|
log('发送视频', path, payloadFileName || fileName)
|
||||||
|
let thumb = sendMsg.data?.thumb
|
||||||
|
if (thumb) {
|
||||||
|
let uri2LocalRes = await uri2local(thumb)
|
||||||
|
if (uri2LocalRes.success) {
|
||||||
|
thumb = uri2LocalRes.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb))
|
||||||
|
}
|
||||||
|
else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||||
|
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
||||||
|
}
|
||||||
|
else if (sendMsg.type === OB11MessageDataType.image) {
|
||||||
sendElements.push(
|
sendElements.push(
|
||||||
SendMsgElementConstructor.reply(
|
await SendMsgElementConstructor.pic(
|
||||||
replyMsg.msgSeq,
|
path,
|
||||||
replyMsg.msgId,
|
sendMsg.data.summary || '',
|
||||||
replyMsg.senderUin,
|
<PicSubType>parseInt(sendMsg.data?.subType?.toString()) || 0,
|
||||||
replyMsg.senderUin,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
|
||||||
case OB11MessageDataType.face:
|
|
||||||
{
|
|
||||||
const faceId = sendMsg.data?.id
|
|
||||||
if (faceId) {
|
|
||||||
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case OB11MessageDataType.mface: {
|
|
||||||
sendElements.push(
|
|
||||||
SendMsgElementConstructor.mface(sendMsg.data.emoji_package_id, sendMsg.data.emoji_id, sendMsg.data.key, sendMsg.data.summary),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
case OB11MessageDataType.image:
|
break
|
||||||
case OB11MessageDataType.file:
|
case OB11MessageDataType.json: {
|
||||||
case OB11MessageDataType.video:
|
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
||||||
case OB11MessageDataType.voice:
|
}
|
||||||
{
|
break
|
||||||
const data = (sendMsg as OB11MessageFile).data
|
case OB11MessageDataType.poke: {
|
||||||
let file = data.file
|
let qq = sendMsg.data?.qq || sendMsg.data?.id
|
||||||
const payloadFileName = data?.name
|
if (qq) {
|
||||||
if (file) {
|
if ('groupCode' in target) {
|
||||||
const cache = await dbUtil.getFileCache(file)
|
crychic.sendGroupPoke(target.groupCode, qq.toString())
|
||||||
if (cache) {
|
|
||||||
if (fs.existsSync(cache.filePath)) {
|
|
||||||
file = 'file://' + cache.filePath
|
|
||||||
} else if (cache.downloadFunc) {
|
|
||||||
await cache.downloadFunc()
|
|
||||||
file = cache.filePath
|
|
||||||
} else if (cache.url) {
|
|
||||||
file = cache.url
|
|
||||||
}
|
|
||||||
log('找到文件缓存', file)
|
|
||||||
}
|
|
||||||
const { path, isLocal, fileName, errMsg } = await uri2local(file)
|
|
||||||
if (errMsg) {
|
|
||||||
throw errMsg
|
|
||||||
}
|
|
||||||
if (path) {
|
|
||||||
if (!isLocal) {
|
|
||||||
// 只删除http和base64转过来的文件
|
|
||||||
deleteAfterSentFiles.push(path)
|
|
||||||
}
|
|
||||||
if (sendMsg.type === OB11MessageDataType.file) {
|
|
||||||
log('发送文件', path, payloadFileName || fileName)
|
|
||||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName))
|
|
||||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
|
||||||
log('发送视频', path, payloadFileName || fileName)
|
|
||||||
let thumb = sendMsg.data?.thumb
|
|
||||||
if (thumb) {
|
|
||||||
let uri2LocalRes = await uri2local(thumb)
|
|
||||||
if (uri2LocalRes.success) {
|
|
||||||
thumb = uri2LocalRes.path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb))
|
|
||||||
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
|
||||||
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
|
||||||
} else if (sendMsg.type === OB11MessageDataType.image) {
|
|
||||||
sendElements.push(
|
|
||||||
await SendMsgElementConstructor.pic(
|
|
||||||
path,
|
|
||||||
sendMsg.data.summary || '',
|
|
||||||
<PicSubType>parseInt(sendMsg.data?.subType?.toString()) || 0,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
break
|
if (!qq) {
|
||||||
case OB11MessageDataType.json:
|
qq = parseInt(target.uin)
|
||||||
{
|
|
||||||
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data))
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case OB11MessageDataType.poke:
|
|
||||||
{
|
|
||||||
let qq = sendMsg.data?.qq || sendMsg.data?.id
|
|
||||||
if (qq) {
|
|
||||||
if ('groupCode' in target) {
|
|
||||||
crychic.sendGroupPoke(target.groupCode, qq.toString())
|
|
||||||
} else {
|
|
||||||
if (!qq) {
|
|
||||||
qq = parseInt(target.uin)
|
|
||||||
}
|
|
||||||
crychic.sendFriendPoke(qq.toString())
|
|
||||||
}
|
}
|
||||||
sendElements.push(SendMsgElementConstructor.poke('', ''))
|
crychic.sendFriendPoke(qq.toString())
|
||||||
}
|
}
|
||||||
|
sendElements.push(SendMsgElementConstructor.poke('', ''))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.dice:
|
case OB11MessageDataType.dice: {
|
||||||
{
|
const resultId = sendMsg.data?.result
|
||||||
const resultId = sendMsg.data?.result
|
sendElements.push(SendMsgElementConstructor.dice(resultId))
|
||||||
sendElements.push(SendMsgElementConstructor.dice(resultId))
|
}
|
||||||
}
|
|
||||||
break
|
break
|
||||||
case OB11MessageDataType.RPS:
|
case OB11MessageDataType.RPS: {
|
||||||
{
|
const resultId = sendMsg.data?.result
|
||||||
const resultId = sendMsg.data?.result
|
sendElements.push(SendMsgElementConstructor.rps(resultId))
|
||||||
sendElements.push(SendMsgElementConstructor.rps(resultId))
|
}
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,10 +306,34 @@ export async function sendMsg(
|
|||||||
if (!sendElements.length) {
|
if (!sendElements.length) {
|
||||||
throw '消息体无法解析,请检查是否发送了不支持的消息类型'
|
throw '消息体无法解析,请检查是否发送了不支持的消息类型'
|
||||||
}
|
}
|
||||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000)
|
// 计算发送的文件大小
|
||||||
|
let totalSize = 0
|
||||||
|
for (const fileElement of sendElements) {
|
||||||
|
try {
|
||||||
|
if (fileElement.elementType === ElementType.PTT) {
|
||||||
|
totalSize += fs.statSync(fileElement.pttElement.filePath).size
|
||||||
|
}
|
||||||
|
if (fileElement.elementType === ElementType.FILE) {
|
||||||
|
totalSize += fs.statSync(fileElement.fileElement.filePath).size
|
||||||
|
}
|
||||||
|
if (fileElement.elementType === ElementType.VIDEO) {
|
||||||
|
totalSize += fs.statSync(fileElement.videoElement.filePath).size
|
||||||
|
}
|
||||||
|
if (fileElement.elementType === ElementType.PIC) {
|
||||||
|
totalSize += fs.statSync(fileElement.picElement.sourcePath).size
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log('文件大小计算失败', e, fileElement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log('发送消息总大小', totalSize, 'bytes')
|
||||||
|
let timeout = ((totalSize / 1024 / 100) * 1000) + 5000 // 100kb/s
|
||||||
|
log('设置消息超时时间', timeout)
|
||||||
|
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout)
|
||||||
log('消息发送结果', returnMsg)
|
log('消息发送结果', returnMsg)
|
||||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {}))
|
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
||||||
|
}))
|
||||||
return returnMsg
|
return returnMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,14 +342,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||||
const messages = convertMessage2List(payload.message)
|
const messages = convertMessage2List(payload.message)
|
||||||
const fmNum = this.getSpecialMsgNum(payload, OB11MessageDataType.node)
|
const fmNum = this.getSpecialMsgNum(messages, OB11MessageDataType.node)
|
||||||
if (fmNum && fmNum != messages.length) {
|
if (fmNum && fmNum != messages.length) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素',
|
message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const musicNum = this.getSpecialMsgNum(payload, OB11MessageDataType.music)
|
const musicNum = this.getSpecialMsgNum(messages, OB11MessageDataType.music)
|
||||||
if (musicNum && messages.length > 1) {
|
if (musicNum && messages.length > 1) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
@@ -358,7 +397,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
if (friend) {
|
if (friend) {
|
||||||
// peer.name = friend.nickName
|
// peer.name = friend.nickName
|
||||||
peer.peerUid = friend.uid
|
peer.peerUid = friend.uid
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
peer.chatType = ChatType.temp
|
peer.chatType = ChatType.temp
|
||||||
const tempUserUid = getUidByUin(payload.user_id.toString())
|
const tempUserUid = getUidByUin(payload.user_id.toString())
|
||||||
if (!tempUserUid) {
|
if (!tempUserUid) {
|
||||||
@@ -371,25 +411,29 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
if (payload?.group_id && payload.message_type === 'group') {
|
if (payload?.group_id && payload.message_type === 'group') {
|
||||||
await genGroupPeer()
|
await genGroupPeer()
|
||||||
} else if (payload?.user_id) {
|
}
|
||||||
|
else if (payload?.user_id) {
|
||||||
genFriendPeer()
|
genFriendPeer()
|
||||||
} else if (payload.group_id) {
|
}
|
||||||
|
else if (payload.group_id) {
|
||||||
await genGroupPeer()
|
await genGroupPeer()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw '发送消息参数错误, 请指定group_id或user_id'
|
throw '发送消息参数错误, 请指定group_id或user_id'
|
||||||
}
|
}
|
||||||
const messages = convertMessage2List(
|
const messages = convertMessage2List(
|
||||||
payload.message,
|
payload.message,
|
||||||
payload.auto_escape === true || payload.auto_escape === 'true',
|
payload.auto_escape === true || payload.auto_escape === 'true',
|
||||||
)
|
)
|
||||||
if (this.getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
if (this.getSpecialMsgNum(messages, OB11MessageDataType.node)) {
|
||||||
try {
|
try {
|
||||||
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[], group)
|
||||||
return { message_id: returnMsg.msgShortId }
|
return { message_id: returnMsg.msgShortId }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw '发送转发消息失败 ' + e.toString()
|
throw '发送转发消息失败 ' + e.toString()
|
||||||
}
|
}
|
||||||
} else if (this.getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
}
|
||||||
|
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
|
||||||
const music = messages[0] as OB11MessageMusic
|
const music = messages[0] as OB11MessageMusic
|
||||||
if (music) {
|
if (music) {
|
||||||
const { musicSignUrl } = getConfigUtil().getConfig()
|
const { musicSignUrl } = getConfigUtil().getConfig()
|
||||||
@@ -405,9 +449,30 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
;(postData as CustomMusicSignPostData).singer = music.data.content
|
;(postData as CustomMusicSignPostData).singer = music.data.content
|
||||||
delete (postData as OB11MessageCustomMusic['data']).content
|
delete (postData as OB11MessageCustomMusic['data']).content
|
||||||
}
|
}
|
||||||
|
if (type === 'custom') {
|
||||||
|
const customMusicData = music.data as CustomMusicSignPostData
|
||||||
|
if (!customMusicData.url) {
|
||||||
|
throw '自定义音卡缺少参数url'
|
||||||
|
}
|
||||||
|
if (!customMusicData.audio) {
|
||||||
|
throw '自定义音卡缺少参数audio'
|
||||||
|
}
|
||||||
|
if (!customMusicData.title) {
|
||||||
|
throw '自定义音卡缺少参数title'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type === 'qq' || type === '163') {
|
||||||
|
const idMusicData = music.data as IdMusicSignPostData
|
||||||
|
if (!idMusicData.id) {
|
||||||
|
throw '音乐卡片缺少id参数'
|
||||||
|
}
|
||||||
|
}
|
||||||
let jsonContent: string
|
let jsonContent: string
|
||||||
try {
|
try {
|
||||||
jsonContent = await new MusicSign(musicSignUrl).sign(postData)
|
jsonContent = await new MusicSign(musicSignUrl).sign(postData)
|
||||||
|
if (!jsonContent) {
|
||||||
|
throw '音乐消息生成失败,提交内容有误或者签名服务器签名失败'
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw `签名音乐消息失败:${e}`
|
throw `签名音乐消息失败:${e}`
|
||||||
}
|
}
|
||||||
@@ -425,13 +490,14 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
const returnMsg = await sendMsg(peer, sendElements, deleteAfterSentFiles)
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {}))
|
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
||||||
|
}))
|
||||||
return { message_id: returnMsg.msgShortId }
|
return { message_id: returnMsg.msgShortId }
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
private getSpecialMsgNum(message: OB11MessageData[], msgType: OB11MessageDataType): number {
|
||||||
if (Array.isArray(payload.message)) {
|
if (Array.isArray(message)) {
|
||||||
return payload.message.filter((msg) => msg.type == msgType).length
|
return message.filter((msg) => msg.type == msgType).length
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -483,7 +549,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId))
|
let nodeMsg = await dbUtil.getMsgByShortId(parseInt(nodeId))
|
||||||
if (!needClone) {
|
if (!needClone) {
|
||||||
nodeMsgIds.push(nodeMsg.msgId)
|
nodeMsgIds.push(nodeMsg.msgId)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (nodeMsg.peerUid !== selfInfo.uid) {
|
if (nodeMsg.peerUid !== selfInfo.uid) {
|
||||||
const cloneMsg = await this.cloneMsg(nodeMsg)
|
const cloneMsg = await this.cloneMsg(nodeMsg)
|
||||||
if (cloneMsg) {
|
if (cloneMsg) {
|
||||||
@@ -491,7 +558,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// 自定义的消息
|
// 自定义的消息
|
||||||
// 提取消息段,发给自己生成消息id
|
// 提取消息段,发给自己生成消息id
|
||||||
try {
|
try {
|
||||||
@@ -513,7 +581,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
sendElementsSplit[splitIndex] = [ele]
|
sendElementsSplit[splitIndex] = [ele]
|
||||||
splitIndex++
|
splitIndex++
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sendElementsSplit[splitIndex].push(ele)
|
sendElementsSplit[splitIndex].push(ele)
|
||||||
}
|
}
|
||||||
log(sendElementsSplit)
|
log(sendElementsSplit)
|
||||||
@@ -525,7 +594,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
await sleep(500)
|
await sleep(500)
|
||||||
log('转发节点生成成功', nodeMsg.msgId)
|
log('转发节点生成成功', nodeMsg.msgId)
|
||||||
}
|
}
|
||||||
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {}))
|
deleteAfterSentFiles.map((f) => fs.unlink(f, () => {
|
||||||
|
}))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('生成转发消息节点失败', e)
|
log('生成转发消息节点失败', e)
|
||||||
}
|
}
|
||||||
@@ -542,7 +612,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
nodeMsgArray.push(nodeMsg)
|
nodeMsgArray.push(nodeMsg)
|
||||||
if (!srcPeer) {
|
if (!srcPeer) {
|
||||||
srcPeer = { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }
|
srcPeer = { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }
|
||||||
} else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
}
|
||||||
|
else if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||||
needSendSelf = true
|
needSendSelf = true
|
||||||
srcPeer = selfPeer
|
srcPeer = selfPeer
|
||||||
}
|
}
|
||||||
|
149
src/onebot11/action/quick-operation.ts
Normal file
149
src/onebot11/action/quick-operation.ts
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
// handle quick action, create at 2024-5-18 10:54:39 by linyuchen
|
||||||
|
|
||||||
|
|
||||||
|
import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from '../types'
|
||||||
|
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
||||||
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
||||||
|
import { dbUtil } from '@/common/db'
|
||||||
|
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '@/ntqqapi/api'
|
||||||
|
import { ChatType, Group, GroupRequestOperateTypes } from '@/ntqqapi/types'
|
||||||
|
import { getGroup, getUidByUin } from '@/common/data'
|
||||||
|
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
||||||
|
import { isNull, log } from '@/common/utils'
|
||||||
|
import { getConfigUtil } from '@/common/config'
|
||||||
|
|
||||||
|
|
||||||
|
interface QuickOperationPrivateMessage {
|
||||||
|
reply?: string
|
||||||
|
auto_escape?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickOperationGroupMessage extends QuickOperationPrivateMessage {
|
||||||
|
// 回复群消息
|
||||||
|
at_sender?: boolean
|
||||||
|
delete?: boolean
|
||||||
|
kick?: boolean
|
||||||
|
ban?: boolean
|
||||||
|
ban_duration?: number
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickOperationFriendRequest {
|
||||||
|
approve?: boolean
|
||||||
|
remark?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QuickOperationGroupRequest {
|
||||||
|
approve?: boolean
|
||||||
|
reason?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type QuickOperation = QuickOperationPrivateMessage &
|
||||||
|
QuickOperationGroupMessage &
|
||||||
|
QuickOperationFriendRequest &
|
||||||
|
QuickOperationGroupRequest
|
||||||
|
|
||||||
|
export type QuickOperationEvent = OB11Message | OB11FriendRequestEvent | OB11GroupRequestEvent;
|
||||||
|
|
||||||
|
export async function handleQuickOperation(context: QuickOperationEvent, quickAction: QuickOperation) {
|
||||||
|
if (context.post_type === 'message') {
|
||||||
|
handleMsg(context as OB11Message, quickAction).then().catch(log)
|
||||||
|
}
|
||||||
|
if (context.post_type === 'request') {
|
||||||
|
const friendRequest = context as OB11FriendRequestEvent
|
||||||
|
const groupRequest = context as OB11GroupRequestEvent
|
||||||
|
if ((friendRequest).request_type === 'friend') {
|
||||||
|
handleFriendRequest(friendRequest, quickAction).then().catch(log)
|
||||||
|
}
|
||||||
|
else if (groupRequest.request_type === 'group') {
|
||||||
|
handleGroupRequest(groupRequest, quickAction).then().catch(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMessage | QuickOperationGroupMessage) {
|
||||||
|
msg = msg as OB11Message
|
||||||
|
const rawMessage = await dbUtil.getMsgByShortId(msg.message_id)
|
||||||
|
const reply = quickAction.reply
|
||||||
|
const ob11Config = getConfigUtil().getConfig().ob11
|
||||||
|
let peer: Peer = {
|
||||||
|
chatType: ChatType.friend,
|
||||||
|
peerUid: msg.user_id.toString(),
|
||||||
|
}
|
||||||
|
if (msg.message_type == 'private') {
|
||||||
|
peer.peerUid = getUidByUin(msg.user_id.toString())
|
||||||
|
if (msg.sub_type === 'group') {
|
||||||
|
peer.chatType = ChatType.temp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
peer.chatType = ChatType.group
|
||||||
|
peer.peerUid = msg.group_id.toString()
|
||||||
|
}
|
||||||
|
if (reply) {
|
||||||
|
let group: Group = null
|
||||||
|
let replyMessage: OB11MessageData[] = []
|
||||||
|
if (ob11Config.enableQOAutoQuote) {
|
||||||
|
replyMessage.push({
|
||||||
|
type: OB11MessageDataType.reply,
|
||||||
|
data: {
|
||||||
|
id: msg.message_id.toString(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.message_type == 'group') {
|
||||||
|
group = await getGroup(msg.group_id.toString())
|
||||||
|
if ((quickAction as QuickOperationGroupMessage).at_sender) {
|
||||||
|
replyMessage.push({
|
||||||
|
type: 'at',
|
||||||
|
data: {
|
||||||
|
qq: msg.user_id.toString(),
|
||||||
|
},
|
||||||
|
} as OB11MessageAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
replyMessage = replyMessage.concat(convertMessage2List(reply, quickAction.auto_escape))
|
||||||
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group)
|
||||||
|
log(`发送消息给`, peer, sendElements)
|
||||||
|
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then().catch(log)
|
||||||
|
}
|
||||||
|
if (msg.message_type === 'group') {
|
||||||
|
const groupMsgQuickAction = quickAction as QuickOperationGroupMessage
|
||||||
|
// handle group msg
|
||||||
|
if (groupMsgQuickAction.delete) {
|
||||||
|
NTQQMsgApi.recallMsg(peer, [rawMessage.msgId]).then().catch(log)
|
||||||
|
}
|
||||||
|
if (groupMsgQuickAction.kick) {
|
||||||
|
NTQQGroupApi.kickMember(peer.peerUid, [rawMessage.senderUid]).then().catch(log)
|
||||||
|
}
|
||||||
|
if (groupMsgQuickAction.ban) {
|
||||||
|
NTQQGroupApi.banMember(peer.peerUid, [
|
||||||
|
{
|
||||||
|
uid: rawMessage.senderUid,
|
||||||
|
timeStamp: groupMsgQuickAction.ban_duration || 60 * 30,
|
||||||
|
},
|
||||||
|
]).then().catch(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleFriendRequest(request: OB11FriendRequestEvent,
|
||||||
|
quickAction: QuickOperationFriendRequest) {
|
||||||
|
if (!isNull(quickAction.approve)) {
|
||||||
|
// todo: set remark
|
||||||
|
NTQQFriendApi.handleFriendRequest(request.flag, quickAction.approve).then().catch(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function handleGroupRequest(request: OB11GroupRequestEvent,
|
||||||
|
quickAction: QuickOperationGroupRequest) {
|
||||||
|
if (!isNull(quickAction.approve)) {
|
||||||
|
NTQQGroupApi.handleGroupRequest(
|
||||||
|
request.flag,
|
||||||
|
quickAction.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||||
|
quickAction.reason,
|
||||||
|
).then().catch(log)
|
||||||
|
}
|
||||||
|
}
|
@@ -21,6 +21,7 @@ export enum ActionName {
|
|||||||
SetConfig = 'set_config',
|
SetConfig = 'set_config',
|
||||||
Debug = 'llonebot_debug',
|
Debug = 'llonebot_debug',
|
||||||
GetFile = 'get_file',
|
GetFile = 'get_file',
|
||||||
|
GetFriendsWithCategory = 'get_friends_with_category',
|
||||||
// onebot 11
|
// onebot 11
|
||||||
SendLike = 'send_like',
|
SendLike = 'send_like',
|
||||||
GetLoginInfo = 'get_login_info',
|
GetLoginInfo = 'get_login_info',
|
||||||
@@ -66,4 +67,7 @@ export enum ActionName {
|
|||||||
GoCQHTTP_DownloadFile = 'download_file',
|
GoCQHTTP_DownloadFile = 'download_file',
|
||||||
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',
|
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',
|
||||||
GoCQHTTP_GetForwardMsg = 'get_forward_msg',
|
GoCQHTTP_GetForwardMsg = 'get_forward_msg',
|
||||||
|
GoCQHTTP_GetEssenceMsg = "get_essence_msg_list",
|
||||||
|
GoCQHTTP_HandleQuickOperation = ".handle_quick_operation",
|
||||||
|
GetGroupHonorInfo = "get_group_honor_info",
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,16 @@
|
|||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { NTQQUserApi } from '../../../ntqqapi/api'
|
import { NTQQUserApi } from '@/ntqqapi/api'
|
||||||
import { groups } from '../../../common/data'
|
import { ActionName } from '../types'
|
||||||
import { ActionName } from '../types'
|
|
||||||
|
interface Payload {
|
||||||
export class GetCookies extends BaseAction<null, { cookies: string; bkn: string }> {
|
domain: string
|
||||||
actionName = ActionName.GetCookies
|
}
|
||||||
|
|
||||||
protected async _handle() {
|
export class GetCookies extends BaseAction<Payload, { cookies: string; bkn: string }> {
|
||||||
return NTQQUserApi.getCookie(groups[0])
|
actionName = ActionName.GetCookies
|
||||||
}
|
|
||||||
}
|
protected async _handle(payload: Payload) {
|
||||||
|
const domain = payload.domain || 'qun.qq.com'
|
||||||
|
return NTQQUserApi.getCookies(domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
import { OB11User } from '../../types'
|
import { OB11User } from '../../types'
|
||||||
import { OB11Constructor } from '../../constructor'
|
import { OB11Constructor } from '../../constructor'
|
||||||
import { friends } from '../../../common/data'
|
import { friends, rawFriends } from '@/common/data'
|
||||||
import BaseAction from '../BaseAction'
|
import BaseAction from '../BaseAction'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import { NTQQFriendApi } from '../../../ntqqapi/api'
|
import { NTQQFriendApi } from '@/ntqqapi/api'
|
||||||
import { log } from '../../../common/utils'
|
import { CategoryFriend } from '@/ntqqapi/types'
|
||||||
|
|
||||||
interface Payload{
|
interface Payload {
|
||||||
no_cache: boolean | string
|
no_cache: boolean | string
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
export class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
||||||
actionName = ActionName.GetFriendList
|
actionName = ActionName.GetFriendList
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
@@ -26,4 +26,11 @@ class GetFriendList extends BaseAction<Payload, OB11User[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GetFriendList
|
|
||||||
|
export class GetFriendWithCategory extends BaseAction<void, Array<CategoryFriend>> {
|
||||||
|
actionName = ActionName.GetFriendsWithCategory;
|
||||||
|
|
||||||
|
protected async _handle(payload: void) {
|
||||||
|
return rawFriends;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
import fastXmlParser, { XMLParser } from 'fast-xml-parser'
|
import fastXmlParser from 'fast-xml-parser'
|
||||||
import {
|
import {
|
||||||
OB11Group,
|
OB11Group,
|
||||||
OB11GroupMember,
|
OB11GroupMember,
|
||||||
@@ -16,8 +16,7 @@ import {
|
|||||||
GrayTipElementSubType,
|
GrayTipElementSubType,
|
||||||
Group,
|
Group,
|
||||||
GroupMember,
|
GroupMember,
|
||||||
IMAGE_HTTP_HOST,
|
PicType,
|
||||||
IMAGE_HTTP_HOST_NT,
|
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SelfInfo,
|
SelfInfo,
|
||||||
Sex,
|
Sex,
|
||||||
@@ -25,7 +24,7 @@ import {
|
|||||||
User,
|
User,
|
||||||
VideoElement,
|
VideoElement,
|
||||||
} from '../ntqqapi/types'
|
} from '../ntqqapi/types'
|
||||||
import { deleteGroup, getFriend, getGroupMember, groups, selfInfo, tempGroupCodeMap } from '../common/data'
|
import { deleteGroup, getFriend, getGroupMember, selfInfo, tempGroupCodeMap } from '../common/data'
|
||||||
import { EventType } from './event/OB11BaseEvent'
|
import { EventType } from './event/OB11BaseEvent'
|
||||||
import { encodeCQCode } from './cqcode'
|
import { encodeCQCode } from './cqcode'
|
||||||
import { dbUtil } from '../common/db'
|
import { dbUtil } from '../common/db'
|
||||||
@@ -46,6 +45,8 @@ import { NTQQGroupApi } from '../ntqqapi/api'
|
|||||||
import { OB11GroupMsgEmojiLikeEvent } from './event/notice/OB11MsgEmojiLikeEvent'
|
import { OB11GroupMsgEmojiLikeEvent } from './event/notice/OB11MsgEmojiLikeEvent'
|
||||||
import { mFaceCache } from '../ntqqapi/constructor'
|
import { mFaceCache } from '../ntqqapi/constructor'
|
||||||
import { OB11FriendAddNoticeEvent } from './event/notice/OB11FriendAddNoticeEvent'
|
import { OB11FriendAddNoticeEvent } from './event/notice/OB11FriendAddNoticeEvent'
|
||||||
|
import { OB11FriendRecallNoticeEvent } from './event/notice/OB11FriendRecallNoticeEvent'
|
||||||
|
import { OB11GroupRecallNoticeEvent } from './event/notice/OB11GroupRecallNoticeEvent'
|
||||||
|
|
||||||
let lastRKeyUpdateTime = 0
|
let lastRKeyUpdateTime = 0
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ export class OB11Constructor {
|
|||||||
let config = getConfigUtil().getConfig()
|
let config = getConfigUtil().getConfig()
|
||||||
const {
|
const {
|
||||||
enableLocalFile2Url,
|
enableLocalFile2Url,
|
||||||
|
debug,
|
||||||
ob11: { messagePostFormat },
|
ob11: { messagePostFormat },
|
||||||
} = config
|
} = config
|
||||||
const message_type = msg.chatType == ChatType.group ? 'group' : 'private'
|
const message_type = msg.chatType == ChatType.group ? 'group' : 'private'
|
||||||
@@ -63,6 +65,7 @@ export class OB11Constructor {
|
|||||||
time: parseInt(msg.msgTime) || Date.now(),
|
time: parseInt(msg.msgTime) || Date.now(),
|
||||||
message_id: msg.msgShortId,
|
message_id: msg.msgShortId,
|
||||||
real_id: msg.msgShortId,
|
real_id: msg.msgShortId,
|
||||||
|
message_seq: msg.msgShortId,
|
||||||
message_type: msg.chatType == ChatType.group ? 'group' : 'private',
|
message_type: msg.chatType == ChatType.group ? 'group' : 'private',
|
||||||
sender: {
|
sender: {
|
||||||
user_id: parseInt(msg.senderUin),
|
user_id: parseInt(msg.senderUin),
|
||||||
@@ -76,21 +79,26 @@ export class OB11Constructor {
|
|||||||
message_format: messagePostFormat === 'string' ? 'string' : 'array',
|
message_format: messagePostFormat === 'string' ? 'string' : 'array',
|
||||||
post_type: selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
|
post_type: selfInfo.uin == msg.senderUin ? EventType.MESSAGE_SENT : EventType.MESSAGE,
|
||||||
}
|
}
|
||||||
|
if (debug) {
|
||||||
|
resMsg.raw = msg
|
||||||
|
}
|
||||||
if (msg.chatType == ChatType.group) {
|
if (msg.chatType == ChatType.group) {
|
||||||
resMsg.sub_type = 'normal' // 这里go-cqhttp是group,而onebot11标准是normal, 蛋疼
|
resMsg.sub_type = 'normal'
|
||||||
resMsg.group_id = parseInt(msg.peerUin)
|
resMsg.group_id = parseInt(msg.peerUin)
|
||||||
const member = await getGroupMember(msg.peerUin, msg.senderUin)
|
const member = await getGroupMember(msg.peerUin, msg.senderUin)
|
||||||
if (member) {
|
if (member) {
|
||||||
resMsg.sender.role = OB11Constructor.groupMemberRole(member.role)
|
resMsg.sender.role = OB11Constructor.groupMemberRole(member.role)
|
||||||
resMsg.sender.nickname = member.nick
|
resMsg.sender.nickname = member.nick
|
||||||
}
|
}
|
||||||
} else if (msg.chatType == ChatType.friend) {
|
}
|
||||||
|
else if (msg.chatType == ChatType.friend) {
|
||||||
resMsg.sub_type = 'friend'
|
resMsg.sub_type = 'friend'
|
||||||
const friend = await getFriend(msg.senderUin)
|
const friend = await getFriend(msg.senderUin)
|
||||||
if (friend) {
|
if (friend) {
|
||||||
resMsg.sender.nickname = friend.nick
|
resMsg.sender.nickname = friend.nick
|
||||||
}
|
}
|
||||||
} else if (msg.chatType == ChatType.temp) {
|
}
|
||||||
|
else if (msg.chatType == ChatType.temp) {
|
||||||
resMsg.sub_type = 'group'
|
resMsg.sub_type = 'group'
|
||||||
const tempGroupCode = tempGroupCodeMap[msg.peerUin]
|
const tempGroupCode = tempGroupCodeMap[msg.peerUin]
|
||||||
if (tempGroupCode) {
|
if (tempGroupCode) {
|
||||||
@@ -108,7 +116,8 @@ export class OB11Constructor {
|
|||||||
if (element.textElement.atType == AtType.atAll) {
|
if (element.textElement.atType == AtType.atAll) {
|
||||||
// message_data["data"]["mention"] = "all"
|
// message_data["data"]["mention"] = "all"
|
||||||
message_data['data']['qq'] = 'all'
|
message_data['data']['qq'] = 'all'
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
let atUid = element.textElement.atNtUid
|
let atUid = element.textElement.atNtUid
|
||||||
let atQQ = element.textElement.atUid
|
let atQQ = element.textElement.atUid
|
||||||
if (!atQQ || atQQ === '0') {
|
if (!atQQ || atQQ === '0') {
|
||||||
@@ -122,14 +131,16 @@ export class OB11Constructor {
|
|||||||
message_data['data']['qq'] = atQQ
|
message_data['data']['qq'] = atQQ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (element.textElement) {
|
}
|
||||||
|
else if (element.textElement) {
|
||||||
message_data['type'] = 'text'
|
message_data['type'] = 'text'
|
||||||
let text = element.textElement.content
|
let text = element.textElement.content
|
||||||
if (!text.trim()) {
|
if (!text.trim()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
message_data['data']['text'] = text
|
message_data['data']['text'] = text
|
||||||
} else if (element.replyElement) {
|
}
|
||||||
|
else if (element.replyElement) {
|
||||||
message_data['type'] = 'reply'
|
message_data['type'] = 'reply'
|
||||||
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
// log("收到回复消息", element.replyElement.replayMsgSeq)
|
||||||
try {
|
try {
|
||||||
@@ -137,26 +148,34 @@ export class OB11Constructor {
|
|||||||
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
// log("找到回复消息", replyMsg.msgShortId, replyMsg.msgId)
|
||||||
if (replyMsg) {
|
if (replyMsg) {
|
||||||
message_data['data']['id'] = replyMsg.msgShortId.toString()
|
message_data['data']['id'] = replyMsg.msgShortId.toString()
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq)
|
log('获取不到引用的消息', e.stack, element.replyElement.replayMsgSeq)
|
||||||
}
|
}
|
||||||
} else if (element.picElement) {
|
}
|
||||||
|
else if (element.picElement) {
|
||||||
message_data['type'] = 'image'
|
message_data['type'] = 'image'
|
||||||
// message_data["data"]["file"] = element.picElement.sourcePath
|
// message_data["data"]["file"] = element.picElement.sourcePath
|
||||||
message_data['data']['file'] = element.picElement.fileName
|
let fileName = element.picElement.fileName
|
||||||
|
const sourcePath = element.picElement.sourcePath
|
||||||
|
if (element.picElement.picType === PicType.gif && !fileName.endsWith('.gif')) {
|
||||||
|
fileName += '.gif'
|
||||||
|
}
|
||||||
|
message_data['data']['file'] = fileName
|
||||||
// message_data["data"]["path"] = element.picElement.sourcePath
|
// message_data["data"]["path"] = element.picElement.sourcePath
|
||||||
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
// let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
|
||||||
|
|
||||||
message_data['data']['url'] = await NTQQFileApi.getImageUrl(msg)
|
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement, msg.chatType)
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
message_data['data']['file_size'] = element.picElement.fileSize
|
message_data['data']['file_size'] = element.picElement.fileSize
|
||||||
dbUtil
|
dbUtil
|
||||||
.addFileCache(element.picElement.fileName, {
|
.addFileCache(fileName, {
|
||||||
fileName: element.picElement.fileName,
|
fileName,
|
||||||
filePath: element.picElement.sourcePath,
|
elementId: element.elementId,
|
||||||
|
filePath: sourcePath,
|
||||||
fileSize: element.picElement.fileSize.toString(),
|
fileSize: element.picElement.fileSize.toString(),
|
||||||
url: message_data['data']['url'],
|
url: message_data['data']['url'],
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
@@ -172,7 +191,8 @@ export class OB11Constructor {
|
|||||||
})
|
})
|
||||||
.then()
|
.then()
|
||||||
// 不在自动下载图片
|
// 不在自动下载图片
|
||||||
} else if (element.videoElement || element.fileElement) {
|
}
|
||||||
|
else if (element.videoElement || element.fileElement) {
|
||||||
const videoOrFileElement = element.videoElement || element.fileElement
|
const videoOrFileElement = element.videoElement || element.fileElement
|
||||||
const ob11MessageDataType = element.videoElement ? OB11MessageDataType.video : OB11MessageDataType.file
|
const ob11MessageDataType = element.videoElement ? OB11MessageDataType.video : OB11MessageDataType.file
|
||||||
message_data['type'] = ob11MessageDataType
|
message_data['type'] = ob11MessageDataType
|
||||||
@@ -180,9 +200,17 @@ export class OB11Constructor {
|
|||||||
message_data['data']['path'] = videoOrFileElement.filePath
|
message_data['data']['path'] = videoOrFileElement.filePath
|
||||||
message_data['data']['file_id'] = videoOrFileElement.fileUuid
|
message_data['data']['file_id'] = videoOrFileElement.fileUuid
|
||||||
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
message_data['data']['file_size'] = videoOrFileElement.fileSize
|
||||||
|
if (element.videoElement) {
|
||||||
|
message_data['data']['url'] = await NTQQFileApi.getVideoUrl({
|
||||||
|
chatType: msg.chatType,
|
||||||
|
peerUid: msg.peerUid,
|
||||||
|
}, msg.msgId, element.elementId,
|
||||||
|
)
|
||||||
|
}
|
||||||
dbUtil
|
dbUtil
|
||||||
.addFileCache(videoOrFileElement.fileUuid, {
|
.addFileCache(videoOrFileElement.fileUuid, {
|
||||||
msgId: msg.msgId,
|
msgId: msg.msgId,
|
||||||
|
elementId: element.elementId,
|
||||||
fileName: videoOrFileElement.fileName,
|
fileName: videoOrFileElement.fileName,
|
||||||
filePath: videoOrFileElement.filePath,
|
filePath: videoOrFileElement.filePath,
|
||||||
fileSize: videoOrFileElement.fileSize,
|
fileSize: videoOrFileElement.fileSize,
|
||||||
@@ -201,7 +229,8 @@ export class OB11Constructor {
|
|||||||
})
|
})
|
||||||
.then()
|
.then()
|
||||||
// 怎么拿到url呢
|
// 怎么拿到url呢
|
||||||
} else if (element.pttElement) {
|
}
|
||||||
|
else if (element.pttElement) {
|
||||||
message_data['type'] = OB11MessageDataType.voice
|
message_data['type'] = OB11MessageDataType.voice
|
||||||
message_data['data']['file'] = element.pttElement.fileName
|
message_data['data']['file'] = element.pttElement.fileName
|
||||||
message_data['data']['path'] = element.pttElement.filePath
|
message_data['data']['path'] = element.pttElement.filePath
|
||||||
@@ -209,6 +238,7 @@ export class OB11Constructor {
|
|||||||
message_data['data']['file_size'] = element.pttElement.fileSize
|
message_data['data']['file_size'] = element.pttElement.fileSize
|
||||||
dbUtil
|
dbUtil
|
||||||
.addFileCache(element.pttElement.fileName, {
|
.addFileCache(element.pttElement.fileName, {
|
||||||
|
elementId: element.elementId,
|
||||||
fileName: element.pttElement.fileName,
|
fileName: element.pttElement.fileName,
|
||||||
filePath: element.pttElement.filePath,
|
filePath: element.pttElement.filePath,
|
||||||
fileSize: element.pttElement.fileSize,
|
fileSize: element.pttElement.fileSize,
|
||||||
@@ -221,22 +251,27 @@ export class OB11Constructor {
|
|||||||
// }).catch(err => {
|
// }).catch(err => {
|
||||||
// console.log("语音转文字失败", err);
|
// console.log("语音转文字失败", err);
|
||||||
// })
|
// })
|
||||||
} else if (element.arkElement) {
|
}
|
||||||
|
else if (element.arkElement) {
|
||||||
message_data['type'] = OB11MessageDataType.json
|
message_data['type'] = OB11MessageDataType.json
|
||||||
message_data['data']['data'] = element.arkElement.bytesData
|
message_data['data']['data'] = element.arkElement.bytesData
|
||||||
} else if (element.faceElement) {
|
}
|
||||||
|
else if (element.faceElement) {
|
||||||
const faceId = element.faceElement.faceIndex
|
const faceId = element.faceElement.faceIndex
|
||||||
if (faceId === FaceIndex.dice) {
|
if (faceId === FaceIndex.dice) {
|
||||||
message_data['type'] = OB11MessageDataType.dice
|
message_data['type'] = OB11MessageDataType.dice
|
||||||
message_data['data']['result'] = element.faceElement.resultId
|
message_data['data']['result'] = element.faceElement.resultId
|
||||||
} else if (faceId === FaceIndex.RPS) {
|
}
|
||||||
|
else if (faceId === FaceIndex.RPS) {
|
||||||
message_data['type'] = OB11MessageDataType.RPS
|
message_data['type'] = OB11MessageDataType.RPS
|
||||||
message_data['data']['result'] = element.faceElement.resultId
|
message_data['data']['result'] = element.faceElement.resultId
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
message_data['type'] = OB11MessageDataType.face
|
message_data['type'] = OB11MessageDataType.face
|
||||||
message_data['data']['id'] = element.faceElement.faceIndex.toString()
|
message_data['data']['id'] = element.faceElement.faceIndex.toString()
|
||||||
}
|
}
|
||||||
} else if (element.marketFaceElement) {
|
}
|
||||||
|
else if (element.marketFaceElement) {
|
||||||
message_data['type'] = OB11MessageDataType.mface
|
message_data['type'] = OB11MessageDataType.mface
|
||||||
message_data['data']['summary'] = element.marketFaceElement.faceName
|
message_data['data']['summary'] = element.marketFaceElement.faceName
|
||||||
const md5 = element.marketFaceElement.emojiId
|
const md5 = element.marketFaceElement.emojiId
|
||||||
@@ -249,11 +284,13 @@ export class OB11Constructor {
|
|||||||
message_data['data']['emoji_id'] = element.marketFaceElement.emojiId
|
message_data['data']['emoji_id'] = element.marketFaceElement.emojiId
|
||||||
message_data['data']['emoji_package_id'] = String(element.marketFaceElement.emojiPackageId)
|
message_data['data']['emoji_package_id'] = String(element.marketFaceElement.emojiPackageId)
|
||||||
message_data['data']['key'] = element.marketFaceElement.key
|
message_data['data']['key'] = element.marketFaceElement.key
|
||||||
mFaceCache.set(md5, element.marketFaceElement.faceName);
|
mFaceCache.set(md5, element.marketFaceElement.faceName)
|
||||||
} else if (element.markdownElement) {
|
}
|
||||||
|
else if (element.markdownElement) {
|
||||||
message_data['type'] = OB11MessageDataType.markdown
|
message_data['type'] = OB11MessageDataType.markdown
|
||||||
message_data['data']['data'] = element.markdownElement.content
|
message_data['data']['data'] = element.markdownElement.content
|
||||||
} else if (element.multiForwardMsgElement) {
|
}
|
||||||
|
else if (element.multiForwardMsgElement) {
|
||||||
message_data['type'] = OB11MessageDataType.forward
|
message_data['type'] = OB11MessageDataType.forward
|
||||||
message_data['data']['id'] = msg.msgId
|
message_data['data']['id'] = msg.msgId
|
||||||
}
|
}
|
||||||
@@ -261,7 +298,8 @@ export class OB11Constructor {
|
|||||||
const cqCode = encodeCQCode(message_data)
|
const cqCode = encodeCQCode(message_data)
|
||||||
if (messagePostFormat === 'string') {
|
if (messagePostFormat === 'string') {
|
||||||
;(resMsg.message as string) += cqCode
|
;(resMsg.message as string) += cqCode
|
||||||
} else (resMsg.message as OB11MessageData[]).push(message_data)
|
}
|
||||||
|
else (resMsg.message as OB11MessageData[]).push(message_data)
|
||||||
|
|
||||||
resMsg.raw_message += cqCode
|
resMsg.raw_message += cqCode
|
||||||
}
|
}
|
||||||
@@ -310,7 +348,8 @@ export class OB11Constructor {
|
|||||||
// log("构造群增加事件", event)
|
// log("构造群增加事件", event)
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
} else if (groupElement.type === TipGroupElementType.ban) {
|
}
|
||||||
|
else if (groupElement.type === TipGroupElementType.ban) {
|
||||||
log('收到群群员禁言提示', groupElement)
|
log('收到群群员禁言提示', groupElement)
|
||||||
const memberUid = groupElement.shutUp.member.uid
|
const memberUid = groupElement.shutUp.member.uid
|
||||||
const adminUid = groupElement.shutUp.admin.uid
|
const adminUid = groupElement.shutUp.admin.uid
|
||||||
@@ -321,7 +360,8 @@ export class OB11Constructor {
|
|||||||
memberUin =
|
memberUin =
|
||||||
(await getGroupMember(msg.peerUid, memberUid))?.uin ||
|
(await getGroupMember(msg.peerUid, memberUid))?.uin ||
|
||||||
(await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
(await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
memberUin = '0' // 0表示全员禁言
|
memberUin = '0' // 0表示全员禁言
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
duration = -1
|
duration = -1
|
||||||
@@ -338,7 +378,8 @@ export class OB11Constructor {
|
|||||||
sub_type,
|
sub_type,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (groupElement.type == TipGroupElementType.kicked) {
|
}
|
||||||
|
else if (groupElement.type == TipGroupElementType.kicked) {
|
||||||
log(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement)
|
log(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement)
|
||||||
deleteGroup(msg.peerUid)
|
deleteGroup(msg.peerUid)
|
||||||
NTQQGroupApi.quitGroup(msg.peerUid).then()
|
NTQQGroupApi.quitGroup(msg.peerUid).then()
|
||||||
@@ -358,7 +399,8 @@ export class OB11Constructor {
|
|||||||
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), 0, 'leave')
|
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), 0, 'leave')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (element.fileElement) {
|
}
|
||||||
|
else if (element.fileElement) {
|
||||||
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
|
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
|
||||||
id: element.fileElement.fileUuid,
|
id: element.fileElement.fileUuid,
|
||||||
name: element.fileElement.fileName,
|
name: element.fileElement.fileName,
|
||||||
@@ -423,7 +465,8 @@ export class OB11Constructor {
|
|||||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), 'invite')
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), 'invite')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
}
|
||||||
|
else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) {
|
||||||
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr)
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
@@ -463,14 +506,41 @@ export class OB11Constructor {
|
|||||||
|
|
||||||
static async FriendAddEvent(msg: RawMessage): Promise<OB11FriendAddNoticeEvent | undefined> {
|
static async FriendAddEvent(msg: RawMessage): Promise<OB11FriendAddNoticeEvent | undefined> {
|
||||||
if (msg.chatType !== ChatType.friend) {
|
if (msg.chatType !== ChatType.friend) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
if (msg.msgType === 5 && msg.subMsgType === 12) {
|
if (msg.msgType === 5 && msg.subMsgType === 12) {
|
||||||
const event = new OB11FriendAddNoticeEvent(parseInt(msg.peerUin));
|
const event = new OB11FriendAddNoticeEvent(parseInt(msg.peerUin))
|
||||||
return event;
|
return event
|
||||||
}
|
}
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async RecallEvent(
|
||||||
|
msg: RawMessage,
|
||||||
|
): Promise<OB11FriendRecallNoticeEvent | OB11GroupRecallNoticeEvent | undefined> {
|
||||||
|
let msgElement = msg.elements.find(
|
||||||
|
(element) => element.grayTipElement?.subElementType === GrayTipElementSubType.RECALL,
|
||||||
|
)
|
||||||
|
if (!msgElement) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const isGroup = msg.chatType === ChatType.group
|
||||||
|
const revokeElement = msgElement.grayTipElement.revokeElement
|
||||||
|
if (isGroup) {
|
||||||
|
const operator = await getGroupMember(msg.peerUid, revokeElement.operatorUid)
|
||||||
|
const sender = await getGroupMember(msg.peerUid, revokeElement.origMsgSenderUid)
|
||||||
|
return new OB11GroupRecallNoticeEvent(
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
parseInt(sender.uin),
|
||||||
|
parseInt(operator.uin),
|
||||||
|
msg.msgShortId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new OB11FriendRecallNoticeEvent(parseInt(msg.senderUin), msg.msgShortId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static friend(friend: User): OB11User {
|
static friend(friend: User): OB11User {
|
||||||
return {
|
return {
|
||||||
user_id: parseInt(friend.uin),
|
user_id: parseInt(friend.uin),
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent';
|
import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent'
|
||||||
|
|
||||||
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
|
export class OB11FriendAddNoticeEvent extends OB11BaseNoticeEvent {
|
||||||
notice_type = 'friend_add';
|
notice_type = 'friend_add'
|
||||||
user_id: number;
|
user_id: number
|
||||||
|
|
||||||
public constructor(userId: number) {
|
public constructor(userId: number) {
|
||||||
super();
|
super()
|
||||||
this.user_id = userId;
|
this.user_id = userId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ export class OB11GroupRequestEvent extends OB11GroupNoticeEvent {
|
|||||||
post_type = EventType.REQUEST
|
post_type = EventType.REQUEST
|
||||||
request_type: 'group' = 'group'
|
request_type: 'group' = 'group'
|
||||||
sub_type: 'add' | 'invite' = 'add'
|
sub_type: 'add' | 'invite' = 'add'
|
||||||
|
invitor_id: number | undefined = undefined
|
||||||
comment: string
|
comment: string
|
||||||
flag: string
|
flag: string
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
import { Response } from 'express'
|
import { Response } from 'express'
|
||||||
import { OB11Response } from '../action/OB11Response'
|
import { OB11Response } from '../action/OB11Response'
|
||||||
import { HttpServerBase } from '../../common/server/http'
|
import { HttpServerBase } from '@/common/server/http'
|
||||||
import { actionHandlers, actionMap } from '../action'
|
import { actionHandlers, actionMap } from '../action'
|
||||||
import { getConfigUtil } from '../../common/config'
|
import { getConfigUtil } from '@/common/config'
|
||||||
import { postOB11Event } from './postOB11Event'
|
import { postOb11Event } from './post-ob11-event'
|
||||||
import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent'
|
import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent'
|
||||||
import { selfInfo } from '../../common/data'
|
import { selfInfo } from '@/common/data'
|
||||||
|
|
||||||
class OB11HTTPServer extends HttpServerBase {
|
class OB11HTTPServer extends HttpServerBase {
|
||||||
name = 'OneBot V11 server'
|
name = 'LLOneBot server'
|
||||||
|
|
||||||
handleFailed(res: Response, payload: any, e: any) {
|
handleFailed(res: Response, payload: any, e: any) {
|
||||||
res.send(OB11Response.error(e.stack.toString(), 200))
|
res.send(OB11Response.error(e.stack.toString(), 200))
|
||||||
@@ -40,7 +40,7 @@ class HTTPHeart {
|
|||||||
}
|
}
|
||||||
this.intervalId = setInterval(() => {
|
this.intervalId = setInterval(() => {
|
||||||
// ws的心跳是ws自己维护的
|
// ws的心跳是ws自己维护的
|
||||||
postOB11Event(new OB11HeartbeatEvent(selfInfo.online, true, heartInterval), false, false)
|
postOb11Event(new OB11HeartbeatEvent(selfInfo.online, true, heartInterval), false, false)
|
||||||
}, heartInterval)
|
}, heartInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
81
src/onebot11/server/post-ob11-event.ts
Normal file
81
src/onebot11/server/post-ob11-event.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { OB11Message } from '../types'
|
||||||
|
import { selfInfo } from '@/common/data'
|
||||||
|
import { OB11BaseMetaEvent } from '../event/meta/OB11BaseMetaEvent'
|
||||||
|
import { OB11BaseNoticeEvent } from '../event/notice/OB11BaseNoticeEvent'
|
||||||
|
import { WebSocket as WebSocketClass } from 'ws'
|
||||||
|
import { wsReply } from './ws/reply'
|
||||||
|
import { log } from '@/common/utils'
|
||||||
|
import { getConfigUtil } from '@/common/config'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
import { handleQuickOperation, QuickOperationEvent } from '../action/quick-operation'
|
||||||
|
|
||||||
|
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
|
||||||
|
const eventWSList: WebSocketClass[] = []
|
||||||
|
|
||||||
|
export function registerWsEventSender(ws: WebSocketClass) {
|
||||||
|
eventWSList.push(ws)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unregisterWsEventSender(ws: WebSocketClass) {
|
||||||
|
let index = eventWSList.indexOf(ws)
|
||||||
|
if (index !== -1) {
|
||||||
|
eventWSList.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postWsEvent(event: PostEventType) {
|
||||||
|
for (const ws of eventWSList) {
|
||||||
|
new Promise(() => {
|
||||||
|
wsReply(ws, event)
|
||||||
|
}).then().catch(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postOb11Event(msg: PostEventType, reportSelf = false, postWs = true) {
|
||||||
|
const config = getConfigUtil().getConfig()
|
||||||
|
// 判断msg是否是event
|
||||||
|
if (!config.reportSelfMessage && !reportSelf) {
|
||||||
|
if (msg.post_type === 'message' && (msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.ob11.enableHttpPost) {
|
||||||
|
const msgStr = JSON.stringify(msg)
|
||||||
|
const hmac = crypto.createHmac('sha1', config.ob11.httpSecret)
|
||||||
|
hmac.update(msgStr)
|
||||||
|
const sig = hmac.digest('hex')
|
||||||
|
let headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-self-id': selfInfo.uin,
|
||||||
|
}
|
||||||
|
if (config.ob11.httpSecret) {
|
||||||
|
headers['x-signature'] = 'sha1=' + sig
|
||||||
|
}
|
||||||
|
for (const host of config.ob11.httpHosts) {
|
||||||
|
fetch(host, {
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
|
body: msgStr,
|
||||||
|
}).then(
|
||||||
|
async (res) => {
|
||||||
|
log(`新消息事件HTTP上报成功: ${host} `, msgStr)
|
||||||
|
try {
|
||||||
|
const resJson = await res.json()
|
||||||
|
log(`新消息事件HTTP上报返回快速操作: `, JSON.stringify(resJson))
|
||||||
|
handleQuickOperation(msg as QuickOperationEvent, resJson).then().catch(log);
|
||||||
|
} catch (e) {
|
||||||
|
log(`新消息事件HTTP上报没有返回快速操作,不需要处理`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err: any) => {
|
||||||
|
log(`新消息事件HTTP上报失败: ${host} `, err, msg)
|
||||||
|
},
|
||||||
|
).catch(log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (postWs) {
|
||||||
|
postWsEvent(msg)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,185 +0,0 @@
|
|||||||
import { OB11Message, OB11MessageAt, OB11MessageData } from '../types'
|
|
||||||
import { getFriend, getGroup, getUidByUin, selfInfo } from '../../common/data'
|
|
||||||
import { OB11BaseMetaEvent } from '../event/meta/OB11BaseMetaEvent'
|
|
||||||
import { OB11BaseNoticeEvent } from '../event/notice/OB11BaseNoticeEvent'
|
|
||||||
import { WebSocket as WebSocketClass } from 'ws'
|
|
||||||
import { wsReply } from './ws/reply'
|
|
||||||
import { log } from '../../common/utils/log'
|
|
||||||
import { getConfigUtil } from '../../common/config'
|
|
||||||
import crypto from 'crypto'
|
|
||||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '../../ntqqapi/api'
|
|
||||||
import { ChatType, Group, GroupRequestOperateTypes } from '../../ntqqapi/types'
|
|
||||||
import { convertMessage2List, createSendElements, sendMsg } from '../action/msg/SendMsg'
|
|
||||||
import { dbUtil } from '../../common/db'
|
|
||||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
|
||||||
import { isNull } from '../../common/utils'
|
|
||||||
|
|
||||||
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
|
||||||
|
|
||||||
interface QuickActionPrivateMessage {
|
|
||||||
reply?: string
|
|
||||||
auto_escape?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface QuickActionGroupMessage extends QuickActionPrivateMessage {
|
|
||||||
// 回复群消息
|
|
||||||
at_sender?: boolean
|
|
||||||
delete?: boolean
|
|
||||||
kick?: boolean
|
|
||||||
ban?: boolean
|
|
||||||
ban_duration?: number
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
interface QuickActionFriendRequest {
|
|
||||||
approve?: boolean
|
|
||||||
remark?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface QuickActionGroupRequest {
|
|
||||||
approve?: boolean
|
|
||||||
reason?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type QuickAction = QuickActionPrivateMessage &
|
|
||||||
QuickActionGroupMessage &
|
|
||||||
QuickActionFriendRequest &
|
|
||||||
QuickActionGroupRequest
|
|
||||||
|
|
||||||
const eventWSList: WebSocketClass[] = []
|
|
||||||
|
|
||||||
export function registerWsEventSender(ws: WebSocketClass) {
|
|
||||||
eventWSList.push(ws)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function unregisterWsEventSender(ws: WebSocketClass) {
|
|
||||||
let index = eventWSList.indexOf(ws)
|
|
||||||
if (index !== -1) {
|
|
||||||
eventWSList.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postWsEvent(event: PostEventType) {
|
|
||||||
for (const ws of eventWSList) {
|
|
||||||
new Promise(() => {
|
|
||||||
wsReply(ws, event)
|
|
||||||
}).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function postOB11Event(msg: PostEventType, reportSelf = false, postWs = true) {
|
|
||||||
const config = getConfigUtil().getConfig()
|
|
||||||
// 判断msg是否是event
|
|
||||||
if (!config.reportSelfMessage && !reportSelf) {
|
|
||||||
if (msg.post_type === 'message' && (msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (config.ob11.enableHttpPost) {
|
|
||||||
const msgStr = JSON.stringify(msg)
|
|
||||||
const hmac = crypto.createHmac('sha1', config.ob11.httpSecret)
|
|
||||||
hmac.update(msgStr)
|
|
||||||
const sig = hmac.digest('hex')
|
|
||||||
let headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'x-self-id': selfInfo.uin,
|
|
||||||
}
|
|
||||||
if (config.ob11.httpSecret) {
|
|
||||||
headers['x-signature'] = 'sha1=' + sig
|
|
||||||
}
|
|
||||||
for (const host of config.ob11.httpHosts) {
|
|
||||||
fetch(host, {
|
|
||||||
method: 'POST',
|
|
||||||
headers,
|
|
||||||
body: msgStr,
|
|
||||||
}).then(
|
|
||||||
async (res) => {
|
|
||||||
log(`新消息事件HTTP上报成功: ${host} `, msgStr)
|
|
||||||
// todo: 处理不够优雅,应该使用高级泛型进行QuickAction类型识别
|
|
||||||
let resJson: QuickAction
|
|
||||||
try {
|
|
||||||
resJson = await res.json()
|
|
||||||
log(`新消息事件HTTP上报返回快速操作: `, JSON.stringify(resJson))
|
|
||||||
} catch (e) {
|
|
||||||
log(`新消息事件HTTP上报没有返回快速操作,不需要处理`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (msg.post_type === 'message') {
|
|
||||||
msg = msg as OB11Message
|
|
||||||
const rawMessage = await dbUtil.getMsgByShortId(msg.message_id)
|
|
||||||
resJson = resJson as QuickActionPrivateMessage | QuickActionGroupMessage
|
|
||||||
const reply = resJson.reply
|
|
||||||
let peer: Peer = {
|
|
||||||
chatType: ChatType.friend,
|
|
||||||
peerUid: msg.user_id.toString(),
|
|
||||||
}
|
|
||||||
if (msg.message_type == 'private') {
|
|
||||||
peer.peerUid = getUidByUin(msg.user_id.toString())
|
|
||||||
if (msg.sub_type === 'group') {
|
|
||||||
peer.chatType = ChatType.temp
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
peer.chatType = ChatType.group
|
|
||||||
peer.peerUid = msg.group_id.toString()
|
|
||||||
}
|
|
||||||
if (reply) {
|
|
||||||
let group: Group = null
|
|
||||||
let replyMessage: OB11MessageData[] = []
|
|
||||||
|
|
||||||
if (msg.message_type == 'group') {
|
|
||||||
group = await getGroup(msg.group_id.toString())
|
|
||||||
if ((resJson as QuickActionGroupMessage).at_sender) {
|
|
||||||
replyMessage.push({
|
|
||||||
type: 'at',
|
|
||||||
data: {
|
|
||||||
qq: msg.user_id.toString(),
|
|
||||||
},
|
|
||||||
} as OB11MessageAt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
replyMessage = replyMessage.concat(convertMessage2List(reply, resJson.auto_escape))
|
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group)
|
|
||||||
log(`发送消息给`, peer, sendElements)
|
|
||||||
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then()
|
|
||||||
} else if (resJson.delete) {
|
|
||||||
NTQQMsgApi.recallMsg(peer, [rawMessage.msgId]).then()
|
|
||||||
} else if (resJson.kick) {
|
|
||||||
NTQQGroupApi.kickMember(peer.peerUid, [rawMessage.senderUid]).then()
|
|
||||||
} else if (resJson.ban) {
|
|
||||||
NTQQGroupApi.banMember(peer.peerUid, [
|
|
||||||
{
|
|
||||||
uid: rawMessage.senderUid,
|
|
||||||
timeStamp: resJson.ban_duration || 60 * 30,
|
|
||||||
},
|
|
||||||
]).then()
|
|
||||||
}
|
|
||||||
} else if (msg.post_type === 'request') {
|
|
||||||
if ((msg as OB11FriendRequestEvent).request_type === 'friend') {
|
|
||||||
resJson = resJson as QuickActionFriendRequest
|
|
||||||
if (!isNull(resJson.approve)) {
|
|
||||||
// todo: set remark
|
|
||||||
NTQQFriendApi.handleFriendRequest((msg as OB11FriendRequestEvent).flag, resJson.approve).then()
|
|
||||||
}
|
|
||||||
} else if ((msg as OB11GroupRequestEvent).request_type === 'group') {
|
|
||||||
resJson = resJson as QuickActionGroupRequest
|
|
||||||
if (!isNull(resJson.approve)) {
|
|
||||||
NTQQGroupApi.handleGroupRequest(
|
|
||||||
(msg as OB11FriendRequestEvent).flag,
|
|
||||||
resJson.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
|
||||||
resJson.reason,
|
|
||||||
).then()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(err: any) => {
|
|
||||||
log(`新消息事件HTTP上报失败: ${host} `, err, msg)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (postWs) {
|
|
||||||
postWsEvent(msg)
|
|
||||||
}
|
|
||||||
}
|
|
@@ -4,12 +4,13 @@ import { ActionName } from '../../action/types'
|
|||||||
import { OB11Response } from '../../action/OB11Response'
|
import { OB11Response } from '../../action/OB11Response'
|
||||||
import BaseAction from '../../action/BaseAction'
|
import BaseAction from '../../action/BaseAction'
|
||||||
import { actionMap } from '../../action'
|
import { actionMap } from '../../action'
|
||||||
import { postWsEvent, registerWsEventSender, unregisterWsEventSender } from '../postOB11Event'
|
import { postWsEvent, registerWsEventSender, unregisterWsEventSender } from '../post-ob11-event'
|
||||||
import { wsReply } from './reply'
|
import { wsReply } from './reply'
|
||||||
import { WebSocket as WebSocketClass } from 'ws'
|
import { WebSocket as WebSocketClass } from 'ws'
|
||||||
import { OB11HeartbeatEvent } from '../../event/meta/OB11HeartbeatEvent'
|
import { OB11HeartbeatEvent } from '../../event/meta/OB11HeartbeatEvent'
|
||||||
import { log } from '../../../common/utils/log'
|
import { log } from '../../../common/utils/log'
|
||||||
import { getConfigUtil } from '../../../common/config'
|
import { getConfigUtil } from '../../../common/config'
|
||||||
|
import { version } from '../../../version'
|
||||||
|
|
||||||
export let rwsList: ReverseWebsocket[] = []
|
export let rwsList: ReverseWebsocket[] = []
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ export class ReverseWebsocket {
|
|||||||
'X-Self-ID': selfInfo.uin,
|
'X-Self-ID': selfInfo.uin,
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
'x-client-role': 'Universal', // koishi-adapter-onebot 需要这个字段
|
'x-client-role': 'Universal', // koishi-adapter-onebot 需要这个字段
|
||||||
|
'User-Agent': `LLOneBot/${version}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
registerWsEventSender(this.websocket)
|
registerWsEventSender(this.websocket)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { WebSocket } from 'ws'
|
import { WebSocket } from 'ws'
|
||||||
import { actionMap } from '../../action'
|
import { actionMap } from '../../action'
|
||||||
import { OB11Response } from '../../action/OB11Response'
|
import { OB11Response } from '../../action/OB11Response'
|
||||||
import { postWsEvent, registerWsEventSender, unregisterWsEventSender } from '../postOB11Event'
|
import { postWsEvent, registerWsEventSender, unregisterWsEventSender } from '../post-ob11-event'
|
||||||
import { ActionName } from '../../action/types'
|
import { ActionName } from '../../action/types'
|
||||||
import BaseAction from '../../action/BaseAction'
|
import BaseAction from '../../action/BaseAction'
|
||||||
import { LifeCycleSubType, OB11LifeCycleEvent } from '../../event/meta/OB11LifeCycleEvent'
|
import { LifeCycleSubType, OB11LifeCycleEvent } from '../../event/meta/OB11LifeCycleEvent'
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { WebSocket as WebSocketClass } from 'ws'
|
import { WebSocket as WebSocketClass } from 'ws'
|
||||||
import { OB11Response } from '../../action/OB11Response'
|
import { OB11Response } from '../../action/OB11Response'
|
||||||
import { PostEventType } from '../postOB11Event'
|
import { PostEventType } from '../post-ob11-event'
|
||||||
import { log } from '../../../common/utils/log'
|
import { log } from '../../../common/utils/log'
|
||||||
import { isNull } from '../../../common/utils/helper'
|
import { isNull } from '../../../common/utils/helper'
|
||||||
|
|
||||||
|
@@ -75,6 +75,7 @@ export interface OB11Message {
|
|||||||
self_id?: number
|
self_id?: number
|
||||||
time: number
|
time: number
|
||||||
message_id: number
|
message_id: number
|
||||||
|
message_seq: number // go-cqhttp字段,实际上是message_id
|
||||||
real_id: number
|
real_id: number
|
||||||
user_id: number
|
user_id: number
|
||||||
group_id?: number
|
group_id?: number
|
||||||
|
@@ -171,6 +171,11 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="musicSignUrl" type="text" value="${config.musicSignUrl}" placeholder="未设置" /></div>`,
|
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="musicSignUrl" type="text" value="${config.musicSignUrl}" placeholder="未设置" /></div>`,
|
||||||
'config-musicSignUrl',
|
'config-musicSignUrl',
|
||||||
),
|
),
|
||||||
|
SettingItem(
|
||||||
|
'快速操作回复自动引用原消息',
|
||||||
|
null,
|
||||||
|
SettingSwitch('ob11.enableQOAutoQuote', config.ob11.enableQOAutoQuote, { 'control-display-id': 'config-ob11-enableQOAutoQuote' }),
|
||||||
|
),
|
||||||
SettingItem('', null, SettingButton('保存', 'config-ob11-save', 'primary')),
|
SettingItem('', null, SettingButton('保存', 'config-ob11-save', 'primary')),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = '3.24.0'
|
export const version = '3.26.6'
|
||||||
|
@@ -1,12 +1,18 @@
|
|||||||
import http from 'https'
|
import http from 'https'
|
||||||
|
|
||||||
function checkUrl(imageUrl) {
|
function checkUrl(imageUrl) {
|
||||||
http.get(imageUrl, response => {
|
http
|
||||||
console.log(response.statusCode)
|
.get(imageUrl, (response) => {
|
||||||
}).on('error', e => {
|
console.log(response.statusCode)
|
||||||
console.log(e)
|
})
|
||||||
})
|
.on('error', (e) => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
checkUrl('https://gchat.qpic.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64')
|
checkUrl(
|
||||||
checkUrl('https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64')
|
'https://gchat.qpic.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64',
|
||||||
|
)
|
||||||
|
checkUrl(
|
||||||
|
'https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64',
|
||||||
|
)
|
||||||
|
@@ -7,8 +7,21 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"moduleResolution": "node"
|
"experimentalDecorators": true,
|
||||||
// "sourceMap": true
|
"resolveJsonModule": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"paths": {
|
||||||
|
"@/common/*": [
|
||||||
|
"./src/common/*"
|
||||||
|
],
|
||||||
|
"@/onebot11/*": [
|
||||||
|
"./src/onebot11"
|
||||||
|
],
|
||||||
|
"@/ntqqapi/*": [
|
||||||
|
"./src/ntqqapi/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"include": ["src/*", "src/**/*", "scripts/*"],
|
"include": ["src/*", "src/**/*", "scripts/*"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
|
Reference in New Issue
Block a user