🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -38,12 +38,12 @@ class ConfigAPI:
|
||||
Any: 配置值或默认值
|
||||
"""
|
||||
# 获取插件配置
|
||||
plugin_config = getattr(self, '_plugin_config', {})
|
||||
plugin_config = getattr(self, "_plugin_config", {})
|
||||
if not plugin_config:
|
||||
return default
|
||||
|
||||
# 支持嵌套键访问
|
||||
keys = key.split('.')
|
||||
keys = key.split(".")
|
||||
current = plugin_config
|
||||
|
||||
for k in keys:
|
||||
|
||||
@@ -157,8 +157,6 @@ class MessageAPI:
|
||||
message_type="text", content=text, platform=platform, target_id=user_id, is_group=False
|
||||
)
|
||||
|
||||
|
||||
|
||||
def get_chat_type(self) -> str:
|
||||
"""获取当前聊天类型
|
||||
|
||||
|
||||
@@ -33,7 +33,13 @@ class PluginAPI(MessageAPI, LLMAPI, DatabaseAPI, ConfigAPI, UtilsAPI, StreamAPI,
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, chat_stream=None, expressor=None, replyer=None, observations=None, log_prefix: str = "[PluginAPI]", plugin_config: dict = None
|
||||
self,
|
||||
chat_stream=None,
|
||||
expressor=None,
|
||||
replyer=None,
|
||||
observations=None,
|
||||
log_prefix: str = "[PluginAPI]",
|
||||
plugin_config: dict = None,
|
||||
):
|
||||
"""
|
||||
初始化插件API
|
||||
@@ -109,7 +115,12 @@ class PluginAPI(MessageAPI, LLMAPI, DatabaseAPI, ConfigAPI, UtilsAPI, StreamAPI,
|
||||
|
||||
# 便捷的工厂函数
|
||||
def create_plugin_api(
|
||||
chat_stream=None, expressor=None, replyer=None, observations=None, log_prefix: str = "[Plugin]", plugin_config: dict = None
|
||||
chat_stream=None,
|
||||
expressor=None,
|
||||
replyer=None,
|
||||
observations=None,
|
||||
log_prefix: str = "[Plugin]",
|
||||
plugin_config: dict = None,
|
||||
) -> PluginAPI:
|
||||
"""
|
||||
创建插件API实例的便捷函数
|
||||
@@ -126,7 +137,12 @@ def create_plugin_api(
|
||||
PluginAPI: 配置好的插件API实例
|
||||
"""
|
||||
return PluginAPI(
|
||||
chat_stream=chat_stream, expressor=expressor, replyer=replyer, observations=observations, log_prefix=log_prefix, plugin_config=plugin_config
|
||||
chat_stream=chat_stream,
|
||||
expressor=expressor,
|
||||
replyer=replyer,
|
||||
observations=observations,
|
||||
log_prefix=log_prefix,
|
||||
plugin_config=plugin_config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class BaseAction(ABC):
|
||||
Returns:
|
||||
bool: 是否发送成功
|
||||
"""
|
||||
chat_stream = self.api.get_service('chat_stream')
|
||||
chat_stream = self.api.get_service("chat_stream")
|
||||
if not chat_stream:
|
||||
logger.error(f"{self.log_prefix} 没有可用的聊天流发送回复")
|
||||
return False
|
||||
@@ -129,16 +129,12 @@ class BaseAction(ABC):
|
||||
if chat_stream.group_info:
|
||||
# 群聊
|
||||
return await self.api.send_text_to_group(
|
||||
text=content,
|
||||
group_id=str(chat_stream.group_info.group_id),
|
||||
platform=chat_stream.platform
|
||||
text=content, group_id=str(chat_stream.group_info.group_id), platform=chat_stream.platform
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
return await self.api.send_text_to_user(
|
||||
text=content,
|
||||
user_id=str(chat_stream.user_info.user_id),
|
||||
platform=chat_stream.platform
|
||||
text=content, user_id=str(chat_stream.user_info.user_id), platform=chat_stream.platform
|
||||
)
|
||||
|
||||
async def send_command(self, command_name: str, args: dict = None, display_message: str = None) -> bool:
|
||||
@@ -156,18 +152,14 @@ class BaseAction(ABC):
|
||||
"""
|
||||
try:
|
||||
# 构造命令数据
|
||||
command_data = {
|
||||
"name": command_name,
|
||||
"args": args or {}
|
||||
}
|
||||
command_data = {"name": command_name, "args": args or {}}
|
||||
|
||||
# 使用send_message_to_target方法发送命令
|
||||
chat_stream = self.api.get_service('chat_stream')
|
||||
chat_stream = self.api.get_service("chat_stream")
|
||||
if not chat_stream:
|
||||
logger.error(f"{self.log_prefix} 没有可用的聊天流发送命令")
|
||||
return False
|
||||
|
||||
|
||||
if chat_stream.group_info:
|
||||
# 群聊
|
||||
success = await self.api.send_message_to_target(
|
||||
@@ -176,7 +168,7 @@ class BaseAction(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.group_info.group_id),
|
||||
is_group=True,
|
||||
display_message=display_message or f"执行命令: {command_name}"
|
||||
display_message=display_message or f"执行命令: {command_name}",
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
@@ -186,7 +178,7 @@ class BaseAction(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.user_info.user_id),
|
||||
is_group=False,
|
||||
display_message=display_message or f"执行命令: {command_name}"
|
||||
display_message=display_message or f"执行命令: {command_name}",
|
||||
)
|
||||
|
||||
if success:
|
||||
|
||||
@@ -95,10 +95,7 @@ class BaseCommand(ABC):
|
||||
"""
|
||||
try:
|
||||
# 构造命令数据
|
||||
command_data = {
|
||||
"name": command_name,
|
||||
"args": args or {}
|
||||
}
|
||||
command_data = {"name": command_name, "args": args or {}}
|
||||
|
||||
# 使用send_message_to_target方法发送命令
|
||||
chat_stream = self.message.chat_stream
|
||||
@@ -112,7 +109,7 @@ class BaseCommand(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.group_info.group_id),
|
||||
is_group=True,
|
||||
display_message=display_message or f"执行命令: {command_name}"
|
||||
display_message=display_message or f"执行命令: {command_name}",
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
@@ -122,7 +119,7 @@ class BaseCommand(ABC):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.user_info.user_id),
|
||||
is_group=False,
|
||||
display_message=display_message or f"执行命令: {command_name}"
|
||||
display_message=display_message or f"执行命令: {command_name}",
|
||||
)
|
||||
|
||||
if success:
|
||||
|
||||
@@ -177,7 +177,7 @@ class BasePlugin(ABC):
|
||||
Any: 配置值或默认值
|
||||
"""
|
||||
# 支持嵌套键访问
|
||||
keys = key.split('.')
|
||||
keys = key.split(".")
|
||||
current = self.config
|
||||
|
||||
for k in keys:
|
||||
|
||||
@@ -164,7 +164,12 @@ class ComponentRegistry:
|
||||
if command_name:
|
||||
command_info = self.get_command_info(command_name)
|
||||
if command_info and command_info.enabled:
|
||||
return command_class, match.groupdict(), command_info.intercept_message, command_info.plugin_name
|
||||
return (
|
||||
command_class,
|
||||
match.groupdict(),
|
||||
command_info.intercept_message,
|
||||
command_info.plugin_name,
|
||||
)
|
||||
return None
|
||||
|
||||
# === 插件管理方法 ===
|
||||
@@ -216,6 +221,7 @@ class ComponentRegistry:
|
||||
"""
|
||||
# 从插件管理器获取插件实例的配置
|
||||
from src.plugin_system.core.plugin_manager import plugin_manager
|
||||
|
||||
plugin_instance = plugin_manager.get_plugin_instance(plugin_name)
|
||||
return plugin_instance.config if plugin_instance else None
|
||||
|
||||
|
||||
@@ -342,45 +342,31 @@ class CoreActionsPlugin(BasePlugin):
|
||||
|
||||
return [
|
||||
# 回复动作
|
||||
(ReplyAction.get_action_info(
|
||||
name="reply",
|
||||
description="参与聊天回复,处理文本和表情的发送"
|
||||
), ReplyAction),
|
||||
|
||||
(ReplyAction.get_action_info(name="reply", description="参与聊天回复,处理文本和表情的发送"), ReplyAction),
|
||||
# 不回复动作
|
||||
(NoReplyAction.get_action_info(
|
||||
name="no_reply",
|
||||
description="暂时不回复消息,等待新消息或超时"
|
||||
), NoReplyAction),
|
||||
|
||||
(
|
||||
NoReplyAction.get_action_info(name="no_reply", description="暂时不回复消息,等待新消息或超时"),
|
||||
NoReplyAction,
|
||||
),
|
||||
# 表情动作
|
||||
(EmojiAction.get_action_info(
|
||||
name="emoji",
|
||||
description="发送表情包辅助表达情绪"
|
||||
), EmojiAction),
|
||||
|
||||
(EmojiAction.get_action_info(name="emoji", description="发送表情包辅助表达情绪"), EmojiAction),
|
||||
# 退出专注聊天动作
|
||||
(ExitFocusChatAction.get_action_info(
|
||||
name="exit_focus_chat",
|
||||
description="退出专注聊天,从专注模式切换到普通模式"
|
||||
), ExitFocusChatAction),
|
||||
|
||||
(
|
||||
ExitFocusChatAction.get_action_info(
|
||||
name="exit_focus_chat", description="退出专注聊天,从专注模式切换到普通模式"
|
||||
),
|
||||
ExitFocusChatAction,
|
||||
),
|
||||
# 示例Command - Ping命令
|
||||
(PingCommand.get_command_info(
|
||||
name="ping",
|
||||
description="测试机器人响应,拦截后续处理"
|
||||
), PingCommand),
|
||||
|
||||
(PingCommand.get_command_info(name="ping", description="测试机器人响应,拦截后续处理"), PingCommand),
|
||||
# 示例Command - Log命令
|
||||
(LogCommand.get_command_info(
|
||||
name="log",
|
||||
description="记录消息到日志,不拦截后续处理"
|
||||
), LogCommand)
|
||||
(LogCommand.get_command_info(name="log", description="记录消息到日志,不拦截后续处理"), LogCommand),
|
||||
]
|
||||
|
||||
|
||||
# ===== 示例Command组件 =====
|
||||
|
||||
|
||||
class PingCommand(BaseCommand):
|
||||
"""Ping命令 - 测试响应,拦截消息处理"""
|
||||
|
||||
|
||||
@@ -35,12 +35,15 @@ logger = get_logger("doubao_pic_plugin")
|
||||
|
||||
# ===== Action组件 =====
|
||||
|
||||
|
||||
class DoubaoImageGenerationAction(BaseAction):
|
||||
"""豆包图片生成Action - 根据描述使用火山引擎API生成图片"""
|
||||
|
||||
# Action基本信息
|
||||
action_name = "doubao_image_generation"
|
||||
action_description = "可以根据特定的描述,生成并发送一张图片,如果没提供描述,就根据聊天内容生成,你可以立刻画好,不用等待"
|
||||
action_description = (
|
||||
"可以根据特定的描述,生成并发送一张图片,如果没提供描述,就根据聊天内容生成,你可以立刻画好,不用等待"
|
||||
)
|
||||
|
||||
# 激活设置
|
||||
focus_activation_type = ActionActivationType.LLM_JUDGE # Focus模式使用LLM判定,精确理解需求
|
||||
@@ -243,7 +246,7 @@ class DoubaoImageGenerationAction(BaseAction):
|
||||
"""发送图片"""
|
||||
try:
|
||||
# 使用聊天流信息确定发送目标
|
||||
chat_stream = self.api.get_service('chat_stream')
|
||||
chat_stream = self.api.get_service("chat_stream")
|
||||
if not chat_stream:
|
||||
logger.error(f"{self.log_prefix} 没有可用的聊天流发送图片")
|
||||
return False
|
||||
@@ -256,7 +259,7 @@ class DoubaoImageGenerationAction(BaseAction):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.group_info.group_id),
|
||||
is_group=True,
|
||||
display_message="发送生成的图片"
|
||||
display_message="发送生成的图片",
|
||||
)
|
||||
else:
|
||||
# 私聊
|
||||
@@ -266,7 +269,7 @@ class DoubaoImageGenerationAction(BaseAction):
|
||||
platform=chat_stream.platform,
|
||||
target_id=str(chat_stream.user_info.user_id),
|
||||
is_group=False,
|
||||
display_message="发送生成的图片"
|
||||
display_message="发送生成的图片",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"{self.log_prefix} 发送图片时出错: {e}")
|
||||
@@ -281,14 +284,14 @@ class DoubaoImageGenerationAction(BaseAction):
|
||||
def _cleanup_cache(cls):
|
||||
"""清理缓存,保持大小在限制内"""
|
||||
if len(cls._request_cache) > cls._cache_max_size:
|
||||
keys_to_remove = list(cls._request_cache.keys())[:-cls._cache_max_size//2]
|
||||
keys_to_remove = list(cls._request_cache.keys())[: -cls._cache_max_size // 2]
|
||||
for key in keys_to_remove:
|
||||
del cls._request_cache[key]
|
||||
|
||||
def _validate_image_size(self, image_size: str) -> bool:
|
||||
"""验证图片尺寸格式"""
|
||||
try:
|
||||
width, height = map(int, image_size.split('x'))
|
||||
width, height = map(int, image_size.split("x"))
|
||||
return 100 <= width <= 10000 and 100 <= height <= 10000
|
||||
except (ValueError, TypeError):
|
||||
return False
|
||||
@@ -380,6 +383,7 @@ class DoubaoImageGenerationAction(BaseAction):
|
||||
|
||||
# ===== 插件主类 =====
|
||||
|
||||
|
||||
@register_plugin
|
||||
class DoubaoImagePlugin(BasePlugin):
|
||||
"""豆包图片生成插件
|
||||
@@ -406,9 +410,6 @@ class DoubaoImagePlugin(BasePlugin):
|
||||
|
||||
# 添加图片生成Action
|
||||
if enable_image_generation:
|
||||
components.append((
|
||||
DoubaoImageGenerationAction.get_action_info(),
|
||||
DoubaoImageGenerationAction
|
||||
))
|
||||
components.append((DoubaoImageGenerationAction.get_action_info(), DoubaoImageGenerationAction))
|
||||
|
||||
return components
|
||||
@@ -31,6 +31,7 @@ logger = get_logger("mute_plugin")
|
||||
|
||||
# ===== Action组件 =====
|
||||
|
||||
|
||||
class MuteAction(BaseAction):
|
||||
"""智能禁言Action - 基于LLM智能判断是否需要禁言"""
|
||||
|
||||
@@ -71,7 +72,7 @@ class MuteAction(BaseAction):
|
||||
action_parameters = {
|
||||
"target": "禁言对象,必填,输入你要禁言的对象的名字",
|
||||
"duration": "禁言时长,必填,输入你要禁言的时长(秒),单位为秒,必须为数字",
|
||||
"reason": "禁言理由,可选"
|
||||
"reason": "禁言理由,可选",
|
||||
}
|
||||
|
||||
# Action使用场景
|
||||
@@ -80,7 +81,7 @@ class MuteAction(BaseAction):
|
||||
"当有人刷屏时使用",
|
||||
"当有人发了擦边,或者色情内容时使用",
|
||||
"当有人要求禁言自己时使用",
|
||||
"如果某人已经被禁言了,就不要再次禁言了,除非你想追加时间!!"
|
||||
"如果某人已经被禁言了,就不要再次禁言了,除非你想追加时间!!",
|
||||
]
|
||||
|
||||
async def execute(self) -> Tuple[bool, Optional[str]]:
|
||||
@@ -160,7 +161,7 @@ class MuteAction(BaseAction):
|
||||
success = await self.send_command(
|
||||
command_name="GROUP_BAN",
|
||||
args={"qq_id": str(user_id), "duration": str(duration_int)},
|
||||
display_message=f"禁言了 {target} {time_str}"
|
||||
display_message=f"禁言了 {target} {time_str}",
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -174,11 +175,14 @@ class MuteAction(BaseAction):
|
||||
|
||||
def _get_template_message(self, target: str, duration_str: str, reason: str) -> str:
|
||||
"""获取模板化的禁言消息"""
|
||||
templates = self.api.get_config("mute.templates", [
|
||||
templates = self.api.get_config(
|
||||
"mute.templates",
|
||||
[
|
||||
"好的,禁言 {target} {duration},理由:{reason}",
|
||||
"收到,对 {target} 执行禁言 {duration},因为{reason}",
|
||||
"明白了,禁言 {target} {duration},原因是{reason}"
|
||||
])
|
||||
"明白了,禁言 {target} {duration},原因是{reason}",
|
||||
],
|
||||
)
|
||||
|
||||
template = random.choice(templates)
|
||||
return template.format(target=target, duration=duration_str, reason=reason)
|
||||
@@ -212,6 +216,7 @@ class MuteAction(BaseAction):
|
||||
|
||||
# ===== Command组件 =====
|
||||
|
||||
|
||||
class MuteCommand(BaseCommand):
|
||||
"""禁言命令 - 手动执行禁言操作"""
|
||||
|
||||
@@ -221,11 +226,7 @@ class MuteCommand(BaseCommand):
|
||||
|
||||
command_pattern = r"^/mute\s+(?P<target>\S+)\s+(?P<duration>\d+)(?:\s+(?P<reason>.+))?$"
|
||||
command_help = "禁言指定用户,用法:/mute <用户名> <时长(秒)> [理由]"
|
||||
command_examples = [
|
||||
"/mute 用户名 300",
|
||||
"/mute 张三 600 刷屏",
|
||||
"/mute @某人 1800 违规内容"
|
||||
]
|
||||
command_examples = ["/mute 用户名 300", "/mute 张三 600 刷屏", "/mute @某人 1800 违规内容"]
|
||||
intercept_message = True # 拦截消息处理
|
||||
|
||||
async def execute(self) -> Tuple[bool, Optional[str]]:
|
||||
@@ -284,7 +285,7 @@ class MuteCommand(BaseCommand):
|
||||
success = await self.send_command(
|
||||
command_name="GROUP_BAN",
|
||||
args={"qq_id": str(user_id), "duration": str(duration_int)},
|
||||
display_message=f"禁言了 {target} {time_str}"
|
||||
display_message=f"禁言了 {target} {time_str}",
|
||||
)
|
||||
|
||||
if success:
|
||||
@@ -305,11 +306,14 @@ class MuteCommand(BaseCommand):
|
||||
|
||||
def _get_template_message(self, target: str, duration_str: str, reason: str) -> str:
|
||||
"""获取模板化的禁言消息"""
|
||||
templates = self.api.get_config("mute.templates", [
|
||||
templates = self.api.get_config(
|
||||
"mute.templates",
|
||||
[
|
||||
"✅ 已禁言 {target} {duration},理由:{reason}",
|
||||
"🔇 对 {target} 执行禁言 {duration},因为{reason}",
|
||||
"⛔ 禁言 {target} {duration},原因:{reason}"
|
||||
])
|
||||
"⛔ 禁言 {target} {duration},原因:{reason}",
|
||||
],
|
||||
)
|
||||
|
||||
template = random.choice(templates)
|
||||
return template.format(target=target, duration=duration_str, reason=reason)
|
||||
@@ -343,6 +347,7 @@ class MuteCommand(BaseCommand):
|
||||
|
||||
# ===== 插件主类 =====
|
||||
|
||||
|
||||
@register_plugin
|
||||
class MutePlugin(BasePlugin):
|
||||
"""禁言插件
|
||||
@@ -371,16 +376,10 @@ class MutePlugin(BasePlugin):
|
||||
|
||||
# 添加智能禁言Action
|
||||
if enable_smart_mute:
|
||||
components.append((
|
||||
MuteAction.get_action_info(),
|
||||
MuteAction
|
||||
))
|
||||
components.append((MuteAction.get_action_info(), MuteAction))
|
||||
|
||||
# 添加禁言命令Command
|
||||
if enable_mute_command:
|
||||
components.append((
|
||||
MuteCommand.get_command_info(),
|
||||
MuteCommand
|
||||
))
|
||||
components.append((MuteCommand.get_command_info(), MuteCommand))
|
||||
|
||||
return components
|
||||
@@ -24,6 +24,7 @@
|
||||
from typing import List, Tuple, Type, Optional
|
||||
import time
|
||||
import random
|
||||
|
||||
# 导入新插件系统
|
||||
from src.plugin_system.base.base_plugin import BasePlugin
|
||||
from src.plugin_system.base.base_plugin import register_plugin
|
||||
@@ -37,6 +38,7 @@ logger = get_logger("example_comprehensive")
|
||||
|
||||
# ===== Action组件 =====
|
||||
|
||||
|
||||
class SmartGreetingAction(BaseAction):
|
||||
"""智能问候Action - 基于关键词触发的问候系统"""
|
||||
|
||||
@@ -49,20 +51,15 @@ class SmartGreetingAction(BaseAction):
|
||||
parallel_action = False
|
||||
|
||||
# Action参数定义
|
||||
action_parameters = {
|
||||
"username": "要问候的用户名(可选)"
|
||||
}
|
||||
action_parameters = {"username": "要问候的用户名(可选)"}
|
||||
|
||||
# Action使用场景
|
||||
action_require = [
|
||||
"用户发送包含问候词汇的消息",
|
||||
"检测到新用户加入时",
|
||||
"响应友好交流需求"
|
||||
]
|
||||
action_require = ["用户发送包含问候词汇的消息", "检测到新用户加入时", "响应友好交流需求"]
|
||||
|
||||
|
||||
# ===== Command组件 =====
|
||||
|
||||
|
||||
class ComprehensiveHelpCommand(BaseCommand):
|
||||
"""综合帮助系统 - 显示所有可用命令和Action"""
|
||||
|
||||
@@ -92,21 +89,17 @@ class ComprehensiveHelpCommand(BaseCommand):
|
||||
"""显示特定命令的详细帮助"""
|
||||
# 这里可以扩展为动态获取所有注册的Command信息
|
||||
help_info = {
|
||||
"help": {
|
||||
"description": "显示帮助信息",
|
||||
"usage": "/help [命令名]",
|
||||
"examples": ["/help", "/help send"]
|
||||
},
|
||||
"help": {"description": "显示帮助信息", "usage": "/help [命令名]", "examples": ["/help", "/help send"]},
|
||||
"send": {
|
||||
"description": "发送消息到指定目标",
|
||||
"usage": "/send <group|user> <ID> <消息内容>",
|
||||
"examples": ["/send group 123456 你好", "/send user 789456 私聊"]
|
||||
"examples": ["/send group 123456 你好", "/send user 789456 私聊"],
|
||||
},
|
||||
"status": {
|
||||
"description": "查询系统状态",
|
||||
"usage": "/status [类型]",
|
||||
"examples": ["/status", "/status 系统", "/status 插件"]
|
||||
}
|
||||
"examples": ["/status", "/status 系统", "/status 插件"],
|
||||
},
|
||||
}
|
||||
|
||||
info = help_info.get(command_name.lower())
|
||||
@@ -116,10 +109,10 @@ class ComprehensiveHelpCommand(BaseCommand):
|
||||
response = f"""
|
||||
📖 命令帮助: {command_name}
|
||||
|
||||
📝 描述: {info['description']}
|
||||
⚙️ 用法: {info['usage']}
|
||||
📝 描述: {info["description"]}
|
||||
⚙️ 用法: {info["usage"]}
|
||||
💡 示例:
|
||||
{chr(10).join(f" • {example}" for example in info['examples'])}
|
||||
{chr(10).join(f" • {example}" for example in info["examples"])}
|
||||
""".strip()
|
||||
|
||||
await self.send_reply(response)
|
||||
@@ -162,7 +155,7 @@ class MessageSendCommand(BaseCommand):
|
||||
command_examples = [
|
||||
"/send group 123456789 大家好!",
|
||||
"/send user 987654321 私聊消息",
|
||||
"/send group 555666777 这是来自插件的消息"
|
||||
"/send group 555666777 这是来自插件的消息",
|
||||
]
|
||||
intercept_message = True # 拦截消息处理
|
||||
|
||||
@@ -187,18 +180,10 @@ class MessageSendCommand(BaseCommand):
|
||||
|
||||
# 根据目标类型发送消息
|
||||
if target_type == "group":
|
||||
success = await self.api.send_text_to_group(
|
||||
text=content,
|
||||
group_id=target_id,
|
||||
platform="qq"
|
||||
)
|
||||
success = await self.api.send_text_to_group(text=content, group_id=target_id, platform="qq")
|
||||
target_desc = f"群聊 {target_id}"
|
||||
elif target_type == "user":
|
||||
success = await self.api.send_text_to_user(
|
||||
text=content,
|
||||
user_id=target_id,
|
||||
platform="qq"
|
||||
)
|
||||
success = await self.api.send_text_to_user(text=content, user_id=target_id, platform="qq")
|
||||
target_desc = f"用户 {target_id}"
|
||||
else:
|
||||
await self.send_reply(f"❌ 不支持的目标类型: {target_type}")
|
||||
@@ -358,29 +343,30 @@ class MessageInfoCommand(BaseCommand):
|
||||
|
||||
# 群聊信息
|
||||
if group_info:
|
||||
info_parts.extend([
|
||||
info_parts.extend(
|
||||
[
|
||||
"",
|
||||
"👥 群聊信息:",
|
||||
f" • 群ID: {group_info.group_id}",
|
||||
f" • 群名: {getattr(group_info, 'group_name', '未知')}",
|
||||
" • 聊天类型: 群聊"
|
||||
])
|
||||
" • 聊天类型: 群聊",
|
||||
]
|
||||
)
|
||||
else:
|
||||
info_parts.extend([
|
||||
"",
|
||||
"💭 聊天类型: 私聊"
|
||||
])
|
||||
info_parts.extend(["", "💭 聊天类型: 私聊"])
|
||||
|
||||
# 流信息
|
||||
if hasattr(message, 'chat_stream') and message.chat_stream:
|
||||
if hasattr(message, "chat_stream") and message.chat_stream:
|
||||
stream = message.chat_stream
|
||||
info_parts.extend([
|
||||
info_parts.extend(
|
||||
[
|
||||
"",
|
||||
"🌊 聊天流信息:",
|
||||
f" • 流ID: {stream.stream_id}",
|
||||
f" • 创建时间: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stream.create_time))}",
|
||||
f" • 最后活跃: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stream.last_active_time))}"
|
||||
])
|
||||
f" • 最后活跃: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(stream.last_active_time))}",
|
||||
]
|
||||
)
|
||||
|
||||
response = "\n".join(info_parts)
|
||||
await self.send_reply(response)
|
||||
@@ -428,58 +414,50 @@ class ExampleComprehensivePlugin(BasePlugin):
|
||||
|
||||
# 添加Action组件
|
||||
if enable_greeting:
|
||||
components.append((
|
||||
components.append(
|
||||
(
|
||||
SmartGreetingAction.get_action_info(
|
||||
name="smart_greeting",
|
||||
description="智能问候系统,基于关键词触发"
|
||||
name="smart_greeting", description="智能问候系统,基于关键词触发"
|
||||
),
|
||||
SmartGreetingAction
|
||||
))
|
||||
SmartGreetingAction,
|
||||
)
|
||||
)
|
||||
|
||||
# 添加Command组件
|
||||
if enable_help:
|
||||
components.append((
|
||||
components.append(
|
||||
(
|
||||
ComprehensiveHelpCommand.get_command_info(
|
||||
name="comprehensive_help",
|
||||
description="综合帮助系统,显示所有命令信息"
|
||||
name="comprehensive_help", description="综合帮助系统,显示所有命令信息"
|
||||
),
|
||||
ComprehensiveHelpCommand
|
||||
))
|
||||
ComprehensiveHelpCommand,
|
||||
)
|
||||
)
|
||||
|
||||
if enable_send:
|
||||
components.append((
|
||||
components.append(
|
||||
(
|
||||
MessageSendCommand.get_command_info(
|
||||
name="message_send",
|
||||
description="消息发送命令,支持群聊和私聊"
|
||||
name="message_send", description="消息发送命令,支持群聊和私聊"
|
||||
),
|
||||
MessageSendCommand
|
||||
))
|
||||
MessageSendCommand,
|
||||
)
|
||||
)
|
||||
|
||||
if enable_echo:
|
||||
components.append((
|
||||
EchoCommand.get_command_info(
|
||||
name="echo",
|
||||
description="回声命令,重复用户输入"
|
||||
),
|
||||
EchoCommand
|
||||
))
|
||||
components.append(
|
||||
(EchoCommand.get_command_info(name="echo", description="回声命令,重复用户输入"), EchoCommand)
|
||||
)
|
||||
|
||||
if enable_info:
|
||||
components.append((
|
||||
MessageInfoCommand.get_command_info(
|
||||
name="message_info",
|
||||
description="消息信息查询,显示详细信息"
|
||||
),
|
||||
MessageInfoCommand
|
||||
))
|
||||
components.append(
|
||||
(
|
||||
MessageInfoCommand.get_command_info(name="message_info", description="消息信息查询,显示详细信息"),
|
||||
MessageInfoCommand,
|
||||
)
|
||||
)
|
||||
|
||||
if enable_dice:
|
||||
components.append((
|
||||
DiceCommand.get_command_info(
|
||||
name="dice",
|
||||
description="骰子命令,掷骰子"
|
||||
),
|
||||
DiceCommand
|
||||
))
|
||||
components.append((DiceCommand.get_command_info(name="dice", description="骰子命令,掷骰子"), DiceCommand))
|
||||
|
||||
return components
|
||||
Reference in New Issue
Block a user