From b813fed54c8e5fa3e75507d54c40af8e78acf5bf Mon Sep 17 00:00:00 2001 From: Clansty Date: Sun, 24 Mar 2024 04:20:03 +0800 Subject: [PATCH] feat: add makeLongMsg function --- main/package.json | 2 +- main/src/client/OicqClient.ts | 17 +++++- package.json | 2 +- patches/@icqqjs__icqq@1.0.2.patch | 97 +++++++++++++++++++++++++++++++ patches/icqq@0.6.10.patch | 21 ------- pnpm-lock.yaml | 31 +++++----- 6 files changed, 126 insertions(+), 44 deletions(-) create mode 100644 patches/@icqqjs__icqq@1.0.2.patch delete mode 100644 patches/icqq@0.6.10.patch diff --git a/main/package.json b/main/package.json index 31774fc..58e9dd0 100644 --- a/main/package.json +++ b/main/package.json @@ -26,7 +26,7 @@ "dependencies": { "@fastify/http-proxy": "^9.4.0", "@fastify/static": "^7.0.1", - "@icqqjs/icqq": "^1.1.2", + "@icqqjs/icqq": "1.0.2", "@prisma/client": "5.9.1", "axios": "^1.6.8", "baidu-aip-sdk": "^4.16.15", diff --git a/main/src/client/OicqClient.ts b/main/src/client/OicqClient.ts index 7d1f552..0e08da4 100644 --- a/main/src/client/OicqClient.ts +++ b/main/src/client/OicqClient.ts @@ -4,9 +4,9 @@ import { Friend, Group, GroupMessageEvent, - LogLevel, + LogLevel, MessageElem, Platform, PrivateMessage, - PrivateMessageEvent, + PrivateMessageEvent, Sendable, } from '@icqqjs/icqq'; import random from '../utils/random'; import fs from 'fs'; @@ -14,7 +14,7 @@ import fsP from 'fs/promises'; import { Config } from '@icqqjs/icqq/lib/client'; import dataPath from '../helpers/dataPath'; import os from 'os'; -import { Converter, Image, rand2uuid } from '@icqqjs/icqq/lib/message'; +import { Converter, Image, LongMsgElem, rand2uuid } from '@icqqjs/icqq/lib/message'; import { randomBytes } from 'crypto'; import { gzip, timestamp } from '@icqqjs/icqq/lib/common'; import { pb } from '@icqqjs/icqq/lib/core'; @@ -229,4 +229,15 @@ export default class OicqClient extends Client { resid, }; } + + public async makeLongMsg(message: Sendable): Promise { + const forward = await this.makeForwardMsgSelf({ + message, + user_id: this.uin, + }); + return { + type: 'longmsg', + resId: forward.resid, + }; + } } diff --git a/package.json b/package.json index 0a1c52c..78408ac 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "pnpm": { "patchedDependencies": { - "@icqqjs/icqq@1.1.2": "patches/icqq@0.6.10.patch" + "@icqqjs/icqq@1.0.2": "patches/@icqqjs__icqq@1.0.2.patch" } } } diff --git a/patches/@icqqjs__icqq@1.0.2.patch b/patches/@icqqjs__icqq@1.0.2.patch new file mode 100644 index 0000000..1811b31 --- /dev/null +++ b/patches/@icqqjs__icqq@1.0.2.patch @@ -0,0 +1,97 @@ +diff --git a/lib/message/converter.d.ts b/lib/message/converter.d.ts +index 72bb7f63a49d360b8954f1c196fb22973c2ae07c..870ac46e22d3cc00f53586872294b320ba943e10 100644 +--- a/lib/message/converter.d.ts ++++ b/lib/message/converter.d.ts +@@ -54,6 +54,7 @@ export declare class Converter { + private mirai; + private file; + private reply; ++ private longmsg; + /** 转换为分片消息 */ + toFragments(): Uint8Array[]; + private _divideText; +diff --git a/lib/message/converter.js b/lib/message/converter.js +index c821bb3cdb5a404b1a7ef66883c3b22192b0c16d..bbf9687b48391968fab291c9dd59a05b84e21bac 100644 +--- a/lib/message/converter.js ++++ b/lib/message/converter.js +@@ -92,7 +92,7 @@ class Converter { + return; + } + if (qq === "all") { +- var q = 0, flag = 1, display = "全体成员"; ++ var q = 0, flag = 1, display = text || "全体成员"; + } + else { + var q = Number(qq), flag = 0, display = text || String(qq); +@@ -101,7 +101,6 @@ class Converter { + display = member?.card || member?.nickname || display; + } + } +- display = "@" + display; + if (dummy) + return this._text(display); + const buf = Buffer.allocUnsafe(6); +@@ -437,6 +436,15 @@ class Converter { + }); + this.brief += data; + } ++ longmsg(elem) { ++ const { resId } = elem; ++ this.elems.push({ ++ 37: { ++ 6: 1, ++ 7: resId ++ } ++ }); ++ } + file(elem) { + throw new Error("暂不支持发送或转发file元素,请调用文件相关API完成该操作"); + } +diff --git a/lib/message/elements.d.ts b/lib/message/elements.d.ts +index 3484802aeb6b9a26593dbc672284b30e42a6457e..3c606ea5e5650c3e60ea703ee2717f399d0e3601 100644 +--- a/lib/message/elements.d.ts ++++ b/lib/message/elements.d.ts +@@ -182,6 +182,10 @@ export interface ButtonElem { + }[]; + }; + } ++export interface LongMsgElem { ++ type: "longmsg"; ++ resId: string; ++} + export interface Button { + /** 按钮ID:在一个keyboard消息内设置唯一 */ + id?: string; +@@ -288,7 +292,7 @@ export interface ForwardNode extends Forwardable { + export type ChainElem = TextElem | FaceElem | BfaceElem | MfaceElem | ImageElem | AtElem | MiraiElem | ReplyElem | ForwardNode | QuoteElem | MarkdownElem | ButtonElem; + export declare const ChainElemTypes: ChainElem["type"][]; + /** 注意:只有`ChainElem`中的元素可以组合发送,其他元素只能单独发送 */ +-export type MessageElem = TextElem | FaceElem | BfaceElem | MfaceElem | ImageElem | AtElem | MiraiElem | ReplyElem | FlashElem | PttElem | VideoElem | JsonElem | XmlElem | PokeElem | LocationElem | ShareElem | MusicElem | FileElem | ForwardNode | QuoteElem | MarkdownElem | ButtonElem; ++export type MessageElem = TextElem | FaceElem | BfaceElem | MfaceElem | ImageElem | AtElem | MiraiElem | ReplyElem | FlashElem | PttElem | VideoElem | JsonElem | XmlElem | PokeElem | LocationElem | ShareElem | MusicElem | FileElem | ForwardNode | QuoteElem | MarkdownElem | ButtonElem | LongMsgElem; + /** 可通过`sendMsg`发送的类型集合 (字符串、元素对象,或它们的数组) */ + export type Sendable = string | MessageElem | (string | MessageElem)[]; + /** 用于构造消息元素 */ +@@ -321,6 +325,7 @@ export declare const segment: { + xml(data: string, id?: number): XmlElem; + markdown(content: string): MarkdownElem; + button(content: ButtonElem["content"]): ButtonElem; ++ longmsg(resId: string): LongMsgElem; + /** 一种特殊消息(官方客户端无法解析) */ + mirai(data: string): MiraiElem; + /** 音乐 */ +diff --git a/lib/message/elements.js b/lib/message/elements.js +index de3a1d116c794ae2ee9e18836d6669a4d89d59d0..9c6c5c1fc5949eb49636d539aed4ed140bb3ec0a 100644 +--- a/lib/message/elements.js ++++ b/lib/message/elements.js +@@ -99,6 +99,11 @@ exports.segment = { + type: "button", content + }; + }, ++ longmsg(resId) { ++ return { ++ type: "longmsg", resId ++ }; ++ }, + /** 一种特殊消息(官方客户端无法解析) */ + mirai(data) { + return { diff --git a/patches/icqq@0.6.10.patch b/patches/icqq@0.6.10.patch deleted file mode 100644 index 2dad7c9..0000000 --- a/patches/icqq@0.6.10.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/lib/message/converter.js b/lib/message/converter.js -index c821bb3cdb5a404b1a7ef66883c3b22192b0c16d..e97774395375138be6c4489142ea3db79ba66538 100644 ---- a/lib/message/converter.js -+++ b/lib/message/converter.js -@@ -92,7 +92,7 @@ class Converter { - return; - } - if (qq === "all") { -- var q = 0, flag = 1, display = "全体成员"; -+ var q = 0, flag = 1, display = text || "全体成员"; - } - else { - var q = Number(qq), flag = 0, display = text || String(qq); -@@ -101,7 +101,6 @@ class Converter { - display = member?.card || member?.nickname || display; - } - } -- display = "@" + display; - if (dummy) - return this._text(display); - const buf = Buffer.allocUnsafe(6); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5cfcce..7ab4221 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,9 +5,9 @@ settings: excludeLinksFromLockfile: false patchedDependencies: - '@icqqjs/icqq@1.1.2': - hash: lvxibeykgrherv3ldsrdfzrnaq - path: patches/icqq@0.6.10.patch + '@icqqjs/icqq@1.0.2': + hash: wxe3a6ue6lwbvkaznekqvakwcq + path: patches/@icqqjs__icqq@1.0.2.patch importers: @@ -26,8 +26,8 @@ importers: specifier: ^7.0.1 version: 7.0.1 '@icqqjs/icqq': - specifier: ^1.1.2 - version: 1.1.2(patch_hash=lvxibeykgrherv3ldsrdfzrnaq) + specifier: 1.0.2 + version: 1.0.2(patch_hash=wxe3a6ue6lwbvkaznekqvakwcq) '@prisma/client': specifier: 5.9.1 version: 5.9.1(prisma@5.9.1) @@ -96,7 +96,7 @@ importers: version: 0.2.2 telegram: specifier: https://github.com/clansty/gramjs/releases/download/2.19.10%2Brevert_media/telegram-2.19.10.tgz - version: '@github.com/clansty/gramjs/releases/download/2.19.10%2525252525252Brevert_media/telegram-2.19.10.tgz' + version: '@github.com/clansty/gramjs/releases/download/2.19.10%2525252525252525252Brevert_media/telegram-2.19.10.tgz' tmp-promise: specifier: ^3.0.3 version: 3.0.3 @@ -786,14 +786,14 @@ packages: glob: 10.3.10 dev: false - /@icqqjs/icqq@1.1.2(patch_hash=lvxibeykgrherv3ldsrdfzrnaq): - resolution: {integrity: sha512-5hvFVYlV6qp7leC60c+HGfgjhK5udSIN92mEUfzbWKK+Xx8Z2ruMEAzIzfOcFkBugyzmjX5vxhymDH3diQm0pA==, tarball: https://npm.pkg.github.com/download/@icqqjs/icqq/1.1.2/aa71ad688f4e2ca32f883cef340f2387968d12c6} + /@icqqjs/icqq@1.0.2(patch_hash=wxe3a6ue6lwbvkaznekqvakwcq): + resolution: {integrity: sha512-SThmVjnSMpDNjtiCChjOLHsl8hUnWxrdMYLADGL1DxG+dUu5qgVJY7/bVI15MnC16FGz+moksl50A+cMyTSJww==, tarball: https://npm.pkg.github.com/download/@icqqjs/icqq/1.0.2/e21d5e48c12b466908cdf298283b6e4a2d532d2d} engines: {node: '>= v14'} dependencies: axios: 1.6.8 log4js: 6.9.1 - long: 5.2.3 - pngjs: 7.0.0 + long: 4.0.0 + pngjs: 6.0.0 probe-image-size: 7.2.3 silk-wasm: 3.2.3 triptrap: 0.0.17 @@ -3797,8 +3797,8 @@ packages: - supports-color dev: false - /long@5.2.3: - resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + /long@4.0.0: + resolution: {integrity: sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==} dev: false /lottie-node@2.0.0(canvas@2.11.2)(jsdom@16.7.0)(lottie-web@5.12.2): @@ -4306,11 +4306,6 @@ packages: engines: {node: '>=12.13.0'} dev: false - /pngjs@7.0.0: - resolution: {integrity: sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==} - engines: {node: '>=14.19.0'} - dev: false - /postcss@8.4.35: resolution: {integrity: sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==} engines: {node: ^10 || ^12 || >=14} @@ -5673,7 +5668,7 @@ packages: - utf-8-validate dev: false - '@github.com/clansty/gramjs/releases/download/2.19.10%2525252525252Brevert_media/telegram-2.19.10.tgz': + '@github.com/clansty/gramjs/releases/download/2.19.10%2525252525252525252Brevert_media/telegram-2.19.10.tgz': resolution: {tarball: https://github.com/clansty/gramjs/releases/download/2.19.10%2Brevert_media/telegram-2.19.10.tgz} name: telegram version: 2.19.10