增加每日材料表查询功能

This commit is contained in:
CMHopeSunshine 2022-04-14 18:14:03 +08:00
parent 8175622c37
commit 720de37d5d
11 changed files with 70 additions and 23 deletions

View File

@ -16,7 +16,7 @@
## 简介✨ ## 简介✨
通过米游社接口查询uid的游戏信息并附带各种娱乐功能。 原神多功能机器人通过米游社接口查询uid的游戏信息并提供WIKI查询和各种各样的好玩的功能。
## 功能示例💖 ## 功能示例💖
@ -113,6 +113,7 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
- 3.30 个人信息卡片新增层岩巨渊和神里绫人信息 - 3.30 个人信息卡片新增层岩巨渊和神里绫人信息
- 3.31 实时便签加入参量质变仪信息 - 3.31 实时便签加入参量质变仪信息
- 4.11 改用数据库进行数据存储,优化代码 - 4.11 改用数据库进行数据存储,优化代码
- 4.14 新增每日天赋突破材料表查询
## ToDo🕛 ## ToDo🕛
@ -143,4 +144,4 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
- [hoshino-installer](https://github.com/pcrbot/hoshino-installer) - 一键安装脚本参考 - [hoshino-installer](https://github.com/pcrbot/hoshino-installer) - 一键安装脚本参考
- [bluemushoom](https://bbs.nga.cn/nuke.php?func=ucp&uid=62861898) - 全角色收益曲线和参考面板攻略图来源 - [bluemushoom](https://bbs.nga.cn/nuke.php?func=ucp&uid=62861898) - 全角色收益曲线和参考面板攻略图来源
- [genshin-gacha-export](https://github.com/sunfkny/genshin-gacha-export) - 抽卡记录导出参考 - [genshin-gacha-export](https://github.com/sunfkny/genshin-gacha-export) - 抽卡记录导出参考
- [Adachi-BOT](https://github.com/Arondight/Adachi-BOT) - 部分资源来源 - [Adachi-BOT](https://github.com/SilveryStar/Adachi-BOT) - 部分资源来源

View File

@ -22,7 +22,7 @@ def reload_public_cookie(is_drop=True):
with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r', encoding='utf-8') as f: with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r', encoding='utf-8') as f:
data = json.load(f) data = json.load(f)
for d in data['通用']: for d in data['通用']:
cursor.execute('INSERT IGNORE INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie'])) cursor.execute('INSERT OR IGNORE INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie']))
conn.commit() conn.commit()
conn.close() conn.close()
logger.info('---公共cookie池载入成功!---') logger.info('---公共cookie池载入成功!---')
@ -104,7 +104,7 @@ async def insert_public_cookie(cookie):
cookie TEXT, cookie TEXT,
status TEXT status TEXT
);''') );''')
cursor.execute('INSERT IGNORE INTO public_cookies (cookie, status) VALUES (?,"OK");', (cookie,)) cursor.execute('INSERT OR IGNORE INTO public_cookies (cookie, status) VALUES (?,"OK");', (cookie,))
conn.commit() conn.commit()
conn.close() conn.close()

View File

@ -27,7 +27,7 @@ async def ckjl(bot,ev):
return return
uid, msg, user_id, use_cache = await get_uid_in_msg(ev) uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
if not uid: if not uid:
await bot.send(ev,'请把uid给派蒙哦比如获取抽卡记录100000001 链接',at_sender=True) await bot.send(ev,'请把uid给派蒙哦比如导出抽卡记录100000001 xlsx',at_sender=True)
return return
find_filetype = r'(?P<filetype>xlsx|json)' find_filetype = r'(?P<filetype>xlsx|json)'
match = re.search(find_filetype, msg) match = re.search(find_filetype, msg)

View File

