本次提交对核心模块进行了深度重构,引入 Pydantic 增强配置管理的类型安全性,并全面优化了插件管理系统。 主要变更详情: 1. 核心架构与配置 - 重构配置加载模块:引入 Pydantic 模型 (`core/config_models.py`),提供严格的配置项类型检查、验证及默认值管理。 - 统一模块结构:规范化模块导入路径,移除冗余的 `__init__.py` 文件,提升项目结构的清晰度。 - 性能优化:集成 Redis 缓存支持 (`RedisManager`),有效降低高频 API 调用开销,提升响应速度。 2. 插件系统升级 - 实现热重载机制:新增插件文件变更监听功能,支持开发过程中自动重载插件,提升开发效率。 - 优化生命周期管理:改进插件加载与卸载逻辑,支持精确卸载指定插件及其关联的命令、事件处理器和定时任务。 3. 功能特性增强 - 新增媒体 API:引入 `MediaAPI` 模块,封装图片、语音等富媒体资源的获取与处理接口。 - 完善权限体系:重构权限管理系统,实现管理员与操作员的分级控制,支持更细粒度的命令权限校验。 4. 代码质量与稳定性 - 全面类型修复:解决 `mypy` 静态类型检查发现的大量类型错误(包括 `CommandManager`、`EventFactory` 及 `Bot` API 签名不匹配问题)。 - 增强错误处理:优化消息处理管道的异常捕获机制,完善关键路径的日志记录,提升系统运行稳定性。
152 lines
4.5 KiB
Python
152 lines
4.5 KiB
Python
"""
|
||
今日人品插件
|
||
|
||
提供 /jrcd 和 /bbcd 指令,用于娱乐。
|
||
"""
|
||
|
||
import random
|
||
from datetime import datetime
|
||
|
||
from core.bot import Bot
|
||
from core.managers.command_manager import matcher
|
||
from core.utils.executor import run_in_thread_pool
|
||
from models.events.message import MessageEvent, MessageSegment
|
||
|
||
__plugin_meta__ = {
|
||
"name": "jrcd",
|
||
"description": "来看看你的长度吧!",
|
||
"usage": "/jrcd\n/bbcd [@某人]",
|
||
}
|
||
|
||
# jrcd
|
||
JRCDMSG_1 = [
|
||
"今天的长度是%scm,可以让我一口吃掉吗罒ω罒",
|
||
"今天的长度是%scm,啥啊?怎么这么小啊?(*°ー°)v",
|
||
"今天的长度是%scm,什么嘛,原来是可爱的小豆丁呀(*°ー°)v",
|
||
]
|
||
JRCDMSG_2 = [
|
||
"今天的长度是%scm,还行,也不是不能接受(๑´ㅂ´๑)",
|
||
"今天的长度是%scm,小老弟不错啊,和哥哥一起玩会儿吗(〃∇〃)",
|
||
"今天的长度是%scm,也许我们今晚能做很多很多事情呢(〃∇〃)",
|
||
]
|
||
JRCDMSG_3 = [
|
||
"今天的长度是%scm,哦豁?听说你很勇哦?(✧◡✧)",
|
||
"今天的长度是%scm,嘶哈嘶哈(((o(*°▽°*)o)))...",
|
||
"今天的长度是%scm,我靠,让哥哥爽一-爽吧!(((o(*°▽°*)o)))...",
|
||
"今天的长度是%scm,单是看到哥哥的长度就....(〃w〃)",
|
||
]
|
||
|
||
# bbcd long
|
||
BBCDMSG1 = ["还行,可以尝试一下(๑‾ ꇴ ‾๑)"]
|
||
BBCDMSG2 = ["不错的成绩,努力一下或许可以让他受孕哦..(〃w〃)"]
|
||
BBCDMSG3 = ["好猛,试试强制让他受孕吧!!!(((o(*°▽°*)o)))"]
|
||
|
||
# bbcd short
|
||
BBCDMSG4 = ["差的不多,富贵险中求一下(*°ー°)v?"]
|
||
BBCDMSG5 = ["还行,可以尝试一下(๑‾ ꇴ ‾๑)"]
|
||
BBCDMSG6 = ["快逃!!!!!!!!(o(*°▽°*)o)"]
|
||
|
||
# bbcd equal
|
||
BBCDMSG7 = ["试试刺刀看看谁能赢吧!"]
|
||
|
||
|
||
def get_jrcd(user_id: int) -> int:
|
||
"""
|
||
根据用户ID和当前日期生成一个伪随机的“长度”值。
|
||
|
||
:param user_id: 用户QQ号。
|
||
:return: 返回一个1到30之间的整数。
|
||
"""
|
||
current_time = (
|
||
datetime.now().year * 100 + datetime.now().month * 100 + datetime.now().day
|
||
)
|
||
|
||
random.seed(hash(user_id + current_time))
|
||
jrcd = random.randint(1, 30)
|
||
random.seed()
|
||
|
||
return jrcd
|
||
|
||
|
||
@matcher.command("jrcd")
|
||
async def handle_jrcd(bot: Bot, event: MessageEvent, args: list[str]):
|
||
"""
|
||
处理 jrcd 指令,回复用户的“今日长度”。
|
||
|
||
:param bot: Bot 实例。
|
||
:param event: 消息事件对象。
|
||
:param args: 指令参数列表(未使用)。
|
||
"""
|
||
user_id = event.user_id
|
||
jrcd = await run_in_thread_pool(get_jrcd, user_id)
|
||
|
||
msg_text = ""
|
||
if jrcd <= 9:
|
||
msg_text = random.choice(JRCDMSG_1) % jrcd
|
||
elif jrcd <= 19:
|
||
msg_text = random.choice(JRCDMSG_2) % jrcd
|
||
else:
|
||
msg_text = random.choice(JRCDMSG_3) % jrcd
|
||
|
||
reply_segments = [MessageSegment.at(user_id), MessageSegment.from_text(msg_text)]
|
||
await event.reply(reply_segments)
|
||
|
||
|
||
@matcher.command("bbcd")
|
||
async def handle_bbcd(bot: Bot, event: MessageEvent, args: list[str]):
|
||
"""
|
||
处理 bbcd 指令,比较两位用户的“长度”。
|
||
|
||
:param bot: Bot 实例。
|
||
:param event: 消息事件对象。
|
||
:param args: 指令参数列表(未使用)。
|
||
"""
|
||
message = event.message
|
||
print(message)
|
||
if len(message) < 2:
|
||
return
|
||
|
||
user_id1 = event.user_id
|
||
try:
|
||
user_id2 = int(message[1].data.get("qq", 0))
|
||
except Exception:
|
||
return
|
||
|
||
if user_id1 == user_id2:
|
||
await event.reply("不能和自己比!")
|
||
return
|
||
|
||
jrcd1 = await run_in_thread_pool(get_jrcd, user_id1)
|
||
jrcd2 = await run_in_thread_pool(get_jrcd, user_id2)
|
||
|
||
jrcz = jrcd1 - jrcd2
|
||
|
||
text_part = ""
|
||
if jrcz == 0:
|
||
text_part = f" 一样长。{random.choice(BBCDMSG7)}"
|
||
elif jrcz > 0:
|
||
text_part = f" 长{jrcz}cm。"
|
||
if jrcz <= 9:
|
||
text_part += random.choice(BBCDMSG1)
|
||
elif jrcz <= 19:
|
||
text_part += random.choice(BBCDMSG2)
|
||
else:
|
||
text_part += random.choice(BBCDMSG3)
|
||
else: # jrcz < 0
|
||
text_part = f" 短{abs(jrcz)}cm。"
|
||
if jrcz >= -9:
|
||
text_part += random.choice(BBCDMSG4)
|
||
elif jrcz >= -19:
|
||
text_part += random.choice(BBCDMSG5)
|
||
else:
|
||
text_part += random.choice(BBCDMSG6)
|
||
|
||
segments = [
|
||
MessageSegment.at(user_id1),
|
||
MessageSegment.from_text(" 你的长度比 "),
|
||
MessageSegment.at(user_id2),
|
||
MessageSegment.from_text(text_part),
|
||
]
|
||
|
||
await event.reply(segments)
|