Преглед изворни кода

refactor: rename WechatComChannel to WechatComAppChannel

master
lanvent пре 1 година
родитељ
комит
d2bf90c6c7
4 измењених фајлова са 22 додато и 21 уклоњено
  1. +2
    -2
      channel/channel_factory.py
  2. +11
    -11
      channel/wechatcom/wechatcomapp_channel.py
  3. +1
    -1
      channel/wechatcom/wechatcomapp_message.py
  4. +8
    -7
      config.py

+ 2
- 2
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

channel/wechatcom/wechatcom_channel.py → 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"

channel/wechatcom/wechatcom_message.py → 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

+ 8
- 7
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配置


Loading…
Откажи
Сачувај