(msg: Api.Message, args: string[])
| 1089 | } |
| 1090 | |
| 1091 | async 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 | |
| 1143 | async function processAudioGeneration( |
| 1144 | msg: Api.Message, text: string, p0: string, |
no test coverage detected