Skip to content

Commit

Permalink
chore: 上传转发失败详情到 pastebin
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Jun 25, 2024
1 parent f38c983 commit e6ff038
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
23 changes: 19 additions & 4 deletions main/src/services/ForwardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import BigInteger from 'big-integer';
import { Image } from '@icqqjs/icqq/lib/message';
import probe from 'probe-image-size';
import markdownEscape from 'markdown-escape';
import pastebin from '../utils/pastebin';

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 @@ -98,8 +99,8 @@ export default class ForwardService {
}

public async forwardFromQq(event: PrivateMessageEvent | GroupMessageEvent, pair: Pair) {
const tempFiles: FileResult[] = [];
try {
const tempFiles: FileResult[] = [];
let message = '',
files: FileLike[] = [],
buttons: ButtonLike[] = [],
Expand Down Expand Up @@ -458,19 +459,33 @@ export default class ForwardService {
if (this.instance.workMode === 'personal' && event.message_type === 'group' && event.atall) {
await tgMessage.pin({ notify: false });
}

tempFiles.forEach(it => it.cleanup());
return { tgMessage, richHeaderUsed };
}
catch (e) {
this.log.error('从 QQ 到 TG 的消息转发失败', e);
let pbUrl: string;
try {
pbUrl = await pastebin.upload(JSON.stringify({
error: e,
event,
}));
}
catch (e) {
this.log.error('上传到 Pastebin 失败', e);
}
try {
this.instance.workMode === 'personal' && await pair.tg.sendMessage('<i>有一条来自 QQ 的消息转发失败</i>');
this.instance.workMode === 'personal' && await pair.tg.sendMessage({
message: '<i>有一条来自 QQ 的消息转发失败</i>',
buttons: pbUrl ? [[Button.url('查看详情', pbUrl)]] : [],
});
}
catch {
}
return {};
}
finally {
tempFiles.forEach(it => it.cleanup());
}
}

public async forwardFromTelegram(message: Api.Message, pair: Pair): Promise<Array<QQMessageSent>> {
Expand Down
14 changes: 14 additions & 0 deletions main/src/utils/pastebin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
async upload(data: string) {
const req = await fetch('https://fars.ee', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
c: data,
}),
});
return req.headers.get('Location');
},
};

0 comments on commit e6ff038

Please sign in to comment.