MCPcopy Create free account
hub / github.com/Loping151/RoverSign / RoverSubscribe

Class RoverSubscribe

RoverSign/utils/database/rover_subscribe.py:18–145  ·  view source on GitHub ↗

群组Bot记录表 自动记录每个群最后使用的bot_self_id 当检测到bot变化时,自动更新该群所有订阅的bot_id

Source from the content-addressed store, hash-verified

16
17
18class RoverSubscribe(BaseModel, table=True):
19 """群组Bot记录表
20
21 自动记录每个群最后使用的bot_self_id
22 当检测到bot变化时,自动更新该群所有订阅的bot_id
23 """
24
25 __tablename__ = "RoverSubscribe"
26 __table_args__: Dict[str, Any] = {"extend_existing": True}
27
28 group_id: str = Field(default="", title="群组ID", unique=True)
29 bot_self_id: str = Field(default="", title="BotSelfID")
30 updated_at: Optional[int] = Field(default=None, title="最后更新时间")
31
32 @classmethod
33 @with_lock
34 @with_session
35 async def check_and_update_bot(
36 cls: Type[T_RoverSubscribe],
37 session: AsyncSession,
38 group_id: str,
39 bot_id: str,
40 bot_self_id: str,
41 ) -> bool:
42 """检查并更新群组的bot_self_id
43
44 如果bot_self_id发生变化,自动更新该群所有订阅的bot_self_id
45
46 Args:
47 group_id: 群组ID
48 bot_id: 平台 bot_id(onebot / qqgroup / ...)
49 bot_self_id: 新的bot_self_id
50
51 Returns:
52 bool: 是否发生了bot变更
53 """
54 import time
55 from gsuid_core.logger import logger
56
57 current_time = int(time.time())
58
59 logger.debug(
60 f"[库洛签到·订阅] check_and_update_bot 被调用: group_id={group_id}, bot_id={bot_id}, bot_self_id={bot_self_id}"
61 )
62
63 # 查询现有记录
64 sql = select(cls).where(cls.group_id == group_id)
65 result = await session.execute(sql)
66 existing = result.scalars().first()
67
68 if existing:
69 logger.debug(
70 f"[库洛签到·订阅] 找到现有记录: group_id={group_id}, existing.bot_self_id={existing.bot_self_id}, new_bot_self_id={bot_self_id}"
71 )
72 # 检查bot是否变化
73 if existing.bot_self_id != bot_self_id:
74 old_bot_self_id = existing.bot_self_id
75 logger.info(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected