zhayujie пре 10 месеци
родитељ
комит
4536f9c177
3 измењених фајлова са 38 додато и 8 уклоњено
  1. +8
    -3
      bot/linkai/link_ai_bot.py
  2. +26
    -3
      channel/wechat/wechat_channel.py
  3. +4
    -2
      common/linkai_client.py

+ 8
- 3
bot/linkai/link_ai_bot.py Прегледај датотеку

@@ -360,7 +360,9 @@ class LinkAIBot(Bot):
suffix += f"{turn.get('thought')}\n"
if plugin_name:
plugin_list.append(turn.get('plugin_name'))
suffix += f"{turn.get('plugin_icon')} {turn.get('plugin_name')}"
if turn.get('plugin_icon'):
suffix += f"{turn.get('plugin_icon')} "
suffix += f"{turn.get('plugin_name')}"
if turn.get('plugin_input'):
suffix += f":{turn.get('plugin_input')}"
if i < len(chain) - 1:
@@ -385,12 +387,15 @@ class LinkAIBot(Bot):
return
try:
for url in image_urls:
reply = Reply(ReplyType.IMAGE_URL, url)
if url.endswith(".mp4"):
reply_type = ReplyType.VIDEO_URL
else:
reply_type = ReplyType.IMAGE_URL
reply = Reply(reply_type, url)
channel.send(reply, context)
except Exception as e:
logger.error(e)


class LinkAISessionManager(SessionManager):
def session_msg_query(self, query, session_id):
session = self.build_session(session_id)


+ 26
- 3
channel/wechat/wechat_channel.py Прегледај датотеку

@@ -95,7 +95,7 @@ def qrCallback(uuid, status, qrcode):
print(qr_api4)
print(qr_api2)
print(qr_api1)
_send_qr_code([qr_api1, qr_api2, qr_api3, qr_api4])
qr = qrcode.QRCode(border=1)
qr.add_data(url)
qr.make(fit=True)
@@ -131,12 +131,15 @@ class WechatChannel(ChatChannel):
itchat.run()

def exitCallback(self):
_send_logout()
time.sleep(3)
self.auto_login_times += 1
if self.auto_login_times < 100:
self.startup()

def loginCallback(self):
pass
logger.debug("Login success")
_send_login_success()

# handle_* 系列函数处理收到的消息后构造Context,然后传入produce函数中处理Context和发送回复
# Context包含了消息的所有信息,包括以下属性
@@ -149,7 +152,6 @@ class WechatChannel(ChatChannel):
# msg: ChatMessage消息对象
# origin_ctype: 原始消息类型,语音转文字后,私聊时如果匹配前缀失败,会根据初始消息是否是语音来放宽触发规则
# desire_rtype: 希望回复类型,默认是文本回复,设置为ReplyType.VOICE是语音回复

@time_checker
@_check
def handle_single(self, cmsg: ChatMessage):
@@ -245,3 +247,24 @@ class WechatChannel(ChatChannel):
video_storage.seek(0)
itchat.send_video(video_storage, toUserName=receiver)
logger.info("[WX] sendVideo url={}, receiver={}".format(video_url, receiver))

def _send_login_success():
try:
from common.linkai_client import chat_client
chat_client.send_login_success()
except Exception as e:
pass

def _send_logout():
try:
from common.linkai_client import chat_client
chat_client.send_logout()
except Exception as e:
pass

def _send_qr_code(qrcode_list: list):
try:
from common.linkai_client import chat_client
chat_client.send_qrcode(qrcode_list)
except Exception as e:
pass

+ 4
- 2
common/linkai_client.py Прегледај датотеку

@@ -4,6 +4,7 @@ from common.log import logger
from linkai import LinkAIClient, PushMsg
from config import conf

chat_client: LinkAIClient

class ChatClient(LinkAIClient):
def __init__(self, api_key, host, channel):
@@ -23,6 +24,7 @@ class ChatClient(LinkAIClient):


def start(channel):
client = ChatClient(api_key=conf().get("linkai_api_key"),
global chat_client
chat_client = ChatClient(api_key=conf().get("linkai_api_key"),
host="link-ai.chat", channel=channel)
client.start()
chat_client.start()

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