Skip to content

Commit

Permalink
Merge branch 'Clansty:rainbowcat' into rainbowcat
Browse files Browse the repository at this point in the history
  • Loading branch information
Nofated095 authored Oct 4, 2023
2 parents 2ca6e5b + 52e17e7 commit 9c73508
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"file-type": "^17.1.4",
"fluent-ffmpeg": "^2.1.2",
"icqq": "^0.4.12",
"image-size": "^1.0.2",
"lodash": "^4.17.21",
"log4js": "^6.6.1",
"nodejs-base64": "^2.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/forwardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getLogger } from 'log4js';
import { Entity } from 'telegram/define';
import { ForwardMessage } from 'icqq';
import { Api } from 'telegram';
import { imageSize } from 'image-size';

const log = getLogger('ForwardHelper');

Expand All @@ -21,6 +22,18 @@ export default {
return new CustomFile(filename, file.length, '', file);
}
const type = await fileTypeFromBuffer(file);
// The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20
if (type.ext === 'png' || type.ext === 'jpg') {
const dimensions = imageSize(file);
const aspectRatio = dimensions.width / dimensions.height;
if (aspectRatio > 20 || aspectRatio < 1 / 20
|| dimensions.width + dimensions.height > 10000
|| file.length > 1024 * 1024 * 10
) {
// 让 Telegram 服务器下载
return url
}
}
if (allowWebp) {
return new CustomFile(`image.${type.ext}`, file.length, '', file);
}
Expand Down
2 changes: 2 additions & 0 deletions src/services/ForwardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ export default class ForwardService {
try {
if (elem.type === 'image' && elem.asface
&& !(elem.file as string).toLowerCase().endsWith('.gif')
// 同时存在文字消息就不作为 sticker 发送
&& !event.message.some(it => it.type === 'text')
// 防止在 TG 中一起发送多个 sticker 失败
&& event.message.filter(it => it.type === 'image').length === 1
) {
Expand Down
Loading

0 comments on commit 9c73508

Please sign in to comment.