mirror of https://github.com/Nofated095/Q2TG.git
fix: 防止 webp 作为贴纸发送时丢失发送者信息
This commit is contained in:
parent
e09d6d4f49
commit
6d671fe7ad
|
@ -7,11 +7,17 @@ import { Entity } from 'telegram/define';
|
|||
const log = getLogger('ForwardHelper');
|
||||
|
||||
export default {
|
||||
async downloadToCustomFile(url: string) {
|
||||
async downloadToCustomFile(url: string, allowWebp = false) {
|
||||
const { fileTypeFromBuffer } = await (Function('return import("file-type")')() as Promise<typeof import('file-type')>);
|
||||
const file = await fetchFile(url);
|
||||
const type = await fileTypeFromBuffer(file);
|
||||
return new CustomFile(`image.${type.ext}`, file.length, '', file);
|
||||
if (allowWebp) {
|
||||
return new CustomFile(`image.${type.ext}`, file.length, '', file);
|
||||
}
|
||||
else {
|
||||
// 防止 webp 作为贴纸发送时丢失发送者信息
|
||||
return new CustomFile(`image.${type.ext === 'gif' ? 'gif' : 'jpg'}`, file.length, '', file);
|
||||
}
|
||||
},
|
||||
|
||||
hSize(size: number) {
|
||||
|
@ -116,11 +122,11 @@ export default {
|
|||
return user.firstName +
|
||||
(user.lastName ? ' ' + user.lastName : '');
|
||||
}
|
||||
else if('title' in user){
|
||||
return user.title
|
||||
else if ('title' in user) {
|
||||
return user.title;
|
||||
}
|
||||
else if('id' in user){
|
||||
return user.id.toString()
|
||||
else if ('id' in user) {
|
||||
return user.id.toString();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import Telegram from '../client/Telegram';
|
||||
import OicqClient from '../client/OicqClient';
|
||||
import { Friend, Group, GroupMessageEvent, PrivateMessageEvent, Quotable, segment, Sendable } from 'oicq';
|
||||
import { Group, GroupMessageEvent, PrivateMessageEvent, Quotable, segment, Sendable } from 'oicq';
|
||||
import { Pair } from '../providers/forwardPairs';
|
||||
import { fetchFile, getBigFaceUrl, getImageUrlByMd5 } from '../utils/urls';
|
||||
import { FileLike, MarkupLike } from 'telegram/define';
|
||||
|
@ -70,7 +70,7 @@ export default class ForwardService {
|
|||
if ('url' in elem)
|
||||
url = elem.url;
|
||||
try {
|
||||
files.push(await helper.downloadToCustomFile(url));
|
||||
files.push(await helper.downloadToCustomFile(url, !(message || messageHeader)));
|
||||
}
|
||||
catch (e) {
|
||||
this.log.error('下载媒体失败', e);
|
||||
|
@ -92,7 +92,7 @@ export default class ForwardService {
|
|||
// 是图片
|
||||
const url = await pair.qq.getFileUrl(elem.fid);
|
||||
try {
|
||||
files.push(await helper.downloadToCustomFile(url));
|
||||
files.push(await helper.downloadToCustomFile(url, !(message || messageHeader)));
|
||||
}
|
||||
catch (e) {
|
||||
this.log.error('下载媒体失败', e);
|
||||
|
|
Loading…
Reference in New Issue