Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonebot2-beta1 分支的一些修复工作 #118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import asyncio
import base64

from nonebot import on_command, require, on_startswith, get_driver, logger, get_bots
from nonebot.adapters.onebot.v11 import GROUP, PRIVATE_FRIEND, Bot, MessageEvent, GroupMessageEvent
from nonebot import (get_bot, get_driver, logger, on_command, on_startswith,
require)
from nonebot.adapters.onebot.v11 import (GROUP, PRIVATE_FRIEND, Bot,
GroupMessageEvent, MessageEvent,
MessageSegment)
from nonebot.adapters.onebot.v11.exception import ActionFailed
from nonebot.permission import SUPERUSER

Expand Down Expand Up @@ -69,15 +72,15 @@ async def clean_cache():
# 每隔半小时检测树脂是否超过设定值
@resin_notic_schedule.scheduled_job('cron', minute="*/30")
async def push():
bot = get_bots().values()
bot = get_bot()
now_data = await daily()
if now_data is not None:
for i in now_data:
if i['gid'] == "on":
await bot.call_api(api='send_private_msg', **{'user_id': i['qid'], 'message': i['message']})
else:
await bot.call_api(api='send_group_msg',
**{'group_id': i['gid'], 'message': f"[CQ:at,qq={i['qid']}]" + "\n" + i['message']})
**{'group_id': i['gid'], 'message': MessageSegment.at(i['qid']) + f"\n{i['message']}"})
else:
pass

Expand All @@ -89,7 +92,7 @@ async def sign_at_night():


async def daily_sign():
bot = get_bots().values()
bot = get_bot()
conn = sqlite3.connect('ID_DATA.db')
c = conn.cursor()
cursor = c.execute(
Expand All @@ -105,7 +108,7 @@ async def daily_sign():
except Exception:
logger.exception(f"{im} Error")
else:
message = f"[CQ:at,qq={row[2]}]\n{im}"
message = MessageSegment.at(row[2]) + f"\n{im}"
if await config_check("SignReportSimple"):
for i in temp_list:
if row[4] == i["push_group"]:
Expand All @@ -117,22 +120,26 @@ async def daily_sign():
break
else:
if im == "签到失败,请检查Cookies是否失效。":
temp_list.append({"push_group": row[4], "push_message": message, "success": 0, "failed": 1})
temp_list.append(
{"push_group": row[4], "push_message": message, "success": 0, "failed": 1})
else:
temp_list.append({"push_group": row[4], "push_message": "", "success": 1, "failed": 0})
temp_list.append(
{"push_group": row[4], "push_message": "", "success": 1, "failed": 0})
else:
for i in temp_list:
if row[4] == i["push_group"] and i["num"] < 4:
i["push_message"] += "\n" + message
i["num"] += 1
break
else:
temp_list.append({"push_group": row[4], "push_message": message, "num": 1})
temp_list.append(
{"push_group": row[4], "push_message": message, "num": 1})
await asyncio.sleep(6 + random.randint(1, 3))
if await config_check("SignReportSimple"):
for i in temp_list:
try:
report = "以下为签到失败报告:{}".format(i["push_message"]) if i["push_message"] != "" else ""
report = "以下为签到失败报告:{}".format(
i["push_message"]) if i["push_message"] != "" else ""
await bot.call_api(
api='send_group_msg', group_id=i["push_group"],
message="今日自动签到已完成!\n本群共签到成功{}人,共签到失败{}人。{}".format(i["success"], i["failed"], report))
Expand All @@ -156,7 +163,7 @@ async def send_audio(event: MessageEvent):
name = ''.join(re.findall('[\u4e00-\u9fa5]', message))
im = await audio_wiki(name, message)
try:
await get_audio.send(Message(im))
await get_audio.send(im)
except ActionFailed:
await get_audio.send("不存在该语音ID或者不存在该角色。")
except Exception:
Expand Down Expand Up @@ -333,7 +340,7 @@ async def send_events():
ls_f = base64.b64encode(f.read()).decode()
img_mes = 'base64://' + ls_f
f.close()
im = Message(f'[CQ:image,file={img_mes}]')
im = MessageSegment.image(img_mes)
break
else:
await draw_event_pic()
Expand Down Expand Up @@ -536,7 +543,7 @@ async def check_cookies(bot: Bot):
**{'user_id': i[0],
'message': "您绑定的Cookies(uid{})已失效,以下功能将会受到影响:\n查看完整信息列表\n查看深渊配队\n自动签到/当前状态/每月统计\n"
"请及时重新绑定Cookies并重新开关相应功能。".format(
i[1])})
i[1])})
await asyncio.sleep(3 + random.randint(1, 3))
except ActionFailed as e:
await get_lots.send("机器人发送消息失败:{}".format(e.info['wording']))
Expand Down
18 changes: 9 additions & 9 deletions get_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import random
import threading
import time
from bs4 import BeautifulSoup
from base64 import b64encode
from io import BytesIO
from re import findall

