3
0

🐛 修复:同步新的WikiAPI接口;优化:错误提示.

This commit is contained in:
xtaodada 2022-01-27 12:07:54 +08:00
parent 26f06c3138
commit f8d7cce4c3
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
4 changed files with 51 additions and 40 deletions

View File

@ -1,17 +1,16 @@
from io import BytesIO
from os import sep
import requests, yaml, re
import requests
from json.decoder import JSONDecodeError
from PIL import Image
from defs.character import repl
from defs.weapons import headers
def get_url(name: str):
res = requests.get(url=f'https://api.minigg.cn/artifacts?query={name}', headers=headers)
if res.text == "undefined\n":
res = requests.get(url=f'https://info.minigg.cn/artifacts?query={name}', headers=headers)
if "errcode" in res.text:
raise JSONDecodeError("", "", 0)
py_dict = yaml.safe_load(re.sub(r'\[? *(, *)+\]?', repl, res.text))
py_dict = res.json()
return py_dict

View File

@ -1,4 +1,4 @@
import difflib, json, re, requests, yaml
import difflib, json, re, requests
from os import getcwd, sep
from xpinyin import Pinyin
from json.decoder import JSONDecodeError
@ -17,38 +17,38 @@ def nic2name(name):
return name
def repl(match):
content = re.sub(" ", "",match.group(0))
length = len(content) - 1
result = ''
if content[0] == '[':
result = '[""'
length -= 1
after = ','
if content[-1] == ']':
length -= 1
after += '""]'
return result + (',""' * length) + after
# def repl(match):
# content = re.sub(" ", "",match.group(0))
# length = len(content) - 1
# result = ''
# if content[0] == '[':
# result = '[""'
# length -= 1
#
# after = ','
# if content[-1] == ']':
# length -= 1
# after += '""]'
#
# return result + (',""' * length) + after
def get_json(name: str) -> dict:
if name not in ["", ""]:
name = nic2name(name)
res = requests.get(f'https://api.minigg.cn/characters?query={name}')
if res.text == "undefined\n":
res = requests.get(f'https://info.minigg.cn/characters?query={name}')
if "errcode" in res.text:
raise JSONDecodeError("", "", 0)
py_dict = yaml.safe_load(re.sub(r'\[? *(, *)+\]?', repl, res.text))
py_dict = res.json()
return py_dict
def get_json_mz(name: str) -> dict:
name = nic2name(name)
res = requests.get(f'https://api.minigg.cn/constellations?query={name}')
if res.text == "undefined\n":
res = requests.get(f'https://info.minigg.cn/constellations?query={name}')
if "errcode" in res.text:
raise JSONDecodeError("", "", 0)
py_dict = yaml.safe_load(re.sub(r'\[? *(, *)+\]?', repl, res.text))
py_dict = res.json()
return py_dict

View File

@ -1,8 +1,7 @@
import difflib, json, requests, yaml, re
import difflib, json, requests
from os import getcwd, sep
from xpinyin import Pinyin
from json.decoder import JSONDecodeError
from defs.character import repl
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/89.0.4389.82 Safari/537.36"}
@ -13,10 +12,10 @@ weapon_type = {1: "单手剑", 2: "双手剑", 3: "弓", 4: "法器", 5: "长枪
def get_url(name: str):
res = requests.get(url=f'https://api.minigg.cn/weapons?query={name}', headers=headers)
if res.text == "undefined\n":
res = requests.get(url=f'https://info.minigg.cn/weapons?query={name}', headers=headers)
if "errcode" in res.text:
raise JSONDecodeError("", "", 0)
py_dict = yaml.safe_load(re.sub(r'\[? *(, *)+\]?', repl, res.text))
py_dict = res.json()
return py_dict
@ -24,7 +23,7 @@ async def get_weapon(name: str):
for i in weapon_all:
if name in i['name']:
try:
url = (get_url(i['name'][0]))["images"]["image"]
url = (get_url(i['name'][0]))["images"]["icon"]
except (JSONDecodeError, KeyError):
url = None
text = f"<b>{i['name'][0]}</b> {'' * i['star']}\n" \

View File

@ -12,6 +12,7 @@ from defs.event import generate_event
from defs.mys2 import award, sign, daily
from ci import scheduler, app
from defs.redis_load import redis
SUPERUSERS = []
@ -19,7 +20,7 @@ SUPERUSERS = []
async def mys2_msg(client: Client, message: Message):
text = message.text.replace("米游社", "")
userid = message.from_user.id
if '添加 ' in text:
if '添加' in text:
try:
mes = text.replace('添加', '').strip()
if not mes:
@ -35,7 +36,9 @@ async def mys2_msg(client: Client, message: Message):
f'例如:<code>米游社绑定uid123456789</code>。')
except Exception as e:
traceback.print_exc()
await message.reply(f'校验失败请输入正确的Cookies', quote=True)
await message.reply(f'校验失败请输入正确的Cookies获取 Cookie 请参考:'
f'[link](https://github.com/Womsxd/AutoMihoyoBBS/'
f'#%E8%8E%B7%E5%8F%96%E7%B1%B3%E6%B8%B8%E7%A4%BEcookie)', quote=True)
elif '推送' in text:
try:
uid = await selectDB(userid, mode="uid")
@ -46,7 +49,7 @@ async def mys2_msg(client: Client, message: Message):
im = await OpenPush(int(uid[0]), userid, "off", "StatusA")
await message.reply(im, quote=True)
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
await message.reply("未找到uid绑定记录。", quote=True)
elif '自动签到' in text:
try:
@ -58,7 +61,7 @@ async def mys2_msg(client: Client, message: Message):
im = await OpenPush(int(uid[0]), userid, "off", "StatusA")
await message.reply(im, quote=True)
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
await message.reply("未找到uid绑定记录。", quote=True)
@ -82,7 +85,7 @@ async def mys2_qun_msg(client: Client, message: Message):
im = await OpenPush(int(uid[0]), message.from_user.id, "off", "StatusB")
await message.reply(im)
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
await message.reply("未绑定uid信息")
elif "推送" in text:
try:
@ -99,7 +102,7 @@ async def mys2_qun_msg(client: Client, message: Message):
im = await OpenPush(int(uid[0]), message.from_user.id, "off", "StatusA")
await message.reply(im)
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
await message.reply("未绑定uid信息")
elif "每月统计" in text:
try:
@ -117,7 +120,7 @@ async def mys2_qun_msg(client: Client, message: Message):
im = await sign(uid)
await message.reply(im)
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
await message.reply('未找到绑定信息')
elif "效验全部" in text:
im = await CheckDB()
@ -129,7 +132,7 @@ async def mys2_qun_msg(client: Client, message: Message):
mes = await daily("ask", uid)
im = mes[0]['message']
except Exception as e:
print(e.with_traceback)
traceback.print_exc()
im = "没有找到绑定信息。"
await message.reply(im)
elif "绑定uid" in text:
@ -148,6 +151,16 @@ async def push():
daily_data = await daily()
if daily_data is not None:
for i in daily_data:
# 过滤重复推送
data = i['message'].split('==============')
if len(data) > 2:
text = "".join(data[1:-1])
data = redis.get("daily_" + str(i['qid']))
if data:
if text == data.decode():
continue
redis.set("daily_" + str(i['qid']), text)
if i['gid'] == "on":
await app.send_message(int(i['qid']), i['message'])
else: