11from typing import List , Tuple , Type , Optional
2- from src .plugin_system import (
3- BasePlugin ,
4- register_plugin ,
5- BaseCommand ,
6- ComponentInfo ,
7- ConfigField
8- )
2+ from src .plugin_system import BasePlugin , register_plugin , BaseCommand , ComponentInfo , ConfigField
93from src .plugin_system .apis import send_api , frequency_api
104
5+
116class SetTalkFrequencyCommand (BaseCommand ):
127 """设置当前聊天的talk_frequency值"""
8+
139 command_name = "set_talk_frequency"
1410 command_description = "设置当前聊天的talk_frequency值:/chat talk_frequency <数字> 或 /chat t <数字>"
1511 command_pattern = r"^/chat\s+(?:talk_frequency|t)\s+(?P<value>[+-]?\d*\.?\d+)$"
@@ -19,35 +15,35 @@ async def execute(self) -> Tuple[bool, Optional[str], bool]:
1915 # 获取命令参数 - 使用命名捕获组
2016 if not self .matched_groups or "value" not in self .matched_groups :
2117 return False , "命令格式错误" , False
22-
18+
2319 value_str = self .matched_groups ["value" ]
2420 if not value_str :
2521 return False , "无法获取数值参数" , False
26-
22+
2723 value = float (value_str )
28-
24+
2925 # 获取聊天流ID
3026 if not self .message .chat_stream or not hasattr (self .message .chat_stream , "stream_id" ):
3127 return False , "无法获取聊天流信息" , False
32-
28+
3329 chat_id = self .message .chat_stream .stream_id
34-
30+
3531 # 设置talk_frequency
3632 frequency_api .set_talk_frequency_adjust (chat_id , value )
37-
33+
3834 final_value = frequency_api .get_current_talk_value (chat_id )
3935 adjust_value = frequency_api .get_talk_frequency_adjust (chat_id )
4036 base_value = final_value / adjust_value
41-
37+
4238 # 发送反馈消息(不保存到数据库)
4339 await send_api .text_to_stream (
4440 f"已设置当前聊天的talk_frequency调整值为: { value } \n 当前talk_value: { final_value :.2f} \n 发言频率调整: { adjust_value :.2f} \n 基础值: { base_value :.2f} " ,
4541 chat_id ,
46- storage_message = False
42+ storage_message = False ,
4743 )
48-
44+
4945 return True , None , False
50-
46+
5147 except ValueError :
5248 error_msg = "数值格式错误,请输入有效的数字"
5349 await self .send_text (error_msg , storage_message = False )
@@ -60,6 +56,7 @@ async def execute(self) -> Tuple[bool, Optional[str], bool]:
6056
6157class ShowFrequencyCommand (BaseCommand ):
6258 """显示当前聊天的频率控制状态"""
59+
6360 command_name = "show_frequency"
6461 command_description = "显示当前聊天的频率控制状态:/chat show 或 /chat s"
6562 command_pattern = r"^/chat\s+(?:show|s)$"
@@ -116,11 +113,7 @@ class BetterFrequencyPlugin(BasePlugin):
116113 config_file_name : str = "config.toml"
117114
118115 # 配置节描述
119- config_section_descriptions = {
120- "plugin" : "插件基本信息" ,
121- "frequency" : "频率控制配置" ,
122- "features" : "功能开关配置"
123- }
116+ config_section_descriptions = {"plugin" : "插件基本信息" , "frequency" : "频率控制配置" , "features" : "功能开关配置" }
124117
125118 # 配置Schema定义
126119 config_schema : dict = {
@@ -138,13 +131,14 @@ class BetterFrequencyPlugin(BasePlugin):
138131
139132 def get_plugin_components (self ) -> List [Tuple [ComponentInfo , Type ]]:
140133 components = []
141-
134+
142135 # 根据配置决定是否注册命令组件
143136 if self .config .get ("features" , {}).get ("enable_commands" , True ):
144- components .extend ([
145- (SetTalkFrequencyCommand .get_command_info (), SetTalkFrequencyCommand ),
146- (ShowFrequencyCommand .get_command_info (), ShowFrequencyCommand ),
147- ])
148-
149-
137+ components .extend (
138+ [
139+ (SetTalkFrequencyCommand .get_command_info (), SetTalkFrequencyCommand ),
140+ (ShowFrequencyCommand .get_command_info (), ShowFrequencyCommand ),
141+ ]
142+ )
143+
150144 return components
0 commit comments