Skip to content

Commit

Permalink
修复了大量 插件化后各种功能出现的新bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoRabi committed Aug 19, 2022
1 parent 3511734 commit 6b11c87
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion core/fun/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def welcome(event: MemberJoinEvent) -> None:
await sendMsgChain(
messagechain_builder(text=info, at=personid), grouptarget=event.member.group.id)
if os.path.exists(r'./plugin/Petpet/gif.py'):
from plugin import petpet
from plugin.Petpet.gif import petpet
await petpet(personid)
await sendMsgChain(grouptarget=groupid,
msg=messagechain_builder(imgpath=f'./images/PetPet/temp/tempPetPet-{personid}.gif'))
Expand Down
7 changes: 6 additions & 1 deletion plugin/ImgOperation/csgokill.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ async def cskill(event: GroupMessage):
elif At in event.message_chain:
target_id = event.message_chain.get_first(At).target
memberinfo = await bot.get_group_member(group=event.group.id, id_=target_id)
await bot.send(event, await jisha(event.sender.member_name, memberinfo.member_name))
if not memberinfo:
memberprofile = await bot.member_profile.get(target=event.group.id, member_id=target_id)
membername = memberprofile.nickname
else:
membername = memberinfo.member_name
await bot.send(event, await jisha(event.sender.member_name, membername))
2 changes: 1 addition & 1 deletion plugin/MajSoulInfo/bot_majsoul.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async def qhdrawcards(event: GroupMessage):
else:
result = majsoul.drawcards(userid=event.sender.id, up=False)
if result['error']:
return await bot.send(event, messagechain_builder(at=event.sender.id), text=result['resultsmsg'])
return await bot.send(event, messagechain_builder(at=event.sender.id, text=result['resultsmsg']))
mergeimgs(
result.get('results'), event.sender.id)
await bot.send(event, messagechain_builder(
Expand Down
12 changes: 6 additions & 6 deletions plugin/MajSoulInfo/majsoulinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def asyrecordsrequest(playerid, type, counts) -> list:
except asyncio.TimeoutError as e:
print(e)
ERROR = True
paipuInfo = '牌谱查询超时'
paipuInfo = '牌谱查询超时,请稍后再试'
result = dict(msg=paipuInfo, err=ERROR)
if not ERROR:
result['img64'] = text_to_image(text=paipuInfo, needtobase64=True)
Expand Down Expand Up @@ -475,7 +475,7 @@ def getrank(playerinfo: dict):
msg += paipumsg
except asyncio.exceptions.TimeoutError as e:
print(f'\n牌谱读取超时:\t{e}\n')
return dict(msg="查询超时,请再试一次", error=True)
return dict(msg="查询超时,请稍后再试", error=True)
try:
if selecttype == "4":
url = f"https://ak-data-5.sapk.ch/api/v2/pl4/player_extended_stats/{playerid}/{selectmontht}/{nextmontht}?mode=16.12.9.15.11.8"
Expand All @@ -497,7 +497,7 @@ def getrank(playerinfo: dict):
msg += infomsg
except asyncio.exceptions.TimeoutError as e:
print(f'\n玩家详情读取超时:\t{e}\n')
return dict(msg="查询超时,请再试一次", error=True)
return dict(msg="查询超时,请稍后再试", error=True)
text_to_image(path=f"MajsoulInfo/yb{playername}.png", text=msg)
return dict(msg=msg, error=False)

Expand Down Expand Up @@ -581,7 +581,7 @@ async def query(self, username: str, selecttype: str = "", selectindex: int = 0)
if userinfo['error']:
if userinfo['offline']:
return dict(msg="牌谱屋服务器离线", error=True)
return dict(msg="查询超时", error=True)
return dict(msg="查询超时,请稍后再试", error=True)
prtmsg = username
playerid = userinfo['playerid']
if playerid:
Expand Down Expand Up @@ -650,7 +650,7 @@ async def getcertaininfo(self, username: str, selecttype: str = "4", selectindex
playerinfo = await response.json()
except asyncio.exceptions.TimeoutError as e:
print(f"查询超时\t {e}")
return "查询超时"
return "查询超时,请稍后再试"
if len(playerinfo) == 0:
return "不存在该玩家"
elif len(playerinfo) < selectindex:
Expand Down Expand Up @@ -1165,7 +1165,7 @@ async def asysearchqh(url, type="3"):
return dict(msg=text, error=False)
except asyncio.exceptions.TimeoutError as e:
print(f"查询超时,{e}")
return dict(msg="查询超时,请再试一次", error=True)
return dict(msg="查询超时,请稍后再试", error=True)

def db_init():
cx = sqlite3.connect('./database/MajSoulInfo/majsoul.sqlite')
Expand Down
34 changes: 27 additions & 7 deletions plugin/Setu/setu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import json

from io import BytesIO

from PIL.Image import Image
from mirai import GroupMessage, Plain
from core import bot, commandpre, commands_map, config
from utils.MessageChainBuilder import messagechain_builder
Expand Down Expand Up @@ -39,16 +41,27 @@
]


async def download_setu_base64_from_url(url):
async def download_setu_base64_from_url(userid):
url = f'http://q1.qlogo.cn/g?b=qq&nk={userid}&s=640'
async with aiohttp.ClientSession() as session:
async with session.get(url=url) as resp:
img_content = await resp.read()

# 将图片转换为 base64
img_bytes = BytesIO(img_content)
b_content = img_bytes.getvalue()
imgcontent = base64.b64encode(b_content)
return imgcontent
pic_base64 = base64.b64encode(img_content)
print(pic_base64)
return pic_base64


# async def download_setu_base64_from_url(url):
# async with aiohttp.ClientSession() as session:
# async with session.get(url=url) as resp:
# img_content = await resp.read()
#
# # 将图片转换为 base64
# img_bytes = BytesIO(img_content)
# b_content = img_bytes.getvalue()
# imgcontent = base64.b64encode(b_content)
# return imgcontent


async def getsetuinfo(description: str, num: int) -> dict:
Expand Down Expand Up @@ -192,7 +205,9 @@ async def getsomesetu(event: GroupMessage):
m1.group(2), groupid=event.group.id)
if imginfo['FoundError']:
return await bot.send(event, messagechain_builder(at=event.sender.id, text=imginfo['ErrorMsg']))
# imgb64 = download_setu_base64_from_url(imginfo['url'])
res = await bot.send(event, messagechain_builder(imgurl=imginfo['url']))
# res = await bot.send(event,messagechain_builder(imgbase64=imgb64))
if res != -1 and stfinder.recalltime != -1:
await asyncio.sleep(stfinder.recalltime)
await bot.recall(res)
Expand All @@ -210,9 +225,14 @@ async def getsomesetu(event: GroupMessage):
if settings['setu'] and event.group.id in config['setugroups']:
if not cmdbuffer.updategroupcache(groupcommand(event.group.id, event.sender.id, 'setu')):
return bot.send(event, messagechain_builder(at=event.sender.id, text="你冲的频率太频繁了,休息一下吧"))
setu_num = m2.group(1)
if not setu_num:
setu_num = 1
else:
setu_num = int(setu_num)
try:
imginfo = await stfinder.getsetu(
m2.group(2), event.group.id, int(m2.group(1)))
m2.group(2), event.group.id, setu_num)
if imginfo['FoundError']:
return await bot.send(event, messagechain_builder(at=event.sender.id, text=imginfo['ErrorMsg']))
res = await bot.send(event, messagechain_builder(imgurl=imginfo['url']))
Expand Down

0 comments on commit 6b11c87

Please sign in to comment.