mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
refactor code
This commit is contained in:
+13
-13
@@ -3,15 +3,15 @@ import textwrap
|
||||
from configs.path_config import IMAGE_PATH, TTF_PATH
|
||||
from nonebot import on_command
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent
|
||||
from utils.init_result import image
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
|
||||
from utils.message_builder import image
|
||||
from services.log import logger
|
||||
from utils.utils import UserExistLimiter, get_message_text
|
||||
from utils.img_utils import pic2b64
|
||||
from utils.image_utils import pic2b64
|
||||
|
||||
__plugin_name__ = '鲁迅说'
|
||||
__plugin_name__ = "鲁迅说"
|
||||
|
||||
__plugin_usage__ = '用法:鲁迅说 [消息]'
|
||||
__plugin_usage__ = "用法:鲁迅说 [消息]"
|
||||
|
||||
_ulmt = UserExistLimiter()
|
||||
|
||||
@@ -22,17 +22,17 @@ luxun = on_command("鲁迅说过", aliases={"鲁迅说"}, priority=5, block=True
|
||||
@luxun.handle()
|
||||
async def handle(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if _ulmt.check(event.user_id):
|
||||
await luxun.finish('你的鲁迅正在说,等会', at_sender=True)
|
||||
await luxun.finish("你的鲁迅正在说,等会", at_sender=True)
|
||||
args = get_message_text(event.json())
|
||||
if args:
|
||||
state["content"] = args if args else '烦了,不说了'
|
||||
state["content"] = args if args else "烦了,不说了"
|
||||
|
||||
|
||||
@luxun.got("content", prompt="你让鲁迅说点啥?")
|
||||
async def handle_event(bot: Bot, event: MessageEvent, state: T_State):
|
||||
filename = str(event.user_id) + "_.jpg"
|
||||
content = state["content"].strip()
|
||||
if content.startswith(',') or content.startswith(','):
|
||||
if content.startswith(",") or content.startswith(","):
|
||||
content = content[1:]
|
||||
_ulmt.set_True(event.user_id)
|
||||
if len(content) > 20:
|
||||
@@ -40,10 +40,12 @@ async def handle_event(bot: Bot, event: MessageEvent, state: T_State):
|
||||
await luxun.finish("太长了, 鲁迅说不完!", at_sender=True)
|
||||
else:
|
||||
if len(content) >= 12:
|
||||
content = content[:12] + '\n' + content[12:]
|
||||
content = content[:12] + "\n" + content[12:]
|
||||
img = image(b64=process_pic(content, filename))
|
||||
logger.info(f"USER {event.user_id} GROUP "
|
||||
f"{event.group_id if event.message_type != 'private' else 'private'} 鲁迅说过 {content}")
|
||||
logger.info(
|
||||
f"USER {event.user_id} GROUP "
|
||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'} 鲁迅说过 {content}"
|
||||
)
|
||||
await luxun.send(img)
|
||||
_ulmt.set_False(event.user_id)
|
||||
|
||||
@@ -64,5 +66,3 @@ def process_pic(content, filename) -> str:
|
||||
current_h += h + pad
|
||||
draw.text((320, 400), "——鲁迅", font=font2, fill=(255, 255, 255))
|
||||
return pic2b64(bk_img)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user