From cd948bb5b0a496a9d9d7e5773668c6d8233b7e8d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 02:40:19 +0000 Subject: [PATCH 01/24] chore(deps-dev): bump @types/node from 20.10.8 to 20.11.0 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.10.8 to 20.11.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 2 +- pnpm-lock.yaml | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index d852bd62..2b32940c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@types/dockerode": "^3.3.23", "@types/fluent-ffmpeg": "^2.1.24", "@types/lodash": "^4.14.201", - "@types/node": "^20.10.8", + "@types/node": "^20.11.0", "@types/prompts": "^2.4.9", "ts-node": "^10.9.2", "typescript": "^5.3.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e417ed01..3c190452 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,14 +98,14 @@ devDependencies: specifier: ^4.14.201 version: 4.14.201 '@types/node': - specifier: ^20.10.8 - version: 20.10.8 + specifier: ^20.11.0 + version: 20.11.0 '@types/prompts': specifier: ^2.4.9 version: 2.4.9 ts-node: specifier: ^10.9.2 - version: 10.9.2(@types/node@20.10.8)(typescript@5.3.3) + version: 10.9.2(@types/node@20.11.0)(typescript@5.3.3) typescript: specifier: ^5.3.3 version: 5.3.3 @@ -781,7 +781,7 @@ packages: /@types/cli-progress@3.11.5: resolution: {integrity: sha512-D4PbNRbviKyppS5ivBGyFO29POlySLmA2HyUFE4p5QGazAMM3CwkKWcvTl8gvElSuxRh6FPKL8XmidX873ou4g==} dependencies: - '@types/node': 20.10.8 + '@types/node': 20.11.0 dev: true /@types/date-and-time@3.0.3: @@ -794,7 +794,7 @@ packages: /@types/docker-modem@3.0.6: resolution: {integrity: sha512-yKpAGEuKRSS8wwx0joknWxsmLha78wNMe9R2S3UNsVOkZded8UqOrV8KoeDXoXsjndxwyF3eIhyClGbO1SEhEg==} dependencies: - '@types/node': 20.10.8 + '@types/node': 20.11.0 '@types/ssh2': 1.11.18 dev: true @@ -802,13 +802,13 @@ packages: resolution: {integrity: sha512-Lz5J+NFgZS4cEVhquwjIGH4oQwlVn2h7LXD3boitujBnzOE5o7s9H8hchEjoDK2SlRsJTogdKnQeiJgPPKLIEw==} dependencies: '@types/docker-modem': 3.0.6 - '@types/node': 20.10.8 + '@types/node': 20.11.0 dev: true /@types/fluent-ffmpeg@2.1.24: resolution: {integrity: sha512-g5oQO8Jgi2kFS3tTub7wLvfLztr1s8tdXmRd8PiL/hLMLzTIAyMR2sANkTggM/rdEDAg3d63nYRRVepwBiCw5A==} dependencies: - '@types/node': 20.10.8 + '@types/node': 20.11.0 dev: true /@types/lodash@4.14.201: @@ -825,8 +825,8 @@ packages: undici-types: 5.26.5 dev: true - /@types/node@20.10.8: - resolution: {integrity: sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==} + /@types/node@20.11.0: + resolution: {integrity: sha512-o9bjXmDNcF7GbM4CNQpmi+TutCgap/K3w1JyKgxAjqx41zp9qlIAVFi0IhCNsJcXolEqLWhbFbEeL0PvYm4pcQ==} dependencies: undici-types: 5.26.5 dev: true @@ -834,7 +834,7 @@ packages: /@types/prompts@2.4.9: resolution: {integrity: sha512-qTxFi6Buiu8+50/+3DGIWLHM6QuWsEKugJnnP6iv2Mc4ncxE4A/OJkjuVOA+5X0X1S/nq5VJRa8Lu+nwcvbrKA==} dependencies: - '@types/node': 20.10.8 + '@types/node': 20.11.0 kleur: 3.0.3 dev: true @@ -3367,7 +3367,7 @@ packages: engines: {node: '>=14.0.0'} dev: false - /ts-node@10.9.2(@types/node@20.10.8)(typescript@5.3.3): + /ts-node@10.9.2(@types/node@20.11.0)(typescript@5.3.3): resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} hasBin: true peerDependencies: @@ -3386,7 +3386,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 20.10.8 + '@types/node': 20.11.0 acorn: 8.11.2 acorn-walk: 8.3.0 arg: 4.1.3 From 3dfa9b5b423fa98753b4e7a18da161df7f3f7ca2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 09:30:26 +0000 Subject: [PATCH 02/24] chore(deps-dev): bump @types/lodash from 4.14.201 to 4.14.202 Bumps [@types/lodash](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/lodash) from 4.14.201 to 4.14.202. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/lodash) --- updated-dependencies: - dependency-name: "@types/lodash" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2b32940c..5663dc77 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/date-and-time": "^3.0.3", "@types/dockerode": "^3.3.23", "@types/fluent-ffmpeg": "^2.1.24", - "@types/lodash": "^4.14.201", + "@types/lodash": "^4.14.202", "@types/node": "^20.11.0", "@types/prompts": "^2.4.9", "ts-node": "^10.9.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3c190452..f700bbc9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,8 +95,8 @@ devDependencies: specifier: ^2.1.24 version: 2.1.24 '@types/lodash': - specifier: ^4.14.201 - version: 4.14.201 + specifier: ^4.14.202 + version: 4.14.202 '@types/node': specifier: ^20.11.0 version: 20.11.0 @@ -811,8 +811,8 @@ packages: '@types/node': 20.11.0 dev: true - /@types/lodash@4.14.201: - resolution: {integrity: sha512-y9euML0cim1JrykNxADLfaG0FgD1g/yTHwUs/Jg9ZIU7WKj2/4IW9Lbb1WZbvck78W/lfGXFfe+u2EGfIJXdLQ==} + /@types/lodash@4.14.202: + resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==} dev: true /@types/node@16.9.1: From d78be6ebb909b4f0e6d1a657616f3d1aadcab1e5 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 18:15:29 +0800 Subject: [PATCH 03/24] =?UTF-8?q?chore:=20=E5=8F=AF=E4=BB=A5=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E7=94=A8=20/setup=20=E5=BC=80=E5=A7=8B=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SetupController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/SetupController.ts b/src/controllers/SetupController.ts index 5429f7ee..ad9e0c26 100644 --- a/src/controllers/SetupController.ts +++ b/src/controllers/SetupController.ts @@ -32,7 +32,7 @@ export default class SetupController { return false; } - if (message.text === '/setup' || message.text === '/start setup') { + if (message.message === '/setup' || message.message === '/start setup' || message.message === '/start') { this.isInProgress = true; await this.doSetup(Number(message.sender.id)); await this.finishSetup(); From 29f471245051f2cf372a932e3e909e66c775792b Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 20:40:32 +0800 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20TG=20=E4=B8=AD=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=8E=9F=E5=9C=B0=E8=BD=AC=E5=8F=91=E5=A4=8D=E8=AF=BB=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=20QQ=20=E7=9A=84=E6=B6=88=E6=81=AF=EF=BC=8C=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E5=88=B0=20QQ=20=E7=9A=84=E5=A4=8D=E8=AF=BB=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=B8=AD=E4=B8=8D=E5=8C=85=E5=90=AB=E5=8E=9F=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E5=8F=91=E9=80=81=E4=BA=BA=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/ForwardService.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/services/ForwardService.ts b/src/services/ForwardService.ts index b60f976e..01962b26 100644 --- a/src/services/ForwardService.ts +++ b/src/services/ForwardService.ts @@ -393,7 +393,7 @@ export default class ForwardService { const senderId = Number(message.senderId || message.sender?.id); // 这条消息在 tg 中被回复的时候显示的 let brief = '', isSpoilerPhoto = false; - const messageHeader = helper.getUserDisplayName(message.sender) + + let messageHeader = helper.getUserDisplayName(message.sender) + (message.forward ? ' 转发自 ' + // 要是隐私设置了,应该会有这个,然后下面两个都获取不到 (message.fwdFrom?.fromName || @@ -555,8 +555,8 @@ export default class ForwardService { } if (message.message && !isSpoilerPhoto) { - if (message.entities) { - const emojiEntities = message.entities.filter(it => it instanceof Api.MessageEntityCustomEmoji) as Api.MessageEntityCustomEmoji[]; + const emojiEntities = (message.entities || []).filter(it => it instanceof Api.MessageEntityCustomEmoji) as Api.MessageEntityCustomEmoji[]; + if (emojiEntities.length) { const isMessageAllEmojis = _.sum(emojiEntities.map(it => it.length)) === message.message.length; const newChain = [] as (string | MessageElem)[]; let messageLeft = message.message; @@ -572,11 +572,23 @@ export default class ForwardService { }); } chain.push(messageLeft, ...newChain); + brief += message.message; + } + // Q2TG Bot 转发的消息目前不会包含 custom emoji + else if (message.forward?.senderId?.eq?.(this.tgBot.me.id) && /^.*: ?$/.test(message.message.split('\n')[0])) { + // 复读了某一条来自 QQ 的消息 (Repeat as forward) + const originalMessage = message.message.includes('\n') ? + message.message.substring(message.message.indexOf('\n') + 1) : ''; + chain.push(originalMessage); + brief += originalMessage; + + messageHeader = helper.getUserDisplayName(message.sender) + ' 转发自 ' + + message.message.substring(0, message.message.indexOf(':')) + ': \n'; } else { chain.push(message.message); + brief += message.message; } - brief += message.message; } // 处理回复 From 8fd26c7bd4e054cf15fa4619a262bcd386e39c9f Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 21:01:45 +0800 Subject: [PATCH 05/24] =?UTF-8?q?chore:=20=E5=AE=B9=E5=99=A8=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E4=B8=8D=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=20generate=20prisma=20client=20library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5663dc77..c6e462d0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "scripts": { "dev": "ts-node src/index.ts", "build": "tsc", - "start": "prisma db push --accept-data-loss && node build/index.js", + "start": "prisma db push --accept-data-loss --skip-generate && node build/index.js", "prisma": "prisma", "import": "ts-node tools/import" }, From a2ea2d014b267cb5b80e2fa8c28c9ad2d8dc1eac Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 22:44:56 +0800 Subject: [PATCH 06/24] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8=20flag=20?= =?UTF-8?q?=E6=94=B9=E9=80=A0=E7=8E=B0=E6=9C=89=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma/schema.prisma | 6 +- src/constants/flags.ts | 8 +++ src/controllers/ForwardController.ts | 13 ++-- src/controllers/InChatCommandsController.ts | 13 ++-- src/models/ForwardPairs.ts | 4 +- src/models/Pair.ts | 72 ++------------------- 6 files changed, 30 insertions(+), 86 deletions(-) create mode 100644 src/constants/flags.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 83aefab1..4134f568 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -87,11 +87,7 @@ model ForwardPair { avatarCache AvatarCache[] instanceId Int @default(0) instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) - joinNotice Boolean @default(true) - poke Boolean @default(true) - enable Boolean @default(true) - disableQ2TG Boolean @default(false) - disableTG2Q Boolean @default(false) + flags Int @default(0) @@unique([qqRoomId, instanceId]) @@unique([tgChatId, instanceId]) diff --git a/src/constants/flags.ts b/src/constants/flags.ts new file mode 100644 index 00000000..c5aad642 --- /dev/null +++ b/src/constants/flags.ts @@ -0,0 +1,8 @@ +enum flags { + DISABLE_Q2TG = 1, + DISABLE_TG2Q = 1 << 1, + DISABLE_JOIN_NOTICE = 1 << 2, + DISABLE_POKE = 1 << 3 +} + +export default flags; diff --git a/src/controllers/ForwardController.ts b/src/controllers/ForwardController.ts index c06637dc..9db51d2b 100644 --- a/src/controllers/ForwardController.ts +++ b/src/controllers/ForwardController.ts @@ -18,6 +18,7 @@ import { CustomFile } from 'telegram/client/uploads'; import forwardHelper from '../helpers/forwardHelper'; import helper from '../helpers/forwardHelper'; import ZincSearch from 'zincsearch-node'; +import flags from '../constants/flags'; export default class ForwardController { private readonly forwardService: ForwardService; @@ -45,8 +46,7 @@ export default class ForwardController { const target = event.message_type === 'private' ? event.friend : event.group; const pair = this.instance.forwardPairs.find(target); if (!pair) return; - if (!pair.enable) return; - if (pair.disableQ2TG) return; + if (pair.flags & flags.DISABLE_Q2TG) return; // 如果是多张图片的话,是一整条消息,只过一次,所以不受这个判断影响 let existed = event.message_type === 'private' && await db.message.findFirst({ where: { @@ -102,8 +102,7 @@ export default class ForwardController { if (message.senderId?.eq(this.instance.botMe.id)) return true; const pair = this.instance.forwardPairs.find(message.chat); if (!pair) return false; - if (!pair.enable) return; - if (pair.disableTG2Q) return; + if (pair.flags & flags.DISABLE_TG2Q) return; const qqMessagesSent = await this.forwardService.forwardFromTelegram(message, pair); if (qqMessagesSent) { // 更新数据库 @@ -141,7 +140,7 @@ export default class ForwardController { private onQqGroupMemberIncrease = async (event: MemberIncreaseEvent) => { try { const pair = this.instance.forwardPairs.find(event.group); - if (!pair?.joinNotice) return false; + if (pair?.flags & flags.DISABLE_JOIN_NOTICE) return false; const avatar = await getAvatar(event.user_id); await pair.tg.sendMessage({ file: new CustomFile('avatar.png', avatar.length, '', avatar), @@ -157,7 +156,7 @@ export default class ForwardController { private onTelegramParticipant = async (event: Api.UpdateChannelParticipant) => { try { const pair = this.instance.forwardPairs.find(event.channelId); - if (!pair?.joinNotice) return false; + if (pair?.flags & flags.DISABLE_JOIN_NOTICE) return false; if ( !(event.newParticipant instanceof Api.ChannelParticipantAdmin) && !(event.newParticipant instanceof Api.ChannelParticipantCreator) && @@ -175,7 +174,7 @@ export default class ForwardController { private onQqPoke = async (event: FriendPokeEvent | GroupPokeEvent) => { const target = event.notice_type === 'friend' ? event.friend : event.group; const pair = this.instance.forwardPairs.find(target); - if (!pair?.poke) return; + if (pair?.flags & flags.DISABLE_POKE) return; let operatorName: string, targetName: string; if (target instanceof Friend) { if (event.operator_id === target.user_id) { diff --git a/src/controllers/InChatCommandsController.ts b/src/controllers/InChatCommandsController.ts index 877340c3..0025b319 100644 --- a/src/controllers/InChatCommandsController.ts +++ b/src/controllers/InChatCommandsController.ts @@ -6,6 +6,7 @@ import OicqClient from '../client/OicqClient'; import { Api } from 'telegram'; import { Group } from 'icqq'; import RecoverMessageHelper from '../helpers/RecoverMessageHelper'; +import flags from '../constants/flags'; export default class InChatCommandsController { private readonly service: InChatCommandsService; @@ -43,27 +44,27 @@ export default class InChatCommandsController { await this.service.poke(message, pair); return true; case '/forwardoff': - pair.enable = false; + pair.flags |= flags.DISABLE_Q2TG | flags.DISABLE_TG2Q; await message.reply({ message: '转发已禁用' }); return true; case '/forwardon': - pair.enable = true; + pair.flags &= ~flags.DISABLE_Q2TG & ~flags.DISABLE_TG2Q; await message.reply({ message: '转发已启用' }); return true; case '/disable_qq_forward': - pair.disableQ2TG = true; + pair.flags |= flags.DISABLE_Q2TG; await message.reply({ message: 'QQ->TG已禁用' }); return true; case '/enable_qq_forward': - pair.disableQ2TG = false; + pair.flags &= ~flags.DISABLE_Q2TG; await message.reply({ message: 'QQ->TG已启用' }); return true; case '/disable_tg_forward': - pair.disableTG2Q = true; + pair.flags |= flags.DISABLE_TG2Q; await message.reply({ message: 'TG->QQ已禁用' }); return true; case '/enable_tg_forward': - pair.disableTG2Q = false; + pair.flags &= ~flags.DISABLE_TG2Q; await message.reply({ message: 'TG->QQ已启用' }); return true; case '/refresh': diff --git a/src/models/ForwardPairs.ts b/src/models/ForwardPairs.ts index a88513b0..3d0426ae 100644 --- a/src/models/ForwardPairs.ts +++ b/src/models/ForwardPairs.ts @@ -27,7 +27,7 @@ export default class ForwardPairs { const qq = oicq.getChat(Number(i.qqRoomId)); const tg = await tgBot.getChat(Number(i.tgChatId)); if (qq && tg) { - this.pairs.push(new Pair(qq, tg, i.id, i.joinNotice, i.poke, i.enable, i.disableQ2TG, i.disableTG2Q)); + this.pairs.push(new Pair(qq, tg, i.id, i.flags)); } } catch (e) { @@ -50,7 +50,7 @@ export default class ForwardPairs { instanceId: this.instanceId, }, }); - this.pairs.push(new Pair(qq, tg, dbEntry.id, true, true, true, false, false)); + this.pairs.push(new Pair(qq, tg, dbEntry.id, dbEntry.flags)); return dbEntry; } diff --git a/src/models/Pair.ts b/src/models/Pair.ts index f44fd237..47f1362c 100644 --- a/src/models/Pair.ts +++ b/src/models/Pair.ts @@ -17,11 +17,7 @@ export class Pair { public readonly qq: Friend | Group, private _tg: TelegramChat, public dbId: number, - private _joinNotice: boolean, - private _poke: boolean, - private _enable: boolean, - private _disableQ2TG: boolean, - private _disableTG2Q: boolean, + private _flags: number, ) { } @@ -67,72 +63,16 @@ export class Pair { .then(() => log.info(`出现了到超级群组的转换: ${value.id}`)); } - get joinNotice() { - return this._joinNotice; + get flags() { + return this._flags; } - set joinNotice(value) { - this._joinNotice = value; + set flags(value) { + this._flags = value; db.forwardPair .update({ where: { id: this.dbId }, - data: { joinNotice: value }, - }) - .then(() => 0); - } - - get poke() { - return this._poke; - } - - set poke(value) { - this._poke = value; - db.forwardPair - .update({ - where: { id: this.dbId }, - data: { poke: value }, - }) - .then(() => 0); - } - - get enable() { - return this._enable; - } - - set enable(value) { - this._enable = value; - db.forwardPair - .update({ - where: { id: this.dbId }, - data: { enable: value }, - }) - .then(() => 0); - } - - get disableQ2TG() { - return this._disableQ2TG; - } - - set disableQ2TG(value) { - this._disableQ2TG = value; - db.forwardPair - .update({ - where: { id: this.dbId }, - data: { disableQ2TG: value }, - }) - .then(() => 0); - } - - get disableTG2Q() { - return this._disableTG2Q; - } - - set disableTG2Q(value) { - this._disableTG2Q = value; - db.forwardPair - .update({ - where: { id: this.dbId }, - data: { disableTG2Q: value }, + data: { flags: value }, }) .then(() => 0); } From d6dcdd0bbfe3e2f02b146630a25f2e1e68d6e3cf Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 23:18:12 +0800 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=AE=BE=E7=BD=AE=20flags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/InChatCommandsController.ts | 10 +++++++ src/services/InChatCommandsService.ts | 32 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/controllers/InChatCommandsController.ts b/src/controllers/InChatCommandsController.ts index 0025b319..48538a41 100644 --- a/src/controllers/InChatCommandsController.ts +++ b/src/controllers/InChatCommandsController.ts @@ -67,6 +67,16 @@ export default class InChatCommandsController { pair.flags &= ~flags.DISABLE_TG2Q; await message.reply({ message: 'TG->QQ已启用' }); return true; + case '/flags': + case '/flag': + if (!message.senderId.eq(this.instance.owner)) { + await message.reply({ message: '权限不够' }); + return true; + } + await message.reply({ + message: await this.service.editFlags(messageParts, pair), + }); + return true; case '/refresh': if (this.instance.workMode !== 'personal' || !message.senderId?.eq(this.instance.owner)) return false; await pair.updateInfo(); diff --git a/src/services/InChatCommandsService.ts b/src/services/InChatCommandsService.ts index 4c91cf15..9b217bb3 100644 --- a/src/services/InChatCommandsService.ts +++ b/src/services/InChatCommandsService.ts @@ -11,6 +11,7 @@ import db from '../models/db'; import { Friend, Group } from 'icqq'; import { format } from 'date-and-time'; import ZincSearch from 'zincsearch-node'; +import flags from '../constants/flags'; export default class InChatCommandsService { private readonly log: Logger; @@ -145,4 +146,35 @@ export default class InChatCommandsService { }); return rpy.join('\n'); } + + public async editFlags(params: string[], pair: Pair) { + if (!params.length) { + return '0b' + pair.flags.toString(2); + } + if (params.length !== 2) return '参数格式错误'; + + let operand = Number(params[1]); + if (isNaN(operand)) { + operand = flags[params[1].toUpperCase()]; + } + if (isNaN(operand)) return 'flag 格式错误'; + + switch (params[0]) { + case 'add': + case 'set': + pair.flags |= operand; + break; + case 'rm': + case 'remove': + case 'del': + case 'delete': + pair.flags &= ~operand; + break; + case 'put': + pair.flags = operand; + break; + } + + return '0b' + pair.flags.toString(2); + } } From 31d9f503f160f7c019431572050285104d8f24e9 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 23:29:40 +0800 Subject: [PATCH 08/24] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E5=9C=A8=20tg=20=E5=90=8C=E6=AD=A5=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=9A=84=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/TelegramChat.ts | 6 +++++- src/constants/flags.ts | 3 ++- src/controllers/DeleteMessageController.ts | 14 ++++---------- src/services/DeleteMessageService.ts | 13 +++++++++++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/client/TelegramChat.ts b/src/client/TelegramChat.ts index 88cab5ec..90fd6a58 100644 --- a/src/client/TelegramChat.ts +++ b/src/client/TelegramChat.ts @@ -2,7 +2,7 @@ import { BigInteger } from 'big-integer'; import { Api, TelegramClient, utils } from 'telegram'; import { ButtonLike, Entity, EntityLike, MessageIDLike } from 'telegram/define'; import WaitForMessageHelper from '../helpers/WaitForMessageHelper'; -import { SendMessageParams } from 'telegram/client/messages'; +import { EditMessageParams, SendMessageParams } from 'telegram/client/messages'; import { CustomFile } from 'telegram/client/uploads'; import Telegram from './Telegram'; import createPaginatedInlineSelector from '../utils/paginatedInlineSelector'; @@ -186,6 +186,10 @@ export default class TelegramChat { return await this.client.deleteMessages(this.entity, messageId, { revoke: true }); } + public async editMessages(params: EditMessageParams) { + return await this.client.editMessage(this.entity, params); + } + public async inviteMember(member: EntityLike | EntityLike[]) { if (!Array.isArray(member)) { member = [member]; diff --git a/src/constants/flags.ts b/src/constants/flags.ts index c5aad642..612d0f6b 100644 --- a/src/constants/flags.ts +++ b/src/constants/flags.ts @@ -2,7 +2,8 @@ enum flags { DISABLE_Q2TG = 1, DISABLE_TG2Q = 1 << 1, DISABLE_JOIN_NOTICE = 1 << 2, - DISABLE_POKE = 1 << 3 + DISABLE_POKE = 1 << 3, + NO_DELETE_MESSAGE = 1 << 4, } export default flags; diff --git a/src/controllers/DeleteMessageController.ts b/src/controllers/DeleteMessageController.ts index 5fb05090..e5e3d7ab 100644 --- a/src/controllers/DeleteMessageController.ts +++ b/src/controllers/DeleteMessageController.ts @@ -17,8 +17,8 @@ export default class DeleteMessageController { tgBot.addNewMessageEventHandler(this.onTelegramMessage); tgBot.addEditedMessageEventHandler(this.onTelegramEditMessage); tgUser.addDeletedMessageEventHandler(this.onTgDeletedMessage); - oicq.on('notice.friend.recall', this.onQqFriendRecall); - oicq.on('notice.group.recall', this.onQqGroupRecall); + oicq.on('notice.friend.recall', this.onQqRecall); + oicq.on('notice.group.recall', this.onQqRecall); } private onTelegramMessage = async (message: Api.Message) => { @@ -42,14 +42,8 @@ export default class DeleteMessageController { return await this.onTelegramMessage(message); }; - private onQqFriendRecall = async (event: FriendRecallEvent) => { - const pair = this.instance.forwardPairs.find(event.friend); - if (!pair) return; - await this.deleteMessageService.handleQqRecall(event, pair); - }; - - private onQqGroupRecall = async (event: GroupRecallEvent) => { - const pair = this.instance.forwardPairs.find(event.group); + private onQqRecall = async (event: FriendRecallEvent | GroupRecallEvent) => { + const pair = this.instance.forwardPairs.find('friend' in event ? event.friend : event.group); if (!pair) return; await this.deleteMessageService.handleQqRecall(event, pair); }; diff --git a/src/services/DeleteMessageService.ts b/src/services/DeleteMessageService.ts index 3e86fdbc..60020d63 100644 --- a/src/services/DeleteMessageService.ts +++ b/src/services/DeleteMessageService.ts @@ -7,6 +7,7 @@ import Instance from '../models/Instance'; import { Pair } from '../models/Pair'; import { consumer } from '../utils/highLevelFunces'; import forwardHelper from '../helpers/forwardHelper'; +import flags from '../constants/flags'; export default class DeleteMessageService { private readonly log: Logger; @@ -143,11 +144,19 @@ export default class DeleteMessageService { instanceId: this.instance.id, }, }); - if (message) { + if (!message) return; + if (pair.flags & flags.NO_DELETE_MESSAGE) { + await pair.tg.editMessages({ + message: message.tgMsgId, + text: `${message.tgMessageText}\n此消息已删除`, + parseMode: 'html', + }); + } + else { + await pair.tg.deleteMessages(message.tgMsgId); await db.message.delete({ where: { id: message.id }, }); - await pair.tg.deleteMessages(message.tgMsgId); } } catch (e) { From d98d5e72c96c7bb048a53fc5d0bd4ba327681694 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 23:37:59 +0800 Subject: [PATCH 09/24] =?UTF-8?q?feat:=20=E6=98=BE=E7=A4=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=90=AF=E7=94=A8=E7=9A=84=20flag=20=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/inChatCommandsHelper.ts | 14 ++++++++++++++ src/services/InChatCommandsService.ts | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/helpers/inChatCommandsHelper.ts diff --git a/src/helpers/inChatCommandsHelper.ts b/src/helpers/inChatCommandsHelper.ts new file mode 100644 index 00000000..07f5bb7c --- /dev/null +++ b/src/helpers/inChatCommandsHelper.ts @@ -0,0 +1,14 @@ +import flags from '../constants/flags'; + +export default { + displayFlag(flag: number) { + const enabled = []; + for (const name in flags) { + const value = flags[name] as any as number; + if (flag & value) { + enabled.push(name); + } + } + return ['0b' + flag.toString(2), ...enabled].join('\n'); + }, +}; diff --git a/src/services/InChatCommandsService.ts b/src/services/InChatCommandsService.ts index 9b217bb3..92933e47 100644 --- a/src/services/InChatCommandsService.ts +++ b/src/services/InChatCommandsService.ts @@ -12,6 +12,7 @@ import { Friend, Group } from 'icqq'; import { format } from 'date-and-time'; import ZincSearch from 'zincsearch-node'; import flags from '../constants/flags'; +import inChatCommandsHelper from '../helpers/inChatCommandsHelper'; export default class InChatCommandsService { private readonly log: Logger; @@ -149,7 +150,7 @@ export default class InChatCommandsService { public async editFlags(params: string[], pair: Pair) { if (!params.length) { - return '0b' + pair.flags.toString(2); + return inChatCommandsHelper.displayFlag(pair.flags); } if (params.length !== 2) return '参数格式错误'; @@ -175,6 +176,6 @@ export default class InChatCommandsService { break; } - return '0b' + pair.flags.toString(2); + return inChatCommandsHelper.displayFlag(pair.flags); } } From d1ae64ddb4ec29df7f53fa765a228cd90daaef46 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 12 Jan 2024 23:58:50 +0800 Subject: [PATCH 10/24] =?UTF-8?q?fix:=20=E5=8F=AF=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=20telegram=20=E4=B8=AD=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=AF=E8=83=BD=E7=9A=84=E5=81=87=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/DeleteMessageService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/DeleteMessageService.ts b/src/services/DeleteMessageService.ts index 60020d63..54d9bf06 100644 --- a/src/services/DeleteMessageService.ts +++ b/src/services/DeleteMessageService.ts @@ -61,12 +61,12 @@ export default class DeleteMessageService { // 假如 mapQQ 是普通成员,机器人是管理员,上面撤回失败了也可以由机器人撤回 // 所以撤回两次 // 不知道哪次会成功,所以就都不发失败提示了 - this.recallQqMessage(pair.qq, messageInfo.seq, Number(messageInfo.rand), - pair.qq instanceof Friend ? messageInfo.time : messageInfo.pktnum, - pair, isOthersMsg, !!mapQq); await db.message.delete({ where: { id: messageInfo.id }, }); + this.recallQqMessage(pair.qq, messageInfo.seq, Number(messageInfo.rand), + pair.qq instanceof Friend ? messageInfo.time : messageInfo.pktnum, + pair, isOthersMsg, !!mapQq); } catch (e) { this.log.error(e); From 71684c95b6830fca350cd5182c331dece2f6d6d4 Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 00:15:12 +0800 Subject: [PATCH 11/24] =?UTF-8?q?feat:=20=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20/q=20=E7=94=9F=E6=88=90=20QuotLy=20=E6=80=AA=E8=AF=9D?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/QuotLyController.ts | 46 ++++++++++++++++++----------- src/models/Instance.ts | 5 +--- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/controllers/QuotLyController.ts b/src/controllers/QuotLyController.ts index 43710262..fb759c3d 100644 --- a/src/controllers/QuotLyController.ts +++ b/src/controllers/QuotLyController.ts @@ -25,6 +25,7 @@ export default class { } private onQqMessage = async (event: PrivateMessageEvent | GroupMessageEvent) => { + if (this.instance.workMode === 'personal') return; if (event.message_type !== 'group') return; const pair = this.instance.forwardPairs.find(event.group); if (!pair) return; @@ -53,13 +54,16 @@ export default class { this.log.error('找不到 sourceMessage'); return true; } - try { - await this.sendQuote(pair, sourceMessage); - } - catch (e) { - this.log.error(e); - await event.reply(e.toString(), true); - } + setTimeout(async () => { + // 异步发送,为了让 /q 先到达 + try { + await this.sendQuote(pair, sourceMessage); + } + catch (e) { + this.log.error(e); + await event.reply(e.toString(), true); + } + }, 50); }; private onTelegramMessage = async (message: Api.Message) => { @@ -86,15 +90,20 @@ export default class { this.log.error('找不到 sourceMessage'); return true; } - try { - await this.sendQuote(pair, sourceMessage); - } - catch (e) { - this.log.error(e); - await message.reply({ - message: e.toString(), - }); - } + setTimeout(async () => { + try { + await this.sendQuote(pair, sourceMessage); + } + catch (e) { + this.log.error(e); + await message.reply({ + message: e.toString(), + }); + } + }, 50); + + // 个人模式下,/q 这条消息不转发到 QQ,怪话图只有自己可见 + if (this.instance.workMode === 'personal') return true; }; private async genQuote(message: Message) { @@ -287,10 +296,13 @@ export default class { const tgMessage = await pair.tg.sendMessage({ file: new CustomFile('quote.webp', image.length, undefined, image), }); + + if (this.instance.workMode === 'personal') return; + const qqMessage = await pair.qq.sendMsg({ type: 'image', file: image, - asface: true + asface: true, }); await db.message.create({ data: { diff --git a/src/models/Instance.ts b/src/models/Instance.ts index 604fd0be..e93bd59b 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -151,11 +151,8 @@ export default class Instance { if (this.workMode === 'group') { this.hugController = new HugController(this, this.tgBot, this.oicq); } + this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); this.forwardController = new ForwardController(this, this.tgBot, this.tgUser, this.oicq); - if (this.workMode === 'group') { - // 希望那个 /q 也被转发 - this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); - } this.fileAndFlashPhotoController = new FileAndFlashPhotoController(this, this.tgBot, this.oicq); })() .then(() => this.log.info('初始化已完成')); From 5a87cd2c47c45922e7b3003dae194e08c333b3ff Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 16:51:44 +0800 Subject: [PATCH 12/24] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20instance=20?= =?UTF-8?q?=E7=BA=A7=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prisma/schema.prisma | 1 + src/controllers/ConfigController.ts | 10 +++++ src/controllers/ForwardController.ts | 10 ++--- src/controllers/InChatCommandsController.ts | 3 +- src/helpers/inChatCommandsHelper.ts | 14 ------- src/models/Instance.ts | 16 ++++++++ src/services/DeleteMessageService.ts | 2 +- src/services/InChatCommandsService.ts | 33 --------------- src/utils/flagControl.ts | 45 +++++++++++++++++++++ 9 files changed, 80 insertions(+), 54 deletions(-) delete mode 100644 src/helpers/inChatCommandsHelper.ts create mode 100644 src/utils/flagControl.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4134f568..2f189485 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -45,6 +45,7 @@ model Instance { qqBotId Int? qqBot QqBot? @relation(fields: [qqBotId], references: [id], onDelete: Cascade) reportUrl String? + flags Int @default(0) } model QqBot { diff --git a/src/controllers/ConfigController.ts b/src/controllers/ConfigController.ts index e78d4294..93e8960c 100644 --- a/src/controllers/ConfigController.ts +++ b/src/controllers/ConfigController.ts @@ -12,6 +12,7 @@ import { } from 'icqq'; import Instance from '../models/Instance'; import { getLogger, Logger } from 'log4js'; +import { editFlags } from '../utils/flagControl'; export default class ConfigController { private readonly configService: ConfigService; @@ -48,6 +49,15 @@ export default class ConfigController { return false; } else if (message.isPrivate) { + switch (messageSplit[0]) { + case '/flag': + case '/flags': + messageSplit.shift(); + await message.reply({ + message: await editFlags(messageSplit, this.instance), + }); + return true; + } if (this.instance.workMode === 'personal') { switch (messageSplit[0]) { case '/addfriend': diff --git a/src/controllers/ForwardController.ts b/src/controllers/ForwardController.ts index 9db51d2b..389975d1 100644 --- a/src/controllers/ForwardController.ts +++ b/src/controllers/ForwardController.ts @@ -46,7 +46,7 @@ export default class ForwardController { const target = event.message_type === 'private' ? event.friend : event.group; const pair = this.instance.forwardPairs.find(target); if (!pair) return; - if (pair.flags & flags.DISABLE_Q2TG) return; + if ((pair.flags | this.instance.flags) & flags.DISABLE_Q2TG) return; // 如果是多张图片的话,是一整条消息,只过一次,所以不受这个判断影响 let existed = event.message_type === 'private' && await db.message.findFirst({ where: { @@ -102,7 +102,7 @@ export default class ForwardController { if (message.senderId?.eq(this.instance.botMe.id)) return true; const pair = this.instance.forwardPairs.find(message.chat); if (!pair) return false; - if (pair.flags & flags.DISABLE_TG2Q) return; + if ((pair.flags | this.instance.flags) & flags.DISABLE_TG2Q) return; const qqMessagesSent = await this.forwardService.forwardFromTelegram(message, pair); if (qqMessagesSent) { // 更新数据库 @@ -140,7 +140,7 @@ export default class ForwardController { private onQqGroupMemberIncrease = async (event: MemberIncreaseEvent) => { try { const pair = this.instance.forwardPairs.find(event.group); - if (pair?.flags & flags.DISABLE_JOIN_NOTICE) return false; + if ((pair?.flags | this.instance.flags) & flags.DISABLE_JOIN_NOTICE) return false; const avatar = await getAvatar(event.user_id); await pair.tg.sendMessage({ file: new CustomFile('avatar.png', avatar.length, '', avatar), @@ -156,7 +156,7 @@ export default class ForwardController { private onTelegramParticipant = async (event: Api.UpdateChannelParticipant) => { try { const pair = this.instance.forwardPairs.find(event.channelId); - if (pair?.flags & flags.DISABLE_JOIN_NOTICE) return false; + if ((pair?.flags | this.instance.flags) & flags.DISABLE_JOIN_NOTICE) return false; if ( !(event.newParticipant instanceof Api.ChannelParticipantAdmin) && !(event.newParticipant instanceof Api.ChannelParticipantCreator) && @@ -174,7 +174,7 @@ export default class ForwardController { private onQqPoke = async (event: FriendPokeEvent | GroupPokeEvent) => { const target = event.notice_type === 'friend' ? event.friend : event.group; const pair = this.instance.forwardPairs.find(target); - if (pair?.flags & flags.DISABLE_POKE) return; + if ((pair?.flags | this.instance.flags) & flags.DISABLE_POKE) return; let operatorName: string, targetName: string; if (target instanceof Friend) { if (event.operator_id === target.user_id) { diff --git a/src/controllers/InChatCommandsController.ts b/src/controllers/InChatCommandsController.ts index 48538a41..6f55a128 100644 --- a/src/controllers/InChatCommandsController.ts +++ b/src/controllers/InChatCommandsController.ts @@ -7,6 +7,7 @@ import { Api } from 'telegram'; import { Group } from 'icqq'; import RecoverMessageHelper from '../helpers/RecoverMessageHelper'; import flags from '../constants/flags'; +import { editFlags } from '../utils/flagControl'; export default class InChatCommandsController { private readonly service: InChatCommandsService; @@ -74,7 +75,7 @@ export default class InChatCommandsController { return true; } await message.reply({ - message: await this.service.editFlags(messageParts, pair), + message: await editFlags(messageParts, pair), }); return true; case '/refresh': diff --git a/src/helpers/inChatCommandsHelper.ts b/src/helpers/inChatCommandsHelper.ts deleted file mode 100644 index 07f5bb7c..00000000 --- a/src/helpers/inChatCommandsHelper.ts +++ /dev/null @@ -1,14 +0,0 @@ -import flags from '../constants/flags'; - -export default { - displayFlag(flag: number) { - const enabled = []; - for (const name in flags) { - const value = flags[name] as any as number; - if (flag & value) { - enabled.push(name); - } - } - return ['0b' + flag.toString(2), ...enabled].join('\n'); - }, -}; diff --git a/src/models/Instance.ts b/src/models/Instance.ts index e93bd59b..f244b456 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -32,6 +32,7 @@ export default class Instance { private _userSessionId = 0; private _qq: QqBot; private _reportUrl: string; + private _flags: number; private readonly log: Logger; @@ -84,6 +85,7 @@ export default class Instance { this._isSetup = dbEntry.isSetup; this._workMode = dbEntry.workMode; this._reportUrl = dbEntry.reportUrl; + this._flags = dbEntry.flags; } private async init(botToken?: string) { @@ -255,6 +257,10 @@ export default class Instance { return this._reportUrl; } + get flags() { + return this._flags; + } + set owner(owner: number) { this._owner = owner; db.instance.update({ @@ -309,10 +315,20 @@ export default class Instance { } set reportUrl(reportUrl: string) { + this._reportUrl = reportUrl; db.instance.update({ data: { reportUrl }, where: { id: this.id }, }) .then(() => this.log.trace(reportUrl)); } + + set flags(value) { + this._flags = value; + db.instance.update({ + data: { flags: value }, + where: { id: this.id }, + }) + .then(() => this.log.trace(value)); + } } diff --git a/src/services/DeleteMessageService.ts b/src/services/DeleteMessageService.ts index 54d9bf06..3865cfa4 100644 --- a/src/services/DeleteMessageService.ts +++ b/src/services/DeleteMessageService.ts @@ -145,7 +145,7 @@ export default class DeleteMessageService { }, }); if (!message) return; - if (pair.flags & flags.NO_DELETE_MESSAGE) { + if ((pair.flags | this.instance.flags) & flags.NO_DELETE_MESSAGE) { await pair.tg.editMessages({ message: message.tgMsgId, text: `${message.tgMessageText}\n此消息已删除`, diff --git a/src/services/InChatCommandsService.ts b/src/services/InChatCommandsService.ts index 92933e47..4c91cf15 100644 --- a/src/services/InChatCommandsService.ts +++ b/src/services/InChatCommandsService.ts @@ -11,8 +11,6 @@ import db from '../models/db'; import { Friend, Group } from 'icqq'; import { format } from 'date-and-time'; import ZincSearch from 'zincsearch-node'; -import flags from '../constants/flags'; -import inChatCommandsHelper from '../helpers/inChatCommandsHelper'; export default class InChatCommandsService { private readonly log: Logger; @@ -147,35 +145,4 @@ export default class InChatCommandsService { }); return rpy.join('\n'); } - - public async editFlags(params: string[], pair: Pair) { - if (!params.length) { - return inChatCommandsHelper.displayFlag(pair.flags); - } - if (params.length !== 2) return '参数格式错误'; - - let operand = Number(params[1]); - if (isNaN(operand)) { - operand = flags[params[1].toUpperCase()]; - } - if (isNaN(operand)) return 'flag 格式错误'; - - switch (params[0]) { - case 'add': - case 'set': - pair.flags |= operand; - break; - case 'rm': - case 'remove': - case 'del': - case 'delete': - pair.flags &= ~operand; - break; - case 'put': - pair.flags = operand; - break; - } - - return inChatCommandsHelper.displayFlag(pair.flags); - } } diff --git a/src/utils/flagControl.ts b/src/utils/flagControl.ts new file mode 100644 index 00000000..dc8b0098 --- /dev/null +++ b/src/utils/flagControl.ts @@ -0,0 +1,45 @@ +import flags from '../constants/flags'; +import { Pair } from '../models/Pair'; +import Instance from '../models/Instance'; + +const displayFlag = (flag: number) => { + const enabled = []; + for (const name in flags) { + const value = flags[name] as any as number; + if (flag & value) { + enabled.push(name); + } + } + return ['0b' + flag.toString(2), ...enabled].join('\n'); +}; + +export const editFlags = async (params: string[], target: Pair | Instance) => { + if (!params.length) { + return displayFlag(target.flags); + } + if (params.length !== 2) return '参数格式错误'; + + let operand = Number(params[1]); + if (isNaN(operand)) { + operand = flags[params[1].toUpperCase()]; + } + if (isNaN(operand)) return 'flag 格式错误'; + + switch (params[0]) { + case 'add': + case 'set': + target.flags |= operand; + break; + case 'rm': + case 'remove': + case 'del': + case 'delete': + target.flags &= ~operand; + break; + case 'put': + target.flags = operand; + break; + } + + return displayFlag(target.flags); +}; From 51e4309e1093afad222cea80394765a277cc07a0 Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 17:02:32 +0800 Subject: [PATCH 13/24] =?UTF-8?q?feat:=20=E5=8F=AF=E4=BB=A5=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E7=A7=81=E8=81=8A?= =?UTF-8?q?=E7=9A=84=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/flags.ts | 1 + src/controllers/ConfigController.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/constants/flags.ts b/src/constants/flags.ts index 612d0f6b..2b86bc11 100644 --- a/src/constants/flags.ts +++ b/src/constants/flags.ts @@ -4,6 +4,7 @@ enum flags { DISABLE_JOIN_NOTICE = 1 << 2, DISABLE_POKE = 1 << 3, NO_DELETE_MESSAGE = 1 << 4, + NO_AUTO_CREATE_PM = 1 << 5, } export default flags; diff --git a/src/controllers/ConfigController.ts b/src/controllers/ConfigController.ts index 93e8960c..c94e778c 100644 --- a/src/controllers/ConfigController.ts +++ b/src/controllers/ConfigController.ts @@ -13,6 +13,7 @@ import { import Instance from '../models/Instance'; import { getLogger, Logger } from 'log4js'; import { editFlags } from '../utils/flagControl'; +import flags from '../constants/flags'; export default class ConfigController { private readonly configService: ConfigService; @@ -116,6 +117,7 @@ export default class ConfigController { private handleQqMessage = async (message: GroupMessageEvent | PrivateMessageEvent) => { if (message.message_type !== 'private' || this.instance.workMode === 'group') return false; + if (this.instance.flags & flags.NO_AUTO_CREATE_PM) return false; const pair = this.instance.forwardPairs.find(message.friend); if (pair) return false; // 如果正在创建中,应该阻塞 From e5d1f7cbce84da4251536af7ff104c58fdb0fd90 Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 17:28:27 +0800 Subject: [PATCH 14/24] =?UTF-8?q?fix:=20=E8=BF=99=E4=B8=8B=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=92=A4=E5=9B=9E=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E4=BD=86=E6=98=AF=E6=8F=90=E7=A4=BA=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/DeleteMessageService.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/services/DeleteMessageService.ts b/src/services/DeleteMessageService.ts index 3865cfa4..4d317932 100644 --- a/src/services/DeleteMessageService.ts +++ b/src/services/DeleteMessageService.ts @@ -11,12 +11,22 @@ import flags from '../constants/flags'; export default class DeleteMessageService { private readonly log: Logger; + private readonly lockIds = new Set(); constructor(private readonly instance: Instance, private readonly tgBot: Telegram) { this.log = getLogger(`DeleteMessageService - ${instance.id}`); } + private lock(lockId: string) { + if (this.lockIds.has(lockId)) { + this.log.debug('重复执行消息撤回', lockId); + return true; + } + this.lockIds.add(lockId); + setTimeout(() => this.lockIds.delete(lockId), 5000); + } + // 500ms 内只撤回一条消息,防止频繁导致一部分消息没有成功撤回。不过这样的话,会得不到返回的结果 private recallQqMessage = consumer(async (qq: Friend | Group, seq: number, rand: number, timeOrPktnum: number, pair: Pair, isOthersMsg: boolean, noSendError = false) => { try { @@ -46,6 +56,7 @@ export default class DeleteMessageService { */ async telegramDeleteMessage(messageId: number, pair: Pair, isOthersMsg = false) { // 删除的时候会返回记录 + if (this.lock(`tg-${pair.tgId}-${messageId}`)) return; try { const messageInfo = await db.message.findFirst({ where: { @@ -56,17 +67,18 @@ export default class DeleteMessageService { }); if (messageInfo) { try { + if (this.lock(`qq-${pair.qqRoomId}-${messageInfo.seq}`)) return; const mapQq = pair.instanceMapForTg[messageInfo.tgSenderId.toString()]; mapQq && this.recallQqMessage(mapQq, messageInfo.seq, Number(messageInfo.rand), messageInfo.pktnum, pair, false, true); // 假如 mapQQ 是普通成员,机器人是管理员,上面撤回失败了也可以由机器人撤回 // 所以撤回两次 // 不知道哪次会成功,所以就都不发失败提示了 - await db.message.delete({ - where: { id: messageInfo.id }, - }); this.recallQqMessage(pair.qq, messageInfo.seq, Number(messageInfo.rand), pair.qq instanceof Friend ? messageInfo.time : messageInfo.pktnum, pair, isOthersMsg, !!mapQq); + await db.message.delete({ + where: { id: messageInfo.id }, + }); } catch (e) { this.log.error(e); @@ -135,6 +147,7 @@ export default class DeleteMessageService { } public async handleQqRecall(event: FriendRecallEvent | GroupRecallEvent, pair: Pair) { + if (this.lock(`qq-${pair.qqRoomId}-${event.seq}`)) return; try { const message = await db.message.findFirst({ where: { @@ -145,6 +158,7 @@ export default class DeleteMessageService { }, }); if (!message) return; + if (this.lock(`tg-${pair.tgId}-${message.tgMsgId}`)) return; if ((pair.flags | this.instance.flags) & flags.NO_DELETE_MESSAGE) { await pair.tg.editMessages({ message: message.tgMsgId, From e91af9426b666ff9c514fa90af38d0a811bf72d2 Mon Sep 17 00:00:00 2001 From: Clansty Date: Sat, 13 Jan 2024 23:06:41 +0800 Subject: [PATCH 15/24] =?UTF-8?q?fix:=20=E4=B8=AA=E4=BA=BA=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=A7=81=E8=81=8A=E4=B8=AD=20/q=20=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/QuotLyController.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/QuotLyController.ts b/src/controllers/QuotLyController.ts index fb759c3d..c332acfc 100644 --- a/src/controllers/QuotLyController.ts +++ b/src/controllers/QuotLyController.ts @@ -162,7 +162,10 @@ export default class { title: message.nick, photo: { url: getAvatarUrl(message.qqSenderId) }, }; - if (message.tgMessageText.includes('\n')) { + if (message.qqRoomId > 0) { + quoteMessage.text = message.tgMessageText; + } + else if (message.tgMessageText.includes('\n')) { quoteMessage.text = message.tgMessageText.substring(message.tgMessageText.indexOf('\n')).trim(); } else { From b555a4caec66a1f5d25400ed16430ab41460d50f Mon Sep 17 00:00:00 2001 From: Clansty Date: Sun, 14 Jan 2024 16:17:48 +0800 Subject: [PATCH 16/24] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20NFT=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E6=97=B6=20@=20=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E5=87=BA=E7=8E=B0=20@null=20?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/ForwardService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/services/ForwardService.ts b/src/services/ForwardService.ts index 01962b26..1fa6f845 100644 --- a/src/services/ForwardService.ts +++ b/src/services/ForwardService.ts @@ -351,7 +351,9 @@ export default class ForwardService { } if (this.instance.workMode === 'personal' && event.message_type === 'group' && event.atme && !replyTo) { - message += `\n@${this.instance.userMe.username}`; + message += `\n@${this.instance.userMe.usernames?.length ? + this.instance.userMe.usernames[0].username : + this.instance.userMe.username}`; } // 发送消息 From 4b092d3eb161f691597eb34fe0aea06a234aa4ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 02:43:28 +0000 Subject: [PATCH 17/24] chore(deps): bump date-and-time from 3.1.0 to 3.1.1 Bumps [date-and-time](https://github.com/knowledgecode/date-and-time) from 3.1.0 to 3.1.1. - [Commits](https://github.com/knowledgecode/date-and-time/compare/v3.1.0...v3.1.1) --- updated-dependencies: - dependency-name: date-and-time dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- pnpm-lock.yaml | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index c6e462d0..ddc29ebe 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "baidu-aip-sdk": "^4.16.15", "big-integer": "^1.6.52", "cli-progress": "^3.11.2", - "date-and-time": "^3.1.0", + "date-and-time": "^3.1.1", "dockerode": "^4.0.2", "dotenv": "^16.0.1", "eviltransform": "^0.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f700bbc9..66168177 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,8 @@ dependencies: specifier: ^3.11.2 version: 3.12.0 date-and-time: - specifier: ^3.1.0 - version: 3.1.0 + specifier: ^3.1.1 + version: 3.1.1 dockerode: specifier: ^4.0.2 version: 4.0.2 @@ -788,7 +788,7 @@ packages: resolution: {integrity: sha512-5uHEzTnzhS5gO8UOWIwPQitg13mAnixpoWaWuqUfGLvF9GdxBe7Uo56ZRLTQ7CckanqW/oAv/RyQDv4Knf075A==} deprecated: This is a stub types definition. date-and-time provides its own type definitions, so you do not need this installed. dependencies: - date-and-time: 2.4.3 + date-and-time: 3.1.1 dev: true /@types/docker-modem@3.0.6: @@ -1315,13 +1315,8 @@ packages: whatwg-url: 8.7.0 dev: false - /date-and-time@2.4.3: - resolution: {integrity: sha512-xkS/imTmsyEdpp9ie5oV5UWolg3XkYWNySbT2W4ESWr6v4V8YrsHbhpk9fIeQcr0NFTnYbQJLXlgU1zrLItysA==} - dev: true - - /date-and-time@3.1.0: - resolution: {integrity: sha512-tWIpW3LK8tyLofyuMYxfOUchstWcyXjM+4rzIzve/VtBLzvS6q1oOxkcwhQ710nhU3M04jpfveDQ18IIw8lm2A==} - dev: false + /date-and-time@3.1.1: + resolution: {integrity: sha512-N9kstidT3P0VUk1iKOFilOZ6251r6iTUNx9M9kvgL2jqOk9mljWZUq5CjAtYwCnppWHbERk5YFQUrSbY7FQOpA==} /date-format@4.0.14: resolution: {integrity: sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==} From 02b2b828e468e3e46510a044c39f0d3c5e10bcdf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 02:43:59 +0000 Subject: [PATCH 18/24] chore(deps): bump sharp from 0.33.1 to 0.33.2 Bumps [sharp](https://github.com/lovell/sharp) from 0.33.1 to 0.33.2. - [Release notes](https://github.com/lovell/sharp/releases) - [Changelog](https://github.com/lovell/sharp/blob/main/docs/changelog.md) - [Commits](https://github.com/lovell/sharp/compare/v0.33.1...v0.33.2) --- updated-dependencies: - dependency-name: sharp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- pnpm-lock.yaml | 154 ++++++++++++++++++++++++------------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index c6e462d0..22cb938c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "prisma": "5.8.0", "prompts": "^2.4.2", "quote-api": "https://github.com/Clansty/quote-api/archive/37a0e48a434b94bb04c04c7d86d9f0d2295df869.tar.gz", - "sharp": "^0.33.1", + "sharp": "^0.33.2", "silk-sdk": "^0.2.2", "telegram": "^2.19.10", "tmp-promise": "^3.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f700bbc9..318c6382 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,8 +63,8 @@ dependencies: specifier: https://github.com/Clansty/quote-api/archive/37a0e48a434b94bb04c04c7d86d9f0d2295df869.tar.gz version: '@github.com/Clansty/quote-api/archive/37a0e48a434b94bb04c04c7d86d9f0d2295df869.tar.gz' sharp: - specifier: ^0.33.1 - version: 0.33.1 + specifier: ^0.33.2 + version: 0.33.2 silk-sdk: specifier: ^0.2.2 version: 0.2.2 @@ -127,8 +127,8 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true - /@emnapi/runtime@0.44.0: - resolution: {integrity: sha512-ZX/etZEZw8DR7zAB1eVQT40lNo0jeqpb6dCgOvctB6FIQ5PoXfMuNY8+ayQfu8tNQbAB8gQWSSJupR8NxeiZXw==} + /@emnapi/runtime@0.45.0: + resolution: {integrity: sha512-Txumi3td7J4A/xTTwlssKieHKTGl3j4A1tglBx72auZ49YK7ePY6XZricgIg9mnZT4xPfA+UPCUdnhRuEFDL+w==} requiresBuild: true dependencies: tslib: 2.6.2 @@ -140,30 +140,30 @@ packages: engines: {node: '>=14'} dev: false - /@img/sharp-darwin-arm64@0.33.1: - resolution: {integrity: sha512-esr2BZ1x0bo+wl7Gx2hjssYhjrhUsD88VQulI0FrG8/otRQUOxLWHMBd1Y1qo2Gfg2KUvXNpT0ASnV9BzJCexw==} + /@img/sharp-darwin-arm64@0.33.2: + resolution: {integrity: sha512-itHBs1rPmsmGF9p4qRe++CzCgd+kFYktnsoR1sbIAfsRMrJZau0Tt1AH9KVnufc2/tU02Gf6Ibujx+15qRE03w==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [darwin] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-darwin-arm64': 1.0.0 + '@img/sharp-libvips-darwin-arm64': 1.0.1 dev: false optional: true - /@img/sharp-darwin-x64@0.33.1: - resolution: {integrity: sha512-YrnuB3bXuWdG+hJlXtq7C73lF8ampkhU3tMxg5Hh+E7ikxbUVOU9nlNtVTloDXz6pRHt2y2oKJq7DY/yt+UXYw==} + /@img/sharp-darwin-x64@0.33.2: + resolution: {integrity: sha512-/rK/69Rrp9x5kaWBjVN07KixZanRr+W1OiyKdXcbjQD6KbW+obaTeBBtLUAtbBsnlTTmWthw99xqoOS7SsySDg==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [darwin] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-darwin-x64': 1.0.0 + '@img/sharp-libvips-darwin-x64': 1.0.1 dev: false optional: true - /@img/sharp-libvips-darwin-arm64@1.0.0: - resolution: {integrity: sha512-VzYd6OwnUR81sInf3alj1wiokY50DjsHz5bvfnsFpxs5tqQxESoHtJO6xyksDs3RIkyhMWq2FufXo6GNSU9BMw==} + /@img/sharp-libvips-darwin-arm64@1.0.1: + resolution: {integrity: sha512-kQyrSNd6lmBV7O0BUiyu/OEw9yeNGFbQhbxswS1i6rMDwBBSX+e+rPzu3S+MwAiGU3HdLze3PanQ4Xkfemgzcw==} engines: {macos: '>=11', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [darwin] @@ -171,8 +171,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-darwin-x64@1.0.0: - resolution: {integrity: sha512-dD9OznTlHD6aovRswaPNEy8dKtSAmNo4++tO7uuR4o5VxbVAOoEQ1uSmN4iFAdQneTHws1lkTZeiXPrcCkh6IA==} + /@img/sharp-libvips-darwin-x64@1.0.1: + resolution: {integrity: sha512-eVU/JYLPVjhhrd8Tk6gosl5pVlvsqiFlt50wotCvdkFGf+mDNBJxMh+bvav+Wt3EBnNZWq8Sp2I7XfSjm8siog==} engines: {macos: '>=10.13', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [darwin] @@ -180,8 +180,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linux-arm64@1.0.0: - resolution: {integrity: sha512-xTYThiqEZEZc0PRU90yVtM3KE7lw1bKdnDQ9kCTHWbqWyHOe4NpPOtMGy27YnN51q0J5dqRrvicfPbALIOeAZA==} + /@img/sharp-libvips-linux-arm64@1.0.1: + resolution: {integrity: sha512-bnGG+MJjdX70mAQcSLxgeJco11G+MxTz+ebxlz8Y3dxyeb3Nkl7LgLI0mXupoO+u1wRNx/iRj5yHtzA4sde1yA==} engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] @@ -189,8 +189,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linux-arm@1.0.0: - resolution: {integrity: sha512-VwgD2eEikDJUk09Mn9Dzi1OW2OJFRQK+XlBTkUNmAWPrtj8Ly0yq05DFgu1VCMx2/DqCGQVi5A1dM9hTmxf3uw==} + /@img/sharp-libvips-linux-arm@1.0.1: + resolution: {integrity: sha512-FtdMvR4R99FTsD53IA3LxYGghQ82t3yt0ZQ93WMZ2xV3dqrb0E8zq4VHaTOuLEAuA83oDawHV3fd+BsAPadHIQ==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] @@ -198,8 +198,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linux-s390x@1.0.0: - resolution: {integrity: sha512-o9E46WWBC6JsBlwU4QyU9578G77HBDT1NInd+aERfxeOPbk0qBZHgoDsQmA2v9TbqJRWzoBPx1aLOhprBMgPjw==} + /@img/sharp-libvips-linux-s390x@1.0.1: + resolution: {integrity: sha512-3+rzfAR1YpMOeA2zZNp+aYEzGNWK4zF3+sdMxuCS3ey9HhDbJ66w6hDSHDMoap32DueFwhhs3vwooAB2MaK4XQ==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] @@ -207,8 +207,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linux-x64@1.0.0: - resolution: {integrity: sha512-naldaJy4hSVhWBgEjfdBY85CAa4UO+W1nx6a1sWStHZ7EUfNiuBTTN2KUYT5dH1+p/xij1t2QSXfCiFJoC5S/Q==} + /@img/sharp-libvips-linux-x64@1.0.1: + resolution: {integrity: sha512-3NR1mxFsaSgMMzz1bAnnKbSAI+lHXVTqAHgc1bgzjHuXjo4hlscpUxc0vFSAPKI3yuzdzcZOkq7nDPrP2F8Jgw==} engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] @@ -216,8 +216,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linuxmusl-arm64@1.0.0: - resolution: {integrity: sha512-OdorplCyvmSAPsoJLldtLh3nLxRrkAAAOHsGWGDYfN0kh730gifK+UZb3dWORRa6EusNqCTjfXV4GxvgJ/nPDQ==} + /@img/sharp-libvips-linuxmusl-arm64@1.0.1: + resolution: {integrity: sha512-5aBRcjHDG/T6jwC3Edl3lP8nl9U2Yo8+oTl5drd1dh9Z1EBfzUKAJFUDTDisDjUwc7N4AjnPGfCA3jl3hY8uDg==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] @@ -225,8 +225,8 @@ packages: dev: false optional: true - /@img/sharp-libvips-linuxmusl-x64@1.0.0: - resolution: {integrity: sha512-FW8iK6rJrg+X2jKD0Ajhjv6y74lToIBEvkZhl42nZt563FfxkCYacrXZtd+q/sRQDypQLzY5WdLkVTbJoPyqNg==} + /@img/sharp-libvips-linuxmusl-x64@1.0.1: + resolution: {integrity: sha512-dcT7inI9DBFK6ovfeWRe3hG30h51cBAP5JXlZfx6pzc/Mnf9HFCQDLtYf4MCBjxaaTfjCCjkBxcy3XzOAo5txw==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] @@ -234,84 +234,84 @@ packages: dev: false optional: true - /@img/sharp-linux-arm64@0.33.1: - resolution: {integrity: sha512-59B5GRO2d5N3tIfeGHAbJps7cLpuWEQv/8ySd9109ohQ3kzyCACENkFVAnGPX00HwPTQcaBNF7HQYEfZyZUFfw==} + /@img/sharp-linux-arm64@0.33.2: + resolution: {integrity: sha512-pz0NNo882vVfqJ0yNInuG9YH71smP4gRSdeL09ukC2YLE6ZyZePAlWKEHgAzJGTiOh8Qkaov6mMIMlEhmLdKew==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linux-arm64': 1.0.0 + '@img/sharp-libvips-linux-arm64': 1.0.1 dev: false optional: true - /@img/sharp-linux-arm@0.33.1: - resolution: {integrity: sha512-Ii4X1vnzzI4j0+cucsrYA5ctrzU9ciXERfJR633S2r39CiD8npqH2GMj63uFZRCFt3E687IenAdbwIpQOJ5BNA==} + /@img/sharp-linux-arm@0.33.2: + resolution: {integrity: sha512-Fndk/4Zq3vAc4G/qyfXASbS3HBZbKrlnKZLEJzPLrXoJuipFNNwTes71+Ki1hwYW5lch26niRYoZFAtZVf3EGA==} engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linux-arm': 1.0.0 + '@img/sharp-libvips-linux-arm': 1.0.1 dev: false optional: true - /@img/sharp-linux-s390x@0.33.1: - resolution: {integrity: sha512-tRGrb2pHnFUXpOAj84orYNxHADBDIr0J7rrjwQrTNMQMWA4zy3StKmMvwsI7u3dEZcgwuMMooIIGWEWOjnmG8A==} + /@img/sharp-linux-s390x@0.33.2: + resolution: {integrity: sha512-MBoInDXDppMfhSzbMmOQtGfloVAflS2rP1qPcUIiITMi36Mm5YR7r0ASND99razjQUpHTzjrU1flO76hKvP5RA==} engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linux-s390x': 1.0.0 + '@img/sharp-libvips-linux-s390x': 1.0.1 dev: false optional: true - /@img/sharp-linux-x64@0.33.1: - resolution: {integrity: sha512-4y8osC0cAc1TRpy02yn5omBeloZZwS62fPZ0WUAYQiLhSFSpWJfY/gMrzKzLcHB9ulUV6ExFiu2elMaixKDbeg==} + /@img/sharp-linux-x64@0.33.2: + resolution: {integrity: sha512-xUT82H5IbXewKkeF5aiooajoO1tQV4PnKfS/OZtb5DDdxS/FCI/uXTVZ35GQ97RZXsycojz/AJ0asoz6p2/H/A==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linux-x64': 1.0.0 + '@img/sharp-libvips-linux-x64': 1.0.1 dev: false optional: true - /@img/sharp-linuxmusl-arm64@0.33.1: - resolution: {integrity: sha512-D3lV6clkqIKUizNS8K6pkuCKNGmWoKlBGh5p0sLO2jQERzbakhu4bVX1Gz+RS4vTZBprKlWaf+/Rdp3ni2jLfA==} + /@img/sharp-linuxmusl-arm64@0.33.2: + resolution: {integrity: sha512-F+0z8JCu/UnMzg8IYW1TMeiViIWBVg7IWP6nE0p5S5EPQxlLd76c8jYemG21X99UzFwgkRo5yz2DS+zbrnxZeA==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linuxmusl-arm64': 1.0.0 + '@img/sharp-libvips-linuxmusl-arm64': 1.0.1 dev: false optional: true - /@img/sharp-linuxmusl-x64@0.33.1: - resolution: {integrity: sha512-LOGKNu5w8uu1evVqUAUKTix2sQu1XDRIYbsi5Q0c/SrXhvJ4QyOx+GaajxmOg5PZSsSnCYPSmhjHHsRBx06/wQ==} + /@img/sharp-linuxmusl-x64@0.33.2: + resolution: {integrity: sha512-+ZLE3SQmSL+Fn1gmSaM8uFusW5Y3J9VOf+wMGNnTtJUMUxFhv+P4UPaYEYT8tqnyYVaOVGgMN/zsOxn9pSsO2A==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] requiresBuild: true optionalDependencies: - '@img/sharp-libvips-linuxmusl-x64': 1.0.0 + '@img/sharp-libvips-linuxmusl-x64': 1.0.1 dev: false optional: true - /@img/sharp-wasm32@0.33.1: - resolution: {integrity: sha512-vWI/sA+0p+92DLkpAMb5T6I8dg4z2vzCUnp8yvxHlwBpzN8CIcO3xlSXrLltSvK6iMsVMNswAv+ub77rsf25lA==} + /@img/sharp-wasm32@0.33.2: + resolution: {integrity: sha512-fLbTaESVKuQcpm8ffgBD7jLb/CQLcATju/jxtTXR1XCLwbOQt+OL5zPHSDMmp2JZIeq82e18yE0Vv7zh6+6BfQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [wasm32] requiresBuild: true dependencies: - '@emnapi/runtime': 0.44.0 + '@emnapi/runtime': 0.45.0 dev: false optional: true - /@img/sharp-win32-ia32@0.33.1: - resolution: {integrity: sha512-/xhYkylsKL05R+NXGJc9xr2Tuw6WIVl2lubFJaFYfW4/MQ4J+dgjIo/T4qjNRizrqs/szF/lC9a5+updmY9jaQ==} + /@img/sharp-win32-ia32@0.33.2: + resolution: {integrity: sha512-okBpql96hIGuZ4lN3+nsAjGeggxKm7hIRu9zyec0lnfB8E7Z6p95BuRZzDDXZOl2e8UmR4RhYt631i7mfmKU8g==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [ia32] os: [win32] @@ -319,8 +319,8 @@ packages: dev: false optional: true - /@img/sharp-win32-x64@0.33.1: - resolution: {integrity: sha512-XaM69X0n6kTEsp9tVYYLhXdg7Qj32vYJlAKRutxUsm1UlgQNx6BOhHwZPwukCGXBU2+tH87ip2eV1I/E8MQnZg==} + /@img/sharp-win32-x64@0.33.2: + resolution: {integrity: sha512-E4magOks77DK47FwHUIGH0RYWSgRBfGdK56kIHSVeB9uIS4pPFr4N2kIVsXdQQo4LzOsENKV5KAhRlRL7eMAdg==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [win32] @@ -2932,34 +2932,34 @@ packages: resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==} dev: false - /sharp@0.33.1: - resolution: {integrity: sha512-iAYUnOdTqqZDb3QjMneBKINTllCJDZ3em6WaWy7NPECM4aHncvqHRm0v0bN9nqJxMiwamv5KIdauJ6lUzKDpTQ==} - engines: {libvips: '>=8.15.0', node: ^18.17.0 || ^20.3.0 || >=21.0.0} + /sharp@0.33.2: + resolution: {integrity: sha512-WlYOPyyPDiiM07j/UO+E720ju6gtNtHjEGg5vovUk1Lgxyjm2LFO+37Nt/UI3MMh2l6hxTWQWi7qk3cXJTutcQ==} + engines: {libvips: '>=8.15.1', node: ^18.17.0 || ^20.3.0 || >=21.0.0} requiresBuild: true dependencies: color: 4.2.3 detect-libc: 2.0.2 semver: 7.5.4 optionalDependencies: - '@img/sharp-darwin-arm64': 0.33.1 - '@img/sharp-darwin-x64': 0.33.1 - '@img/sharp-libvips-darwin-arm64': 1.0.0 - '@img/sharp-libvips-darwin-x64': 1.0.0 - '@img/sharp-libvips-linux-arm': 1.0.0 - '@img/sharp-libvips-linux-arm64': 1.0.0 - '@img/sharp-libvips-linux-s390x': 1.0.0 - '@img/sharp-libvips-linux-x64': 1.0.0 - '@img/sharp-libvips-linuxmusl-arm64': 1.0.0 - '@img/sharp-libvips-linuxmusl-x64': 1.0.0 - '@img/sharp-linux-arm': 0.33.1 - '@img/sharp-linux-arm64': 0.33.1 - '@img/sharp-linux-s390x': 0.33.1 - '@img/sharp-linux-x64': 0.33.1 - '@img/sharp-linuxmusl-arm64': 0.33.1 - '@img/sharp-linuxmusl-x64': 0.33.1 - '@img/sharp-wasm32': 0.33.1 - '@img/sharp-win32-ia32': 0.33.1 - '@img/sharp-win32-x64': 0.33.1 + '@img/sharp-darwin-arm64': 0.33.2 + '@img/sharp-darwin-x64': 0.33.2 + '@img/sharp-libvips-darwin-arm64': 1.0.1 + '@img/sharp-libvips-darwin-x64': 1.0.1 + '@img/sharp-libvips-linux-arm': 1.0.1 + '@img/sharp-libvips-linux-arm64': 1.0.1 + '@img/sharp-libvips-linux-s390x': 1.0.1 + '@img/sharp-libvips-linux-x64': 1.0.1 + '@img/sharp-libvips-linuxmusl-arm64': 1.0.1 + '@img/sharp-libvips-linuxmusl-x64': 1.0.1 + '@img/sharp-linux-arm': 0.33.2 + '@img/sharp-linux-arm64': 0.33.2 + '@img/sharp-linux-s390x': 0.33.2 + '@img/sharp-linux-x64': 0.33.2 + '@img/sharp-linuxmusl-arm64': 0.33.2 + '@img/sharp-linuxmusl-x64': 0.33.2 + '@img/sharp-wasm32': 0.33.2 + '@img/sharp-win32-ia32': 0.33.2 + '@img/sharp-win32-x64': 0.33.2 dev: false /should-equal@2.0.0: @@ -3064,12 +3064,12 @@ packages: engines: {node: '>= 6.0.0', npm: '>= 3.0.0'} dev: false - /smartcrop-sharp@2.0.8(sharp@0.33.1): + /smartcrop-sharp@2.0.8(sharp@0.33.2): resolution: {integrity: sha512-0rpK/ddGAx7ou6YqqvJRkw/xyR4qgqmJeUQ2EWDnN3hSuJUk4InPGE6Sa45+TYOfGEEQJrchjF1ujBPMhoe9iA==} peerDependencies: sharp: ^0.32.5 dependencies: - sharp: 0.33.1 + sharp: 0.33.2 smartcrop: 2.0.5 dev: false @@ -3747,8 +3747,8 @@ packages: lru-cache: 5.1.1 object-sizeof: 1.6.3 runes: 0.4.3 - sharp: 0.33.1 - smartcrop-sharp: 2.0.8(sharp@0.33.1) + sharp: 0.33.2 + smartcrop-sharp: 2.0.8(sharp@0.33.2) telegraf: 3.40.0 transitivePeerDependencies: - bufferutil From df9fd35a3225089e29cd338b9999c98aaac32798 Mon Sep 17 00:00:00 2001 From: Clansty Date: Mon, 15 Jan 2024 14:58:33 +0800 Subject: [PATCH 19/24] =?UTF-8?q?fix:=20mapInstance=20=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E8=A7=A6=E5=8F=91=E5=A4=9A=E6=AC=A1=20/q?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/MiraiSkipFilterController.ts | 29 ++++++++++++++++++++ src/models/Instance.ts | 3 ++ src/services/ForwardService.ts | 10 ------- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/controllers/MiraiSkipFilterController.ts diff --git a/src/controllers/MiraiSkipFilterController.ts b/src/controllers/MiraiSkipFilterController.ts new file mode 100644 index 00000000..d45753eb --- /dev/null +++ b/src/controllers/MiraiSkipFilterController.ts @@ -0,0 +1,29 @@ +import Instance from '../models/Instance'; +import Telegram from '../client/Telegram'; +import OicqClient from '../client/OicqClient'; +import { GroupMessageEvent, MiraiElem, PrivateMessageEvent } from 'icqq'; + +export default class { + constructor(private readonly instance: Instance, + private readonly tgBot: Telegram, + private readonly tgUser: Telegram, + private readonly qqBot: OicqClient) { + qqBot.addNewMessageEventHandler(this.onQqMessage); + } + + // 当 mapInstance 用同服务器其他个人模式账号发送消息后,message mirai 会带 q2tgSkip=true + // 防止 bot 重新收到消息再转一圈回来重新转发或者重新响应命令 + private onQqMessage = async (event: PrivateMessageEvent | GroupMessageEvent) => { + if ('friend' in event) return; + if (!event.message) return; + const messageMirai = event.message.find(it => it.type === 'mirai') as MiraiElem; + if (messageMirai) { + try { + const miraiData = JSON.parse(messageMirai.data); + if (miraiData.q2tgSkip) return true; + } + catch { + } + } + }; +} diff --git a/src/models/Instance.ts b/src/models/Instance.ts index f244b456..bdd8e0d9 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -23,6 +23,7 @@ import { QqBot } from '@prisma/client'; import StatusReportController from '../controllers/StatusReportController'; import HugController from '../controllers/HugController'; import QuotLyController from '../controllers/QuotLyController'; +import MiraiSkipFilterController from '../controllers/MiraiSkipFilterController'; export default class Instance { private _owner = 0; @@ -55,6 +56,7 @@ export default class Instance { private statusReportController: StatusReportController; private hugController: HugController; private quotLyController: QuotLyController; + private miraiSkipFilterController: MiraiSkipFilterController; private constructor(public readonly id: number) { this.log = getLogger(`Instance - ${this.id}`); @@ -149,6 +151,7 @@ export default class Instance { this.requestController = new RequestController(this, this.tgBot, this.oicq); this.configController = new ConfigController(this, this.tgBot, this.tgUser, this.oicq); this.deleteMessageController = new DeleteMessageController(this, this.tgBot, this.tgUser, this.oicq); + this.miraiSkipFilterController = new MiraiSkipFilterController(this, this.tgBot, this.tgUser, this.oicq); this.inChatCommandsController = new InChatCommandsController(this, this.tgBot, this.tgUser, this.oicq); if (this.workMode === 'group') { this.hugController = new HugController(this, this.tgBot, this.oicq); diff --git a/src/services/ForwardService.ts b/src/services/ForwardService.ts index 1fa6f845..564315d2 100644 --- a/src/services/ForwardService.ts +++ b/src/services/ForwardService.ts @@ -91,16 +91,6 @@ export default class ForwardService { public async forwardFromQq(event: PrivateMessageEvent | GroupMessageEvent, pair: Pair) { try { - const messageMirai = event.message.find(it => it.type === 'mirai') as MiraiElem; - if (messageMirai) { - try { - const miraiData = JSON.parse(messageMirai.data); - if (miraiData.q2tgSkip) return; - } - catch { - } - } - const tempFiles: FileResult[] = []; let message = '', files: FileLike[] = [], buttons: ButtonLike[] = [], replyTo = 0; let messageHeader = '', sender = ''; From 6b80afca58caf023801c8bcb4f078241467e69ac Mon Sep 17 00:00:00 2001 From: Clansty Date: Mon, 15 Jan 2024 17:58:48 +0800 Subject: [PATCH 20/24] =?UTF-8?q?refactor:=20=E7=94=A8=20zod=20parse=20?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- pnpm-lock.yaml | 7 ++++ src/client/OicqClient.ts | 11 ++--- src/client/Telegram.ts | 21 +++++----- src/controllers/QuotLyController.ts | 3 +- src/controllers/SetupController.ts | 5 ++- src/encoding/tgsToGif.ts | 3 +- src/helpers/RecoverMessageHelper.ts | 38 ++++++++++-------- src/helpers/dataPath.ts | 5 +-- src/models/Instance.ts | 3 +- src/models/TelegramSession.ts | 13 +++--- src/models/env.ts | 39 ++++++++++++++++++ src/services/ForwardService.ts | 58 +++++++++++++++------------ src/services/InChatCommandsService.ts | 9 +++-- 14 files changed, 142 insertions(+), 76 deletions(-) create mode 100644 src/models/env.ts diff --git a/package.json b/package.json index c059235a..8bb6509c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "telegram": "^2.19.10", "tmp-promise": "^3.0.3", "undici": "^6.3.0", - "zincsearch-node": "^2.1.0" + "zincsearch-node": "^2.1.0", + "zod": "^3.22.4" }, "engines": { "node": "^14.13.1 || >=16.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dda1057b..5d992665 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -80,6 +80,9 @@ dependencies: zincsearch-node: specifier: ^2.1.0 version: 2.1.1(undici@6.3.0) + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@types/cli-progress': @@ -3721,6 +3724,10 @@ packages: undici: 6.3.0 dev: false + /zod@3.22.4: + resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} + dev: false + '@github.com/Clansty/quote-api/archive/37a0e48a434b94bb04c04c7d86d9f0d2295df869.tar.gz': resolution: {tarball: https://github.com/Clansty/quote-api/archive/37a0e48a434b94bb04c04c7d86d9f0d2295df869.tar.gz} name: quote-api diff --git a/src/client/OicqClient.ts b/src/client/OicqClient.ts index 5cf2d273..7435dfcc 100644 --- a/src/client/OicqClient.ts +++ b/src/client/OicqClient.ts @@ -20,8 +20,9 @@ import { Converter, Image, rand2uuid } from 'icqq/lib/message'; import { randomBytes } from 'crypto'; import { escapeXml, gzip, timestamp } from 'icqq/lib/common'; import { pb } from 'icqq/lib/core'; +import env from '../models/env'; -const LOG_LEVEL: LogLevel = process.env.LOG_LEVEL as LogLevel || 'warn'; +const LOG_LEVEL: LogLevel = env.OICQ_LOG_LEVEL; type MessageHandler = (event: PrivateMessageEvent | GroupMessageEvent) => Promise @@ -123,10 +124,10 @@ export default class OicqClient extends Client { platform: params.platform, data_dir: dataPath(params.uin.toString()), log_level: LOG_LEVEL, - ffmpeg_path: process.env.FFMPEG_PATH, - ffprobe_path: process.env.FFPROBE_PATH, - sign_api_addr: params.signApi || process.env.SIGN_API, - ver: params.signVer || process.env.SIGN_VER, + ffmpeg_path: env.FFMPEG_PATH, + ffprobe_path: env.FFPROBE_PATH, + sign_api_addr: params.signApi || env.SIGN_API, + ver: params.signVer || env.SIGN_VER, }, params.signDockerId); client.on('system.login.device', loginDeviceHandler); client.on('system.login.slider', loginSliderHandler); diff --git a/src/client/Telegram.ts b/src/client/Telegram.ts index 4ee81da8..e37ba4b7 100644 --- a/src/client/Telegram.ts +++ b/src/client/Telegram.ts @@ -15,6 +15,7 @@ import { BigInteger } from 'big-integer'; import { EditMessageParams, IterMessagesParams } from 'telegram/client/messages'; import { PromisedNetSockets, PromisedWebSockets } from 'telegram/extensions'; import { ConnectionTCPFull, ConnectionTCPObfuscated } from 'telegram/network'; +import env from '../models/env'; type MessageHandler = (message: Api.Message) => Promise; type ServiceMessageHandler = (message: Api.MessageService) => Promise; @@ -41,24 +42,24 @@ export default class Telegram { private constructor(appName: string, sessionId?: number) { this.client = new TelegramClient( new TelegramSession(sessionId), - parseInt(process.env.TG_API_ID), - process.env.TG_API_HASH, + env.TG_API_ID, + env.TG_API_HASH, { connectionRetries: 20, langCode: 'zh', deviceModel: `${appName} On ${os.hostname()}`, appVersion: 'rainbowcat', - useIPV6: !!process.env.IPV6, - proxy: process.env.PROXY_IP ? { + useIPV6: !!env.IPV6, + proxy: env.PROXY_IP ? { socksType: 5, - ip: process.env.PROXY_IP, - port: parseInt(process.env.PROXY_PORT), - ...(process.env.PROXY_USERNAME && { username: process.env.PROXY_USERNAME }), - ...(process.env.PROXY_PASSWORD && { password: process.env.PROXY_PASSWORD }), + ip: env.PROXY_IP, + port: env.PROXY_PORT, + username: env.PROXY_USERNAME, + password: env.PROXY_PASSWORD, } : undefined, autoReconnect: true, - networkSocket: process.env.TG_CONNECTION === 'websocket' ? PromisedWebSockets : PromisedNetSockets, - connection: process.env.TG_CONNECTION === 'websocket' ? ConnectionTCPObfuscated : ConnectionTCPFull, + networkSocket: env.TG_CONNECTION === 'websocket' ? PromisedWebSockets : PromisedNetSockets, + connection: env.TG_CONNECTION === 'websocket' ? ConnectionTCPObfuscated : ConnectionTCPFull, }, ); // this.client.logger.setLevel(LogLevel.WARN); diff --git a/src/controllers/QuotLyController.ts b/src/controllers/QuotLyController.ts index c332acfc..cd371c0e 100644 --- a/src/controllers/QuotLyController.ts +++ b/src/controllers/QuotLyController.ts @@ -12,6 +12,7 @@ import BigInteger from 'big-integer'; import { getAvatarUrl } from '../utils/urls'; import convert from '../helpers/convert'; import { Pair } from '../models/Pair'; +import env from '../models/env'; export default class { private readonly log: Logger; @@ -280,7 +281,7 @@ export default class { throw new Error('不支持的消息类型'); } const res = await quotly({ - botToken: process.env.TG_BOT_TOKEN, + botToken: env.TG_BOT_TOKEN, type, format, backgroundColor, diff --git a/src/controllers/SetupController.ts b/src/controllers/SetupController.ts index ad9e0c26..ebf942e4 100644 --- a/src/controllers/SetupController.ts +++ b/src/controllers/SetupController.ts @@ -9,6 +9,7 @@ import { WorkMode } from '../types/definitions'; import OicqClient from '../client/OicqClient'; import { md5Hex } from '../utils/hashing'; import Instance from '../models/Instance'; +import env from '../models/env'; export default class SetupController { private readonly setupService: SetupService; @@ -106,7 +107,7 @@ export default class SetupController { let signApi: string; - if (!process.env.SIGN_API) { + if (!env.SIGN_API) { signApi = await this.setupService.waitForOwnerInput('请输入签名服务器地址', [ [Button.text('不需要签名服务器', true, true)], ]); @@ -115,7 +116,7 @@ export default class SetupController { let signVer: string; - if (signApi && !process.env.SIGN_VER) { + if (signApi && !env.SIGN_VER) { signVer = await this.setupService.waitForOwnerInput('请输入签名服务器版本', [ [Button.text('8.9.63', true, true), Button.text('8.9.68', true, true)], diff --git a/src/encoding/tgsToGif.ts b/src/encoding/tgsToGif.ts index 739e9e0c..19f82252 100644 --- a/src/encoding/tgsToGif.ts +++ b/src/encoding/tgsToGif.ts @@ -1,8 +1,9 @@ import { spawn } from 'child_process'; +import env from '../models/env'; export default function tgsToGif(tgsPath: string) { return new Promise(resolve => { - spawn(process.env.TGS_TO_GIF || 'tgs_to_gif', [tgsPath]).on('exit', () => { + spawn(env.TGS_TO_GIF, [tgsPath]).on('exit', () => { resolve(tgsPath + '.gif'); }); }); diff --git a/src/helpers/RecoverMessageHelper.ts b/src/helpers/RecoverMessageHelper.ts index fe5f49a8..b72ab859 100644 --- a/src/helpers/RecoverMessageHelper.ts +++ b/src/helpers/RecoverMessageHelper.ts @@ -19,6 +19,7 @@ import axios from 'axios'; import { CustomFile } from 'telegram/client/uploads'; import fsP from 'fs/promises'; import { file } from 'tmp-promise'; +import env from '../models/env'; export default class { private readonly log: Logger; @@ -197,21 +198,26 @@ export default class { } break; case 'forward': - try { - const messages = await this.pair.qq.getForwardMsg(result.resId); - const hash = md5Hex(result.resId); - text += `转发的消息记录 ${process.env.CRV_API}/?hash=${hash}`; - // 传到 Cloudflare - axios.post(`${process.env.CRV_API}/add`, { - auth: process.env.CRV_KEY, - key: hash, - data: messages, - }) - .then(data => this.log.trace('上传消息记录到 Cloudflare', data.data)) - .catch(e => this.log.error('上传消息记录到 Cloudflare 失败', e)); + if (env.CRV_API) { + try { + const messages = await this.pair.qq.getForwardMsg(result.resId); + const hash = md5Hex(result.resId); + text += `转发的消息记录 ${env.CRV_API}/?hash=${hash}`; + // 传到 Cloudflare + axios.post(`${env.CRV_API}/add`, { + auth: env.CRV_KEY, + key: hash, + data: messages, + }) + .then(data => this.log.trace('上传消息记录到 Cloudflare', data.data)) + .catch(e => this.log.error('上传消息记录到 Cloudflare 失败', e)); + } + catch (e) { + text += '[转发多条消息(无法获取)]'; + } } - catch (e) { - text += '[转发多条消息(无法获取)]'; + else { + text += '[转发多条消息]'; } break; } @@ -255,11 +261,11 @@ export default class { ext: 'tgs', mime: 'application/x-tgsticker', } : await fileTypeFromFile(filePath); - if(!type){ + if (!type) { type = { ext: 'bin', mime: 'application/octet-stream', - } + }; } let media: Api.TypeInputMedia; if (['.webp', '.tgs'].includes(path.extname(filePath))) { diff --git a/src/helpers/dataPath.ts b/src/helpers/dataPath.ts index 9fd5ec04..25573db5 100644 --- a/src/helpers/dataPath.ts +++ b/src/helpers/dataPath.ts @@ -1,7 +1,6 @@ import path from 'path'; - -const DATA_DIR = process.env.DATA_DIR || path.resolve('./data'); +import env from '../models/env'; // Wrap of path.join, add base DATA_DIR export default (...paths: string[]) => - path.join(DATA_DIR, ...paths); + path.join(env.DATA_DIR, ...paths); diff --git a/src/models/Instance.ts b/src/models/Instance.ts index bdd8e0d9..a8c51f9b 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -24,6 +24,7 @@ import StatusReportController from '../controllers/StatusReportController'; import HugController from '../controllers/HugController'; import QuotLyController from '../controllers/QuotLyController'; import MiraiSkipFilterController from '../controllers/MiraiSkipFilterController'; +import env from './env'; export default class Instance { private _owner = 0; @@ -96,7 +97,7 @@ export default class Instance { this.tgBot = await Telegram.connect(this._botSessionId); } else { - const token = this.id === 0 ? process.env.TG_BOT_TOKEN : botToken; + const token = this.id === 0 ? env.TG_BOT_TOKEN : botToken; if (!token) { throw new Error('botToken 未指定'); } diff --git a/src/models/TelegramSession.ts b/src/models/TelegramSession.ts index 8ed78a3a..89be1982 100644 --- a/src/models/TelegramSession.ts +++ b/src/models/TelegramSession.ts @@ -2,6 +2,7 @@ import { MemorySession } from 'telegram/sessions'; import db from './db'; import { AuthKey } from 'telegram/crypto/AuthKey'; import { getLogger, Logger } from 'log4js'; +import env from './env'; const PASS = () => 0; @@ -19,19 +20,19 @@ export default class TelegramSession extends MemorySession { async load() { this.log.trace('load'); - if (process.env.TG_INITIAL_DCID) { - this._dcId = Number(process.env.TG_INITIAL_DCID); + if (env.TG_INITIAL_DCID) { + this._dcId = env.TG_INITIAL_DCID; } - if (process.env.TG_INITIAL_SERVER) { - this._serverAddress = process.env.TG_INITIAL_SERVER; + if (env.TG_INITIAL_SERVER) { + this._serverAddress = env.TG_INITIAL_SERVER; } if (!this._dbId) { this.log.debug('Session 不存在,创建'); // 创建并返回 const newDbEntry = await db.session.create({ data: { - dcId: process.env.TG_INITIAL_DCID ? Number(process.env.TG_INITIAL_DCID) : null, - serverAddress: process.env.TG_INITIAL_SERVER, + dcId: env.TG_INITIAL_DCID, + serverAddress: env.TG_INITIAL_SERVER, }, }); this._dbId = newDbEntry.id; diff --git a/src/models/env.ts b/src/models/env.ts new file mode 100644 index 00000000..05bd3605 --- /dev/null +++ b/src/models/env.ts @@ -0,0 +1,39 @@ +import z from 'zod'; +import path from 'path'; + +const configParsed = z.object({ + DATA_DIR: z.string().default(path.resolve('./data')), + OICQ_LOG_LEVEL: z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'mark', 'off']).default('warn'), + FFMPEG_PATH: z.string().optional(), + FFPROBE_PATH: z.string().optional(), + SIGN_API: z.string().url().optional(), + SIGN_VER: z.string().optional(), + TG_API_ID: z.string().regex(/^\d+$/).transform(Number), + TG_API_HASH: z.string(), + TG_BOT_TOKEN: z.string(), + TG_CONNECTION: z.enum(['websocket', 'tcp']).default('tcp'), + TG_INITIAL_DCID: z.string().regex(/^\d+$/).transform(Number).optional(), + TG_INITIAL_SERVER: z.string().ip().optional(), + IPV6: z.string().transform((v) => ['true', '1', 'yes'].includes(v.toLowerCase())).default('false'), + PROXY_IP: z.string().ip().optional(), + PROXY_PORT: z.string().regex(/^\d+$/).transform(Number).optional(), + PROXY_USERNAME: z.string().optional(), + PROXY_PASSWORD: z.string().optional(), + TGS_TO_GIF: z.string().default('tgs_to_gif'), + CRV_API: z.string().url().optional(), + CRV_KEY: z.string().optional(), + ZINC_URL: z.string().url().optional(), + ZINC_USERNAME: z.string().optional(), + ZINC_PASSWORD: z.string().optional(), + BAIDU_APP_ID: z.string().optional(), + BAIDU_API_KEY: z.string().optional(), + BAIDU_SECRET_KEY: z.string().optional(), + DISABLE_FILE_UPLOAD_TIP: z.string().transform((v) => ['true', '1', 'yes'].includes(v.toLowerCase())).default('false'), +}).safeParse(process.env); + +if (!configParsed.success) { + console.error('环境变量解析错误:', (configParsed as any).error); + process.exit(1); +} + +export default configParsed.data; diff --git a/src/services/ForwardService.ts b/src/services/ForwardService.ts index 564315d2..2ef76774 100644 --- a/src/services/ForwardService.ts +++ b/src/services/ForwardService.ts @@ -41,6 +41,7 @@ import random from '../utils/random'; import { escapeXml } from 'icqq/lib/common'; import Docker from 'dockerode'; import ReplyKeyboardHide = Api.ReplyKeyboardHide; +import env from '../models/env'; const NOT_CHAINABLE_ELEMENTS = ['flash', 'record', 'video', 'location', 'share', 'json', 'xml', 'poke']; @@ -55,18 +56,18 @@ export default class ForwardService { private readonly tgBot: Telegram, private readonly oicq: OicqClient) { this.log = getLogger(`ForwardService - ${instance.id}`); - if (process.env.ZINC_URL) { + if (env.ZINC_URL) { this.zincSearch = new ZincSearch({ - url: process.env.ZINC_URL, - user: process.env.ZINC_USERNAME, - password: process.env.ZINC_PASSWORD, + url: env.ZINC_URL, + user: env.ZINC_USERNAME, + password: env.ZINC_PASSWORD, }); } - if (process.env.BAIDU_APP_ID) { + if (env.BAIDU_APP_ID) { this.speechClient = new AipSpeechClient( - process.env.BAIDU_APP_ID, - process.env.BAIDU_API_KEY, - process.env.BAIDU_SECRET_KEY, + env.BAIDU_APP_ID, + env.BAIDU_API_KEY, + env.BAIDU_SECRET_KEY, ); } if (oicq.signDockerId) { @@ -110,22 +111,27 @@ export default class ForwardService { } }; const useForward = async (resId: string) => { - try { - const messages = await pair.qq.getForwardMsg(resId); - message = helper.generateForwardBrief(messages); - const hash = md5Hex(resId); - buttons.push(Button.url('📃查看', `${process.env.CRV_API}/?hash=${hash}`)); - // 传到 Cloudflare - axios.post(`${process.env.CRV_API}/add`, { - auth: process.env.CRV_KEY, - key: hash, - data: messages, - }) - .then(data => this.log.trace('上传消息记录到 Cloudflare', data.data)) - .catch(e => this.log.error('上传消息记录到 Cloudflare 失败', e)); + if(env.CRV_API) { + try { + const messages = await pair.qq.getForwardMsg(resId); + message = helper.generateForwardBrief(messages); + const hash = md5Hex(resId); + buttons.push(Button.url('📃查看', `${env.CRV_API}/?hash=${hash}`)); + // 传到 Cloudflare + axios.post(`${env.CRV_API}/add`, { + auth: env.CRV_KEY, + key: hash, + data: messages, + }) + .then(data => this.log.trace('上传消息记录到 Cloudflare', data.data)) + .catch(e => this.log.error('上传消息记录到 Cloudflare 失败', e)); + } + catch (e) { + message = '[转发多条消息(无法获取)]'; + } } - catch (e) { - message = '[转发多条消息(无法获取)]'; + else { + message = '[转发多条消息(未配置)]'; } }; for (const elem of event.message) { @@ -541,7 +547,7 @@ export default class ForwardService { } } brief += '[文件]'; - if (process.env.DISABLE_FILE_UPLOAD_TIP) { + if (env.DISABLE_FILE_UPLOAD_TIP) { chain = []; } } @@ -713,10 +719,10 @@ export default class ForwardService { nick: string, }) { if (!this.zincSearch) return; - const existsReq = await fetch(process.env.ZINC_URL + `/api/index/q2tg-${pairId}`, { + const existsReq = await fetch(env.ZINC_URL + `/api/index/q2tg-${pairId}`, { method: 'HEAD', headers: { - Authorization: 'Basic ' + Buffer.from(process.env.ZINC_USERNAME + ':' + process.env.ZINC_PASSWORD).toString('base64'), + Authorization: 'Basic ' + Buffer.from(env.ZINC_USERNAME + ':' + env.ZINC_PASSWORD).toString('base64'), }, }); if (existsReq.status === 404) { diff --git a/src/services/InChatCommandsService.ts b/src/services/InChatCommandsService.ts index 4c91cf15..2679c432 100644 --- a/src/services/InChatCommandsService.ts +++ b/src/services/InChatCommandsService.ts @@ -11,6 +11,7 @@ import db from '../models/db'; import { Friend, Group } from 'icqq'; import { format } from 'date-and-time'; import ZincSearch from 'zincsearch-node'; +import env from '../models/env'; export default class InChatCommandsService { private readonly log: Logger; @@ -20,11 +21,11 @@ export default class InChatCommandsService { private readonly tgBot: Telegram, private readonly oicq: OicqClient) { this.log = getLogger(`InChatCommandsService - ${instance.id}`); - if (process.env.ZINC_URL) { + if (env.ZINC_URL) { this.zincSearch = new ZincSearch({ - url: process.env.ZINC_URL, - user: process.env.ZINC_USERNAME, - password: process.env.ZINC_PASSWORD, + url: env.ZINC_URL, + user: env.ZINC_USERNAME, + password: env.ZINC_PASSWORD, }); } } From 38fb1be81fe54265a0ec10951309e98a1e9f4b56 Mon Sep 17 00:00:00 2001 From: Clansty Date: Mon, 15 Jan 2024 18:17:14 +0800 Subject: [PATCH 21/24] =?UTF-8?q?chore:=20=E7=94=A8=20tsx=20=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=20ts-node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- pnpm-lock.yaml | 375 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 273 insertions(+), 106 deletions(-) diff --git a/package.json b/package.json index 8bb6509c..d1b32abe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "q2tg", "scripts": { - "dev": "ts-node src/index.ts", + "dev": "tsx src/index.ts", "build": "tsc", "start": "prisma db push --accept-data-loss --skip-generate && node build/index.js", "prisma": "prisma", @@ -20,7 +20,7 @@ "@types/lodash": "^4.14.202", "@types/node": "^20.11.0", "@types/prompts": "^2.4.9", - "ts-node": "^10.9.2", + "tsx": "^4.7.0", "typescript": "^5.3.3" }, "dependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5d992665..46a4b2f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -106,9 +106,9 @@ devDependencies: '@types/prompts': specifier: ^2.4.9 version: 2.4.9 - ts-node: - specifier: ^10.9.2 - version: 10.9.2(@types/node@20.11.0)(typescript@5.3.3) + tsx: + specifier: ^4.7.0 + version: 4.7.0 typescript: specifier: ^5.3.3 version: 5.3.3 @@ -123,13 +123,6 @@ packages: resolution: {integrity: sha512-PcYz4FDGblO6tM2kSC+VzhhK62vml6k6/YAkiWtyPvrgJVfnDRoHGDtKn5UiaRRUrvUTTocBpvc2rRgTCqxjsg==} dev: false - /@cspotcode/source-map-support@0.8.1: - resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} - engines: {node: '>=12'} - dependencies: - '@jridgewell/trace-mapping': 0.3.9 - dev: true - /@emnapi/runtime@0.45.0: resolution: {integrity: sha512-Txumi3td7J4A/xTTwlssKieHKTGl3j4A1tglBx72auZ49YK7ePY6XZricgIg9mnZT4xPfA+UPCUdnhRuEFDL+w==} requiresBuild: true @@ -138,6 +131,213 @@ packages: dev: false optional: true + /@esbuild/aix-ppc64@0.19.11: + resolution: {integrity: sha512-FnzU0LyE3ySQk7UntJO4+qIiQgI7KoODnZg5xzXIrFJlKd2P2gwHsHY4927xj9y5PJmJSzULiUCWmv7iWnNa7g==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-arm64@0.19.11: + resolution: {integrity: sha512-aiu7K/5JnLj//KOnOfEZ0D90obUkRzDMyqd/wNAUQ34m4YUPVhRZpnqKV9uqDGxT7cToSDnIHsGooyIczu9T+Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-arm@0.19.11: + resolution: {integrity: sha512-5OVapq0ClabvKvQ58Bws8+wkLCV+Rxg7tUVbo9xu034Nm536QTII4YzhaFriQ7rMrorfnFKUsArD2lqKbFY4vw==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/android-x64@0.19.11: + resolution: {integrity: sha512-eccxjlfGw43WYoY9QgB82SgGgDbibcqyDTlk3l3C0jOVHKxrjdc9CTwDUQd0vkvYg5um0OH+GpxYvp39r+IPOg==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/darwin-arm64@0.19.11: + resolution: {integrity: sha512-ETp87DRWuSt9KdDVkqSoKoLFHYTrkyz2+65fj9nfXsaV3bMhTCjtQfw3y+um88vGRKRiF7erPrh/ZuIdLUIVxQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@esbuild/darwin-x64@0.19.11: + resolution: {integrity: sha512-fkFUiS6IUK9WYUO/+22omwetaSNl5/A8giXvQlcinLIjVkxwTLSktbF5f/kJMftM2MJp9+fXqZ5ezS7+SALp4g==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@esbuild/freebsd-arm64@0.19.11: + resolution: {integrity: sha512-lhoSp5K6bxKRNdXUtHoNc5HhbXVCS8V0iZmDvyWvYq9S5WSfTIHU2UGjcGt7UeS6iEYp9eeymIl5mJBn0yiuxA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/freebsd-x64@0.19.11: + resolution: {integrity: sha512-JkUqn44AffGXitVI6/AbQdoYAq0TEullFdqcMY/PCUZ36xJ9ZJRtQabzMA+Vi7r78+25ZIBosLTOKnUXBSi1Kw==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-arm64@0.19.11: + resolution: {integrity: sha512-LneLg3ypEeveBSMuoa0kwMpCGmpu8XQUh+mL8XXwoYZ6Be2qBnVtcDI5azSvh7vioMDhoJFZzp9GWp9IWpYoUg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-arm@0.19.11: + resolution: {integrity: sha512-3CRkr9+vCV2XJbjwgzjPtO8T0SZUmRZla+UL1jw+XqHZPkPgZiyWvbDvl9rqAN8Zl7qJF0O/9ycMtjU67HN9/Q==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-ia32@0.19.11: + resolution: {integrity: sha512-caHy++CsD8Bgq2V5CodbJjFPEiDPq8JJmBdeyZ8GWVQMjRD0sU548nNdwPNvKjVpamYYVL40AORekgfIubwHoA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-loong64@0.19.11: + resolution: {integrity: sha512-ppZSSLVpPrwHccvC6nQVZaSHlFsvCQyjnvirnVjbKSHuE5N24Yl8F3UwYUUR1UEPaFObGD2tSvVKbvR+uT1Nrg==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-mips64el@0.19.11: + resolution: {integrity: sha512-B5x9j0OgjG+v1dF2DkH34lr+7Gmv0kzX6/V0afF41FkPMMqaQ77pH7CrhWeR22aEeHKaeZVtZ6yFwlxOKPVFyg==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-ppc64@0.19.11: + resolution: {integrity: sha512-MHrZYLeCG8vXblMetWyttkdVRjQlQUb/oMgBNurVEnhj4YWOr4G5lmBfZjHYQHHN0g6yDmCAQRR8MUHldvvRDA==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-riscv64@0.19.11: + resolution: {integrity: sha512-f3DY++t94uVg141dozDu4CCUkYW+09rWtaWfnb3bqe4w5NqmZd6nPVBm+qbz7WaHZCoqXqHz5p6CM6qv3qnSSQ==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-s390x@0.19.11: + resolution: {integrity: sha512-A5xdUoyWJHMMlcSMcPGVLzYzpcY8QP1RtYzX5/bS4dvjBGVxdhuiYyFwp7z74ocV7WDc0n1harxmpq2ePOjI0Q==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-x64@0.19.11: + resolution: {integrity: sha512-grbyMlVCvJSfxFQUndw5mCtWs5LO1gUlwP4CDi4iJBbVpZcqLVT29FxgGuBJGSzyOxotFG4LoO5X+M1350zmPA==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@esbuild/netbsd-x64@0.19.11: + resolution: {integrity: sha512-13jvrQZJc3P230OhU8xgwUnDeuC/9egsjTkXN49b3GcS5BKvJqZn86aGM8W9pd14Kd+u7HuFBMVtrNGhh6fHEQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/openbsd-x64@0.19.11: + resolution: {integrity: sha512-ysyOGZuTp6SNKPE11INDUeFVVQFrhcNDVUgSQVDzqsqX38DjhPEPATpid04LCoUr2WXhQTEZ8ct/EgJCUDpyNw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /@esbuild/sunos-x64@0.19.11: + resolution: {integrity: sha512-Hf+Sad9nVwvtxy4DXCZQqLpgmRTQqyFyhT3bZ4F2XlJCjxGmRFF0Shwn9rzhOYRB61w9VMXUkxlBy56dk9JJiQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-arm64@0.19.11: + resolution: {integrity: sha512-0P58Sbi0LctOMOQbpEOvOL44Ne0sqbS0XWHMvvrg6NE5jQ1xguCSSw9jQeUk2lfrXYsKDdOe6K+oZiwKPilYPQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-ia32@0.19.11: + resolution: {integrity: sha512-6YOrWS+sDJDmshdBIQU+Uoyh7pQKrdykdefC1avn76ss5c+RN6gut3LZA4E2cH5xUEp5/cA0+YxRaVtRAb0xBg==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@esbuild/win32-x64@0.19.11: + resolution: {integrity: sha512-vfkhltrjCAb603XaFhqhAF4LGDi2M4OrCRrFusyQ+iTLQ/o60QQXxc9cZC/FFpihBI9N1Grn6SMKVJ4KP7Fuiw==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@fastify/busboy@2.0.0: resolution: {integrity: sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==} engines: {node: '>=14'} @@ -677,22 +877,6 @@ packages: regenerator-runtime: 0.13.11 dev: false - /@jridgewell/resolve-uri@3.1.1: - resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} - engines: {node: '>=6.0.0'} - dev: true - - /@jridgewell/sourcemap-codec@1.4.15: - resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - dev: true - - /@jridgewell/trace-mapping@0.3.9: - resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} - dependencies: - '@jridgewell/resolve-uri': 3.1.1 - '@jridgewell/sourcemap-codec': 1.4.15 - dev: true - /@mapbox/node-pre-gyp@1.0.11: resolution: {integrity: sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==} hasBin: true @@ -765,22 +949,6 @@ packages: engines: {node: '>= 6'} dev: false - /@tsconfig/node10@1.0.9: - resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} - dev: true - - /@tsconfig/node12@1.0.11: - resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} - dev: true - - /@tsconfig/node14@1.0.3: - resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} - dev: true - - /@tsconfig/node16@1.0.4: - resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} - dev: true - /@types/cli-progress@3.11.5: resolution: {integrity: sha512-D4PbNRbviKyppS5ivBGyFO29POlySLmA2HyUFE4p5QGazAMM3CwkKWcvTl8gvElSuxRh6FPKL8XmidX873ou4g==} dependencies: @@ -876,11 +1044,6 @@ packages: engines: {node: '>=0.4.0'} dev: false - /acorn-walk@8.3.0: - resolution: {integrity: sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==} - engines: {node: '>=0.4.0'} - dev: true - /acorn@7.4.1: resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} engines: {node: '>=0.4.0'} @@ -891,6 +1054,7 @@ packages: resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==} engines: {node: '>=0.4.0'} hasBin: true + dev: false /agent-base@6.0.2: resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==} @@ -942,10 +1106,6 @@ packages: readable-stream: 3.6.2 dev: false - /arg@4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: true - /asn1@0.2.6: resolution: {integrity: sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==} dependencies: @@ -1276,10 +1436,6 @@ packages: dev: false optional: true - /create-require@1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: true - /cssom@0.3.8: resolution: {integrity: sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==} dev: false @@ -1434,11 +1590,6 @@ packages: dev: false optional: true - /diff@4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - dev: true - /docker-modem@5.0.3: resolution: {integrity: sha512-89zhop5YVhcPEt5FpUFGr3cDyceGhq/F9J+ZndQ4KfqNvfbJpPMfgeixFgUj5OjCYAboElqODxY5Z1EBsSa6sg==} engines: {node: '>= 8.0'} @@ -1570,6 +1721,37 @@ packages: ext: 1.7.0 dev: false + /esbuild@0.19.11: + resolution: {integrity: sha512-HJ96Hev2hX/6i5cDVwcqiJBBtuo9+FeIJOtZ9W1kA5M6AMJRHUZlpYZ1/SbEwtO0ioNAW8rUooVpC/WehY2SfA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/aix-ppc64': 0.19.11 + '@esbuild/android-arm': 0.19.11 + '@esbuild/android-arm64': 0.19.11 + '@esbuild/android-x64': 0.19.11 + '@esbuild/darwin-arm64': 0.19.11 + '@esbuild/darwin-x64': 0.19.11 + '@esbuild/freebsd-arm64': 0.19.11 + '@esbuild/freebsd-x64': 0.19.11 + '@esbuild/linux-arm': 0.19.11 + '@esbuild/linux-arm64': 0.19.11 + '@esbuild/linux-ia32': 0.19.11 + '@esbuild/linux-loong64': 0.19.11 + '@esbuild/linux-mips64el': 0.19.11 + '@esbuild/linux-ppc64': 0.19.11 + '@esbuild/linux-riscv64': 0.19.11 + '@esbuild/linux-s390x': 0.19.11 + '@esbuild/linux-x64': 0.19.11 + '@esbuild/netbsd-x64': 0.19.11 + '@esbuild/openbsd-x64': 0.19.11 + '@esbuild/sunos-x64': 0.19.11 + '@esbuild/win32-arm64': 0.19.11 + '@esbuild/win32-ia32': 0.19.11 + '@esbuild/win32-x64': 0.19.11 + dev: true + /escape-html@1.0.3: resolution: {integrity: sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==} dev: false @@ -1742,6 +1924,14 @@ packages: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} dev: false + /fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + requiresBuild: true + dev: true + optional: true + /function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} dev: false @@ -1770,6 +1960,12 @@ packages: hasown: 2.0.0 dev: false + /get-tsconfig@4.7.2: + resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: true + /getpass@0.1.7: resolution: {integrity: sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==} dependencies: @@ -2371,10 +2567,6 @@ packages: semver: 6.3.1 dev: false - /make-error@1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: true - /media-typer@0.3.0: resolution: {integrity: sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==} engines: {node: '>= 0.6'} @@ -2859,6 +3051,10 @@ packages: resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} dev: false + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: true + /rfdc@1.3.0: resolution: {integrity: sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==} dev: false @@ -3365,37 +3561,6 @@ packages: engines: {node: '>=14.0.0'} dev: false - /ts-node@10.9.2(@types/node@20.11.0)(typescript@5.3.3): - resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.4 - '@types/node': 20.11.0 - acorn: 8.11.2 - acorn-walk: 8.3.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.3.3 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - dev: true - /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} dev: false @@ -3405,6 +3570,17 @@ packages: engines: {node: '>=0.6.x'} dev: false + /tsx@4.7.0: + resolution: {integrity: sha512-I+t79RYPlEYlHn9a+KzwrvEwhJg35h/1zHsLC2JXvhC2mdynMv6Zxzvhv5EMV6VF5qJlLlkSnMVvdZV3PSIGcg==} + engines: {node: '>=18.0.0'} + hasBin: true + dependencies: + esbuild: 0.19.11 + get-tsconfig: 4.7.2 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /tunnel-agent@0.6.0: resolution: {integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==} dependencies: @@ -3524,10 +3700,6 @@ packages: hasBin: true dev: false - /v8-compile-cache-lib@3.0.1: - resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - dev: true - /vary@1.1.2: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} @@ -3710,11 +3882,6 @@ packages: engines: {node: '>= 4.0.0'} dev: false - /yn@3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - dev: true - /zincsearch-node@2.1.1(undici@6.3.0): resolution: {integrity: sha512-erRhljqQVK96HE7KWfMFQaFsiere3+DrInZY2g5pHpz5ea/78G1z4Exky2vsLvLZ+D320D2JINcc2BVedY+6aQ==} peerDependencies: From 4e43d717214dfeaa381cf2927e10afcf3af2d6cf Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 19 Jan 2024 22:55:06 +0800 Subject: [PATCH 22/24] =?UTF-8?q?chore:=20=E8=A7=A6=E5=8F=91=20/=20?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E7=9A=84=E6=B6=88=E6=81=AF=E4=B9=9F=E8=BD=AC?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Instance.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/Instance.ts b/src/models/Instance.ts index a8c51f9b..06b16e80 100644 --- a/src/models/Instance.ts +++ b/src/models/Instance.ts @@ -154,11 +154,11 @@ export default class Instance { this.deleteMessageController = new DeleteMessageController(this, this.tgBot, this.tgUser, this.oicq); this.miraiSkipFilterController = new MiraiSkipFilterController(this, this.tgBot, this.tgUser, this.oicq); this.inChatCommandsController = new InChatCommandsController(this, this.tgBot, this.tgUser, this.oicq); + this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); + this.forwardController = new ForwardController(this, this.tgBot, this.tgUser, this.oicq); if (this.workMode === 'group') { this.hugController = new HugController(this, this.tgBot, this.oicq); } - this.quotLyController = new QuotLyController(this, this.tgBot, this.oicq); - this.forwardController = new ForwardController(this, this.tgBot, this.tgUser, this.oicq); this.fileAndFlashPhotoController = new FileAndFlashPhotoController(this, this.tgBot, this.oicq); })() .then(() => this.log.info('初始化已完成')); From 4b3b0ac9d5823e1c388d44cf7f54cd8c0f58eba5 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 19 Jan 2024 23:04:02 +0800 Subject: [PATCH 23/24] =?UTF-8?q?feat:=20/=20=E6=8C=87=E4=BB=A4=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/HugController.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/controllers/HugController.ts b/src/controllers/HugController.ts index e906266d..207f46a1 100644 --- a/src/controllers/HugController.ts +++ b/src/controllers/HugController.ts @@ -23,7 +23,7 @@ type ActionSubjectQq = { type ActionSubject = ActionSubjectTg | ActionSubjectQq; -const COMMAND_REGEX = /^\/([^\w\s$]\S*)|^\/\$(\w\S*)/; // /抱 /$rua +const COMMAND_REGEX = /(^\/([^\w\s$]\S*)|^\/\$(\w\S*))( (\S*))?/; // /抱 /$rua export default class { private readonly log: Logger; @@ -47,7 +47,7 @@ export default class { if (firstElem?.type !== 'text') return; const exec = COMMAND_REGEX.exec(firstElem.text.trim()); if (!exec) return; - const action = exec[1] || exec[2]; + const action = exec[2] || exec[3]; if (!action) return; const from: ActionSubject = { from: 'qq', @@ -100,7 +100,7 @@ export default class { id: event.sender.user_id, }; } - await this.sendAction(pair, from, to, action); + await this.sendAction(pair, from, to, action, exec[5]); return true; }; @@ -109,7 +109,7 @@ export default class { if (!pair) return; const exec = COMMAND_REGEX.exec(message.message); if (!exec) return; - const action = exec[1] || exec[2]; + const action = exec[2] || exec[3]; if (!action) return; const from: ActionSubject = { from: 'tg', @@ -152,11 +152,11 @@ export default class { id: (await this.tgBot.getChat(message.senderId)).inputPeer as Api.InputPeerUser, }; } - await this.sendAction(pair, from, to, action); + await this.sendAction(pair, from, to, action, exec[5]); return true; }; - private async sendAction(pair: Pair, from: ActionSubject, to: ActionSubject, action: string) { + private async sendAction(pair: Pair, from: ActionSubject, to: ActionSubject, action: string, suffix?: string) { let tgText = ''; const tgEntities: Api.TypeMessageEntity[] = []; const qqMessageContent: Sendable = []; @@ -193,6 +193,13 @@ export default class { } addText('了 '); addSubject(to); + if (suffix) { + if (!/[\u4e00-\u9fa5]$/.test(suffix) || !/[\u4e00-\u9fa5]$/.test(to.name)) { + // 英文之后加上空格 + tgText += " "; + } + tgText += suffix; + } addText('!'); const tgMessage = await pair.tg.sendMessage({ From af2d02b282db001159b3ec226914c75d5dc2721f Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 19 Jan 2024 23:17:29 +0800 Subject: [PATCH 24/24] =?UTF-8?q?chore:=20/=20=E6=8C=87=E4=BB=A4=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8=20=C2=A5=20=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E7=BC=80=E5=A7=8B=E7=BB=88=E5=8A=A0=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 和神奇海螺表现一样 --- src/controllers/HugController.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/controllers/HugController.ts b/src/controllers/HugController.ts index 207f46a1..7e508993 100644 --- a/src/controllers/HugController.ts +++ b/src/controllers/HugController.ts @@ -23,10 +23,11 @@ type ActionSubjectQq = { type ActionSubject = ActionSubjectTg | ActionSubjectQq; -const COMMAND_REGEX = /(^\/([^\w\s$]\S*)|^\/\$(\w\S*))( (\S*))?/; // /抱 /$rua +const COMMAND_REGEX = /(^\/([^\w\s$¥]\S*)|^\/[$¥](\w\S*))( (\S*))?/; // /抱 /$rua export default class { private readonly log: Logger; + constructor(private readonly instance: Instance, private readonly tgBot: Telegram, private readonly oicq: OicqClient) { @@ -76,7 +77,7 @@ export default class { }, }); if (!sourceMessage) { - this.log.error('找不到 sourceMessage') + this.log.error('找不到 sourceMessage'); return true; } to = { @@ -126,7 +127,7 @@ export default class { }, }); if (!sourceMessage) { - this.log.error('找不到 sourceMessage') + this.log.error('找不到 sourceMessage'); return true; } if (this.tgBot.me.id.eq(sourceMessage.tgSenderId)) { @@ -194,11 +195,7 @@ export default class { addText('了 '); addSubject(to); if (suffix) { - if (!/[\u4e00-\u9fa5]$/.test(suffix) || !/[\u4e00-\u9fa5]$/.test(to.name)) { - // 英文之后加上空格 - tgText += " "; - } - tgText += suffix; + tgText += ' ' + suffix; } addText('!');