1. 修复qq频道发不了图片的问题

This commit is contained in:
Soulter
2023-09-14 08:39:05 +08:00
parent 5852f36557
commit 8352fc269b
4 changed files with 64 additions and 24 deletions
+23 -2
View File
@@ -19,6 +19,8 @@ class QQ:
self.is_start = is_start
self.gocq_loop = gocq_loop
self.cc = cc
self.waiting = {}
self.gocq_cnt = 0
def run_bot(self, gocq):
self.client: CQHTTP = gocq
@@ -26,11 +28,17 @@ class QQ:
def get_msg_loop(self):
return self.gocq_loop
def get_cnt(self):
return self.gocq_cnt
def set_cnt(self, cnt):
self.gocq_cnt = cnt
async def send_qq_msg(self,
source,
res):
self.gocq_cnt += 1
if not self.is_start:
raise Exception("管理员未启动GOCQ平台")
"""
@@ -46,7 +54,7 @@ class QQ:
if isinstance(res, str):
res_str = res
res = []
if source.type == "GroupMessage":
if source.type == "GroupMessage" and not isinstance(source, FakeSource):
res.append(At(qq=source.user_id))
res.append(Plain(text=res_str))
@@ -142,3 +150,16 @@ class QQ:
return p
except Exception as e:
raise e
def wait_for_message(self, group_id):
'''
等待下一条消息
'''
self.waiting[group_id] = ''
while True:
if group_id in self.waiting and self.waiting[group_id] != '':
# 去掉
ret = self.waiting[group_id]
del self.waiting[group_id]
return ret
time.sleep(0.5)
+13 -2
View File
@@ -34,6 +34,14 @@ class NakuruGuildMessage():
return str(self.__dict__)
class QQChan():
def __init__(self, cnt: dict = None) -> None:
self.qqchan_cnt = 0
def get_cnt(self):
return self.qqchan_cnt
def set_cnt(self, cnt):
self.qqchan_cnt = cnt
def run_bot(self, botclient, appid, token):
intents = botpy.Intents(public_guild_messages=True, direct_message=True)
@@ -48,7 +56,10 @@ class QQChan():
if isinstance(i, Plain):
plain_text += i.text
elif isinstance(i, Image) and image_path == None:
image_path = i.file
if i.path is not None:
image_path = i.path
else:
image_path = i.file
return plain_text, image_path
# gocq-频道SDK兼容层(收)
@@ -92,7 +103,7 @@ class QQChan():
def send_qq_msg(self, message: NakuruGuildMessage, res, msg_ref = None):
gu.log("回复QQ频道消息: "+str(res), level=gu.LEVEL_INFO, tag="QQ频道", max_len=500)
self.qqchan_cnt += 1
plain_text = ""
image_path = None
if isinstance(res, list):