Skip to content

Commit

Permalink
feat: 蛇图
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jan 21, 2025
1 parent 4e860b7 commit f0156e7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
8 changes: 7 additions & 1 deletion main/src/client/NapCatClient/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fsP from 'fs/promises';
import env from '../../models/env';
import fs from 'fs';
import { Readable } from 'node:stream';
import { FaceElem } from '@icqqjs/icqq/lib/message/elements';

const createTempFile = (options: Parameters<typeof createTempFileBase>[0] = {}) => createTempFileBase({
tmpdir: env.CACHE_DIR,
Expand Down Expand Up @@ -98,7 +99,12 @@ export type NapCatForwardElem = {
content: ForwardMessage[],
}

export const napCatReceiveToMessageElem = (data: Receive[keyof Receive]): MessageElem | NapCatForwardElem => {
export type FaceElemEx = FaceElem & {
resultId?: string,
chainCount?: number,
}

export const napCatReceiveToMessageElem = (data: Receive[keyof Receive]): MessageElem | NapCatForwardElem | FaceElemEx => {
switch (data.type) {
case 'text':
case 'face':
Expand Down
8 changes: 5 additions & 3 deletions main/src/client/QQClient/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Friend, Group, QQUser, Sendable } from './index';
import type { MessageElem } from '@icqqjs/icqq';
import { NapCatForwardElem } from '../NapCatClient/convert';
import { FaceElemEx, NapCatForwardElem } from '../NapCatClient/convert';

export abstract class ChatEvent {
protected constructor(
Expand All @@ -19,6 +19,8 @@ export abstract class ChatEvent {
}
}

export type MessageElemRecv = MessageElem | NapCatForwardElem | FaceElemEx;

export class MessageEvent extends ChatEvent {
constructor(
public readonly from: {
Expand All @@ -28,7 +30,7 @@ export class MessageEvent extends ChatEvent {
card?: string;
},
chat: Friend | Group,
public readonly message: (MessageElem | NapCatForwardElem)[],
public readonly message: MessageElemRecv[],
public readonly seq: number,
public readonly rand: number,
public readonly pktnum: number,
Expand All @@ -39,7 +41,7 @@ export class MessageEvent extends ChatEvent {
time: number;
seq: number;
rand: number;
message: (MessageElem | NapCatForwardElem)[];
message: MessageElemRecv[];
},
public readonly anonymous: {
name: string;
Expand Down
13 changes: 7 additions & 6 deletions main/src/constants/lottie.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export default {
packInfo: {
qlottie_2: [364, 362, 397, 396, 360, 361, 363, 365, 367],
qlottie_3: [413, 405, 404, 406, 411, 407, 408, 412, 409],
qlottie_4: [403, 402, 390, 391, 388, 389, 386, 385, 384, 387],
qlottie_5: [382, 383, 401, 400, 380, 381, 379, 376, 378, 377],
qlottie_6: [399, 398, 373, 370, 375, 368, 369, 371, 372, 374],
QQAniSticker: [5, 311, 312, 319, 320, 339, 137, 346, 344, 345, 181, 74, 75, 349, 350],
qlottie_2: ["364", "362", "397", "396", "360", "361", "363", "365", "367"],
qlottie_3: ["413", "405", "404", "406", "411", "407", "408", "412", "409"],
qlottie_4: ["403", "402", "390", "391", "388", "389", "386", "385", "384", "387"],
qlottie_5: ["382", "383", "401", "400", "380", "381", "379", "376", "378", "377"],
qlottie_6: ["399", "398", "373", "370", "375", "368", "369", "371", "372", "374"],
QQAniSticker: ["5", "311", "312", "319", "320", "339", "137", "346", "344", "345", "181", "74", "75", "349", "350"],
qq_snake: ["429", "430", "431_1", "431_2", "431_3", "431_4", "431_5", "431_6", "432"],
},
};
6 changes: 5 additions & 1 deletion main/src/constants/qface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,9 @@ export default {
"425": "/求放过",
"426": "/玩火",
"427": "/偷感",
"428": "/收到"
"428": "/收到",
"429": "/蛇年快乐",
"430": "/蛇身",
"431": "/蛇尾",
"432": "/灵蛇献瑞",
}
2 changes: 1 addition & 1 deletion main/src/controllers/InChatCommandsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class InChatCommandsController {
return true;
}
try {
if(await (pair.qq as Group).announce(params.trim())) {
if (await (pair.qq as Group).announce(params.trim())) {
await message.reply({ message: '发送成功' });
}
else {
Expand Down
29 changes: 21 additions & 8 deletions main/src/services/ForwardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import fsP from 'fs/promises';
import regExps from '../constants/regExps';
import qface from '../constants/qface';
import qfaceChannelMap from '../constants/qfaceChannelMap';
import { FaceElemEx } from '../client/NapCatClient/convert';

const NOT_CHAINABLE_ELEMENTS = ['flash', 'record', 'video', 'location', 'share', 'json', 'xml', 'poke'];
const IMAGE_MIMES = ['image/jpeg', 'image/png', 'image/apng', 'image/webp', 'image/gif', 'image/bmp', 'image/tiff', 'image/x-icon', 'image/avif', 'image/heic', 'image/heif'];
Expand Down Expand Up @@ -102,24 +103,32 @@ export default class ForwardService {
}
}

private getStickerByQQFaceId(id: number) {
private getStickerByQQFaceId(id: number | string, resultId?: number | string) {
for (const [pack, ids] of Object.entries(lottie.packInfo)) {
if (ids.includes(id)) {
if(resultId && ids.includes(`${id}_${resultId}`)) {
if (this.stickerPackMap[pack])
return this.stickerPackMap[pack][ids.indexOf(id)] as Api.Document;
return this.stickerPackMap[pack][ids.indexOf(`${id}_${resultId}`)] as Api.Document;
}
if (ids.includes(id.toString())) {
if (this.stickerPackMap[pack])
return this.stickerPackMap[pack][ids.indexOf(id.toString())] as Api.Document;
}
}
}

private getFaceByTgFileId(fileId: BigInteger.BigNumber): FaceElem | undefined {
private getFaceByTgFileId(fileId: BigInteger.BigNumber): FaceElemEx | undefined {
for (const [pack, documents] of Object.entries(this.stickerPackMap)) {
for (const document of documents) {
if (document.id.eq(fileId))
if (document.id.eq(fileId)) {
const id: string = lottie.packInfo[pack][documents.indexOf(document)];
const ids = id.split('_');
return {
type: 'face',
id: lottie.packInfo[pack][documents.indexOf(document)],
id: parseInt(ids[0]),
resultId: ids[1],
stickerType: 1,
};
}
}
}
}
Expand Down Expand Up @@ -288,7 +297,7 @@ export default class ForwardService {
}
case 'face':
// 判断 tgs 表情
const tgs = this.getStickerByQQFaceId(Number(elem.id));
const tgs = this.getStickerByQQFaceId(elem.id, (elem as FaceElemEx).resultId);
if (tgs && chain.length === 1) {
useSticker(tgs);
}
Expand Down Expand Up @@ -752,7 +761,11 @@ export default class ForwardService {
}
else if (message.video || message.videoNote || message.gif) {
const file = message.video || message.videoNote || message.gif;
if (file.size.gt(200 * 1024 * 1024)) {
const face = this.getFaceByTgFileId(message.sticker.id);
if (face) {
chain.push(face);
}
else if (file.size.gt(200 * 1024 * 1024)) {
chain.push('[视频大于 200MB]');
}
else if (file.mimeType === 'video/webm' || message.gif) {
Expand Down

0 comments on commit f0156e7

Please sign in to comment.