From d2bf90c6c713f729e437c646c4b0a63c19d3a9a1 Mon Sep 17 00:00:00 2001 From: lanvent Date: Thu, 20 Apr 2023 08:31:42 +0800 Subject: [PATCH] refactor: rename WechatComChannel to WechatComAppChannel --- channel/channel_factory.py | 4 ++-- ...com_channel.py => wechatcomapp_channel.py} | 22 +++++++++---------- ...com_message.py => wechatcomapp_message.py} | 2 +- config.py | 15 +++++++------ 4 files changed, 22 insertions(+), 21 deletions(-) rename channel/wechatcom/{wechatcom_channel.py => wechatcomapp_channel.py} (91%) rename channel/wechatcom/{wechatcom_message.py => wechatcomapp_message.py} (98%) diff --git a/channel/channel_factory.py b/channel/channel_factory.py index fed3234..d6625d4 100644 --- a/channel/channel_factory.py +++ b/channel/channel_factory.py @@ -30,7 +30,7 @@ def create_channel(channel_type): return WechatMPChannel(passive_reply=False) elif channel_type == "wechatcom": - from channel.wechatcom.wechatcom_channel import WechatComChannel + from channel.wechatcom.wechatcomapp_channel import WechatComAppChannel - return WechatComChannel() + return WechatComAppChannel() raise RuntimeError diff --git a/channel/wechatcom/wechatcom_channel.py b/channel/wechatcom/wechatcomapp_channel.py similarity index 91% rename from channel/wechatcom/wechatcom_channel.py rename to channel/wechatcom/wechatcomapp_channel.py index 90c7b22..a791e41 100644 --- a/channel/wechatcom/wechatcom_channel.py +++ b/channel/wechatcom/wechatcomapp_channel.py @@ -14,7 +14,7 @@ from wechatpy.exceptions import InvalidSignatureException, WeChatClientException from bridge.context import Context from bridge.reply import Reply, ReplyType from channel.chat_channel import ChatChannel -from channel.wechatcom.wechatcom_message import WechatComMessage +from channel.wechatcom.wechatcomapp_message import WechatComAppMessage from common.log import logger from common.singleton import singleton from config import conf @@ -22,16 +22,16 @@ from voice.audio_convert import any_to_amr @singleton -class WechatComChannel(ChatChannel): +class WechatComAppChannel(ChatChannel): NOT_SUPPORT_REPLYTYPE = [] def __init__(self): super().__init__() self.corp_id = conf().get("wechatcom_corp_id") - self.secret = conf().get("wechatcom_secret") - self.agent_id = conf().get("wechatcom_agent_id") - self.token = conf().get("wechatcom_token") - self.aes_key = conf().get("wechatcom_aes_key") + self.secret = conf().get("wechatcomapp_secret") + self.agent_id = conf().get("wechatcomapp_agent_id") + self.token = conf().get("wechatcomapp_token") + self.aes_key = conf().get("wechatcomapp_aes_key") print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key) logger.info( "[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format( @@ -43,9 +43,9 @@ class WechatComChannel(ChatChannel): def startup(self): # start message listener - urls = ("/wxcom", "channel.wechatcom.wechatcom_channel.Query") + urls = ("/wxcom", "channel.wechatcom.wechatcomapp_channel.Query") app = web.application(urls, globals(), autoreload=False) - port = conf().get("wechatcom_port", 8080) + port = conf().get("wechatcomapp_port", 8080) web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", port)) def send(self, reply: Reply, context: Context): @@ -111,7 +111,7 @@ class WechatComChannel(ChatChannel): class Query: def GET(self): - channel = WechatComChannel() + channel = WechatComAppChannel() params = web.input() signature = params.msg_signature timestamp = params.timestamp @@ -127,7 +127,7 @@ class Query: return echostr def POST(self): - channel = WechatComChannel() + channel = WechatComAppChannel() params = web.input() signature = params.msg_signature timestamp = params.timestamp @@ -158,7 +158,7 @@ class Query: return res else: try: - wechatcom_msg = WechatComMessage(msg, client=channel.client) + wechatcom_msg = WechatComAppMessage(msg, client=channel.client) except NotImplementedError as e: logger.debug("[wechatcom] " + str(e)) return "success" diff --git a/channel/wechatcom/wechatcom_message.py b/channel/wechatcom/wechatcomapp_message.py similarity index 98% rename from channel/wechatcom/wechatcom_message.py rename to channel/wechatcom/wechatcomapp_message.py index 9b34f11..f441a68 100644 --- a/channel/wechatcom/wechatcom_message.py +++ b/channel/wechatcom/wechatcomapp_message.py @@ -11,7 +11,7 @@ from lib import itchat from lib.itchat.content import * -class WechatComMessage(ChatMessage): +class WechatComAppMessage(ChatMessage): def __init__(self, msg, client: WeChatClient, is_group=False): super().__init__(msg) self.msg_id = msg.id diff --git a/config.py b/config.py index f6c3983..c5f09ab 100644 --- a/config.py +++ b/config.py @@ -75,13 +75,14 @@ available_setting = { "wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443 "wechatmp_app_id": "", # 微信公众平台的appID,仅服务号需要 "wechatmp_app_secret": "", # 微信公众平台的appsecret,仅服务号需要 - # wechatcom的配置 - "wechatcom_token": "", # 企业微信的token - "wechatcom_port": 9898, # 企业微信的服务端口,不需要端口转发 - "wechatcom_corp_id": "", # 企业微信的corpID - "wechatcom_secret": "", # 企业微信的secret - "wechatcom_agent_id": "", # 企业微信的appID - "wechatcom_aes_key": "", # 企业微信的aes_key + # wechatcom的通用配置 + "wechatcom_corp_id": "", # 企业微信公司的corpID + # wechatcomapp的配置 + "wechatcomapp_token": "", # 企业微信app的token + "wechatcomapp_port": 9898, # 企业微信app的服务端口,不需要端口转发 + "wechatcomapp_secret": "", # 企业微信app的secret + "wechatcomapp_agent_id": "", # 企业微信app的agent_id + "wechatcomapp_aes_key": "", # 企业微信app的aes_key # chatgpt指令自定义触发词 "clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头 # channel配置