mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 08:26:53 +08:00
fix(agent): grant channel owners admin access
This commit is contained in:
@@ -3,7 +3,11 @@ from typing import Any, List, Optional, Tuple, Union
|
||||
|
||||
from app.core.cache import TTLCache
|
||||
from app.core.context import Context, MediaInfo
|
||||
from app.helper.agent import matches_channel_admin
|
||||
from app.helper.agent import (
|
||||
matches_channel_admin,
|
||||
register_channel_admin_resolver,
|
||||
resolve_config_principal_ids,
|
||||
)
|
||||
from app.log import logger
|
||||
from app.modules import _MessageBase, _ModuleBase
|
||||
from app.modules.wechatclawbot.wechatclawbot import WechatClawBot
|
||||
@@ -11,6 +15,14 @@ from app.schemas import CommingMessage, Notification
|
||||
from app.schemas.types import MessageChannel, ModuleType
|
||||
|
||||
|
||||
register_channel_admin_resolver(
|
||||
MessageChannel.WechatClawBot,
|
||||
lambda config: resolve_config_principal_ids(
|
||||
config, "WECHATCLAWBOT_ADMINS", "WECHATCLAWBOT_DEFAULT_TARGET"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class WechatClawBotModule(_ModuleBase, _MessageBase[WechatClawBot]):
|
||||
def __init__(self):
|
||||
"""初始化模块级去重缓存,拦截 iLink 偶发的重复回放消息。"""
|
||||
@@ -182,7 +194,12 @@ class WechatClawBotModule(_ModuleBase, _MessageBase[WechatClawBot]):
|
||||
]
|
||||
callback_data = text[9:].strip() if text.startswith("CALLBACK:") else ""
|
||||
is_admin_command = text.startswith("/") or callback_data.startswith("/")
|
||||
if is_admin_command and admins and user_id not in admins:
|
||||
is_channel_admin = matches_channel_admin(
|
||||
MessageChannel.WechatClawBot,
|
||||
client_config.config,
|
||||
user_id,
|
||||
)
|
||||
if is_admin_command and admins and not is_channel_admin:
|
||||
client = self.get_instance(client_config.name)
|
||||
if client:
|
||||
client.send_msg(title="只有管理员才有权限执行此命令", userid=user_id)
|
||||
@@ -199,9 +216,7 @@ class WechatClawBotModule(_ModuleBase, _MessageBase[WechatClawBot]):
|
||||
source=client_config.name,
|
||||
userid=user_id,
|
||||
username=username,
|
||||
is_channel_admin=matches_channel_admin(
|
||||
client_config.config, "WECHATCLAWBOT_ADMINS", user_id
|
||||
),
|
||||
is_channel_admin=is_channel_admin,
|
||||
text=text,
|
||||
message_id=message_id,
|
||||
chat_id=str(message.get("chat_id") or "") or None,
|
||||
|
||||
Reference in New Issue
Block a user