refactor: extract admin check helper & harden room_store JSON parsing
- Extract duplicated admin/owner check from race.py into shared._is_admin_or_owner() - Add try/except around JSON.loads in room_store.load_rooms for corrupted data resilience - Use .get() for safer dict access in room deserialization
This commit is contained in:
@@ -132,6 +132,21 @@ def _describe_points_delta(delta: int) -> str:
|
||||
return "略有损失"
|
||||
|
||||
|
||||
async def _is_admin_or_owner(bot: Bot, event: Event) -> bool:
|
||||
"""Check if the event sender is a group admin or owner."""
|
||||
if not isinstance(event, GroupMessageEvent):
|
||||
return False
|
||||
try:
|
||||
member_info = await bot.get_group_member_info(
|
||||
group_id=event.group_id,
|
||||
user_id=int(event.get_user_id()),
|
||||
)
|
||||
return member_info.get("role", "") in ("admin", "owner")
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def _build_point_changes(room: Room, odds: dict[str, float]) -> tuple[dict[str, int], dict[str, str]]:
|
||||
point_changes: dict[str, int] = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user