mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
refactor: use enum to specify type
This commit is contained in:
@@ -11,6 +11,7 @@ import time
|
||||
import asyncio
|
||||
import requests
|
||||
from typing import Optional, Union
|
||||
from bridge.context import Context, ContextType
|
||||
from wechaty_puppet import MessageType, FileBox, ScanStatus # type: ignore
|
||||
from wechaty import Wechaty, Contact
|
||||
from wechaty.user import Message, Room, MiniProgram, UrlLink
|
||||
@@ -127,11 +128,9 @@ class WechatyChannel(Channel):
|
||||
try:
|
||||
if not query:
|
||||
return
|
||||
context = dict()
|
||||
context = Context(ContextType.TEXT, query)
|
||||
context['session_id'] = reply_user_id
|
||||
context['type'] = 'TEXT'
|
||||
context['content'] = query
|
||||
reply_text = super().build_reply_content(query, context)['content']
|
||||
reply_text = super().build_reply_content(query, context).content
|
||||
if reply_text:
|
||||
await self.send(conf().get("single_chat_reply_prefix") + reply_text, reply_user_id)
|
||||
except Exception as e:
|
||||
@@ -141,10 +140,8 @@ class WechatyChannel(Channel):
|
||||
try:
|
||||
if not query:
|
||||
return
|
||||
context = dict()
|
||||
context['type'] = 'IMAGE_CREATE'
|
||||
context['content'] = query
|
||||
img_url = super().build_reply_content(query, context)['content']
|
||||
context = Context(ContextType.IMAGE_CREATE, query)
|
||||
img_url = super().build_reply_content(query, context).content
|
||||
if not img_url:
|
||||
return
|
||||
# 图片下载
|
||||
@@ -165,7 +162,7 @@ class WechatyChannel(Channel):
|
||||
async def _do_send_group(self, query, group_id, group_name, group_user_id, group_user_name):
|
||||
if not query:
|
||||
return
|
||||
context = dict()
|
||||
context = Context(ContextType.TEXT, query)
|
||||
group_chat_in_one_session = conf().get('group_chat_in_one_session', [])
|
||||
if ('ALL_GROUP' in group_chat_in_one_session or \
|
||||
group_name in group_chat_in_one_session or \
|
||||
@@ -173,9 +170,7 @@ class WechatyChannel(Channel):
|
||||
context['session_id'] = str(group_id)
|
||||
else:
|
||||
context['session_id'] = str(group_id) + '-' + str(group_user_id)
|
||||
context['type'] = 'TEXT'
|
||||
context['content'] = query
|
||||
reply_text = super().build_reply_content(query, context)['content']
|
||||
reply_text = super().build_reply_content(query, context).content
|
||||
if reply_text:
|
||||
reply_text = '@' + group_user_name + ' ' + reply_text.strip()
|
||||
await self.send_group(conf().get("group_chat_reply_prefix", "") + reply_text, group_id)
|
||||
@@ -184,10 +179,8 @@ class WechatyChannel(Channel):
|
||||
try:
|
||||
if not query:
|
||||
return
|
||||
context = dict()
|
||||
context['type'] = 'IMAGE_CREATE'
|
||||
context['content'] = query
|
||||
img_url = super().build_reply_content(query, context)['content']
|
||||
context = Context(ContextType.IMAGE_CREATE, query)
|
||||
img_url = super().build_reply_content(query, context).content
|
||||
if not img_url:
|
||||
return
|
||||
# 图片发送
|
||||
|
||||
Reference in New Issue
Block a user