mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d6b44053de | ||
![]() |
1d69764952 | ||
![]() |
d9377e4684 | ||
![]() |
f30dd81455 | ||
![]() |
0116f8d384 | ||
![]() |
88d68f4360 | ||
![]() |
ea0f5a9f80 | ||
![]() |
4591c1b659 | ||
![]() |
97a424f62e | ||
![]() |
410ef5a050 | ||
![]() |
128091dff9 | ||
![]() |
c7b6fd89fd | ||
![]() |
b55f35549d |
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.19.4",
|
"name": "LLOneBot v3.20.2",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
|
||||||
"version": "3.19.4",
|
"version": "3.20.2",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@@ -14,7 +14,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.3.3",
|
"silk-wasm": "^3.3.4",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
@@ -5895,9 +5895,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/silk-wasm": {
|
"node_modules/silk-wasm": {
|
||||||
"version": "3.3.3",
|
"version": "3.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.4.tgz",
|
||||||
"integrity": "sha512-9Qj93EtiIuBNkDyEwlPntabEtrm6Xu6LE4y9qZvomvo5+IsXFcXSy+N55kV22OehUTBYlZqOZYtRggA8G9IDGg=="
|
"integrity": "sha512-cvjp9Zw50uPB46EfifHlO8gIh6buZOUKQaL+9BbPoLgH4bAp8wEEzVmPI34gIiltOUyeuEknm4DDGnE3kEEQ/A=="
|
||||||
},
|
},
|
||||||
"node_modules/slash": {
|
"node_modules/slash": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.3.3",
|
"silk-wasm": "^3.3.4",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
|
@@ -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,
|
||||||
|
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
@@ -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)
|
||||||
|
@@ -16,6 +16,17 @@ export interface Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQMsgApi {
|
export class NTQQMsgApi {
|
||||||
|
static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult & {msgList: RawMessage[]}>({
|
||||||
|
methodName: NTQQApiMethod.GET_MULTI_MSG,
|
||||||
|
args: [{
|
||||||
|
peer,
|
||||||
|
rootMsgId,
|
||||||
|
parentMsgId
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
static async activateGroupChat(groupCode: string) {
|
static async activateGroupChat(groupCode: string) {
|
||||||
// await this.fetchRecentContact();
|
// await this.fetchRecentContact();
|
||||||
// await sleep(500);
|
// await sleep(500);
|
||||||
|
@@ -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() {
|
||||||
|
@@ -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,9 +242,14 @@ 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)) {
|
if (!newMembersSet.has(member.uin) && member.uin != selfInfo.uin) {
|
||||||
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin)));
|
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin), parseInt(member.uin), "leave"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +267,8 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
|
|||||||
|
|
||||||
// 群列表变动
|
// 群列表变动
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
||||||
|
// updateType 3是群列表变动,2是群成员变动
|
||||||
|
// log("群列表变动", payload.updateType, payload.groupList)
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
@@ -272,6 +278,8 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROU
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
|
||||||
|
// updateType 3是群列表变动,2是群成员变动
|
||||||
|
// log("群列表变动", payload.updateType, payload.groupList)
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
|
@@ -25,6 +25,8 @@ export enum NTQQApiMethod {
|
|||||||
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||||
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
|
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
|
||||||
|
GET_MULTI_MSG = "nodeIKernelMsgService/getMultiMsg",
|
||||||
|
|
||||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||||
SELF_INFO = "fetchAuthData",
|
SELF_INFO = "fetchAuthData",
|
||||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||||
@@ -33,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",
|
||||||
|
@@ -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, 没有host,host是https://gchat.qpic.cn/
|
originImageUrl: string; // http url, 没有host,host是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;
|
||||||
@@ -279,6 +281,34 @@ export interface VideoElement {
|
|||||||
"sourceVideoCodecFormat"?: number
|
"sourceVideoCodecFormat"?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MarkdownElement {
|
||||||
|
content: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InlineKeyboardElementRowButton{
|
||||||
|
"id": "",
|
||||||
|
"label": string,
|
||||||
|
"visitedLabel": string,
|
||||||
|
"style": 1, // 未知
|
||||||
|
"type": 2, // 未知
|
||||||
|
"clickLimit": 0, // 未知
|
||||||
|
"unsupportTips": "请升级新版手机QQ",
|
||||||
|
"data": string,
|
||||||
|
"atBotShowChannelList": false,
|
||||||
|
"permissionType": 2,
|
||||||
|
"specifyRoleIds": [],
|
||||||
|
"specifyTinyids": [],
|
||||||
|
"isReply": false,
|
||||||
|
"anchor": 0,
|
||||||
|
"enter": false,
|
||||||
|
"subscribeDataTemplateIds": []
|
||||||
|
}
|
||||||
|
export interface InlineKeyboardElement {
|
||||||
|
rows: [{
|
||||||
|
buttons: InlineKeyboardElementRowButton[]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
||||||
operateType: number,
|
operateType: number,
|
||||||
peerUid: string,
|
peerUid: string,
|
||||||
@@ -287,6 +317,7 @@ export interface TipAioOpGrayTipElement { // 这是什么提示来着?
|
|||||||
|
|
||||||
export enum TipGroupElementType {
|
export enum TipGroupElementType {
|
||||||
memberIncrease = 1,
|
memberIncrease = 1,
|
||||||
|
kicked = 3, // 被移出群
|
||||||
ban = 8
|
ban = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +328,7 @@ export interface TipGroupElement {
|
|||||||
"memberUid": string,
|
"memberUid": string,
|
||||||
"memberNick": string,
|
"memberNick": string,
|
||||||
"memberRemark": string,
|
"memberRemark": string,
|
||||||
"adminUid": string, // 同意加群的管理员uid
|
"adminUid": string,
|
||||||
"adminNick": string,
|
"adminNick": string,
|
||||||
"adminRemark": string,
|
"adminRemark": string,
|
||||||
"createGroup": null,
|
"createGroup": null,
|
||||||
@@ -329,6 +360,11 @@ export interface TipGroupElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MultiForwardMsgElement{
|
||||||
|
xmlContent: string, // xml格式的消息内容
|
||||||
|
resId: string,
|
||||||
|
fileName: string,
|
||||||
|
}
|
||||||
|
|
||||||
export interface RawMessage {
|
export interface RawMessage {
|
||||||
msgId: string;
|
msgId: string;
|
||||||
@@ -367,5 +403,8 @@ export interface RawMessage {
|
|||||||
videoElement: VideoElement;
|
videoElement: VideoElement;
|
||||||
fileElement: FileElement;
|
fileElement: FileElement;
|
||||||
marketFaceElement: MarketFaceElement;
|
marketFaceElement: MarketFaceElement;
|
||||||
|
inlineKeyboardElement: InlineKeyboardElement;
|
||||||
|
markdownElement: MarkdownElement;
|
||||||
|
multiForwardMsgElement: MultiForwardMsgElement;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
@@ -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, // 主动退出?
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
src/onebot11/action/go-cqhttp/GetForwardMsg.ts
Normal file
39
src/onebot11/action/go-cqhttp/GetForwardMsg.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {OB11ForwardMessage, OB11Message, OB11MessageData} from "../../types";
|
||||||
|
import {NTQQMsgApi, Peer} from "../../../ntqqapi/api";
|
||||||
|
import {dbUtil} from "../../../common/db";
|
||||||
|
import {OB11Constructor} from "../../constructor";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
message_id: string; // long msg id
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Response{
|
||||||
|
messages: (OB11Message & {content: OB11MessageData})[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any>{
|
||||||
|
actionName = ActionName.GoCQHTTP_GetForwardMsg
|
||||||
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
|
const rootMsg = await dbUtil.getMsgByLongId(payload.message_id)
|
||||||
|
if (!rootMsg){
|
||||||
|
throw Error("msg not found")
|
||||||
|
}
|
||||||
|
let data = await NTQQMsgApi.getMultiMsg({chatType: rootMsg.chatType, peerUid: rootMsg.peerUid}, rootMsg.msgId, rootMsg.msgId)
|
||||||
|
if (data.result !== 0){
|
||||||
|
throw Error("找不到相关的聊天记录" + data.errMsg)
|
||||||
|
}
|
||||||
|
let msgList = data.msgList
|
||||||
|
let messages = await Promise.all(msgList.map(async msg => {
|
||||||
|
let resMsg = await OB11Constructor.message(msg)
|
||||||
|
resMsg.message_id = await dbUtil.addMsg(msg);
|
||||||
|
return resMsg
|
||||||
|
}))
|
||||||
|
messages.map(msg => {
|
||||||
|
(<OB11ForwardMessage>msg).content = msg.message;
|
||||||
|
delete msg.message;
|
||||||
|
})
|
||||||
|
return {messages}
|
||||||
|
}
|
||||||
|
}
|
@@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ import SetQQAvatar from './llonebot/SetQQAvatar'
|
|||||||
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
|
||||||
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
|
||||||
import GetFile from "./file/GetFile";
|
import GetFile from "./file/GetFile";
|
||||||
|
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new GetFile(),
|
new GetFile(),
|
||||||
@@ -82,6 +83,7 @@ export const actionHandlers = [
|
|||||||
new GoCQHTTPMarkMsgAsRead(),
|
new GoCQHTTPMarkMsgAsRead(),
|
||||||
new GoCQHTTPUploadGroupFile(),
|
new GoCQHTTPUploadGroupFile(),
|
||||||
new GoCQHTTPGetGroupMsgHistory(),
|
new GoCQHTTPGetGroupMsgHistory(),
|
||||||
|
new GoCQHTTGetForwardMsgAction(),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@@ -60,4 +60,5 @@ export enum ActionName {
|
|||||||
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
GoCQHTTP_UploadGroupFile = "upload_group_file",
|
||||||
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",
|
||||||
}
|
}
|
@@ -14,12 +14,13 @@ import {
|
|||||||
GrayTipElementSubType,
|
GrayTipElementSubType,
|
||||||
Group,
|
Group,
|
||||||
GroupMember,
|
GroupMember,
|
||||||
IMAGE_HTTP_HOST,
|
IMAGE_HTTP_HOST, IMAGE_HTTP_HOST_NT,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SelfInfo,
|
SelfInfo,
|
||||||
Sex,
|
Sex,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
User, VideoElement
|
User,
|
||||||
|
VideoElement
|
||||||
} from '../ntqqapi/types';
|
} from '../ntqqapi/types';
|
||||||
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||||
import {EventType} from "./event/OB11BaseEvent";
|
import {EventType} from "./event/OB11BaseEvent";
|
||||||
@@ -37,11 +38,12 @@ import {sleep} from "../common/utils/helper";
|
|||||||
import {getConfigUtil} from "../common/config";
|
import {getConfigUtil} from "../common/config";
|
||||||
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
|
||||||
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
|
||||||
|
import {OB11GroupDecreaseEvent} from "./event/notice/OB11GroupDecreaseEvent";
|
||||||
|
|
||||||
|
|
||||||
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}} = getConfigUtil().getConfig()
|
||||||
const message_type = msg.chatType == ChatType.group ? "group" : "private";
|
const message_type = msg.chatType == ChatType.group ? "group" : "private";
|
||||||
const resMsg: OB11Message = {
|
const resMsg: OB11Message = {
|
||||||
@@ -138,9 +140,26 @@ 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"
|
||||||
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
|
||||||
|
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
|
||||||
@@ -206,6 +225,12 @@ export class OB11Constructor {
|
|||||||
} else if (element.marketFaceElement) {
|
} else if (element.marketFaceElement) {
|
||||||
message_data["type"] = OB11MessageDataType.mface;
|
message_data["type"] = OB11MessageDataType.mface;
|
||||||
message_data["data"]["text"] = element.marketFaceElement.faceName;
|
message_data["data"]["text"] = element.marketFaceElement.faceName;
|
||||||
|
} else if (element.markdownElement){
|
||||||
|
message_data["type"] = OB11MessageDataType.markdown;
|
||||||
|
message_data["data"]["data"] = element.markdownElement.content;
|
||||||
|
} else if (element.multiForwardMsgElement){
|
||||||
|
message_data["type"] = OB11MessageDataType.forward;
|
||||||
|
message_data["data"]["id"] = msg.msgId
|
||||||
}
|
}
|
||||||
if (message_data.type !== "unknown" && message_data.data) {
|
if (message_data.type !== "unknown" && message_data.data) {
|
||||||
const cqCode = encodeCQCode(message_data);
|
const cqCode = encodeCQCode(message_data);
|
||||||
@@ -275,6 +300,13 @@ export class OB11Constructor {
|
|||||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (groupElement.type == TipGroupElementType.kicked){
|
||||||
|
log("收到我被踢出提示", groupElement)
|
||||||
|
const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(groupElement.adminUid))?.uin
|
||||||
|
if (adminUin) {
|
||||||
|
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), parseInt(adminUin), "kick_me");
|
||||||
|
}
|
||||||
|
}
|
||||||
} 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,
|
||||||
@@ -297,6 +329,7 @@ export class OB11Constructor {
|
|||||||
while ((match = regex.exec(xmlElement.content)) !== null) {
|
while ((match = regex.exec(xmlElement.content)) !== null) {
|
||||||
matches.push(match[1]);
|
matches.push(match[1]);
|
||||||
}
|
}
|
||||||
|
// log("新人进群匹配到的QQ号", matches)
|
||||||
if (matches.length === 2) {
|
if (matches.length === 2) {
|
||||||
const [inviter, invitee] = matches;
|
const [inviter, invitee] = matches;
|
||||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||||
|
|
||||||
|
export type GroupDecreaseSubType = "leave" | "kick" | "kick_me";
|
||||||
|
|
||||||
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = "group_decrease";
|
notice_type = "group_decrease";
|
||||||
sub_type: "leave" | "kick" | "kick_me" = "leave"; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
sub_type: GroupDecreaseSubType = "leave"; // TODO: 实现其他几种子类型的识别 ("leave" | "kick" | "kick_me")
|
||||||
operator_id: number;
|
operator_id: number;
|
||||||
|
|
||||||
constructor(groupId: number, userId: number) {
|
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = "leave") {
|
||||||
super();
|
super();
|
||||||
this.group_id = groupId;
|
this.group_id = groupId;
|
||||||
this.operator_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
|
||||||
this.user_id = userId;
|
this.user_id = userId;
|
||||||
|
this.sub_type = subType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
|
|||||||
const config = getConfigUtil().getConfig();
|
const config = getConfigUtil().getConfig();
|
||||||
// 判断msg是否是event
|
// 判断msg是否是event
|
||||||
if (!config.reportSelfMessage && !reportSelf) {
|
if (!config.reportSelfMessage && !reportSelf) {
|
||||||
if ((msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
if (msg.post_type === "message" && (msg as OB11Message).user_id.toString() == selfInfo.uin) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -88,6 +88,10 @@ export interface OB11Message {
|
|||||||
raw?: RawMessage
|
raw?: RawMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface OB11ForwardMessage extends OB11Message {
|
||||||
|
content: OB11MessageData[] | string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface OB11Return<DataType> {
|
export interface OB11Return<DataType> {
|
||||||
status: string
|
status: string
|
||||||
retcode: number
|
retcode: number
|
||||||
@@ -109,7 +113,10 @@ export enum OB11MessageDataType {
|
|||||||
json = "json",
|
json = "json",
|
||||||
face = "face",
|
face = "face",
|
||||||
mface = "mface", // 商城表情
|
mface = "mface", // 商城表情
|
||||||
node = "node", // 合并转发消息
|
markdown = "markdown",
|
||||||
|
node = "node", // 合并转发消息节点
|
||||||
|
forward = "forward", // 合并转发消息,用于上报
|
||||||
|
xml = "xml"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11MessageMFace{
|
export interface OB11MessageMFace{
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = "3.19.4"
|
export const version = "3.20.2"
|
Reference in New Issue
Block a user