refactor: rename WechatComChannel to WechatComAppChannel

This commit is contained in:
lanvent
2023-04-20 08:31:42 +08:00
parent 3ea8781381
commit d2bf90c6c7
4 changed files with 22 additions and 21 deletions

View File

@@ -30,7 +30,7 @@ def create_channel(channel_type):
return WechatMPChannel(passive_reply=False) return WechatMPChannel(passive_reply=False)
elif channel_type == "wechatcom": elif channel_type == "wechatcom":
from channel.wechatcom.wechatcom_channel import WechatComChannel from channel.wechatcom.wechatcomapp_channel import WechatComAppChannel
return WechatComChannel() return WechatComAppChannel()
raise RuntimeError raise RuntimeError

View File

@@ -14,7 +14,7 @@ from wechatpy.exceptions import InvalidSignatureException, WeChatClientException
from bridge.context import Context from bridge.context import Context
from bridge.reply import Reply, ReplyType from bridge.reply import Reply, ReplyType
from channel.chat_channel import ChatChannel 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.log import logger
from common.singleton import singleton from common.singleton import singleton
from config import conf from config import conf
@@ -22,16 +22,16 @@ from voice.audio_convert import any_to_amr
@singleton @singleton
class WechatComChannel(ChatChannel): class WechatComAppChannel(ChatChannel):
NOT_SUPPORT_REPLYTYPE = [] NOT_SUPPORT_REPLYTYPE = []
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.corp_id = conf().get("wechatcom_corp_id") self.corp_id = conf().get("wechatcom_corp_id")
self.secret = conf().get("wechatcom_secret") self.secret = conf().get("wechatcomapp_secret")
self.agent_id = conf().get("wechatcom_agent_id") self.agent_id = conf().get("wechatcomapp_agent_id")
self.token = conf().get("wechatcom_token") self.token = conf().get("wechatcomapp_token")
self.aes_key = conf().get("wechatcom_aes_key") self.aes_key = conf().get("wechatcomapp_aes_key")
print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key) print(self.corp_id, self.secret, self.agent_id, self.token, self.aes_key)
logger.info( logger.info(
"[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format( "[wechatcom] init: corp_id: {}, secret: {}, agent_id: {}, token: {}, aes_key: {}".format(
@@ -43,9 +43,9 @@ class WechatComChannel(ChatChannel):
def startup(self): def startup(self):
# start message listener # start message listener
urls = ("/wxcom", "channel.wechatcom.wechatcom_channel.Query") urls = ("/wxcom", "channel.wechatcom.wechatcomapp_channel.Query")
app = web.application(urls, globals(), autoreload=False) 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)) web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", port))
def send(self, reply: Reply, context: Context): def send(self, reply: Reply, context: Context):
@@ -111,7 +111,7 @@ class WechatComChannel(ChatChannel):
class Query: class Query:
def GET(self): def GET(self):
channel = WechatComChannel() channel = WechatComAppChannel()
params = web.input() params = web.input()
signature = params.msg_signature signature = params.msg_signature
timestamp = params.timestamp timestamp = params.timestamp
@@ -127,7 +127,7 @@ class Query:
return echostr return echostr
def POST(self): def POST(self):
channel = WechatComChannel() channel = WechatComAppChannel()
params = web.input() params = web.input()
signature = params.msg_signature signature = params.msg_signature
timestamp = params.timestamp timestamp = params.timestamp
@@ -158,7 +158,7 @@ class Query:
return res return res
else: else:
try: try:
wechatcom_msg = WechatComMessage(msg, client=channel.client) wechatcom_msg = WechatComAppMessage(msg, client=channel.client)
except NotImplementedError as e: except NotImplementedError as e:
logger.debug("[wechatcom] " + str(e)) logger.debug("[wechatcom] " + str(e))
return "success" return "success"

View File

@@ -11,7 +11,7 @@ from lib import itchat
from lib.itchat.content import * from lib.itchat.content import *
class WechatComMessage(ChatMessage): class WechatComAppMessage(ChatMessage):
def __init__(self, msg, client: WeChatClient, is_group=False): def __init__(self, msg, client: WeChatClient, is_group=False):
super().__init__(msg) super().__init__(msg)
self.msg_id = msg.id self.msg_id = msg.id

View File

@@ -75,13 +75,14 @@ available_setting = {
"wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443 "wechatmp_port": 8080, # 微信公众平台的端口,需要端口转发到80或443
"wechatmp_app_id": "", # 微信公众平台的appID仅服务号需要 "wechatmp_app_id": "", # 微信公众平台的appID仅服务号需要
"wechatmp_app_secret": "", # 微信公众平台的appsecret仅服务号需要 "wechatmp_app_secret": "", # 微信公众平台的appsecret仅服务号需要
# wechatcom的配置 # wechatcom的通用配置
"wechatcom_token": "", # 企业微信的token "wechatcom_corp_id": "", # 企业微信公司的corpID
"wechatcom_port": 9898, # 企业微信的服务端口,不需要端口转发 # wechatcomapp的配置
"wechatcom_corp_id": "", # 企业微信的corpID "wechatcomapp_token": "", # 企业微信app的token
"wechatcom_secret": "", # 企业微信的secret "wechatcomapp_port": 9898, # 企业微信app的服务端口,不需要端口转发
"wechatcom_agent_id": "", # 企业微信appID "wechatcomapp_secret": "", # 企业微信app的secret
"wechatcom_aes_key": "", # 企业微信的aes_key "wechatcomapp_agent_id": "", # 企业微信app的agent_id
"wechatcomapp_aes_key": "", # 企业微信app的aes_key
# chatgpt指令自定义触发词 # chatgpt指令自定义触发词
"clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头 "clear_memory_commands": ["#清除记忆"], # 重置会话指令,必须以#开头
# channel配置 # channel配置