Phase 1 - Plugin code review (14/14 plugins): - Security: 3x token leak in print→logger.debug, Bearer prefix handling - Bug: bare except→specific exceptions, HorseState type safety, sync→async - Critical: response_model undefined, route dead code, sync blocking event loop - Quality: 11x print()→logger, variable name shadowing, consistent logging Phase 2 - Deep analysis: - Fix: payout int truncation→max(1, round(amount*odds)) - Fix: room_store get_lock race condition→dict.setdefault() - Verify: data_manager f-string SQL is safe (uses ? placeholders) Infrastructure: review reports generated for all plugins.
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
from nonebot import on_request, get_plugin_config, logger
|
|
from nonebot.adapters.onebot.v11 import FriendRequestEvent, Bot
|
|
from .config import Config
|
|
import asyncio
|
|
import random
|
|
|
|
# 获取插件配置
|
|
plugin_config = get_plugin_config(Config)
|
|
|
|
# 注册好友请求事件处理器
|
|
friend_request = on_request(priority=5, block=True)
|
|
|
|
@friend_request.handle()
|
|
async def handle_friend_request(bot: Bot, event: FriendRequestEvent):
|
|
"""处理好友请求,根据配置自动同意并发送欢迎消息"""
|
|
|
|
if not plugin_config.auto_accept_enabled:
|
|
logger.info(f"好友请求被忽略(功能禁用): user_id={event.user_id} flag={event.flag}")
|
|
return
|
|
|
|
# 同意好友请求
|
|
try:
|
|
await bot.set_friend_add_request(flag=event.flag, approve=True)
|
|
except Exception as e:
|
|
logger.error(f"同意好友请求失败: user_id={event.user_id} flag={event.flag} error={e}")
|
|
return
|
|
|
|
logger.info(f"已自动同意好友请求: user_id={event.user_id} flag={event.flag}")
|
|
|
|
# 发送欢迎消息(如果配置了)
|
|
if not plugin_config.auto_reply_message:
|
|
return
|
|
|
|
await asyncio.sleep(random.uniform(
|
|
plugin_config.reply_delay_min,
|
|
plugin_config.reply_delay_max
|
|
))
|
|
|
|
try:
|
|
await bot.send_private_msg(
|
|
user_id=event.user_id,
|
|
message=plugin_config.auto_reply_message
|
|
)
|
|
logger.info(f"已发送欢迎消息: user_id={event.user_id}")
|
|
except Exception as e:
|
|
logger.error(f"发送欢迎消息失败: user_id={event.user_id} error={e}") |