Compare commits

..

11 Commits

Author SHA1 Message Date
linyuchen
de8c2e1168 chore: ver 3.20.3 2024-03-29 21:42:07 +08:00
linyuchen
2a1fc07b94 fix: image rkey expired 2024-03-29 21:26:29 +08:00
linyuchen
c1b6daaf32 refactor: emmm 2024-03-29 01:30:05 +08:00
linyuchen
02c973fe5e refactor: optimize save image rkey 2024-03-29 01:26:38 +08:00
linyuchen
d6b44053de chore: ver 3.20.2 2024-03-29 00:32:14 +08:00
linyuchen
1d69764952 refactor: optimize save config 2024-03-29 00:30:47 +08:00
linyuchen
d9377e4684 fix: kick group member event sub_type 2024-03-29 00:19:03 +08:00
linyuchen
f30dd81455 Merge branch 'main' into dev
# Conflicts:
#	src/onebot11/constructor.ts
2024-03-28 23:37:27 +08:00
linyuchen
0116f8d384 fix: user info level 2024-03-28 23:35:52 +08:00
linyuchen
88d68f4360 Merge pull request #166 from CHH2000day/dev
修复rkey缺失导致的某些图片无法获取
2024-03-28 23:03:00 +08:00
Ayatsuki Renge
ea0f5a9f80 fix:invalid image url due to missing rkey
ref:2c8094c8c8
2024-03-28 22:47:49 +08:00
14 changed files with 104 additions and 53 deletions

View File

@@ -1,10 +1,10 @@
{ {
"manifest_version": 4, "manifest_version": 4,
"type": "extension", "type": "extension",
"name": "LLOneBot v3.20.1", "name": "LLOneBot v3.20.3",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新", "description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
"version": "3.20.1", "version": "3.20.3",
"icon": "./icon.jpg", "icon": "./icon.jpg",
"authors": [ "authors": [
{ {

View File

@@ -1,4 +1,5 @@
import fs from "fs"; import fs from "fs";
import fsPromise from "fs/promises";
import {Config, OB11Config} from './types'; import {Config, OB11Config} from './types';
import {mergeNewProperties} from "./utils/helper"; import {mergeNewProperties} from "./utils/helper";
@@ -76,7 +77,7 @@ export class ConfigUtil {
setConfig(config: Config) { setConfig(config: Config) {
this.config = config; this.config = config;
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8") fsPromise.writeFile(this.configPath, JSON.stringify(config, null, 2), "utf-8").then()
} }
private checkOldConfig(currentConfig: Config | OB11Config, private checkOldConfig(currentConfig: Config | OB11Config,

View File

@@ -94,9 +94,9 @@ export async function refreshGroupMembers(groupQQ: string) {
export const uidMaps: Record<string, string> = {} // 一串加密的字符串(uid) -> qq号 export const uidMaps: Record<string, string> = {} // 一串加密的字符串(uid) -> qq号
export function getUidByUin(uin: string) { export function getUidByUin(uin: string) {
for (const key in uidMaps) { for (const uid in uidMaps) {
if (uidMaps[key] === uin) { if (uidMaps[uid] === uin) {
return key return uid
} }
} }
} }

View File

@@ -15,6 +15,7 @@ export interface CheckVersion {
version: string version: string
} }
export interface Config { export interface Config {
imageRKey?: string;
ob11: OB11Config ob11: OB11Config
token?: string token?: string
heartInterval?: number // ms heartInterval?: number // ms

View File

@@ -18,7 +18,7 @@ import {
friendRequests, friendRequests,
getFriend, getFriend,
getGroup, getGroup,
getGroupMember, getGroupMember, groups,
llonebotError, llonebotError,
refreshGroupMembers, refreshGroupMembers,
selfInfo, selfInfo,
@@ -53,7 +53,7 @@ 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";
let running = false; let running = false;
@@ -63,7 +63,6 @@ let mainWindow: BrowserWindow | null = null;
function onLoad() { function onLoad() {
log("llonebot main onLoad"); log("llonebot main onLoad");
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => { ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
return checkNewVersion(); return checkNewVersion();
}); });
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => { ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
@@ -298,11 +297,23 @@ function onLoad() {
} else { } else {
log("获取群通知的成员信息失败", notify, getGroup(notify.group.groupCode)); log("获取群通知的成员信息失败", notify, getGroup(notify.group.groupCode));
} }
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT) { } else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
// log("有成员退出通知"); log("有成员退出通知", notify);
// const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid); try {
// let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin)) const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid);
// postEvent(groupDecreaseEvent, true); let operatorId = member1.uin;
let subType: GroupDecreaseSubType = "leave";
if (notify.user2.uid) {
// 是被踢的
const member2 = await getGroupMember(notify.group.groupCode, notify.user2.uid);
operatorId = member2.uin;
subType = "kick";
}
let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin), parseInt(operatorId), subType)
postOB11Event(groupDecreaseEvent, true);
} catch (e) {
log("获取群通知的成员信息失败", notify, e.stack.toString())
}
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) { } else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
log("有加群请求"); log("有加群请求");
let groupRequestEvent = new OB11GroupRequestEvent(); let groupRequestEvent = new OB11GroupRequestEvent();
@@ -373,13 +384,7 @@ function onLoad() {
} }
}) })
startReceiveHook().then(); startReceiveHook().then();
// NTQQGroupApi.getGroups(true).then(_groups => { NTQQGroupApi.getGroups(true).then()
// _groups.map(group => {
// if (!groups.find(g => g.groupCode == group.groupCode)) {
// groups.push(group)
// }
// })
// })
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)

