2024-11-21 19:38:09 +08:00
|
|
|
import contextlib
|
|
|
|
import json
|
2024-12-13 02:23:38 +08:00
|
|
|
import traceback
|
2024-11-21 19:38:09 +08:00
|
|
|
from typing import Optional
|
|
|
|
|
2024-12-13 02:23:38 +08:00
|
|
|
from arclet.alconna import Alconna, AllParam, Args
|
|
|
|
from nonebot import get_driver, logger, on_command
|
|
|
|
from nonebot.adapters import Event, Message
|
2024-11-21 19:38:09 +08:00
|
|
|
from nonebot.params import CommandArg
|
|
|
|
from nonebot.permission import SUPERUSER
|
2024-12-13 02:23:38 +08:00
|
|
|
from nonebot_plugin_alconna import MsgTarget, on_alconna
|
2024-11-21 19:38:09 +08:00
|
|
|
from nonebot_plugin_alconna.uniseg import UniMessage, UniMsg
|
2024-12-13 02:23:38 +08:00
|
|
|
|
|
|
|
from .config import config
|
2024-11-21 19:38:09 +08:00
|
|
|
from .constants import *
|
|
|
|
from .metadata import metadata
|
|
|
|
from .models import MarshoContext
|
|
|
|
from .util_hunyuan import *
|
2024-12-13 02:23:38 +08:00
|
|
|
|
2024-11-21 19:38:09 +08:00
|
|
|
genimage_cmd = on_alconna(
|
|
|
|
Alconna(
|
|
|
|
"genimage",
|
|
|
|
Args["prompt?", str],
|
|
|
|
)
|
2024-12-13 02:23:38 +08:00
|
|
|
)
|
|
|
|
|
2024-11-21 19:38:09 +08:00
|
|
|
|
|
|
|
@genimage_cmd.handle()
|
|
|
|
async def genimage(event: Event, prompt=None):
|
|
|
|
if not prompt:
|
2024-12-13 02:23:38 +08:00
|
|
|
await genimage_cmd.finish("无提示词")
|
2024-11-21 19:38:09 +08:00
|
|
|
try:
|
|
|
|
result = generate_image(prompt)
|
|
|
|
url = json.loads(result)["ResultImage"]
|
|
|
|
await UniMessage.image(url=url).send()
|
|
|
|
except Exception as e:
|
2024-12-13 02:23:38 +08:00
|
|
|
# await genimage_cmd.finish(str(e))
|
2024-11-21 19:38:09 +08:00
|
|
|
traceback.print_exc()
|