MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / downloadAndProcessImage

Function downloadAndProcessImage

outdated/gemini/gemini.ts:995–1028  ·  view source on GitHub ↗
(
  client: any,
  message: Api.Message,
  infoMessage: Api.Message
)

Source from the content-addressed store, hash-verified

993}
994
995async function downloadAndProcessImage(
996 client: any,
997 message: Api.Message,
998 infoMessage: Api.Message
999): Promise<string> {
1000 await infoMessage.edit({ text: "下载图片..." });
1001 let mediaMsg = message;
1002 const replyMsg = await message.getReplyMessage();
1003 if (!message.media && replyMsg?.media) {
1004 mediaMsg = replyMsg;
1005 }
1006
1007 if (!mediaMsg.media) {
1008 throw new Error("未找到图片");
1009 }
1010
1011 const buffer = await client.downloadMedia(mediaMsg.media, {
1012 workers: 1,
1013 progressCallback: (received: number, total: number) => {
1014 const percent = (received * 100 / total);
1015 infoMessage.edit({
1016 text: `下载图片 ${percent.toFixed(1)}%`
1017 }).catch(() => {});
1018 }
1019 });
1020
1021 if (!buffer) {
1022 throw new Error("图片下载失败");
1023 }
1024
1025 await infoMessage.edit({ text: "下载图片 100%" });
1026
1027 return (buffer as Buffer).toString('base64');
1028}
1029
1030function extractQuestionFromArgs(args: string[], replyMsg?: Api.Message | null): { userQuestion: string; displayQuestion: string; apiQuestion: string } {
1031 const userQuestion = args.join(" ");

Callers 1

handleGeminiRequestFunction · 0.70

Calls 2

editMethod · 0.45
downloadMediaMethod · 0.45

Tested by

no test coverage detected