mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 08:39:59 +08:00
update alapi
This commit is contained in:
+120
-119
@@ -18,7 +18,7 @@ genshin_up_char = Path(DRAW_PATH + "/draw_card_up/genshin_up_char.json")
|
||||
pretty_up_char = Path(DRAW_PATH + "/draw_card_up/pretty_up_char.json")
|
||||
guardian_up_char = Path(DRAW_PATH + "/draw_card_up/guardian_up_char.json")
|
||||
|
||||
prts_url = "https://wiki.biligame.com/arknights/%E6%96%B0%E9%97%BB%E5%85%AC%E5%91%8A"
|
||||
prts_url = "https://ak.hypergryph.com/news.html"
|
||||
genshin_url = "https://wiki.biligame.com/ys/%E7%A5%88%E6%84%BF"
|
||||
pretty_url = "https://wiki.biligame.com/umamusume/%E5%85%AC%E5%91%8A"
|
||||
guardian_url = "https://wiki.biligame.com/gt/%E9%A6%96%E9%A1%B5"
|
||||
@@ -36,19 +36,10 @@ def is_expired(data: dict):
|
||||
|
||||
|
||||
# 检查写入
|
||||
def check_write(data: dict, up_char_file, game_name: str = ''):
|
||||
tmp = data
|
||||
if game_name in ['genshin', 'pretty', 'guardian']:
|
||||
tmp = data['char']
|
||||
if not is_expired(tmp):
|
||||
if game_name in ['genshin', 'guardian']:
|
||||
data['char']['title'] = ''
|
||||
data['arms']['title'] = ''
|
||||
elif game_name in ['pretty']:
|
||||
data['char']['title'] = ''
|
||||
data['card']['title'] = ''
|
||||
else:
|
||||
data['title'] = ''
|
||||
def check_write(data: dict, up_char_file):
|
||||
if not is_expired(data['char']):
|
||||
for x in list(data.keys()):
|
||||
data[x]['title'] = ''
|
||||
else:
|
||||
with open(up_char_file, 'w', encoding='utf8') as f:
|
||||
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||
@@ -58,10 +49,7 @@ def check_write(data: dict, up_char_file, game_name: str = ''):
|
||||
else:
|
||||
with open(up_char_file, 'r', encoding='utf8') as f:
|
||||
old_data = json.load(f)
|
||||
tmp = old_data
|
||||
if game_name in ['genshin', 'pretty', 'guardian']:
|
||||
tmp = old_data['char']
|
||||
if is_expired(tmp):
|
||||
if is_expired(data['char']):
|
||||
return old_data
|
||||
else:
|
||||
with open(up_char_file, 'w', encoding='utf8') as f:
|
||||
@@ -69,100 +57,104 @@ def check_write(data: dict, up_char_file, game_name: str = ''):
|
||||
return data
|
||||
|
||||
|
||||
def _get_up_char(r: str, text: str):
|
||||
pr = re.search(r, text)
|
||||
chars = pr.group(1)
|
||||
probability = pr.group(2)
|
||||
chars = chars.replace('[限定]', '').replace('[', '').replace(']', '')
|
||||
probability = probability.replace('【', '')
|
||||
return chars, probability
|
||||
|
||||
|
||||
class PrtsAnnouncement:
|
||||
|
||||
@staticmethod
|
||||
async def get_announcement_text():
|
||||
def __init__(self):
|
||||
self.game_name = '明日方舟'
|
||||
|
||||
async def _get_announcement_text(self):
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
async with session.get(prts_url, timeout=7) as res:
|
||||
soup = BeautifulSoup(await res.text(), 'lxml')
|
||||
trs = soup.find('table').find('tbody').find_all('tr')
|
||||
for tr in trs:
|
||||
a = tr.find_all('td')[-1].find('a')
|
||||
if a.text.find('寻访') != -1:
|
||||
url = a.get('href')
|
||||
break
|
||||
async with session.get(f'https://wiki.biligame.com/{url}', timeout=7) as res:
|
||||
return await res.text(), a.text[:-4]
|
||||
ol = soup.find('ol', {'class': 'articleList active', 'data-category-key': 'LATEST'})
|
||||
for li in ol:
|
||||
itype = li.find('span', {'class': 'articleItemCate'}).text
|
||||
if itype == '活动':
|
||||
a = li.find('a')['href']
|
||||
async with session.get(f'https://ak.hypergryph.com{a}', headers=headers, timeout=7) as res:
|
||||
return await res.text()
|
||||
|
||||
@staticmethod
|
||||
async def update_up_char():
|
||||
async def update_up_char(self):
|
||||
prts_up_char.parent.mkdir(parents=True, exist_ok=True)
|
||||
data = {'up_char': {'6': {}, '5': {}, '4': {}}, 'title': '', 'time': '', 'pool_img': ''}
|
||||
try:
|
||||
text, title = await PrtsAnnouncement.get_announcement_text()
|
||||
data = {'char': {'up_char': {'6': {}, '5': {}, '4': {}}, 'title': '', 'time': '', 'pool_img': ''}}
|
||||
text = await self._get_announcement_text()
|
||||
soup = BeautifulSoup(text, 'lxml')
|
||||
data['title'] = title
|
||||
context = soup.find('div', {'id': 'mw-content-text'}).find('div')
|
||||
data['pool_img'] = str(context.find('div', {'class': 'center'}).find('div').find('a').
|
||||
find('img').get('srcset')).split(' ')[-2]
|
||||
# print(context.find_all('p'))
|
||||
for p in context.find_all('p')[1:]:
|
||||
if p.text.find('活动时间') != -1:
|
||||
pr = re.search(r'.*?活动时间:(.*)', p.text)
|
||||
data['time'] = pr.group(1)
|
||||
elif p.text.find('★★★★★★') != -1:
|
||||
chars, probability = _get_up_char(r'.*?★★★★★★:(.*?)(.*?出率的?(.*?)%.*?).*?', p.text)
|
||||
slt = '/'
|
||||
if chars.find('\\') != -1:
|
||||
slt = '\\'
|
||||
for char in chars.split(slt):
|
||||
data['up_char']['6'][char.strip()] = probability.strip()
|
||||
elif p.text.find('★★★★★') != -1:
|
||||
chars, probability = _get_up_char(r'.*?★★★★★:(.*?)(.*?出率的?(.*?)%.*?).*?', p.text)
|
||||
slt = '/'
|
||||
if chars.find('\\') != -1:
|
||||
slt = '\\'
|
||||
for char in chars.split(slt):
|
||||
data['up_char']['5'][char.strip()] = probability.strip()
|
||||
elif p.text.find('★★★★') != -1:
|
||||
chars, probability = _get_up_char(r'.*?★★★★:(.*?)(.*?出率的?(.*?)%.*?).*?', p.text)
|
||||
slt = '/'
|
||||
if chars.find('\\') != -1:
|
||||
slt = '\\'
|
||||
for char in chars.split(slt):
|
||||
data['up_char']['4'][char.strip()] = probability.strip()
|
||||
break
|
||||
pr = re.search(r'.*?★:(.*?)(在(.*?)★.*?以(.*?)倍权值.*?).*?', p.text)
|
||||
if pr:
|
||||
char = pr.group(1)
|
||||
star = pr.group(2)
|
||||
weight = pr.group(3)
|
||||
char = char.replace('[限定]', '').replace('[', '').replace(']', '')
|
||||
data['up_char'][star][char.strip()] = f'权{weight}'
|
||||
# data['time'] = '03月09日16:00 - 05月23日03:5
|
||||
content = soup.find('div', {'class': 'article-content'})
|
||||
contents = [x for x in content.contents if x.text or str(x).find('img') != -1]
|
||||
start_index = -1
|
||||
end_index = -1
|
||||
for i in range(len(contents)):
|
||||
if str(contents[i]).startswith('<p>'):
|
||||
r = re.search('(.*)(寻访|复刻).*?开启', contents[i].text)
|
||||
if r:
|
||||
if str(contents[i+3].text).find('★') != -1:
|
||||
img = contents[i-1].find('img')
|
||||
if img:
|
||||
data['char']['pool_img'] = img['src']
|
||||
start_index = i
|
||||
for j in range(i, len(contents)):
|
||||
if str(contents[j]).find('注意') != -1:
|
||||
end_index = j
|
||||
break
|
||||
break
|
||||
contents = contents[start_index: end_index]
|
||||
title = contents[0].text
|
||||
data['char']['title'] = title[title.find('【'): title.find('】') + 1]
|
||||
data['char']['time'] = str(contents[1].text).split(':', maxsplit=1)[1]
|
||||
for p in contents[2:]:
|
||||
p = str(p.text)
|
||||
r = None
|
||||
if p.find('★') != -1:
|
||||
if p.find('权值') == -1:
|
||||
r = re.search(r'.*?:(.*)(占(.*)★.*?的(.*)%)', p)
|
||||
else:
|
||||
r = re.search(r'.*?:(.*)(在(.*)★.*?以(.*)倍权值.*?)', p)
|
||||
star = r.group(2)
|
||||
if r:
|
||||
chars = r.group(1)
|
||||
if chars.find('/') != -1:
|
||||
chars = chars.strip().split('/')
|
||||
elif chars.find('\\') != -1:
|
||||
chars = chars.strip().split('\\')
|
||||
else:
|
||||
chars = chars.split('\n')
|
||||
chars = [x.replace('[限定]', '').strip() for x in chars]
|
||||
probability = r.group(3)
|
||||
probability = probability if int(probability) > 10 else f'权{probability}'
|
||||
for char in chars:
|
||||
if char.strip():
|
||||
data['char']['up_char'][star][char.strip()] = probability
|
||||
except TimeoutError:
|
||||
print(f'更新明日方舟UP池信息超时...')
|
||||
with open(prts_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
logger.warning(f'更新明日方舟UP池信息超时...')
|
||||
if prts_up_char.exists():
|
||||
with open(prts_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
logger.error(f'更新明日方舟未知错误 e:{e}')
|
||||
if prts_up_char.exists():
|
||||
with open(prts_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
return check_write(data, prts_up_char)
|
||||
|
||||
|
||||
class GenshinAnnouncement:
|
||||
|
||||
@staticmethod
|
||||
async def get_announcement_text():
|
||||
def __init__(self):
|
||||
self.game_name = '原神'
|
||||
|
||||
async def _get_announcement_text(self):
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
async with session.get(genshin_url, timeout=7) as res:
|
||||
return await res.text()
|
||||
|
||||
@staticmethod
|
||||
async def update_up_char():
|
||||
async def update_up_char(self):
|
||||
genshin_up_char.parent.mkdir(exist_ok=True, parents=True)
|
||||
data = {
|
||||
'char': {'up_char': {'5': {}, '4': {}}, 'title': '', 'time': '', 'pool_img': ''},
|
||||
'arms': {'up_char': {'5': {}, '4': {}}, 'title': '', 'time': '', 'pool_img': ''}
|
||||
}
|
||||
text = await GenshinAnnouncement.get_announcement_text()
|
||||
text = await self._get_announcement_text()
|
||||
soup = BeautifulSoup(text, 'lxml')
|
||||
try:
|
||||
div = soup.find_all('div', {'class': 'row'})[1]
|
||||
@@ -194,25 +186,30 @@ class GenshinAnnouncement:
|
||||
for a in trs[3].find('td').find_all('a'):
|
||||
char_name = a['title']
|
||||
data[itype]['up_char']['4'][char_name] = "50"
|
||||
except TimeoutError as e:
|
||||
except TimeoutError:
|
||||
logger.warning(f'更新原神UP池信息超时...')
|
||||
with open(genshin_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
if genshin_up_char.exists():
|
||||
with open(genshin_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f'更新原神UP失败,疑似UP池已结束, e:{e}')
|
||||
with open(genshin_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
data['char']['title'] = ''
|
||||
data['arms']['title'] = ''
|
||||
with open(genshin_up_char, 'w', encoding='utf8') as wf:
|
||||
json.dump(data, wf, ensure_ascii=False, indent=4)
|
||||
return data
|
||||
return check_write(data, genshin_up_char, 'genshin')
|
||||
logger.error(f'更新原神UP失败,疑似UP池已结束, e:{e}')
|
||||
if genshin_up_char.exists():
|
||||
with open(genshin_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
data['char']['title'] = ''
|
||||
data['arms']['title'] = ''
|
||||
with open(genshin_up_char, 'w', encoding='utf8') as wf:
|
||||
json.dump(data, wf, ensure_ascii=False, indent=4)
|
||||
return data
|
||||
return check_write(data, genshin_up_char)
|
||||
|
||||
|
||||
class PrettyAnnouncement:
|
||||
@staticmethod
|
||||
async def get_announcement_text():
|
||||
|
||||
def __init__(self):
|
||||
self.game_name = '赛马娘'
|
||||
|
||||
async def _get_announcement_text(self):
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
async with session.get(pretty_url, timeout=7) as res:
|
||||
soup = BeautifulSoup(await res.text(), 'lxml')
|
||||
@@ -229,14 +226,13 @@ class PrettyAnnouncement:
|
||||
async with session.get(f'https://wiki.biligame.com/{url}', timeout=7) as res:
|
||||
return await res.text(), title[:-2]
|
||||
|
||||
@staticmethod
|
||||
async def update_up_char():
|
||||
async def update_up_char(self):
|
||||
data = {
|
||||
'char': {'up_char': {'3': {}, '2': {}, '1': {}}, 'title': '', 'time': '', 'pool_img': ''},
|
||||
'card': {'up_char': {'3': {}, '2': {}, '1': {}}, 'title': '', 'time': '', 'pool_img': ''}
|
||||
}
|
||||
try:
|
||||
text, title = await PrettyAnnouncement.get_announcement_text()
|
||||
text, title = await self._get_announcement_text()
|
||||
soup = BeautifulSoup(text, 'lxml')
|
||||
context = soup.find('div', {'class': 'toc-sticky'})
|
||||
if not context:
|
||||
@@ -299,26 +295,30 @@ class PrettyAnnouncement:
|
||||
with open(pretty_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
logger.error(f'赛马娘up更新失败 {type(e)}:{e}')
|
||||
return check_write(data, pretty_up_char, 'pretty')
|
||||
logger.error(f'赛马娘up更新未知错误 {type(e)}:{e}')
|
||||
if pretty_up_char.exists():
|
||||
with open(pretty_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
return check_write(data, pretty_up_char)
|
||||
|
||||
|
||||
class GuardianAnnouncement:
|
||||
|
||||
@staticmethod
|
||||
async def get_announcement_text():
|
||||
def __init__(self):
|
||||
self.game_name = '坎公骑冠剑'
|
||||
|
||||
async def _get_announcement_text(self):
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
async with session.get(guardian_url, timeout=7) as res:
|
||||
return await res.text()
|
||||
|
||||
@staticmethod
|
||||
async def update_up_char():
|
||||
async def update_up_char(self):
|
||||
data = {
|
||||
'char': {'up_char': {'3': {}}, 'title': '', 'time': '', 'pool_img': ''},
|
||||
'arms': {'up_char': {'5': {}}, 'title': '', 'time': '', 'pool_img': ''}
|
||||
}
|
||||
try:
|
||||
text = await GuardianAnnouncement.get_announcement_text()
|
||||
text = await self._get_announcement_text()
|
||||
soup = BeautifulSoup(text, 'lxml')
|
||||
context = soup.select('div.col-sm-3:nth-child(3) > div:nth-child(2) > div:nth-child(1) '
|
||||
'> div:nth-child(2) > div:nth-child(3) > font:nth-child(1)')[0]
|
||||
@@ -346,16 +346,17 @@ class GuardianAnnouncement:
|
||||
end_idx = index
|
||||
break
|
||||
index += 1
|
||||
for x in divs[start_idx+1: end_idx]:
|
||||
for x in divs[start_idx + 1: end_idx]:
|
||||
name = x.find('p').find_all('a')[-1].text
|
||||
data['char']['up_char']['3'][name] = '0'
|
||||
for x in divs[end_idx+1:]:
|
||||
for x in divs[end_idx + 1:]:
|
||||
name = x.find('p').find_all('a')[-1].text
|
||||
data['arms']['up_char']['5'][name] = '0'
|
||||
except TimeoutError:
|
||||
print(f'更新坎公骑冠剑UP池信息超时...')
|
||||
with open(pretty_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
logger.warning(f'更新坎公骑冠剑UP池信息超时...')
|
||||
if guardian_up_char.exists():
|
||||
with open(guardian_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
except Exception as e:
|
||||
print(f'坎公骑冠剑up更新失败 {type(e)}:{e}')
|
||||
return check_write(data, guardian_up_char, 'guardian')
|
||||
logger.error(f'坎公骑冠剑up更新未知错误 {type(e)}:{e}')
|
||||
return check_write(data, guardian_up_char)
|
||||
|
||||
@@ -24,7 +24,7 @@ async def azur_draw(count: int, pool_name: str):
|
||||
cnlist = ['金', '紫', '蓝', '白']
|
||||
star_list = [0, 0, 0, 0]
|
||||
char_list, char_dict, max_star_list, star_list, max_star_index_list = \
|
||||
format_card_information(count, star_list, _get_azur_card, pool_name)
|
||||
format_card_information(count, star_list, _get_azur_card, pool_name, guaranteed=False)
|
||||
rst = init_star_rst(star_list, cnlist, max_star_list, max_star_index_list)
|
||||
if count > 90:
|
||||
char_list = set_list(char_list)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import os
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from nonebot.adapters.cqhttp import MessageSegment, Message
|
||||
import nonebot
|
||||
import random
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from .update_game_info import update_info
|
||||
from .util import generate_img, init_star_rst, BaseData, set_list, get_star, UpEvent, download_img
|
||||
from .util import generate_img, init_star_rst, BaseData, set_list, get_star, init_up_char
|
||||
from .config import GENSHIN_FIVE_P, GENSHIN_FOUR_P, GENSHIN_G_FIVE_P, GENSHIN_G_FOUR_P, GENSHIN_THREE_P, I72_ADD, \
|
||||
DRAW_PATH, GENSHIN_FLAG
|
||||
from dataclasses import dataclass
|
||||
from .init_card_pool import init_game_pool
|
||||
from .announcement import GenshinAnnouncement
|
||||
from services.log import logger
|
||||
from util.init_result import image
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
@@ -20,6 +17,8 @@ except ModuleNotFoundError:
|
||||
|
||||
driver: nonebot.Driver = nonebot.get_driver()
|
||||
|
||||
announcement = GenshinAnnouncement()
|
||||
|
||||
genshin_five = {}
|
||||
genshin_count = {}
|
||||
genshin_pl_count = {}
|
||||
@@ -85,7 +84,7 @@ async def update_genshin_info():
|
||||
'攻击力(MAX)', '副属性(MAX)', '技能'])
|
||||
if code == 200:
|
||||
ALL_ARMS = init_game_pool('genshin_arms', data, GenshinChar)
|
||||
await _init_up_char()
|
||||
await _genshin_init_up_char()
|
||||
|
||||
|
||||
async def init_genshin_data():
|
||||
@@ -100,7 +99,7 @@ async def init_genshin_data():
|
||||
genshin_ARMS_dict = json.load(f)
|
||||
ALL_CHAR = init_game_pool('genshin', genshin_dict, GenshinChar)
|
||||
ALL_ARMS = init_game_pool('genshin_arms', genshin_ARMS_dict, GenshinChar)
|
||||
await _init_up_char()
|
||||
await _genshin_init_up_char()
|
||||
|
||||
|
||||
# 抽取卡池
|
||||
@@ -201,36 +200,11 @@ def reset_count(user_id: int):
|
||||
|
||||
|
||||
# 获取up和概率
|
||||
async def _init_up_char():
|
||||
async def _genshin_init_up_char():
|
||||
global _CURRENT_CHAR_POOL_TITLE, _CURRENT_ARMS_POOL_TITLE, UP_CHAR, UP_ARMS, POOL_IMG
|
||||
UP_CHAR = []
|
||||
UP_ARMS = []
|
||||
up_char_dict = await GenshinAnnouncement.update_up_char()
|
||||
_CURRENT_CHAR_POOL_TITLE = up_char_dict['char']['title']
|
||||
_CURRENT_ARMS_POOL_TITLE = up_char_dict['arms']['title']
|
||||
|
||||
if _CURRENT_CHAR_POOL_TITLE and _CURRENT_ARMS_POOL_TITLE:
|
||||
await download_img(up_char_dict['char']['pool_img'], 'genshin', 'up_char_pool_img')
|
||||
await download_img(up_char_dict['arms']['pool_img'], 'genshin', 'up_arms_pool_img')
|
||||
POOL_IMG = image('up_char_pool_img.png', '/draw_card/genshin/') + \
|
||||
image('up_arms_pool_img.png', '/draw_card/genshin/')
|
||||
else:
|
||||
if os.path.exists(IMAGE_PATH + '/draw_card/genshin/up_char_pool_img.png'):
|
||||
os.remove(IMAGE_PATH + '/draw_card/genshin/up_char_pool_img.png')
|
||||
if os.path.exists(IMAGE_PATH + '/draw_card/genshin/up_arms_pool_img.png'):
|
||||
os.remove(IMAGE_PATH + '/draw_card/genshin/up_arms_pool_img.png')
|
||||
logger.info(f'成功获取原神当前up信息...当前up池: {_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE}')
|
||||
for key in up_char_dict.keys():
|
||||
for star in up_char_dict[key]['up_char'].keys():
|
||||
up_char_lst = []
|
||||
for char in up_char_dict[key]['up_char'][star].keys():
|
||||
up_char_lst.append(char)
|
||||
if key == 'char':
|
||||
UP_CHAR.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
else:
|
||||
UP_ARMS.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
_CURRENT_CHAR_POOL_TITLE, _CURRENT_ARMS_POOL_TITLE, POOL_IMG, UP_CHAR, UP_ARMS = await init_up_char(announcement)
|
||||
|
||||
|
||||
async def reload_genshin_pool():
|
||||
await _init_up_char()
|
||||
return f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE} {POOL_IMG}'
|
||||
await _genshin_init_up_char()
|
||||
return Message(f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE} {POOL_IMG}')
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
|
||||
import os
|
||||
import nonebot
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from nonebot.adapters.cqhttp import MessageSegment, Message
|
||||
from .update_game_info import update_info
|
||||
from services.log import logger
|
||||
from .announcement import GuardianAnnouncement
|
||||
from .util import init_star_rst, generate_img, max_card, BaseData,\
|
||||
set_list, get_star, format_card_information, UpEvent
|
||||
set_list, get_star, format_card_information, init_up_char
|
||||
import random
|
||||
from .config import DRAW_PATH, GUARDIAN_ONE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIAN_THREE_CHAR_P, \
|
||||
GUARDIAN_THREE_CHAR_UP_P, GUARDIAN_TWO_ARMS_P, GUARDIAN_FIVE_ARMS_P, GUARDIAN_THREE_CHAR_OTHER_P, \
|
||||
@@ -21,6 +20,8 @@ except ModuleNotFoundError:
|
||||
|
||||
driver: nonebot.Driver = nonebot.get_driver()
|
||||
|
||||
announcement = GuardianAnnouncement()
|
||||
|
||||
ALL_CHAR = []
|
||||
ALL_ARMS = []
|
||||
|
||||
@@ -92,6 +93,7 @@ async def update_guardian_info():
|
||||
if code_1 == 200 and code_2 == 200:
|
||||
data.update(tmp)
|
||||
ALL_ARMS = init_game_pool('guardian_arms', data, GuardianArms)
|
||||
await _guardian_init_up_char()
|
||||
|
||||
|
||||
async def init_guardian_data():
|
||||
@@ -106,21 +108,27 @@ async def init_guardian_data():
|
||||
guardian_arms_dict = json.load(f)
|
||||
ALL_CHAR = init_game_pool('guardian', guardian_char_dict, GuardianChar)
|
||||
ALL_ARMS = init_game_pool('guardian_arms', guardian_arms_dict, GuardianArms)
|
||||
await _init_up_char()
|
||||
await _guardian_init_up_char()
|
||||
|
||||
|
||||
# 抽取卡池
|
||||
def _get_guardian_card(pool_name: str):
|
||||
def _get_guardian_card(pool_name: str = '', mode: int = 1):
|
||||
global ALL_ARMS, ALL_CHAR, UP_ARMS, UP_CHAR, _CURRENT_ARMS_POOL_TITLE, _CURRENT_CHAR_POOL_TITLE
|
||||
if pool_name == 'char':
|
||||
star = get_star([3, 2, 1], [GUARDIAN_THREE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIAN_ONE_CHAR_P])
|
||||
if mode == 1:
|
||||
star = get_star([3, 2, 1], [GUARDIAN_THREE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIAN_ONE_CHAR_P])
|
||||
else:
|
||||
star = get_star([3, 2], [GUARDIAN_THREE_CHAR_P, GUARDIAN_TWO_CHAR_P])
|
||||
up_lst = UP_CHAR
|
||||
flag = _CURRENT_CHAR_POOL_TITLE
|
||||
_max_star = 3
|
||||
all_data = ALL_CHAR
|
||||
else:
|
||||
star = get_star([5, 4, 3, 2], [GUARDIAN_FIVE_ARMS_P, GUARDIAN_FOUR_ARMS_P,
|
||||
GUARDIAN_THREE_ARMS_P, GUARDIAN_TWO_ARMS_P])
|
||||
if mode == 1:
|
||||
star = get_star([5, 4, 3, 2], [GUARDIAN_FIVE_ARMS_P, GUARDIAN_FOUR_ARMS_P,
|
||||
GUARDIAN_THREE_ARMS_P, GUARDIAN_TWO_ARMS_P])
|
||||
else:
|
||||
star = get_star([5, 4], [GUARDIAN_FIVE_ARMS_P, GUARDIAN_FOUR_ARMS_P])
|
||||
up_lst = UP_ARMS
|
||||
flag = _CURRENT_ARMS_POOL_TITLE
|
||||
_max_star = 5
|
||||
@@ -144,28 +152,11 @@ def _get_guardian_card(pool_name: str):
|
||||
|
||||
|
||||
# 获取up和概率
|
||||
async def _init_up_char():
|
||||
async def _guardian_init_up_char():
|
||||
global _CURRENT_CHAR_POOL_TITLE, _CURRENT_ARMS_POOL_TITLE, UP_CHAR, UP_ARMS, POOL_IMG
|
||||
UP_CHAR = []
|
||||
UP_ARMS = []
|
||||
up_char_dict = await GuardianAnnouncement.update_up_char()
|
||||
_CURRENT_CHAR_POOL_TITLE = up_char_dict['char']['title']
|
||||
_CURRENT_ARMS_POOL_TITLE = up_char_dict['arms']['title']
|
||||
if _CURRENT_CHAR_POOL_TITLE and _CURRENT_ARMS_POOL_TITLE:
|
||||
POOL_IMG = MessageSegment.image(up_char_dict['char']['pool_img']) + \
|
||||
MessageSegment.image(up_char_dict['arms']['pool_img'])
|
||||
logger.info(f'成功获取坎公骑冠剑当前up信息...当前up池: {_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE}')
|
||||
for key in up_char_dict.keys():
|
||||
for star in up_char_dict[key]['up_char'].keys():
|
||||
up_char_lst = []
|
||||
for char in up_char_dict[key]['up_char'][star].keys():
|
||||
up_char_lst.append(char)
|
||||
if key == 'char':
|
||||
UP_CHAR.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
else:
|
||||
UP_ARMS.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
_CURRENT_CHAR_POOL_TITLE, _CURRENT_ARMS_POOL_TITLE, POOL_IMG, UP_CHAR, UP_ARMS = await init_up_char(announcement)
|
||||
|
||||
|
||||
async def reload_guardian_pool():
|
||||
await _init_up_char()
|
||||
return f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE} {POOL_IMG}'
|
||||
await _guardian_init_up_char()
|
||||
return Message(f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE}')
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import os
|
||||
|
||||
import nonebot
|
||||
from .update_game_info import update_info
|
||||
from .announcement import PrettyAnnouncement
|
||||
from .util import download_img, init_star_rst, generate_img, max_card, BaseData, \
|
||||
set_list, get_star, format_card_information, UpEvent
|
||||
from .util import init_star_rst, generate_img, max_card, BaseData, \
|
||||
set_list, get_star, format_card_information, init_up_char
|
||||
import random
|
||||
from .config import PRETTY_THREE_P, PRETTY_TWO_P, DRAW_PATH, PRETTY_ONE_P, PRETTY_FLAG
|
||||
from dataclasses import dataclass
|
||||
from .init_card_pool import init_game_pool
|
||||
from util.init_result import image
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import MessageSegment, Message
|
||||
|
||||
try:
|
||||
import ujson as json
|
||||
@@ -19,6 +17,8 @@ except ModuleNotFoundError:
|
||||
|
||||
driver: nonebot.Driver = nonebot.get_driver()
|
||||
|
||||
announcement = PrettyAnnouncement()
|
||||
|
||||
ALL_CHAR = []
|
||||
ALL_CARD = []
|
||||
|
||||
@@ -76,7 +76,7 @@ async def pretty_draw(count: int, pool_name):
|
||||
rst = init_star_rst(star_list, cnlist, three_list, three_olist, up_list)
|
||||
if count > 90:
|
||||
obj_list = set_list(obj_list)
|
||||
return pool_info + image(b64=await generate_img(obj_list, 'pretty', star_list)) \
|
||||
return pool_info + MessageSegment.image("base64://" + await generate_img(obj_list, 'pretty', star_list)) \
|
||||
+ '\n' + rst[:-1] + '\n' + max_card(obj_dict)
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ async def update_pretty_info():
|
||||
data, code = await update_info(url, 'pretty_card')
|
||||
if code == 200:
|
||||
ALL_CARD = init_game_pool('pretty_card', data, PrettyChar)
|
||||
await _init_up_char()
|
||||
await _pretty_init_up_char()
|
||||
|
||||
|
||||
async def init_pretty_data():
|
||||
@@ -102,13 +102,16 @@ async def init_pretty_data():
|
||||
pretty_card_dict = json.load(f)
|
||||
ALL_CHAR = init_game_pool('pretty', pretty_char_dict, PrettyChar)
|
||||
ALL_CARD = init_game_pool('pretty_card', pretty_card_dict, PrettyChar)
|
||||
await _init_up_char()
|
||||
await _pretty_init_up_char()
|
||||
|
||||
|
||||
# 抽取卡池
|
||||
def _get_pretty_card(pool_name: str):
|
||||
def _get_pretty_card(pool_name: str, mode: int = 1):
|
||||
global ALL_CHAR, ALL_CARD, _CURRENT_CHAR_POOL_TITLE, _CURRENT_CARD_POOL_TITLE
|
||||
star = get_star([3, 2, 1], [PRETTY_THREE_P, PRETTY_TWO_P, PRETTY_ONE_P])
|
||||
if mode == 1:
|
||||
star = get_star([3, 2, 1], [PRETTY_THREE_P, PRETTY_TWO_P, PRETTY_ONE_P])
|
||||
else:
|
||||
star = get_star([3, 2], [PRETTY_THREE_P, PRETTY_TWO_P])
|
||||
if pool_name == 'card':
|
||||
title = _CURRENT_CARD_POOL_TITLE
|
||||
up_data = UP_CARD
|
||||
@@ -126,6 +129,7 @@ def _get_pretty_card(pool_name: str):
|
||||
acquire_operator = random.choice(all_up_star)
|
||||
if pool_name == 'char':
|
||||
acquire_operator = acquire_operator.split(']')[1]
|
||||
print(acquire_operator)
|
||||
acquire_operator = [x for x in data if x.name == acquire_operator][0]
|
||||
else:
|
||||
acquire_operator = random.choice([x for x in data if x.star == star and not x.limited])
|
||||
@@ -135,39 +139,13 @@ def _get_pretty_card(pool_name: str):
|
||||
|
||||
|
||||
# 获取up和概率
|
||||
async def _init_up_char():
|
||||
async def _pretty_init_up_char():
|
||||
global _CURRENT_CHAR_POOL_TITLE, _CURRENT_CARD_POOL_TITLE, UP_CHAR, UP_CARD, POOL_IMG
|
||||
UP_CHAR = []
|
||||
UP_CARD = []
|
||||
up_char_dict = await PrettyAnnouncement.update_up_char()
|
||||
_CURRENT_CHAR_POOL_TITLE = up_char_dict['char']['title']
|
||||
_CURRENT_CARD_POOL_TITLE = up_char_dict['card']['title']
|
||||
if _CURRENT_CHAR_POOL_TITLE and _CURRENT_CARD_POOL_TITLE:
|
||||
await download_img(up_char_dict['char']['pool_img'], 'pretty', 'up_char_pool_img')
|
||||
await download_img(up_char_dict['card']['pool_img'], 'pretty', 'up_card_pool_img')
|
||||
POOL_IMG = image('up_char_pool_img.png', '/draw_card/pretty/') + \
|
||||
image('up_card_pool_img.png', '/draw_card/pretty/')
|
||||
else:
|
||||
if os.path.exists(IMAGE_PATH + '/draw_card/genshin/up_char_pool_img.png'):
|
||||
os.remove(IMAGE_PATH + '/draw_card/pretty/up_char_pool_img.png')
|
||||
if os.path.exists(IMAGE_PATH + '/draw_card/genshin/up_arms_pool_img.png'):
|
||||
os.remove(IMAGE_PATH + '/draw_card/pretty/up_card_pool_img.png')
|
||||
logger.info(f'成功获取赛马娘当前up信息...当前up池: {_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_CARD_POOL_TITLE}')
|
||||
for key in up_char_dict.keys():
|
||||
for star in up_char_dict[key]['up_char'].keys():
|
||||
up_lst = []
|
||||
for char in up_char_dict[key]['up_char'][star].keys():
|
||||
up_lst.append(char)
|
||||
if key == 'char':
|
||||
if up_lst:
|
||||
UP_CHAR.append(UpEvent(star=int(star), operators=up_lst, zoom=0))
|
||||
else:
|
||||
if up_lst:
|
||||
UP_CARD.append(UpEvent(star=int(star), operators=up_lst, zoom=0))
|
||||
_CURRENT_CHAR_POOL_TITLE, _CURRENT_CARD_POOL_TITLE, POOL_IMG, UP_CHAR, UP_CARD = await init_up_char(announcement)
|
||||
|
||||
|
||||
async def reload_pretty_pool():
|
||||
await _init_up_char()
|
||||
return f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_CARD_POOL_TITLE} {POOL_IMG}'
|
||||
await _pretty_init_up_char()
|
||||
return Message(f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_CARD_POOL_TITLE} {POOL_IMG}')
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from nonebot.adapters.cqhttp import MessageSegment, Message
|
||||
import nonebot
|
||||
import random
|
||||
from .config import PRTS_FIVE_P, PRTS_FOUR_P, PRTS_SIX_P, PRTS_THREE_P, DRAW_PATH, PRTS_FLAG
|
||||
@@ -17,6 +17,8 @@ except ModuleNotFoundError:
|
||||
|
||||
driver: nonebot.Driver = nonebot.get_driver()
|
||||
|
||||
announcement = PrtsAnnouncement()
|
||||
|
||||
up_char_file = Path() / "data" / "draw_card" / "draw_card_up" / "prts_up_char.json"
|
||||
|
||||
prts_dict = {}
|
||||
@@ -38,15 +40,22 @@ async def prts_draw(count: int = 300):
|
||||
star_list = [0, 0, 0, 0]
|
||||
operator_list, operator_dict, six_list, star_list, six_index_list = format_card_information(count, star_list)
|
||||
up_list = []
|
||||
tmp = ''
|
||||
if _CURRENT_POOL_TITLE:
|
||||
for x in UP_OPERATOR:
|
||||
for operator in x.operators:
|
||||
up_list.append(operator)
|
||||
if x.star == 6:
|
||||
tmp += f'六星UP:{" ".join(x.operators)} \n'
|
||||
elif x.star == 5:
|
||||
tmp += f'五星UP:{" ".join(x.operators)} \n'
|
||||
elif x.star == 4:
|
||||
tmp += f'四星UP:{" ".join(x.operators)}'
|
||||
rst = init_star_rst(star_list, cnlist, six_list, six_index_list, up_list)
|
||||
if count > 90:
|
||||
operator_list = set_list(operator_list)
|
||||
pool_info = "当前up池: " if _CURRENT_POOL_TITLE else ""
|
||||
return pool_info + _CURRENT_POOL_TITLE + MessageSegment.image(
|
||||
pool_info = f"当前up池: {_CURRENT_POOL_TITLE}\n{tmp}" if _CURRENT_POOL_TITLE else ""
|
||||
return pool_info + MessageSegment.image(
|
||||
"base64://" + await generate_img(operator_list, 'prts', star_list)) \
|
||||
+ '\n' + rst[:-1] + '\n' + max_card(operator_dict)
|
||||
|
||||
@@ -137,11 +146,11 @@ def format_card_information(count: int, star_list: list):
|
||||
async def _init_up_char():
|
||||
global _CURRENT_POOL_TITLE, POOL_IMG, UP_OPERATOR
|
||||
UP_OPERATOR = []
|
||||
up_char_dict = await PrtsAnnouncement.update_up_char()
|
||||
_CURRENT_POOL_TITLE = up_char_dict['title']
|
||||
up_char_dict = await announcement.update_up_char()
|
||||
_CURRENT_POOL_TITLE = up_char_dict['char']['title']
|
||||
if _CURRENT_POOL_TITLE:
|
||||
POOL_IMG = MessageSegment.image(up_char_dict['pool_img'])
|
||||
up_char_dict = up_char_dict['up_char']
|
||||
POOL_IMG = MessageSegment.image(up_char_dict['char']['pool_img'])
|
||||
up_char_dict = up_char_dict['char']['up_char']
|
||||
logger.info(f'成功获取明日方舟当前up信息...当前up池: {_CURRENT_POOL_TITLE}')
|
||||
average_dict = {'6': {}, '5': {}, '4': {}}
|
||||
for star in up_char_dict.keys():
|
||||
@@ -161,4 +170,4 @@ async def _init_up_char():
|
||||
|
||||
async def reload_prts_pool():
|
||||
await _init_up_char()
|
||||
return f'当前UP池:{_CURRENT_POOL_TITLE} {POOL_IMG}'
|
||||
return Message(f'当前UP池:{_CURRENT_POOL_TITLE} {POOL_IMG}')
|
||||
|
||||
@@ -3,6 +3,7 @@ import aiohttp
|
||||
import aiofiles
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from aiohttp.client_exceptions import InvalidURL
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
from typing import List, Union, Set
|
||||
from pathlib import Path
|
||||
from .config import path_dict
|
||||
@@ -218,21 +219,76 @@ def get_star(star_lst: List[int], probability_lst: List[float]) -> int:
|
||||
return star_lst[i]
|
||||
|
||||
|
||||
# 获取up和概率
|
||||
async def init_up_char(announcement):
|
||||
UP_CHAR = []
|
||||
UP_ARMS = []
|
||||
tmp = ''
|
||||
up_char_dict = await announcement.update_up_char()
|
||||
for x in list(up_char_dict.keys()):
|
||||
tmp += up_char_dict[x]['title'] + '[\n]'
|
||||
tmp = tmp.split('[\n]')
|
||||
_CURRENT_CHAR_POOL_TITLE = tmp[0]
|
||||
if len(up_char_dict) > 1:
|
||||
_CURRENT_ARMS_POOL_TITLE = tmp[1]
|
||||
else:
|
||||
_CURRENT_ARMS_POOL_TITLE = ''
|
||||
POOL_IMG = ''
|
||||
x = [x for x in list(up_char_dict.keys())]
|
||||
if _CURRENT_CHAR_POOL_TITLE:
|
||||
POOL_IMG += MessageSegment.image(up_char_dict[x[0]]['pool_img'])
|
||||
try:
|
||||
if _CURRENT_ARMS_POOL_TITLE:
|
||||
POOL_IMG += MessageSegment.image(up_char_dict[x[1]]['pool_img'])
|
||||
except (IndexError, KeyError):
|
||||
pass
|
||||
logger.info(f'成功获取{announcement.game_name}当前up信息...当前up池: {_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE}')
|
||||
for key in up_char_dict.keys():
|
||||
for star in up_char_dict[key]['up_char'].keys():
|
||||
up_char_lst = []
|
||||
for char in up_char_dict[key]['up_char'][star].keys():
|
||||
up_char_lst.append(char)
|
||||
if up_char_lst:
|
||||
if key == 'char':
|
||||
UP_CHAR.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
else:
|
||||
UP_ARMS.append(UpEvent(star=int(star), operators=up_char_lst, zoom=0))
|
||||
return _CURRENT_CHAR_POOL_TITLE, _CURRENT_ARMS_POOL_TITLE, POOL_IMG, UP_CHAR, UP_ARMS
|
||||
|
||||
|
||||
# 整理数据
|
||||
def format_card_information(count: int, star_list: List[int], func, pool_name: str = ''):
|
||||
def format_card_information(count: int, star_list: List[int], func, pool_name: str = '', guaranteed: bool = True):
|
||||
max_star_lst = [] # 获取的最高星级角色列表
|
||||
max_index_lst = [] # 获取最高星级角色的次数
|
||||
obj_list = [] # 获取所有角色
|
||||
obj_dict = {} # 获取角色次数字典
|
||||
_count = -1
|
||||
if guaranteed:
|
||||
_count = 0
|
||||
for i in range(count):
|
||||
if guaranteed:
|
||||
_count += 1
|
||||
if pool_name:
|
||||
obj, code = func(pool_name)
|
||||
if _count == 10:
|
||||
obj, code = func(pool_name, 2)
|
||||
_count = 0
|
||||
else:
|
||||
obj, code = func(pool_name)
|
||||
else:
|
||||
obj, code = func()
|
||||
if _count == 10:
|
||||
obj, code = func(mode=2)
|
||||
_count = 0
|
||||
else:
|
||||
obj, code = func()
|
||||
star_list[code] += 1
|
||||
if code == 0:
|
||||
max_star_lst.append(obj.name)
|
||||
max_index_lst.append(i)
|
||||
if guaranteed:
|
||||
_count = 0
|
||||
if code == 1:
|
||||
if guaranteed:
|
||||
_count = 0
|
||||
try:
|
||||
obj_dict[obj.name] += 1
|
||||
except KeyError:
|
||||
|
||||
Reference in New Issue
Block a user