优化admin 内容
This commit is contained in:
@@ -255,5 +255,6 @@ class RobotMenuPlugin(MessagePluginInterface):
|
|||||||
|
|
||||||
def _is_admin(self, user_id: str, gbm: GroupBotManager) -> bool:
|
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
|
return user_id in admin_list
|
||||||
|
|||||||
1
robot.py
1
robot.py
@@ -109,6 +109,7 @@ class Robot:
|
|||||||
sender_email=self.config.email.get("sender_email", "bovine_liu@163.com"),
|
sender_email=self.config.email.get("sender_email", "bovine_liu@163.com"),
|
||||||
sender_password=self.config.email.get("sender_password", "LTS9BhmX9XhS36QS")
|
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)
|
self.recent_msg_ids = deque(maxlen=20)
|
||||||
|
|
||||||
def init_wechat_ipad(self):
|
def init_wechat_ipad(self):
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ class GroupBotManager:
|
|||||||
"group_list": set() # 用于缓存 group:list
|
"group_list": set() # 用于缓存 group:list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 管理员列表缓存
|
||||||
|
admin_list = [] # 用于缓存管理员列表
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def display_menu_status(group_id):
|
def display_menu_status(group_id):
|
||||||
"""显示所有功能列表及其在指定群组中的当前状态,带emoji"""
|
"""显示所有功能列表及其在指定群组中的当前状态,带emoji"""
|
||||||
@@ -159,6 +162,7 @@ class GroupBotManager:
|
|||||||
def load_local_cache():
|
def load_local_cache():
|
||||||
r = get_redis_connection()
|
r = get_redis_connection()
|
||||||
"""从 Redis 加载数据到本地缓存"""
|
"""从 Redis 加载数据到本地缓存"""
|
||||||
|
# 加载管理员列表
|
||||||
group_list = r.smembers("group:list")
|
group_list = r.smembers("group:list")
|
||||||
# 输出group_list 列表
|
# 输出group_list 列表
|
||||||
logger.debug(f"group_list: {group_list}")
|
logger.debug(f"group_list: {group_list}")
|
||||||
@@ -334,17 +338,10 @@ class GroupBotManager:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_admin_list() -> List[str]:
|
def get_admin_list() -> List[str]:
|
||||||
"""获取管理员列表
|
"""获取管理员列表
|
||||||
|
|
||||||
返回系统管理员的微信ID列表
|
返回系统管理员的微信ID列表
|
||||||
|
直接返回缓存的 admin_list,性能更好
|
||||||
"""
|
"""
|
||||||
# 从配置文件中获取管理员列表
|
return GroupBotManager.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
|
|
||||||
|
|
||||||
|
|
||||||
# 示例命令
|
# 示例命令
|
||||||
|
|||||||
Reference in New Issue
Block a user