View File

@@ -3,7 +3,9 @@ import {SelfInfo, User} from "../types";
import {ReceiveCmdS} from "../hook"; import {ReceiveCmdS} from "../hook";
import {uidMaps} from "../../common/data"; import {uidMaps} from "../../common/data";
import {NTQQWindowApi, NTQQWindows} from "./window"; import {NTQQWindowApi, NTQQWindows} from "./window";
import {isQQ998, sleep} from "../../common/utils";
let userInfoCache: Record<string, User> = {}; // uid: User
export class NTQQUserApi{ export class NTQQUserApi{
static async setQQAvatar(filePath: string) { static async setQQAvatar(filePath: string) {
@@ -30,28 +32,40 @@ export class NTQQUserApi{
}) })
return result.profiles.get(uid) return result.profiles.get(uid)
} }
static async getUserDetailInfo(uid: string) { static async getUserDetailInfo(uid: string, getLevel=false) {
const result = await callNTQQApi<{ info: User }>({ // this.getUserInfo(uid);
methodName: NTQQApiMethod.USER_DETAIL_INFO, let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
cbCmd: ReceiveCmdS.USER_DETAIL_INFO, const fetchInfo = async ()=>{
afterFirstCmd: false, const result = await callNTQQApi<{ info: User }>({
cmdCB: (payload) => { methodName,
const success = payload.info.uid == uid cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
// log("get user detail info", success, uid, payload) afterFirstCmd: false,
return success cmdCB: (payload) => {
}, const success = payload.info.uid == uid
args: [ // log("get user detail info", success, uid, payload)
{ return success
uid
}, },
null args: [
] {
}) uid
const info = result.info },
if (info?.uin) { null
uidMaps[info.uid] = info.uin ]
})
const info = result.info
if (info?.uin) {
uidMaps[info.uid] = info.uin
}
return info
} }
return info // 首次请求两次才能拿到的等级信息
if (!userInfoCache[uid] && getLevel) {
await fetchInfo()
await sleep(1000);
}
let userInfo = await fetchInfo()
userInfoCache[uid] = userInfo
return userInfo
} }
static async getPSkey() { static async getPSkey() {

View File

@@ -1,7 +1,7 @@
import {BrowserWindow} from 'electron'; import {BrowserWindow} from 'electron';
import {NTQQApiClass} from "./ntcall"; import {NTQQApiClass} from "./ntcall";
import {NTQQMsgApi, sendMessagePool} from "./api/msg" import {NTQQMsgApi, sendMessagePool} from "./api/msg"
import {ChatType, Group, GroupMember, RawMessage, User} from "./types"; import {ChatType, Group, GroupMember, GroupMemberRole, RawMessage, User} from "./types";
import {friends, getGroupMember, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data"; import {friends, getGroupMember, groups, selfInfo, tempGroupCodeMap, uidMaps} 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"
@@ -12,7 +12,6 @@ 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/log";
import {sleep} from "../common/utils/helper"; import {sleep} from "../common/utils/helper";
import {OB11GroupCardEvent} from "../onebot11/event/notice/OB11GroupCardEvent";
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {} export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
@@ -243,6 +242,11 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
newMembersSet.add(member.uin); newMembersSet.add(member.uin);
} }
// 判断bot是否是管理员如果是管理员不需要从这里得知有人退群这里的退群无法得知是主动退群还是被踢
let bot = await getGroupMember(group.groupCode, selfInfo.uin)
if (bot.role == GroupMemberRole.admin || bot.role == GroupMemberRole.owner) {
continue
}
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(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin), parseInt(member.uin), "leave")); postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin), parseInt(member.uin), "leave"));

View File

