西多说 by 姬嵇
This commit is contained in:
BIN
assets/img/meme/kiosay.jpg
Executable file
BIN
assets/img/meme/kiosay.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
17
konabot/common/utils/to_async.py
Normal file
17
konabot/common/utils/to_async.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import asyncio
|
||||||
|
import functools
|
||||||
|
|
||||||
|
from typing import Awaitable, Callable, ParamSpec, TypeVar
|
||||||
|
|
||||||
|
|
||||||
|
TA = ParamSpec("TA")
|
||||||
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
|
def make_async(func: Callable[TA, T]) -> Callable[TA, Awaitable[T]]:
|
||||||
|
@functools.wraps(func, assigned=("__module__", "__name__", "__qualname__", "__doc__", "__annotations__"))
|
||||||
|
async def wrapper(*args: TA.args, **kwargs: TA.kwargs):
|
||||||
|
return await asyncio.to_thread(func, *args, **kwargs)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
@ -24,6 +24,7 @@ from konabot.plugins.memepack.drawing.display import (
|
|||||||
from konabot.plugins.memepack.drawing.saying import (
|
from konabot.plugins.memepack.drawing.saying import (
|
||||||
draw_cute_ten,
|
draw_cute_ten,
|
||||||
draw_geimao,
|
draw_geimao,
|
||||||
|
draw_kiosay,
|
||||||
draw_mnk,
|
draw_mnk,
|
||||||
draw_pt,
|
draw_pt,
|
||||||
draw_suan,
|
draw_suan,
|
||||||
@ -275,3 +276,29 @@ async def _(msg: UniMsg, evt: Event, bot: Bot):
|
|||||||
.export()
|
.export()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
kiosay = on_alconna(
|
||||||
|
Alconna(
|
||||||
|
"西多说",
|
||||||
|
Args[
|
||||||
|
"saying",
|
||||||
|
MultiVar(str, "+"),
|
||||||
|
Field(missing_tips=lambda: "你没有写西多说了什么"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
use_cmd_start=True,
|
||||||
|
use_cmd_sep=False,
|
||||||
|
skip_for_unmatch=False,
|
||||||
|
aliases=set(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@kiosay.handle()
|
||||||
|
async def _(saying: list[str]):
|
||||||
|
img = await draw_kiosay("\n".join(saying))
|
||||||
|
img_bytes = BytesIO()
|
||||||
|
img.save(img_bytes, format="PNG")
|
||||||
|
|
||||||
|
await kiosay.send(await UniMessage().image(raw=img_bytes).export())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import imagetext_py
|
|||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
|
||||||
from konabot.common.path import ASSETS_PATH
|
from konabot.common.path import ASSETS_PATH
|
||||||
|
from konabot.common.utils.to_async import make_async
|
||||||
|
|
||||||
from .base.fonts import HARMONYOS_SANS_SC_BLACK, HARMONYOS_SANS_SC_REGULAR, LXGWWENKAI_REGULAR
|
from .base.fonts import HARMONYOS_SANS_SC_BLACK, HARMONYOS_SANS_SC_REGULAR, LXGWWENKAI_REGULAR
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ mnk_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "mnksay.jpg").convert(
|
|||||||
dasuan_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "dss.png").convert("RGBA")
|
dasuan_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "dss.png").convert("RGBA")
|
||||||
suan_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "suanleba.png").convert("RGBA")
|
suan_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "suanleba.png").convert("RGBA")
|
||||||
cute_ten_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "tententen.png").convert("RGBA")
|
cute_ten_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "tententen.png").convert("RGBA")
|
||||||
|
kio_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "kiosay.jpg").convert("RGBA")
|
||||||
|
|
||||||
|
|
||||||
def _draw_geimao(saying: str):
|
def _draw_geimao(saying: str):
|
||||||
@ -29,7 +31,7 @@ def _draw_geimao(saying: str):
|
|||||||
draw_emojis=True,
|
draw_emojis=True,
|
||||||
)
|
)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
||||||
async def draw_geimao(saying: str):
|
async def draw_geimao(saying: str):
|
||||||
return await asyncio.to_thread(_draw_geimao, saying)
|
return await asyncio.to_thread(_draw_geimao, saying)
|
||||||
@ -106,3 +108,18 @@ def _draw_cute_ten(saying: str):
|
|||||||
|
|
||||||
async def draw_cute_ten(saying: str):
|
async def draw_cute_ten(saying: str):
|
||||||
return await asyncio.to_thread(_draw_cute_ten, saying)
|
return await asyncio.to_thread(_draw_cute_ten, saying)
|
||||||
|
|
||||||
|
|
||||||
|
@make_async
|
||||||
|
def draw_kiosay(saying: str):
|
||||||
|
img = kio_image.copy()
|
||||||
|
with imagetext_py.Writer(img) as iw:
|
||||||
|
iw.draw_text_wrapped(
|
||||||
|
saying, 450, 540, 0.5, 0.5, 900, 96, LXGWWENKAI_REGULAR,
|
||||||
|
imagetext_py.Paint.Color(imagetext_py.Color.from_hex("000000FF")),
|
||||||
|
1.0,
|
||||||
|
imagetext_py.TextAlign.Center,
|
||||||
|
draw_emojis=True,
|
||||||
|
)
|
||||||
|
return img
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user