fix(race): 代码质量审查修复 + commands包拆分 + 赛马取消命令
- P1: bet.py赔率计算移入锁内防竞态 - P1: config.py TESTERS解析失败添加warning日志 - P2: 新增赛马取消命令(积分退还/任务取消/状态重置) - P3: bet.py清理未使用的_send_to_scope导入 - 将commands.py拆分为commands/包(access/bet/help/race/register) - OpenSpec变更提案: fix-race-conditions-and-logs
This commit is contained in:
31
danding_bot/plugins/group_horse_racing/commands/access.py
Normal file
31
danding_bot/plugins/group_horse_racing/commands/access.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from nonebot.adapters.onebot.v11 import Bot, Event, GroupMessageEvent, PrivateMessageEvent
|
||||
from .. import plugin_config as config
|
||||
|
||||
def get_scope(event: Event) -> str:
|
||||
"""Get room scope from event."""
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
return f"group_{event.group_id}"
|
||||
elif isinstance(event, PrivateMessageEvent):
|
||||
return f"test_{event.user_id}"
|
||||
return ""
|
||||
|
||||
|
||||
async def check_access(bot: Bot, event: Event) -> bool:
|
||||
"""Check if user has access to horse racing."""
|
||||
if isinstance(event, PrivateMessageEvent):
|
||||
if not config.TEST_MODE:
|
||||
return False
|
||||
return event.user_id in config.TESTERS
|
||||
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
if config.TEST_MODE:
|
||||
return event.group_id in config.TEST_GROUPS
|
||||
return event.group_id in config.ALLOWED_GROUPS
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_event_id(event: Event) -> str:
|
||||
"""Get user id as string from event."""
|
||||
return str(event.user_id)
|
||||
|
||||
Reference in New Issue
Block a user