@@ -35,6 +35,7 @@ export enum NTQQApiMethod {
GROUP_MEMBERS = "nodeIKernelGroupService/getNextMemberList", GROUP_MEMBERS = "nodeIKernelGroupService/getNextMemberList",
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",
FILE_TYPE = "getFileType", FILE_TYPE = "getFileType",
FILE_MD5 = "getFileMd5", FILE_MD5 = "getFileMd5",
FILE_COPY = "copyFile", FILE_COPY = "copyFile",

View File

@@ -172,9 +172,11 @@ export interface ArkElement {
} }
export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn" export const IMAGE_HTTP_HOST = "https://gchat.qpic.cn"
export const IMAGE_HTTP_HOST_NT = "https://multimedia.nt.qq.com.cn"
export interface PicElement { export interface PicElement {
originImageUrl: string; // http url, 没有hosthost是https://gchat.qpic.cn/ originImageUrl: string; // http url, 没有hosthost是https://gchat.qpic.cn/, 带download参数的是https://multimedia.nt.qq.com.cn
originImageMd5?: string;
sourcePath: string; // 图片本地路径 sourcePath: string; // 图片本地路径
thumbPath: Map<number, string>; thumbPath: Map<number, string>;
picWidth: number; picWidth: number;

View File

@@ -4,8 +4,9 @@ export enum GroupNotifyTypes {
INVITED_JOIN = 4, // 有人接受了邀请入群 INVITED_JOIN = 4, // 有人接受了邀请入群
JOIN_REQUEST = 7, JOIN_REQUEST = 7,
ADMIN_SET = 8, ADMIN_SET = 8,
KICK_MEMBER = 9,
MEMBER_EXIT = 11, // 主动退出
ADMIN_UNSET = 12, ADMIN_UNSET = 12,
MEMBER_EXIT = 11, // 主动退出?
} }

View File

@@ -15,6 +15,6 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: numbe
if (!uid) { if (!uid) {
throw new Error("查无此人") throw new Error("查无此人")
} }
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid)) return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid, true))
} }
} }

View File

@@ -21,7 +21,7 @@ class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
if (member) { if (member) {
if (isNull(member.sex)){ if (isNull(member.sex)){
log("获取群成员详细信息") log("获取群成员详细信息")
let info = (await NTQQUserApi.getUserDetailInfo(member.uid)) let info = (await NTQQUserApi.getUserDetailInfo(member.uid, true))
log("群成员详细信息结果", info) log("群成员详细信息结果", info)
Object.assign(member, info); Object.assign(member, info);
} }

View File

@@ -14,7 +14,7 @@ import {
GrayTipElementSubType, GrayTipElementSubType,
Group, Group,
GroupMember, GroupMember,
IMAGE_HTTP_HOST, IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT,
RawMessage, RawMessage,
SelfInfo, SelfInfo,
Sex, Sex,
@@ -40,11 +40,12 @@ import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent"; import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
import {OB11GroupDecreaseEvent} from "./event/notice/OB11GroupDecreaseEvent"; import {OB11GroupDecreaseEvent} from "./event/notice/OB11GroupDecreaseEvent";
let lastRKeyUpdateTime = 0;
export class OB11Constructor { export class OB11Constructor {
static async message(msg: RawMessage): Promise<OB11Message> { static async message(msg: RawMessage): Promise<OB11Message> {
let config = getConfigUtil().getConfig();
const {enableLocalFile2Url, ob11: {messagePostFormat}} = getConfigUtil().getConfig() const {enableLocalFile2Url, ob11: {messagePostFormat}} = config;
const message_type = msg.chatType == ChatType.group ? "group" : "private"; const message_type = msg.chatType == ChatType.group ? "group" : "private";
const resMsg: OB11Message = { const resMsg: OB11Message = {
self_id: parseInt(selfInfo.uin), self_id: parseInt(selfInfo.uin),
@@ -140,9 +141,30 @@ export class OB11Constructor {
// message_data["data"]["path"] = element.picElement.sourcePath // message_data["data"]["path"] = element.picElement.sourcePath
const url = element.picElement.originImageUrl const url = element.picElement.originImageUrl
const fileMd5 = element.picElement.md5HexStr const fileMd5 = element.picElement.md5HexStr
// let currentRKey = config.imageRKey || "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
if (url) { if (url) {
message_data["data"]["url"] = IMAGE_HTTP_HOST + url if (url.startsWith("/download")) {
} else if (fileMd5 && element.picElement.fileUuid.indexOf("_") === -1) { // fileuuid有下划线的是Linux发送的这个url是另外的格式目前尚未得知如何组装 if (url.includes("&rkey=")) {
// 正则提取rkey
// const rkey = url.match(/&rkey=([^&]+)/)[1]
// // log("图片url已有rkey", rkey)
// if (rkey != currentRKey){
// config.imageRKey = rkey
// if (Date.now() - lastRKeyUpdateTime > 1000 * 60) {
// lastRKeyUpdateTime = Date.now()
// getConfigUtil().setConfig(config)
// }
// }
message_data["data"]["url"] = IMAGE_HTTP_HOST_NT + url
}
else{
message_data["data"]["url"] = IMAGE_HTTP_HOST_NT + url + "&rkey=" + currentRKey
}
} else {
message_data["data"]["url"] = IMAGE_HTTP_HOST + url
}
} else if (fileMd5) {
message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0` message_data["data"]["url"] = `${IMAGE_HTTP_HOST}/gchatpic_new/0/0-0-${fileMd5.toUpperCase()}/0`
} }
// message_data["data"]["file_id"] = element.picElement.fileUuid // message_data["data"]["file_id"] = element.picElement.fileUuid

View File

@@ -1 +1 @@
export const version = "3.20.1" export const version = "3.20.3"