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

Method execute

ai/ai.ts:4714–4804  ·  view source on GitHub ↗
(
    msg: Api.Message,
    args: string[],
    _prefixes: string[],
  )

Source from the content-addressed store, hash-verified

4712
4713 async execute(
4714 msg: Api.Message,
4715 args: string[],
4716 _prefixes: string[],
4717 ): Promise<void> {
4718 const prefixes = getPrefixes();
4719 const configManager = await this.getConfigManager();
4720 const config = configManager.getConfig();
4721 const replyMsg = await safeGetReplyMessage(msg);
4722 const replyToId = replyMsg?.id;
4723
4724 const subCommand = args[1]?.toLowerCase();
4725 if (subCommand === "preview") {
4726 const state = args[2]?.toLowerCase();
4727 if (!state) {
4728 await this.editMessage(
4729 msg,
4730 `🖼️ <b>图片预览状态:</b>\n\n📄 当前状态: ${config.imagePreview ? "开启" : "关闭"}`,
4731 );
4732 return;
4733 }
4734 requireUser(state === "on" || state === "off", "参数必须是 on 或 off");
4735 await configManager.updateConfig((cfg) => {
4736 cfg.imagePreview = state === "on";
4737 });
4738 await this.editMessage(
4739 msg,
4740 `✅ 图片预览已${state === "on" ? "开启" : "关闭"}`,
4741 );
4742 return;
4743 }
4744
4745 const promptInput = args.slice(1).join(" ").trim();
4746 const replyText = getMessageText(replyMsg).trim();
4747 const replyImageParts = await getMessageImageParts(replyMsg);
4748 const messageImageParts = await getMessageImageParts(msg);
4749 const imageParts = [...replyImageParts, ...messageImageParts];
4750
4751 const hasPrompt = !!promptInput || !!replyText;
4752 requireUser(hasPrompt, "至少需要一条文字提示");
4753
4754 if (
4755 !config.currentImageTag ||
4756 !config.currentImageModel ||
4757 !config.configs[config.currentImageTag]
4758 ) {
4759 throw new UserError(
4760 `请先配置 API 并设置模型\n使用 ${prefixes[0]}ai config add <tag> <url> <key> [type] 和 ${prefixes[0]}ai model image <tag> <model-path>`,
4761 );
4762 }
4763
4764 const token = this.aiService.createAbortToken();
4765 await sendProcessing(msg, "image");
4766
4767 try {
4768 let prompt = "";
4769 if (promptInput && replyText && replyImageParts.length === 0) {
4770 prompt = `${replyText}\n\n${promptInput}`;
4771 } else if (promptInput && replyImageParts.length > 0) {

Callers

nothing calls this directly

Calls 15

getMessageImagePartsFunction · 0.85
sendProcessingFunction · 0.85
resolveImagePartFunction · 0.85
deleteMessageOrGroupFunction · 0.85
getConfigManagerMethod · 0.80
editMessageMethod · 0.80
createAbortTokenMethod · 0.80
editImageMethod · 0.80
sendImagesMethod · 0.80
releaseTokenMethod · 0.80
requireUserFunction · 0.70
getMessageTextFunction · 0.70

Tested by

no test coverage detected