mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 03:32:33 +08:00
feat: 允许自定义命令前缀
This commit is contained in:
parent
68ddb3a6e1
commit
48cc3656bd
|
@ -20,7 +20,7 @@ class VersionCommand(operator.CommandOperator):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if await self.ap.ver_mgr.is_new_version_available():
|
if await self.ap.ver_mgr.is_new_version_available():
|
||||||
reply_str += "\n\n有新版本可用, 使用 !update 更新"
|
reply_str += "\n\n有新版本可用。"
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import abc
|
import abc
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from ..core import app
|
from . import app
|
||||||
|
|
||||||
|
|
||||||
preregistered_migrations: list[typing.Type[Migration]] = []
|
preregistered_migrations: list[typing.Type[Migration]] = []
|
21
pkg/core/migrations/m011_command_prefix_config.py
Normal file
21
pkg/core/migrations/m011_command_prefix_config.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from .. import migration
|
||||||
|
|
||||||
|
|
||||||
|
@migration.migration_class("command-prefix-config", 11)
|
||||||
|
class CommandPrefixConfigMigration(migration.Migration):
|
||||||
|
"""迁移"""
|
||||||
|
|
||||||
|
async def need_migrate(self) -> bool:
|
||||||
|
"""判断当前环境是否需要运行此迁移"""
|
||||||
|
return 'command-prefix' not in self.ap.command_cfg.data
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
"""执行迁移"""
|
||||||
|
|
||||||
|
self.ap.command_cfg.data['command-prefix'] = [
|
||||||
|
"!", "!"
|
||||||
|
]
|
||||||
|
|
||||||
|
await self.ap.command_cfg.dump_config()
|
|
@ -3,10 +3,10 @@ from __future__ import annotations
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
from .. import stage, app
|
from .. import stage, app
|
||||||
from ...config import migration
|
from .. import migration
|
||||||
from ...config.migrations import m001_sensitive_word_migration, m002_openai_config_migration, m003_anthropic_requester_cfg_completion, m004_moonshot_cfg_completion
|
from ..migrations import m001_sensitive_word_migration, m002_openai_config_migration, m003_anthropic_requester_cfg_completion, m004_moonshot_cfg_completion
|
||||||
from ...config.migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_qcg_center_url, m008_ad_fixwin_config_migrate, m009_msg_truncator_cfg
|
from ..migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_qcg_center_url, m008_ad_fixwin_config_migrate, m009_msg_truncator_cfg
|
||||||
from ...config.migrations import m010_ollama_requester_config
|
from ..migrations import m010_ollama_requester_config, m011_command_prefix_config
|
||||||
|
|
||||||
|
|
||||||
@stage.stage_class("MigrationStage")
|
@stage.stage_class("MigrationStage")
|
||||||
|
|
|
@ -42,7 +42,9 @@ class Processor(stage.PipelineStage):
|
||||||
self.ap.logger.info(f"处理 {query.launcher_type.value}_{query.launcher_id} 的请求({query.query_id}): {message_text}")
|
self.ap.logger.info(f"处理 {query.launcher_type.value}_{query.launcher_id} 的请求({query.query_id}): {message_text}")
|
||||||
|
|
||||||
async def generator():
|
async def generator():
|
||||||
if message_text.startswith('!') or message_text.startswith('!'):
|
cmd_prefix = self.ap.command_cfg.data['command-prefix']
|
||||||
|
|
||||||
|
if any(message_text.startswith(prefix) for prefix in cmd_prefix):
|
||||||
async for result in self.cmd_handler.handle(query):
|
async for result in self.cmd_handler.handle(query):
|
||||||
yield result
|
yield result
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
{
|
{
|
||||||
"privilege": {}
|
"privilege": {},
|
||||||
|
"command-prefix": [
|
||||||
|
"!",
|
||||||
|
"!"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user