import numpy as np
from PIL import Image, ImageDraw, ImageFont, ImageFilter
from bs4 import BeautifulSoup
from httpx import get
from nonebot.adapters.onebot.v11 import Message
from nonebot.adapters.onebot.v11 import MessageSegment
from PIL import Image, ImageDraw, ImageFilter, ImageFont
from wordcloud import WordCloud

from .get_data import get_info, get_character, get_spiral_abyss_info, get_mihoyo_bbs_info, \
error_db, cache_db, get_genshin_events
from .get_data import (cache_db, error_db, get_character, get_genshin_events,
get_info, get_mihoyo_bbs_info, get_spiral_abyss_info)

FILE_PATH = os.path.dirname(__file__)
FILE2_PATH = os.path.join(FILE_PATH, 'mihoyo_bbs')
Expand Down Expand Up @@ -327,7 +327,7 @@ def get_char_id(start, end):
result_buffer = BytesIO()
bg_img.save(result_buffer, format='JPEG', subsampling=0, quality=90)
imgmes = 'base64://' + b64encode(result_buffer.getvalue()).decode()
resultmes = f"[CQ:image,file={imgmes}]"
resultmes = MessageSegment.image(imgmes)
return resultmes


Expand Down Expand Up @@ -653,7 +653,7 @@ async def draw_abyss0_pic(uid, nickname, image=None, mode=2, date="1"):
bg_img.save(result_buffer, format='JPEG', subsampling=0, quality=90)
# bg_img.save(result_buffer, format='PNG')
imgmes = 'base64://' + b64encode(result_buffer.getvalue()).decode()
resultmes = Message(f"[CQ:image,file={imgmes}]")
resultmes = MessageSegment.image(imgmes)
return resultmes


Expand Down Expand Up @@ -849,7 +849,7 @@ async def draw_abyss_pic(uid, nickname, floor_num, image=None, mode=2, date="1")
bg_img.save(result_buffer, format='JPEG', subsampling=0, quality=90)
# bg_img.save(result_buffer, format='PNG')
imgmes = 'base64://' + b64encode(result_buffer.getvalue()).decode()
resultmes = Message(f"[CQ:image,file={imgmes}]")
resultmes = MessageSegment.image(imgmes)
return resultmes


Expand Down Expand Up @@ -1265,7 +1265,7 @@ def get_text(star, step):
result_buffer = BytesIO()
bg_img.save(result_buffer, format='JPEG', subsampling=0, quality=90)
imgmes = 'base64://' + b64encode(result_buffer.getvalue()).decode()
resultmes = f"[CQ:image,file={imgmes}]"
resultmes = MessageSegment.image(imgmes)
return resultmes


Expand Down
12 changes: 7 additions & 5 deletions get_mihoyo_bbs_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from io import BytesIO

import requests
from nonebot.adapters.onebot.v11 import MessageSegment

from .get_data import (get_award, get_char_info, get_daily_data, get_mihoyo_bbs_info, get_audio_info,
get_sign_info, get_sign_list, get_weapon_info, mihoyo_bbs_sign,
cookies_db, get_misc_info)
from .get_data import (cookies_db, get_audio_info, get_award, get_char_info,
get_daily_data, get_mihoyo_bbs_info, get_misc_info,
get_sign_info, get_sign_list, get_weapon_info,
mihoyo_bbs_sign)

FILE_PATH = os.path.dirname(__file__)
FILE2_PATH = os.path.join(FILE_PATH, 'mihoyo_bbs')
Expand Down Expand Up @@ -218,7 +220,7 @@ async def get(_audioid):
tmp_json[_audioid].remove(audioid1)

if name == "列表":
im = f'[CQ:image,file=file://{os.path.join(INDEX_PATH, "语音.png")}]'
im = MessageSegment.image(f'file:///{os.path.join(INDEX_PATH, "语音.png")}')
return im
elif name == "":
return "角色名不正确。"
Expand All @@ -230,7 +232,7 @@ async def get(_audioid):
return "语音获取失败"
if audio:
audios = 'base64://' + b64encode(audio.getvalue()).decode()
return f"[CQ:record,file={audios}]"
return MessageSegment.record(audios)


async def artifacts_wiki(name):
Expand Down