@ -6,6 +6,8 @@ from ..character_alias import get_id_by_alias
from .blue import get_blue_pic from .blue import get_blue_pic
from ..util import pil2b64 from ..util import pil2b64
from hoshino.util import filt_message from hoshino.util import filt_message
import re
import time
help_msg=''' help_msg='''
1.[xx角色攻略]查看西风驿站出品的角色一图流攻略 1.[xx角色攻略]查看西风驿站出品的角色一图流攻略
@ -13,6 +15,7 @@ help_msg='''
3.[xx参考面板]查看blue菌hehe出品的参考面板攻略 3.[xx参考面板]查看blue菌hehe出品的参考面板攻略
4.[xx收益曲线]查看blue菌hehe出品的收益曲线攻略 4.[xx收益曲线]查看blue菌hehe出品的收益曲线攻略
*感谢来自大佬们的授权角色支持别名查询 *感谢来自大佬们的授权角色支持别名查询
5.[今日/明日/周x材料]查看每日角色天赋材料和武器突破材料表
''' '''
sv = Service('派蒙WIKI', bundle='派蒙', help_=help_msg) sv = Service('派蒙WIKI', bundle='派蒙', help_=help_msg)
@ -84,4 +87,37 @@ async def genshinAttribute2(bot,ev):
pic = Image.open(os.path.join(res_path, 'blue', f'{realname}.png')) pic = Image.open(os.path.join(res_path, 'blue', f'{realname}.png'))
pic = pil2b64(pic, 85) pic = pil2b64(pic, 85)
pic = MessageSegment.image(pic) pic = MessageSegment.image(pic)
await bot.send(ev,pic,at_sender=True) await bot.send(ev,pic,at_sender=True)
@sv.on_suffix(('材料', '天赋材料', '角色天赋材料', '突破材料', '武器突破材料'))
async def daily_material(bot, ev):
week = ev.message.extract_plain_text().strip()
if not week:
return
find_week = re.search(r'(?P<week>今日|今天|现在|明天|明日|后天|后日|周一|周二|周三|周四|周五|周六|周日)', week)
if not find_week:
return
else:
if find_week.group('week') in ['今日', '今天', '现在']:
week = time.strftime("%w")
elif find_week.group('week') in ['明日', '明天']:
week = str(int(time.strftime("%w")) + 1)
elif find_week.group('week') in ['后日', '后天']:
week = str(int(time.strftime("%w")) + 2)
elif find_week.group('week') in ['周一', '周四']:
week = '1'
elif find_week.group('week') in ['周二', '周五']:
week = '2'
elif find_week.group('week') in ['周三', '周六']:
week = '3'
else:
week = '0'
if week == "0":
await bot.send(ev, '周日所有材料都可以刷哦!', at_sender = True)
elif week in ['1', '4']:
await bot.send(ev,f'[CQ:image,file=file:///{os.path.join(res_path, "daily_material","周一周四.jpg")}]',at_sender=True)
elif week in ['2', '5']:
await bot.send(ev,f'[CQ:image,file=file:///{os.path.join(res_path, "daily_material","周二周五.jpg")}]',at_sender=True)
else:
await bot.send(ev,f'[CQ:image,file=file:///{os.path.join(res_path, "daily_material","周三周六.jpg")}]',at_sender=True)

View File

@ -17,7 +17,7 @@ async def get_abyss_data(user_id, uid, schedule_type = "1", use_cache=True):
while True: while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊') cookie = await get_use_cookie(user_id, uid=uid, action='查询深渊')
if not cookie: if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!' return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
headers = get_headers(q=f'role_id={uid}&schedule_type={schedule_type}&server={server_id}', cookie=cookie['cookie']) headers = get_headers(q=f'role_id={uid}&schedule_type={schedule_type}&server={server_id}', cookie=cookie['cookie'])
res = await aiorequests.get(url=url, headers=headers, params=params) res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json() data = await res.json()
@ -30,7 +30,7 @@ async def get_daily_note_data(uid):
url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote" url ="https://api-takumi.mihoyo.com/game_record/app/genshin/api/dailyNote"
cookie = await get_own_cookie(uid, action='查询实时便签') cookie = await get_own_cookie(uid, action='查询实时便签')
if not cookie: if not cookie:
return f'你的uid{uid}没有绑定对应的cookie哦,先用ysb给派蒙绑定吧!' return f'你的uid{uid}没有绑定对应的cookie,使用ysb绑定才能用实时便签哦!'
await update_cookie_cache(cookie['cookie'], uid, 'uid') await update_cookie_cache(cookie['cookie'], uid, 'uid')
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie']) headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
params = { params = {
@ -51,7 +51,7 @@ async def get_player_card_data(user_id, uid, use_cache=True):
while True: while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片') cookie = await get_use_cookie(user_id, uid=uid, action='查询原神卡片')
if not cookie: if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!' return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie']) headers = get_headers(q=f'role_id={uid}&server={server_id}', cookie=cookie['cookie'])
res = await aiorequests.get(url=url, headers=headers, params=params) res = await aiorequests.get(url=url, headers=headers, params=params)
data = await res.json() data = await res.json()
@ -70,7 +70,7 @@ async def get_chara_detail_data(user_id, uid, use_cache=True):
while True: while True:
cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情') cookie = await get_use_cookie(user_id, uid=uid, action='查询角色详情')
if not cookie: if not cookie:
return '现在派蒙没有可以用的cookie哦,请让主人 添加公共ck 吧!' return '现在派蒙没有可以用的cookie哦,可能是:\n1.公共cookie全都达到了每日30次上限\n2.公共池全都失效了或没有cookie\n让管理员使用 添加公共ck 吧!'
headers = get_headers(b=json_data, cookie=cookie['cookie']) headers = get_headers(b=json_data, cookie=cookie['cookie'])
res = await aiorequests.post(url=url, headers=headers, json=json_data) res = await aiorequests.post(url=url, headers=headers, json=json_data)
data = await res.json() data = await res.json()
@ -102,7 +102,7 @@ async def get_monthinfo_data(uid, month, use_cache=True):
url = 'https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo' url = 'https://hk4e-api.mihoyo.com/event/ys_ledger/monthInfo'
cookie = await get_own_cookie(uid, action='查询每月札记') cookie = await get_own_cookie(uid, action='查询每月札记')
if not cookie: if not cookie:
return f'你的uid{uid}没有绑定对应的cookie哦,先用ysb给派蒙绑定吧!' return f'你的uid{uid}没有绑定对应的cookie,使用ysb绑定才能用每月札记哦!'
await update_cookie_cache(cookie['cookie'], uid, 'uid') await update_cookie_cache(cookie['cookie'], uid, 'uid')
headers = get_headers(q=f'month={month}&bind_uid={uid}&bind_region={server_id}', cookie=cookie['cookie']) headers = get_headers(q=f'month={month}&bind_uid={uid}&bind_region={server_id}', cookie=cookie['cookie'])
params = { params = {

View File

@ -19,7 +19,7 @@ sv = Service('派蒙原神信息查询', bundle='派蒙', help_=help_msg)
async def player_card(bot,ev): async def player_card(bot,ev):
uid, msg, user_id, use_cache = await get_uid_in_msg(ev) uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
if not uid: if not uid:
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True) await bot.send(ev,'请把正确的uid给派蒙哦,例如ys100123456!',at_sender=True)
return return
try: try:
data = await get_player_card_data(user_id, uid, use_cache=use_cache) data = await get_player_card_data(user_id, uid, use_cache=use_cache)
@ -42,7 +42,7 @@ async def player_card(bot,ev):
async def all_characters(bot,ev): async def all_characters(bot,ev):
uid, msg, user_id, use_cache = await get_uid_in_msg(ev) uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
if not uid: if not uid:
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True) await bot.send(ev,'请把正确的uid给派蒙哦,例如ysa100123456!',at_sender=True)
return return
try: try:
chara_data = await get_chara_detail_data(user_id, uid, use_cache=use_cache) chara_data = await get_chara_detail_data(user_id, uid, use_cache=use_cache)
@ -58,7 +58,7 @@ async def all_characters(bot,ev):
async def my_characters(bot,ev): async def my_characters(bot,ev):
uid, msg, user_id, use_cache = await get_uid_in_msg(ev) uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
if not uid: if not uid:
await bot.send(ev,'请把正确的uid给派蒙哦,例如sy100123456!',at_sender=True) await bot.send(ev,'请把正确的uid给派蒙哦,例如ysc100123456钟离',at_sender=True)
return return
if not msg: if not msg:
await bot.send(ev,f'要把角色名给派蒙呀!例如ysc100123456钟离',at_sender=True) await bot.send(ev,f'要把角色名给派蒙呀!例如ysc100123456钟离',at_sender=True)

View File

@ -218,7 +218,8 @@ async def draw_player_card(data, chara_data, uid, nickname="旅行者"):
# 世界探索 # 世界探索
await draw_world_data(bg_draw,data) await draw_world_data(bg_draw,data)
# 角色 # 角色
if chara_data: nocha = ''
if chara_data['data']:
chara_data = chara_data['data']['avatars'] chara_data = chara_data['data']['avatars']
w = 1045 w = 1045
i = 0 i = 0
@ -231,8 +232,10 @@ async def draw_player_card(data, chara_data, uid, nickname="旅行者"):
bg_img.alpha_composite(chara_card.resize((180, 249)), (840 + (i - 4) * 205, 974)) bg_img.alpha_composite(chara_card.resize((180, 249)), (840 + (i - 4) * 205, 974))
elif i > 8: elif i > 8:
break break
else:
nocha = '*这uid关闭了角色详情显示派蒙看不到哦'
bg_img = pil2b64(bg_img, 80) bg_img = pil2b64(bg_img, 80)
bg_img = MessageSegment.image(bg_img) bg_img = MessageSegment.image(bg_img) + nocha
return bg_img return bg_img

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

View File

@ -15,16 +15,17 @@ from .db_util import get_private_cookie, get_cookie_cache, get_public_cookie, li
async def get_use_cookie(user_id, uid='', mys_id='', action=''): async def get_use_cookie(user_id, uid='', mys_id='', action=''):
cache_cookie = await get_cookie_cache(uid, 'uid') cache_cookie = await get_cookie_cache(uid, 'uid')
if cache_cookie:
if cache_cookie['type'] == 'public':
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
else:
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
return cache_cookie
cookies = await get_private_cookie(user_id, 'user_id') cookies = await get_private_cookie(user_id, 'user_id')
if not cookies: if not cookies:
if cache_cookie:
if cache_cookie['type'] == 'public':
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
else:
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
return cache_cookie
public_cookie = await get_public_cookie() public_cookie = await get_public_cookie()
if not public_cookie: if not public_cookie:
logger.info(f'---派蒙当前没有可用的公共cookie可能是都达到了上限或没有公共cookie---')
return None return None
else: else:
logger.info(f'---派蒙调用{public_cookie[0]}号公共cookie执行{action}操作---') logger.info(f'---派蒙调用{public_cookie[0]}号公共cookie执行{action}操作---')
@ -34,6 +35,12 @@ async def get_use_cookie(user_id, uid='', mys_id='', action=''):
if (uid and uid_ == uid) or (mys_id and mys_id_ == mys_id): if (uid and uid_ == uid) or (mys_id and mys_id_ == mys_id):
logger.info(f'---派蒙调用用户{user_id_}的uid{uid_}私人cookie执行{action}操作---') logger.info(f'---派蒙调用用户{user_id_}的uid{uid_}私人cookie执行{action}操作---')
return {'type':'private', 'user_id': user_id_, 'cookie': cookie, 'uid': uid_, 'mys_id': mys_id_} return {'type':'private', 'user_id': user_id_, 'cookie': cookie, 'uid': uid_, 'mys_id': mys_id_}
if cache_cookie:
if cache_cookie['type'] == 'public':
logger.info(f'---派蒙调用{uid}的缓存公共cookie执行{action}操作---')
else:
logger.info(f'---派蒙调用{uid}的缓存私人cookie执行{action}操作---')
return cache_cookie
use_cookie = random.choice(cookies) use_cookie = random.choice(cookies)
logger.info(f'---派蒙调用用户{use_cookie[0]}的uid{use_cookie[2]}私人cookie执行{action}操作---') logger.info(f'---派蒙调用用户{use_cookie[0]}的uid{use_cookie[2]}私人cookie执行{action}操作---')
return {'type':'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2], 'mys_id': use_cookie[3]} return {'type':'private', 'user_id': use_cookie[0], 'cookie': use_cookie[1], 'uid': use_cookie[2], 'mys_id': use_cookie[3]}
@ -54,7 +61,7 @@ async def get_own_cookie(uid='', mys_id='', action=''):
# 检查数据返回状态10001为ck过期了10101为达到每日30次上线了 # 检查数据返回状态10001为ck过期了10101为达到每日30次上线了
async def check_retcode(data, cookie, uid): async def check_retcode(data, cookie, uid):
if data['retcode'] == 10001: if data['retcode'] == 10001 or data['retcode'] == -100:
await delete_cookie(cookie['cookie'], cookie['type']) await delete_cookie(cookie['cookie'], cookie['type'])
await send_cookie_delete_msg(cookie) await send_cookie_delete_msg(cookie)
return False return False