fix: use Query to properly handle --pingpong flag
Use nonebot_plugin_alconna Query to correctly handle the --pingpong
boolean flag. Previously the flag wasn't working because the
parameter wasn't being properly injected.
Changes:
- Import Query from nonebot_plugin_alconna
- Change Option to not have args (just Option('--pingpong'))
- Use Query[bool] type annotation with default Query('pingpong')
- Check pingpong.available to determine if flag was set
This commit is contained in:
@ -6,7 +6,7 @@ import PIL
|
|||||||
import PIL.Image
|
import PIL.Image
|
||||||
import cv2
|
import cv2
|
||||||
import imageio.v3 as iio
|
import imageio.v3 as iio
|
||||||
from nonebot_plugin_alconna import Alconna, Args, Image, Option, UniMessage, on_alconna
|
from nonebot_plugin_alconna import Alconna, Args, Image, Option, Query, UniMessage, on_alconna
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
from konabot.common.nb.exc import BotExceptionMessage
|
from konabot.common.nb.exc import BotExceptionMessage
|
||||||
@ -34,7 +34,7 @@ cmd_giftool = on_alconna(
|
|||||||
Option("-t", Args["length", str]),
|
Option("-t", Args["length", str]),
|
||||||
Option("-to", Args["end_point", str]),
|
Option("-to", Args["end_point", str]),
|
||||||
Option("--speed", Args["speed_factor", float], default=1.0, alias=["-s"]),
|
Option("--speed", Args["speed_factor", float], default=1.0, alias=["-s"]),
|
||||||
Option("--pingpong", default=False),
|
Option("--pingpong"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ async def _(
|
|||||||
length: str | None = None,
|
length: str | None = None,
|
||||||
speed_factor: float = 1.0,
|
speed_factor: float = 1.0,
|
||||||
end_point: str | None = None,
|
end_point: str | None = None,
|
||||||
pingpong: bool = False,
|
pingpong: Query[bool] = Query("pingpong"),
|
||||||
):
|
):
|
||||||
ss: None | float = None
|
ss: None | float = None
|
||||||
if start_point:
|
if start_point:
|
||||||
@ -165,7 +165,7 @@ async def _(
|
|||||||
rdur_ms = rdur_ms[::-1]
|
rdur_ms = rdur_ms[::-1]
|
||||||
|
|
||||||
# 处理 pingpong 模式
|
# 处理 pingpong 模式
|
||||||
if pingpong:
|
if pingpong.available:
|
||||||
# 复制一份反转的帧序列(去掉第一帧避免重复)
|
# 复制一份反转的帧序列(去掉第一帧避免重复)
|
||||||
pingpong_frames = rframes[1:][::-1] if len(rframes) > 1 else rframes[::-1]
|
pingpong_frames = rframes[1:][::-1] if len(rframes) > 1 else rframes[::-1]
|
||||||
pingpong_durations = rdur_ms[1:][::-1] if len(rdur_ms) > 1 else rdur_ms[::-1]
|
pingpong_durations = rdur_ms[1:][::-1] if len(rdur_ms) > 1 else rdur_ms[::-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user