Files
NeoBot/plugins/jrcd.py
镀铬酸钾 393227fdd2 Dev (#77)
* fix(discord): 修复 WebSocket 连接检测并增强跨平台文件处理

修复 Discord WebSocket 连接检测逻辑,使用正确的属性检查连接状态
为跨平台消息处理添加文件类型支持,并增加详细的调试日志
优化附件处理逻辑,确保所有文件类型都能正确识别和转发

* feat(跨平台): 优化消息处理并添加纯文本提取功能

添加 extract_text_only 函数过滤非文本标记
修改翻译逻辑仅处理纯文本内容
完善附件处理和消息内容拼接
修复仅包含表情时的消息处理问题

* refactor(discord-cross): 使用模块专用日志记录器替换全局日志记录器

将各模块中的全局日志记录器替换为模块专用日志记录器,以提供更清晰的日志来源标识
同时在适配器中添加会话状态检查和重连机制,提升消息发送的可靠性

* feat(翻译): 改进翻译功能,同时显示原文和译文

修改翻译功能,不再替换原文而是同时显示原文和翻译内容,方便用户对照
更新 DeepSeek API 配置为官方地址和模型
优化 Discord 适配器的重连逻辑,直接关闭 WebSocket 触发重连
修复 Discord 频道 ID 转换逻辑,简化处理流程

* feat(cross-platform): 添加跨平台功能支持及配置优化

- 新增跨平台配置模型和全局配置支持
- 优化 Discord 适配器的连接管理和错误处理
- 添加 watchdog 和 discord.py 依赖
- 创建 DeepSeek API 配置文档
- 移除重复的同步帮助图片代码
- 改进跨平台插件配置加载逻辑

* fix(jrcd): 修正群组ID检查条件

删除不再使用的示例插件文件
2026-03-23 16:52:15 +08:00

189 lines
5.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
今日人品插件
提供 /jrcd 和 /bbcd 指令,用于娱乐。
"""
import random
from datetime import datetime
from core.bot import Bot
from core.managers.command_manager import matcher
from core.managers.redis_manager import redis_manager
from core.utils.executor import run_in_thread_pool
from models.events.message import MessageEvent, MessageSegment
from core.utils.logger import logger
__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]):
if event.group_id == 831797331:
return None
"""
处理 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)
# 使用 Lua 脚本原子化地增加总调用次数
lua_script = "return redis.call('INCR', KEYS[1])"
try:
total_calls = await redis_manager.execute_lua_script(
script=lua_script,
keys=["neobot:jrcd:total_calls"],
args=[]
)
if total_calls:
logger.info(f"jrcd 总调用次数: {total_calls}")
except Exception as e:
logger.error(f"jrcd 插件增加调用次数失败: {e}")
@matcher.command("jrcd_stats")
async def handle_jrcd_stats(bot: Bot, event: MessageEvent, args: list[str]):
"""
处理 jrcd_stats 指令,查询 /jrcd 的总调用次数。
:param bot: Bot 实例。
:param event: 消息事件对象。
:param args: 指令参数列表(未使用)。
"""
total_calls = await redis_manager.get("neobot:jrcd:total_calls")
if not total_calls:
total_calls = 0
reply_text = f"/jrcd 指令已被大家调用了 {total_calls} 次啦!"
await event.reply(reply_text)
@matcher.command("bbcd")
async def handle_bbcd(bot: Bot, event: MessageEvent, args: list[str]):
if event.group_id == 831797331:
return None
"""
处理 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)