Skip to content

Commit

Permalink
Merge pull request #27 from Agnes4m/dev-main
Browse files Browse the repository at this point in the history
修复重复构造图片的bug
  • Loading branch information
Agnes4m authored Aug 3, 2023
2 parents f25504d + 2298611 commit 6a3de14
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 35 deletions.
12 changes: 6 additions & 6 deletions nonebot_plugin_l4d2_server/l4d2_queries/qqgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import aiofiles
from nonebot.log import logger

from nonebot_plugin_l4d2_server.l4d2_data.serverip import L4D2Server
from nonebot_plugin_l4d2_server.l4d2_image import server_ip_pic
from nonebot_plugin_l4d2_server.l4d2_queries.local_ip import ALL_HOST
from nonebot_plugin_l4d2_server.l4d2_queries.utils import (
from ..l4d2_data.serverip import L4D2Server
from ..l4d2_image import server_ip_pic
from ..l4d2_utils.message import KAILAO, PRISON, QUEREN
from ..l4d2_utils.utils import split_maohao
from .local_ip import ALL_HOST
from .utils import (
msg_ip_to_list,
player_queries,
player_queries_anne_dict,
queries,
queries_dict,
)
from nonebot_plugin_l4d2_server.l4d2_utils.message import KAILAO, PRISON, QUEREN
from nonebot_plugin_l4d2_server.l4d2_utils.utils import split_maohao

try:
import ujson as json
Expand Down
9 changes: 4 additions & 5 deletions nonebot_plugin_l4d2_server/l4d2_queries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,19 @@ async def queries_server(msg: list) -> str:
return msgs


async def get_anne_server_ip(ip, ismsg: bool = False):
async def get_anne_server_ip(ip: str, ismsg: bool = False):
"""输出查询ip和ping"""
if ismsg:
...
host, port = split_maohao(ip)
data = await queries_server([host, port])

if l4_config.l4_image:
data = mode_txt_to_img(
await mode_txt_to_img(
data.split("\n")[0],
data.replace(data.split("\n")[0], f"\nconnect {ip}"),
)
else:
data += f"\nconnect {ip}"
return None
data += f"\nconnect {ip}"
return data


Expand Down
39 changes: 15 additions & 24 deletions nonebot_plugin_l4d2_server/l4d2_utils/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from typing import Dict, List, Tuple, Type

from nonebot import on_command, on_keyword, on_notice, on_regex
from nonebot.adapters.onebot.v11 import Message, MessageSegment
from nonebot.adapters import Message
from nonebot.log import logger
from nonebot.matcher import Matcher
from nonebot.params import CommandArg, CommandStart, RawCommand
from nonebot_plugin_saa import Image, MessageFactory
from nonebot_plugin_saa import Image, MessageFactory, Text

from ..l4d2_anne.server import group_key, server_key
from ..l4d2_queries import get_group_ip_to_msg
Expand Down Expand Up @@ -205,21 +205,15 @@ async def _(
command = "云"
msg: str = args.extract_plain_text()
push_msg = await get_ip_to_mes(msg, command)
if not push_msg:
if push_msg is None:
return
if isinstance(push_msg, Message):
logger.info("构造")
try:
await matcher.finish(push_msg)
except Exception as E:
logger.warning(E)
return
elif isinstance(push_msg, bytes):

if isinstance(push_msg, bytes):
logger.info("直接发送图片")
send_msg = MessageSegment.image(push_msg)
await MessageFactory([Image(push_msg)]).finish()
elif msg and type(push_msg) == list:
logger.info("更加构造函数")
send_msg = Message(MessageSegment.image(push_msg[0]) + push_msg[-1])
await MessageFactory([Image(push_msg[0]), Text(push_msg[-1])]).finish()
elif msg and isinstance(push_msg, str):
send_msg = push_msg
else:
Expand Down Expand Up @@ -248,10 +242,7 @@ async def get_ip_to_mes(msg: str, command: str = ""):
msg_tuple = (one_ip["id"], host, port)
ip_list.append(msg_tuple)
img = await qq_ip_queries_pic(ip_list, igr)
try:
await MessageFactory([Image(img)]).finish() if img else "服务器无响应"
except Exception:
return img if img else "服务器无响应"
return img if img else None

if not msg[0].isdigit():
# if any(mode in msg for mode in gamemode_list):
Expand All @@ -266,7 +257,10 @@ async def get_ip_to_mes(msg: str, command: str = ""):
logger.info(ip)

try:
return await get_anne_server_ip(ip)
msg_send = await get_anne_server_ip(ip)
if msg_send:
return msg_send

except (OSError, asyncio.exceptions.TimeoutError):
return "服务器无响应"

Expand All @@ -287,15 +281,12 @@ async def _(
msg: str = args.extract_plain_text()
push_msg = await get_group_ip_to_msg(msg, command)
if isinstance(push_msg, bytes):
send_msg = MessageSegment.image(push_msg)
await MessageFactory([Image(push_msg)]).finish()
elif msg and type(push_msg) == list:
send_msg = Message(MessageSegment.image(push_msg[0]) + push_msg[-1])
await MessageFactory([Image(push_msg[0]), Text(push_msg[-1])]).finish()
elif msg and isinstance(push_msg, str):
await str_to_picstr(push_msg, matcher)
return
else:
return
await matcher.finish(send_msg)
await matcher.finish()


# tests = on_command("测试1")
Expand Down

0 comments on commit 6a3de14

Please sign in to comment.