Skip to content

Commit

Permalink
适配rc版本
Browse files Browse the repository at this point in the history
  • Loading branch information
1umine committed Dec 21, 2022
1 parent 1558841 commit 8281746
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions nonebot_plugin_miragetank/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import base64

from nonebot import on_command
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment, MessageEvent
from nonebot.adapters.onebot.v11.helpers import HandleCancellation
from nonebot.params import CommandArg, State
from nonebot.params import CommandArg
from nonebot.typing import T_State
from nonebot.plugin import PluginMetadata

from .data_source import color_car, get_img, gray_car


__plugin_meta__ = PluginMetadata(
"miragetank",
"合成幻影坦克图片",
"/miragetank <图片1> <图片2>"
)

mirage_tank = on_command(
"生成幻影坦克", aliases={"miragetank"}, priority=27
"生成幻影坦克", aliases={"miragetank", "幻影坦克"}, priority=27
)


@mirage_tank.handle()
async def handle_first(
bot: Bot,
event: MessageEvent,
state: T_State = State(),
state: T_State,
args: Message = CommandArg(),
):
images = []
for seg in args:
print(seg)
if seg.type == "text":
state["mod"] = seg.data["text"].strip()
elif seg.type == "image":
Expand All @@ -36,7 +41,7 @@ async def handle_first(
@mirage_tank.got(
"mod", prompt="需要指定结果类型: gray | color", parameterless=[HandleCancellation("已取消")]
)
async def get_mod(event: MessageEvent, state: T_State = State()):
async def get_mod(event: MessageEvent, state: T_State):
mod = str(state["mod"]).strip()
if mod not in ["gray", "color"]:
await mirage_tank.reject('"gray" | "color", 二选一')
Expand All @@ -46,7 +51,7 @@ async def get_mod(event: MessageEvent, state: T_State = State()):
"img1", prompt="请发送两张图,按表里顺序", parameterless=[HandleCancellation("已取消")]
)
@mirage_tank.got("img2", prompt="还需要一张图", parameterless=[HandleCancellation("已取消")])
async def get_images(state: T_State = State()):
async def get_images(state: T_State):
imgs = []
mod = str(state["mod"])
for seg in state["img1"] + state["img2"]:
Expand All @@ -63,8 +68,4 @@ async def get_images(state: T_State = State()):
res = await color_car(imgs[0], imgs[1])
if res:
img_urls = []
await mirage_tank.finish(
MessageSegment.image(
f"base64://{base64.b64encode(res.getvalue()).decode()}"
)
)
await mirage_tank.finish(MessageSegment.image(res))

0 comments on commit 8281746

Please sign in to comment.