Skip to content

Commit

Permalink
update qqbot
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Jan 14, 2025
1 parent d9ec19b commit 651469d
Showing 1 changed file with 97 additions and 59 deletions.
156 changes: 97 additions & 59 deletions bots/qqbot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import filetype
from botpy.message import C2CMessage, DirectMessage, GroupMessage, Message
from botpy.errors import ServerError
from botpy.types.message import Reference

from bots.qqbot.info import *
Expand All @@ -24,6 +25,7 @@
from core.database import BotDBUtil
from core.logger import Logger
from core.utils.http import download, url_pattern
from core.utils.image import msgchain2image

enable_analytics = Config("enable_analytics", False)
enable_send_url = Config("qq_bot_enable_send_url", False, table_name="bot_qqbot")
Expand Down Expand Up @@ -107,25 +109,34 @@ async def send_message(
if images:
image_1 = images[0]
images.pop(0)
send_img = await image_1.get() if image_1 else None
msg_quote = (
Reference(
message_id=self.session.message.id,
ignore_get_message_error=False,
send_img = await image_1.get() if image_1 else None
msg_quote = (
Reference(
message_id=self.session.message.id,
ignore_get_message_error=False,
)
if quote and not send_img
else None
)
if quote and not send_img
else None
)
if not msg_quote and quote:
msg = f"<@{self.session.message.author.id}> \n" + msg
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
if not msg_quote and quote:
msg = f"<@{self.session.message.author.id}> \n" + msg
try:
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
)
except ServerError:
img_chain = filtered_msg
img_chain.insert(0, I18NContext("error.message.limited.msg2img"))
img_chain.append(image_1) if image_1 else None
imgs = await msgchain2image(img_chain, self)
if imgs:
imgs = [Image(img) for img in imgs]
images = imgs + images
if images:
for img in images:
send_img = await img.get()
Expand All @@ -140,24 +151,33 @@ async def send_message(
if images:
image_1 = images[0]
images.pop(0)
send_img = await image_1.get() if image_1 else None
msg_quote = (
Reference(
message_id=self.session.message.id,
ignore_get_message_error=False,
send_img = await image_1.get() if image_1 else None
msg_quote = (
Reference(
message_id=self.session.message.id,
ignore_get_message_error=False,
)
if quote and not send_img
else None
)
if quote and not send_img
else None
)
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
sends.append(send)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
try:
send = await self.session.message.reply(
content=msg, file_image=send_img, message_reference=msg_quote
)
sends.append(send)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
)
except ServerError:
img_chain = filtered_msg
img_chain.insert(0, I18NContext("error.message.limited.msg2img"))
img_chain.append(image_1) if image_1 else None
imgs = await msgchain2image(img_chain, self)
if imgs:
imgs = [Image(img) for img in imgs]
images = imgs + images
if images:
for img in images:
send_img = await img.get()
Expand All @@ -181,20 +201,29 @@ async def send_message(
)
if msg and self.session.message.id:
msg = "\n" + msg
send = await self.session.message.reply(
content=msg,
msg_type=7 if send_img else 0,
media=send_img,
msg_seq=seq,
)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg.strip()}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
try:
send = await self.session.message.reply(
content=msg,
msg_type=7 if send_img else 0,
media=send_img,
msg_seq=seq,
)
if send:
sends.append(send)
seq += 1
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg.strip()}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
)
if send:
sends.append(send)
seq += 1
except ServerError:
img_chain = filtered_msg
img_chain.insert(0, I18NContext("error.message.limited.msg2img"))
img_chain.append(image_1) if image_1 else None
imgs = await msgchain2image(img_chain, self)
if imgs:
imgs = [Image(img) for img in imgs]
images = imgs + images
if images:
for img in images:
send_img = await self.session.message._api.post_group_file(
Expand Down Expand Up @@ -224,20 +253,29 @@ async def send_message(
file_type=1,
file_data=await image_1.get_base64(),
)
send = await self.session.message.reply(
content=msg,
msg_type=7 if send_img else 0,
media=send_img,
msg_seq=seq,
)
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg.strip()}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
try:
send = await self.session.message.reply(
content=msg,
msg_type=7 if send_img else 0,
media=send_img,
msg_seq=seq,
)
if send:
sends.append(send)
seq += 1
Logger.info(f"[Bot] -> [{self.target.target_id}]: {msg.strip()}")
if image_1:
Logger.info(
f"[Bot] -> [{self.target.target_id}]: Image: {str(image_1.__dict__)}"
)
if send:
sends.append(send)
seq += 1
except ServerError:
img_chain = filtered_msg
img_chain.insert(0, I18NContext("error.message.limited.msg2img"))
img_chain.append(image_1) if image_1 else None
imgs = await msgchain2image(img_chain, self)
if imgs:
imgs = [Image(img) for img in imgs]
images = imgs + images
if images:
for img in images:
send_img = await self.session.message._api.post_c2c_file(
Expand Down

0 comments on commit 651469d

Please sign in to comment.