astrbot_plugin_imagestudio/tests/test_astrbot_command_adapter.py

44 行
1.8 KiB
Python

from adapters.astrbot_command_adapter import command_allowed, command_context_from_event, help_text, message_text_from_event
class FakeEvent:
unified_msg_origin = "qq:group:100"
message_str = "确认"
def get_sender_id(self):
return "user-1"
def get_group_id(self):
return "group-1"
def get_platform_name(self):
return "aiocqhttp"
def test_command_context_uses_platform_neutral_event_fields():
context = command_context_from_event(FakeEvent())
assert context.user_id == "user-1"
assert context.group_id == "group-1"
assert context.message_origin == "qq:group:100"
assert context.platform == "aiocqhttp"
assert context.message_id == ""
assert message_text_from_event(FakeEvent()) == "确认"
def test_command_adapter_reuses_allowlist_policy():
config = {"chat_access": {"group_allowlist": ["group-1"], "user_allowlist": ["user-1"]}}
context = command_context_from_event(FakeEvent())
assert command_allowed(config, "quick_profile", context)
assert command_allowed(config, "single_image", context)
assert "/影棚 快速角色" in help_text()
assert "/yp 帮助" in help_text()
def test_event_context_falls_back_for_telegram_and_discord_style_fields():
telegram = type("TelegramEvent", (), {"sender_id": 42, "group_id": -1001, "platform_name": "telegram", "message_origin": "telegram:chat:-1001"})()
discord = type("DiscordEvent", (), {"user_id": "u2", "group_id": "guild-2", "platform_name": "discord", "message_origin": "discord:guild:guild-2"})()
assert command_context_from_event(telegram).platform == "telegram"
assert command_context_from_event(telegram).group_id == "-1001"
assert command_context_from_event(discord).user_id == "u2"
assert command_context_from_event(discord).message_origin == "discord:guild:guild-2"