新增会话注册机制
This commit is contained in:
@@ -742,11 +742,12 @@ class BasicWPSInterface(PluginInterface):
|
||||
def is_enable_plugin(self) -> bool:
|
||||
return False
|
||||
|
||||
def get_webhook_url(self, message: str, user_id: int) -> str:
|
||||
def get_webhook_url(self, message: str, chat_id: int, user_id: int) -> str:
|
||||
'''
|
||||
根据消息和用户ID获取Webhook URL, 返回空字符串表示不需要回复消息
|
||||
Args:
|
||||
message: 消息内容
|
||||
chat_id: 聊天ID
|
||||
user_id: 用户ID
|
||||
Returns:
|
||||
Webhook URL
|
||||
@@ -779,9 +780,9 @@ class BasicWPSInterface(PluginInterface):
|
||||
return message
|
||||
|
||||
async def send_markdown_message(self, message: str, chat_id: int, user_id: int) -> str|None:
|
||||
webhook_url = self.get_webhook_url(message, user_id)
|
||||
webhook_url = self.get_webhook_url(message, chat_id, user_id)
|
||||
if get_internal_debug():
|
||||
logger.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, User ID: {user_id}")
|
||||
logger.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, Chat ID: {chat_id}, User ID: {user_id}")
|
||||
if webhook_url == "" or webhook_url == None:
|
||||
return None
|
||||
|
||||
@@ -1004,8 +1005,11 @@ class WPSAPI(BasicWPSInterface):
|
||||
return MAIN_WEBHOOK_URL != ""
|
||||
|
||||
@override
|
||||
def get_webhook_url(self, message: str, user_id: int) -> str:
|
||||
return MAIN_WEBHOOK_URL
|
||||
def get_webhook_url(self, message: str, chat_id: int, user_id: int) -> str:
|
||||
webhook_url = ProjectConfig().GetFile(f"webhook_url/{chat_id}",False).LoadAsText()
|
||||
if webhook_url == "":
|
||||
webhook_url = MAIN_WEBHOOK_URL
|
||||
return webhook_url
|
||||
|
||||
@override
|
||||
def get_webhook_request(self, data:Any|None) -> None:
|
||||
@@ -1048,4 +1052,24 @@ class WPSAPIHelp(WPSAPI):
|
||||
self.register_plugin("help")
|
||||
self.register_plugin("帮助")
|
||||
|
||||
class WPSAPIWebhook(WPSAPI):
|
||||
@override
|
||||
def dependencies(self) -> List[Type]:
|
||||
return [WPSAPI]
|
||||
|
||||
@override
|
||||
def is_enable_plugin(self) -> bool:
|
||||
return True
|
||||
|
||||
@override
|
||||
def wake_up(self) -> None:
|
||||
logger.Log("Info", f"{ConsoleFrontColor.GREEN}WPSAPIWebhook 插件已加载{ConsoleFrontColor.RESET}")
|
||||
self.register_plugin("chat_url_register")
|
||||
self.register_plugin("会话注册")
|
||||
|
||||
@override
|
||||
async def callback(self, message: str, chat_id: int, user_id: int) -> str|None:
|
||||
ProjectConfig().GetFile(f"webhook_url/{chat_id}",False).SaveAsText(message)
|
||||
return await self.send_markdown_message(f"会话注册成功", chat_id, user_id)
|
||||
|
||||
logger.SaveProperties()
|
||||
Reference in New Issue
Block a user