优化admin 内容
This commit is contained in:
@@ -255,5 +255,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
||||
|
||||
def _is_admin(self, user_id: str, gbm: GroupBotManager) -> bool:
|
||||
"""检查用户是否为管理员"""
|
||||
admin_list = gbm.get_admin_list() if gbm else []
|
||||
# admin_list 现在是 GroupBotManager 的类属性,可以直接访问
|
||||
admin_list = GroupBotManager.get_admin_list()
|
||||
return user_id in admin_list
|
||||
|
||||
3
robot.py
3
robot.py
@@ -47,7 +47,7 @@ class Robot:
|
||||
self.config = config
|
||||
self.LOG = logger
|
||||
|
||||
self.LOG.info(f"="*50)
|
||||
self.LOG.info(f"=" * 50)
|
||||
# wechat_ipad 相关属性
|
||||
self.ipad_bot: WechatAPIClient
|
||||
self.ipad_config = None
|
||||
@@ -109,6 +109,7 @@ class Robot:
|
||||
sender_email=self.config.email.get("sender_email", "bovine_liu@163.com"),
|
||||
sender_password=self.config.email.get("sender_password", "LTS9BhmX9XhS36QS")
|
||||
)
|
||||
self.gbm.admin_list = self.config.wx_config.get("admin", [])
|
||||
self.recent_msg_ids = deque(maxlen=20)
|
||||
|
||||
def init_wechat_ipad(self):
|
||||
|
||||
@@ -144,6 +144,9 @@ class GroupBotManager:
|
||||
"group_list": set() # 用于缓存 group:list
|
||||
}
|
||||
|
||||
# 管理员列表缓存
|
||||
admin_list = [] # 用于缓存管理员列表
|
||||
|
||||
@staticmethod
|
||||
def display_menu_status(group_id):
|
||||
"""显示所有功能列表及其在指定群组中的当前状态,带emoji"""
|
||||
@@ -159,8 +162,9 @@ class GroupBotManager:
|
||||
def load_local_cache():
|
||||
r = get_redis_connection()
|
||||
"""从 Redis 加载数据到本地缓存"""
|
||||
# 加载管理员列表
|
||||
group_list = r.smembers("group:list")
|
||||
# 输出group_list 列表
|
||||
# 输出group_list 列表
|
||||
logger.debug(f"group_list: {group_list}")
|
||||
GroupBotManager.local_cache["group_list"] = set(group_list)
|
||||
|
||||
@@ -334,17 +338,10 @@ class GroupBotManager:
|
||||
@staticmethod
|
||||
def get_admin_list() -> List[str]:
|
||||
"""获取管理员列表
|
||||
|
||||
返回系统管理员的微信ID列表
|
||||
直接返回缓存的 admin_list,性能更好
|
||||
"""
|
||||
# 从配置文件中获取管理员列表
|
||||
pwd = os.path.dirname(os.path.abspath(__file__))
|
||||
with open(f"{pwd}/config.yaml", "rb") as fp:
|
||||
yconfig = yaml.safe_load(fp)
|
||||
wx_config = yconfig.get("wx_config", {})
|
||||
config_admin_list = wx_config.get("admin") # self.config.get("admin_list", [])
|
||||
|
||||
return config_admin_list
|
||||
return GroupBotManager.admin_list
|
||||
|
||||
|
||||
# 示例命令
|
||||
|
||||
Reference in New Issue
Block a user