Compare commits

...

13 Commits

Author SHA1 Message Date
linyuchen
4591c1b659 fix: some audio can't play 2024-03-27 23:17:56 +08:00
linyuchen
97a424f62e Merge pull request #163 from idanran/main
fix: audio
2024-03-27 22:44:07 +08:00
idanran
410ef5a050 fix: audio 2024-03-27 14:35:19 +00:00
linyuchen
128091dff9 chore: ver 3.20.0 2024-03-27 21:29:56 +08:00
linyuchen
c7b6fd89fd fix: bot join group event 2024-03-27 21:27:34 +08:00
linyuchen
b55f35549d feat: report forward msg,get_forward_msg 2024-03-27 20:07:56 +08:00
linyuchen
ca0a6cfb22 chore: ver 3.19.4 2024-03-25 19:04:30 +08:00
linyuchen
3303b30c4c Merge branch 'main' into dev 2024-03-25 19:01:34 +08:00
linyuchen
429d8deb5c feat: gocq api router add send_forward_msg 2024-03-25 19:01:28 +08:00
linyuchen
48f12fc30b fix: pic subType 2024-03-25 18:52:15 +08:00
linyuchen
41f0e8f574 Merge pull request #159 from MisakaTAT/main
feat: added an gocqhttp extended api send_forward_msg
2024-03-25 18:11:05 +08:00
MisakaTAT
cd50df3a56 feat: added an gocqhttp extended api send_forward_msg 2024-03-25 17:51:04 +08:00
linyuchen
4461c7ed47 fix: group card event old_card 2024-03-25 15:07:35 +08:00
19 changed files with 182 additions and 46 deletions

View File

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

8
package-lock.json generated
View File

@@ -14,7 +14,7 @@
"file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2",
"level": "^8.0.1",
"silk-wasm": "^3.3.3",
"silk-wasm": "^3.3.4",
"utf-8-validate": "^6.0.3",
"uuid": "^9.0.1",
"ws": "^8.16.0"
@@ -5895,9 +5895,9 @@
}
},
"node_modules/silk-wasm": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.3.tgz",
"integrity": "sha512-9Qj93EtiIuBNkDyEwlPntabEtrm6Xu6LE4y9qZvomvo5+IsXFcXSy+N55kV22OehUTBYlZqOZYtRggA8G9IDGg=="
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.4.tgz",
"integrity": "sha512-cvjp9Zw50uPB46EfifHlO8gIh6buZOUKQaL+9BbPoLgH4bAp8wEEzVmPI34gIiltOUyeuEknm4DDGnE3kEEQ/A=="
},
"node_modules/slash": {
"version": "4.0.0",

View File

@@ -19,7 +19,7 @@
"file-type": "^19.0.0",
"fluent-ffmpeg": "^2.1.2",
"level": "^8.0.1",
"silk-wasm": "^3.3.3",
"silk-wasm": "^3.3.4",
"utf-8-validate": "^6.0.3",
"uuid": "^9.0.1",
"ws": "^8.16.0"

View File

@@ -47,7 +47,7 @@ export class NTQQFileApi {
}
// 上传文件到QQ的文件夹
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) {
const md5 = await NTQQFileApi.getFileMd5(filePath);
let ext = (await NTQQFileApi.getFileType(filePath))?.ext
if (ext) {
@@ -66,7 +66,7 @@ export class NTQQFileApi {
md5HexStr: md5,
fileName: fileName,
elementType: elementType,
elementSubType: 0,
elementSubType,
thumbSize: 0,
needCreate: true,
downloadType: 1,
@@ -81,7 +81,8 @@ export class NTQQFileApi {
md5,
fileName,
path: mediaPath,
fileSize
fileSize,
ext
}
}

View File

@@ -16,6 +16,17 @@ export interface Peer {
}
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) {
// await this.fetchRecentContact();
// await sleep(500);

View File

@@ -62,32 +62,32 @@ export class SendMsgElementConstructor {
}
}
static async pic(picPath: string, summary: string = ""): Promise<SendPicElement> {
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC);
static async pic(picPath: string, summary: string = "", subType: 0|1=0): Promise<SendPicElement> {
const {md5, fileName, path, fileSize, ext} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType);
if (fileSize === 0) {
throw "文件异常大小为0";
}
const imageSize = await NTQQFileApi.getImageSize(picPath);
const picElement = {
md5HexStr: md5,
fileSize: fileSize,
fileSize: fileSize.toString(),
picWidth: imageSize.width,
picHeight: imageSize.height,
fileName: fileName,
fileName: md5 + ext,
sourcePath: path,
original: true,
picType: isGIF(picPath) ? PicType.gif : PicType.jpg,
picSubType: 0,
picSubType: subType,
fileUuid: "",
fileSubId: "",
thumbFileSize: 0,
summary,
summary
};
log("图片信息", picElement)
return {
elementType: ElementType.PIC,
elementId: "",
picElement
picElement,
};
}
@@ -118,7 +118,7 @@ export class SendMsgElementConstructor {
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
thumb = pathLib.dirname(thumb)
// log("thumb 目录", thumb)
let videoInfo ={
let videoInfo = {
width: 1920, height: 1080,
time: 15,
format: "mp4",
@@ -128,7 +128,7 @@ export class SendMsgElementConstructor {
try {
videoInfo = await getVideoInfo(path);
log("视频信息", videoInfo)
}catch (e) {
} catch (e) {
log("获取视频信息失败", e)
}
const createThumb = new Promise<string>((resolve, reject) => {

View File

@@ -244,8 +244,8 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
}
for (const member of oldMembers) {
if (!newMembersSet.has(member.uin)) {
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin)));
if (!newMembersSet.has(member.uin) && member.uin != selfInfo.uin) {
postOB11Event(new OB11GroupDecreaseEvent(parseInt(group.groupCode), parseInt(member.uin), parseInt(member.uin), "leave"));
break;
}
}
@@ -263,6 +263,8 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
// 群列表变动
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 {
@@ -272,6 +274,8 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROU
}
})
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 {

View File

@@ -25,6 +25,8 @@ export enum NTQQApiMethod {
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
HISTORY_MSG_998 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
HISTORY_MSG = "nodeIKernelMsgService/getMsgsIncludeSelf",
GET_MULTI_MSG = "nodeIKernelMsgService/getMultiMsg",
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
SELF_INFO = "fetchAuthData",
FRIENDS = "nodeIKernelBuddyService/getBuddyList",

View File

@@ -49,24 +49,29 @@ export enum PicType {
jpg = 1000
}
export enum PicSubType {
normal = 0, // 普通图片,大图
face = 1 // 表情包小图
}
export interface SendPicElement {
elementType: ElementType.PIC,
elementId: "",
picElement: {
md5HexStr: string,
fileSize: number,
fileSize: number | string,
picWidth: number,
picHeight: number,
fileName: string,
sourcePath: string,
original: boolean,
picType: PicType,
picSubType: number,
picSubType: PicSubType,
fileUuid: string,
fileSubId: string,
thumbFileSize: number,
summary: string,
}
},
}
export interface SendReplyElement {
@@ -200,7 +205,7 @@ export interface GrayTipElement {
xmlElement: {
content: string;
},
jsonGrayTipElement:{
jsonGrayTipElement: {
jsonStr: string;
}
}
@@ -248,6 +253,7 @@ export interface MarketFaceElement {
],
"apngSupportSize": null
}
export interface VideoElement {
"filePath": string,
"fileName": string,
@@ -273,6 +279,34 @@ export interface VideoElement {
"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 { // 这是什么提示来着?
operateType: number,
peerUid: string,
@@ -281,6 +315,7 @@ export interface TipAioOpGrayTipElement { // 这是什么提示来着?
export enum TipGroupElementType {
memberIncrease = 1,
kicked = 3, // 被移出群
ban = 8
}
@@ -291,7 +326,7 @@ export interface TipGroupElement {
"memberUid": string,
"memberNick": string,
"memberRemark": string,
"adminUid": string, // 同意加群的管理员uid
"adminUid": string,
"adminNick": string,
"adminRemark": string,
"createGroup": null,
@@ -323,6 +358,11 @@ export interface TipGroupElement {
}
}
export interface MultiForwardMsgElement{
xmlContent: string, // xml格式的消息内容
resId: string,
fileName: string,
}
export interface RawMessage {
msgId: string;
@@ -361,5 +401,8 @@ export interface RawMessage {
videoElement: VideoElement;
fileElement: FileElement;
marketFaceElement: MarketFaceElement;
inlineKeyboardElement: InlineKeyboardElement;
markdownElement: MarkdownElement;
multiForwardMsgElement: MultiForwardMsgElement;
}[];
}

View 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}
}
}

View File

@@ -2,17 +2,19 @@ import SendMsg, {convertMessage2List} from "../msg/SendMsg";
import {OB11PostSendMsg} from "../../types";
import {ActionName} from "../types";
export class GoCQHTTPSendGroupForwardMsg extends SendMsg {
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
export class GoCQHTTPSendForwardMsg extends SendMsg {
actionName = ActionName.GoCQHTTP_SendForwardMsg;
protected async check(payload: OB11PostSendMsg) {
if (payload.messages){
payload.message = convertMessage2List(payload.messages);
}
if (payload.messages) payload.message = convertMessage2List(payload.messages);
return super.check(payload);
}
}
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendGroupForwardMsg {
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg {
actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
}
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
}

View File

@@ -14,7 +14,7 @@ import GetVersionInfo from "./system/GetVersionInfo";
import CanSendRecord from "./system/CanSendRecord";
import CanSendImage from "./system/CanSendImage";
import GetStatus from "./system/GetStatus";
import {GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
import {GoCQHTTPSendForwardMsg, GoCQHTTPSendGroupForwardMsg, GoCQHTTPSendPrivateForwardMsg} from "./go-cqhttp/SendForwardMsg";
import GoCQHTTPGetStrangerInfo from "./go-cqhttp/GetStrangerInfo";
import SendLike from "./user/SendLike";
import SetGroupAddRequest from "./group/SetGroupAddRequest";
@@ -39,6 +39,7 @@ import SetQQAvatar from './llonebot/SetQQAvatar'
import GoCQHTTPDownloadFile from "./go-cqhttp/DownloadFile";
import GoCQHTTPGetGroupMsgHistory from "./go-cqhttp/GetGroupMsgHistory";
import GetFile from "./file/GetFile";
import {GoCQHTTGetForwardMsgAction} from "./go-cqhttp/GetForwardMsg";
export const actionHandlers = [
new GetFile(),
@@ -73,6 +74,7 @@ export const actionHandlers = [
new CleanCache(),
//以下为go-cqhttp api
new GoCQHTTPSendForwardMsg(),
new GoCQHTTPSendGroupForwardMsg(),
new GoCQHTTPSendPrivateForwardMsg(),
new GoCQHTTPGetStrangerInfo(),
@@ -81,6 +83,7 @@ export const actionHandlers = [
new GoCQHTTPMarkMsgAsRead(),
new GoCQHTTPUploadGroupFile(),
new GoCQHTTPGetGroupMsgHistory(),
new GoCQHTTGetForwardMsgAction(),
]

View File

@@ -2,7 +2,7 @@ import {
AtType,
ChatType,
ElementType,
Group,
Group, PicSubType,
RawMessage,
SendArkElement,
SendMessageElement
@@ -188,7 +188,7 @@ export async function createSendElements(messageData: OB11MessageData[], group:
} 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 || ""));
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "", <PicSubType>parseInt(sendMsg.data?.subType?.toString()) || 0));
}
}
}

View File

@@ -51,6 +51,7 @@ export enum ActionName {
GetRecord = "get_record",
CleanCache = "clean_cache",
// 以下为go-cqhttp api
GoCQHTTP_SendForwardMsg = "send_forward_msg",
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
GoCQHTTP_GetStrangerInfo = "get_stranger_info",
@@ -59,4 +60,5 @@ export enum ActionName {
GoCQHTTP_UploadGroupFile = "upload_group_file",
GoCQHTTP_DownloadFile = "download_file",
GoCQHTTP_GetGroupMsgHistory = "get_group_msg_history",
GoCQHTTP_GetForwardMsg = "get_forward_msg",
}

View File

@@ -19,7 +19,8 @@ import {
SelfInfo,
Sex,
TipGroupElementType,
User, VideoElement
User,
VideoElement
} from '../ntqqapi/types';
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
import {EventType} from "./event/OB11BaseEvent";
@@ -37,6 +38,7 @@ import {sleep} from "../common/utils/helper";
import {getConfigUtil} from "../common/config";
import {OB11GroupTitleEvent} from "./event/notice/OB11GroupTitleEvent";
import {OB11GroupCardEvent} from "./event/notice/OB11GroupCardEvent";
import {OB11GroupDecreaseEvent} from "./event/notice/OB11GroupDecreaseEvent";
export class OB11Constructor {
@@ -206,6 +208,12 @@ export class OB11Constructor {
} else if (element.marketFaceElement) {
message_data["type"] = OB11MessageDataType.mface;
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) {
const cqCode = encodeCQCode(message_data);
@@ -227,8 +235,9 @@ export class OB11Constructor {
if (msg.senderUin){
let member = await getGroupMember(msg.peerUid, msg.senderUin);
if (member && member.cardName !== msg.sendMemberName) {
const event = new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
member.cardName = msg.sendMemberName;
return new OB11GroupCardEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), msg.sendMemberName, member.cardName)
return event
}
}
// log("group msg", msg);
@@ -274,6 +283,13 @@ export class OB11Constructor {
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) {
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {
id: element.fileElement.fileUuid,
@@ -296,6 +312,7 @@ export class OB11Constructor {
while ((match = regex.exec(xmlElement.content)) !== null) {
matches.push(match[1]);
}
// log("新人进群匹配到的QQ号", matches)
if (matches.length === 2) {
const [inviter, invitee] = matches;
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");

View File

@@ -1,14 +1,17 @@
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
export type GroupDecreaseSubType = "leave" | "kick" | "kick_me";
export class OB11GroupDecreaseEvent extends OB11GroupNoticeEvent {
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;
constructor(groupId: number, userId: number) {
constructor(groupId: number, userId: number, operatorId: number, subType: GroupDecreaseSubType = "leave") {
super();
this.group_id = groupId;
this.operator_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
this.operator_id = operatorId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被踢出的,还是自己主动退出的
this.user_id = userId;
this.sub_type = subType;
}
}

View File

@@ -73,7 +73,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
const config = getConfigUtil().getConfig();
// 判断msg是否是event
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
}
}

View File

@@ -1,4 +1,4 @@
import {RawMessage} from "../ntqqapi/types";
import {PicSubType, RawMessage} from "../ntqqapi/types";
import {EventType} from "./event/OB11BaseEvent";
export interface OB11User {
@@ -88,6 +88,10 @@ export interface OB11Message {
raw?: RawMessage
}
export interface OB11ForwardMessage extends OB11Message {
content: OB11MessageData[] | string;
}
export interface OB11Return<DataType> {
status: string
retcode: number
@@ -109,7 +113,10 @@ export enum OB11MessageDataType {
json = "json",
face = "face",
mface = "mface", // 商城表情
node = "node", // 合并转发消息
markdown = "markdown",
node = "node", // 合并转发消息节点
forward = "forward", // 合并转发消息,用于上报
xml = "xml"
}
export interface OB11MessageMFace{
@@ -134,11 +141,13 @@ interface OB11MessageFileBase {
}
}
export interface OB11MessageImage extends OB11MessageFileBase {
type: OB11MessageDataType.image
data: OB11MessageFileBase['data'] & {
summary ? : string; // 图片摘要
}
subType?: PicSubType
},
}
export interface OB11MessageRecord extends OB11MessageFileBase {

View File

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