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

Function handleImage

outdated/gemini/gemini.ts:1091–1141  ·  view source on GitHub ↗
(msg: Api.Message, args: string[])

Source from the content-addressed store, hash-verified

1089}
1090
1091async function handleImage(msg: Api.Message, args: string[]): Promise<void> {
1092 const replyMsg = await msg.getReplyMessage();
1093 const { userQuestion, displayQuestion, apiQuestion } = extractQuestionFromArgs(args, replyMsg);
1094
1095 if (!apiQuestion) {
1096 await msg.edit({ text: "❌ 请提供图片生成提示或回复一条有文字内容的消息" });
1097 return;
1098 }
1099
1100 await msg.edit({ text: "🎨 生成图片中..." });
1101
1102 try {
1103 const client = await getGeminiClient();
1104 const response = await client.generateImage({
1105 model: getConfig(CONFIG_KEYS.GEMINI_IMAGE_MODEL),
1106 contents: [{ parts: [{ text: apiQuestion }] }]
1107 });
1108
1109 if (!response.imageData) {
1110 await msg.edit({ text: "❌ 图片生成失败" });
1111 return;
1112 }
1113
1114 const replyMsg = await msg.getReplyMessage();
1115 const imageFile = Object.assign(response.imageData, {
1116 name: 'gemini.png'
1117 });
1118
1119 if (replyMsg) {
1120 await msg.client?.sendFile(msg.peerId, {
1121 file: imageFile,
1122 caption: `<b>提示:</b> ${Utils.escapeHtml(displayQuestion || apiQuestion)}\n\n<i>Powered by Gemini Image Generation</i>`,
1123 parseMode: "html",
1124 replyTo: replyMsg.id
1125 });
1126
1127 try {
1128 await msg.delete();
1129 } catch {}
1130 } else {
1131 await msg.edit({
1132 file: imageFile,
1133 text: `<b>提示:</b> ${Utils.escapeHtml(displayQuestion || apiQuestion)}\n\n<i>Powered by Gemini Image Generation</i>`,
1134 parseMode: "html"
1135 });
1136 }
1137
1138 } catch (error: any) {
1139 await msg.edit({ text: Utils.handleError(error, '图片生成') });
1140 }
1141}
1142
1143async function processAudioGeneration(
1144msg: Api.Message, text: string, p0: string,

Callers 1

handleGeminiRequestFunction · 0.85

Calls 8

extractQuestionFromArgsFunction · 0.85
getGeminiClientFunction · 0.85
escapeHtmlMethod · 0.80
getConfigFunction · 0.70
editMethod · 0.45
generateImageMethod · 0.45
deleteMethod · 0.45
handleErrorMethod · 0.45

Tested by

no test coverage detected