mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-11 23:10:02 +08:00
update
This commit is contained in:
@@ -16,10 +16,12 @@ headers = {'User-Agent': '"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Te
|
||||
prts_up_char = Path(DRAW_PATH + "/draw_card_up/prts_up_char.json")
|
||||
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"
|
||||
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,10 +38,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']:
|
||||
if game_name in ['genshin', 'pretty', 'guardian']:
|
||||
tmp = data['char']
|
||||
if not is_expired(tmp):
|
||||
if game_name in ['genshin']:
|
||||
if game_name in ['genshin', 'guardian']:
|
||||
data['char']['title'] = ''
|
||||
data['arms']['title'] = ''
|
||||
elif game_name in ['pretty']:
|
||||
@@ -57,7 +59,7 @@ def check_write(data: dict, up_char_file, game_name: str = ''):
|
||||
with open(up_char_file, 'r', encoding='utf8') as f:
|
||||
old_data = json.load(f)
|
||||
tmp = old_data
|
||||
if game_name in ['genshin', 'pretty']:
|
||||
if game_name in ['genshin', 'pretty', 'guardian']:
|
||||
tmp = old_data['char']
|
||||
if is_expired(tmp):
|
||||
return old_data
|
||||
@@ -256,28 +258,30 @@ class PrettyAnnouncement:
|
||||
for msg in x:
|
||||
if msg.find('★') != -1:
|
||||
msg = msg.replace('<br/>', '')
|
||||
msg = msg.split(' ')
|
||||
if (star := len(msg[0].strip())) == 3:
|
||||
data['char']['up_char']['3'][msg[1]] = '70'
|
||||
char_name = msg[msg.find('['):].strip()
|
||||
if (star := len(msg[:msg.find('[')].strip())) == 3:
|
||||
data['char']['up_char']['3'][char_name] = '70'
|
||||
elif star == 2:
|
||||
data['char']['up_char']['2'][msg[1]] = '70'
|
||||
data['char']['up_char']['2'][char_name] = '70'
|
||||
elif star == 1:
|
||||
data['char']['up_char']['1'][msg[1]] = '70'
|
||||
data['char']['up_char']['1'][char_name] = '70'
|
||||
if str(p).find('(当期UP对象)') != -1 and str(p).find('赛马娘') == -1:
|
||||
data['card']['pool_img'] = p.find('img')['src']
|
||||
r = re.search(r'■全?新?支援卡(当期UP对象)([\s\S]*)</p>', str(p))
|
||||
if r:
|
||||
rmsg = r.group(1)
|
||||
rmsg = r.group(1).strip()
|
||||
rmsg = rmsg.split('<br/>')
|
||||
for x in rmsg[1:]:
|
||||
rmsg = [x for x in rmsg if x]
|
||||
for x in rmsg:
|
||||
x = x.replace('\n', '').replace('・', '')
|
||||
x = x.split(' ')
|
||||
if x[0] == 'SSR':
|
||||
data['card']['up_char']['3'][x[1]] = '70'
|
||||
if x[0] == 'SR':
|
||||
data['card']['up_char']['2'][x[1]] = '70'
|
||||
if x[0] == 'R':
|
||||
data['card']['up_char']['1'][x[1]] = '70'
|
||||
star = x[:x.find('[')].strip()
|
||||
char_name = x[x.find('['):].strip()
|
||||
if star == 'SSR':
|
||||
data['card']['up_char']['3'][char_name] = '70'
|
||||
if star == 'SR':
|
||||
data['card']['up_char']['2'][char_name] = '70'
|
||||
if star == 'R':
|
||||
data['card']['up_char']['1'][char_name] = '70'
|
||||
# 日文->中文
|
||||
with open(DRAW_PATH + 'pretty_card.json', 'r', encoding='utf8') as f:
|
||||
all_data = json.load(f)
|
||||
@@ -291,8 +295,67 @@ class PrettyAnnouncement:
|
||||
data['card']['up_char'][star][all_data[x]['中文名']] = '70'
|
||||
except TimeoutError:
|
||||
logger.warning(f'更新赛马娘UP池信息超时...')
|
||||
with open(pretty_up_char, 'r', encoding='utf8') as f:
|
||||
data = json.load(f)
|
||||
if pretty_up_char.exists():
|
||||
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')
|
||||
|
||||
|
||||
class GuardianAnnouncement:
|
||||
|
||||
@staticmethod
|
||||
async def get_announcement_text():
|
||||
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():
|
||||
data = {
|
||||
'char': {'up_char': {'3': {}}, 'title': '', 'time': '', 'pool_img': ''},
|
||||
'arms': {'up_char': {'5': {}}, 'title': '', 'time': '', 'pool_img': ''}
|
||||
}
|
||||
try:
|
||||
text = await GuardianAnnouncement.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]
|
||||
title = context.find('p').find('b').text
|
||||
tmp = title.split(',')
|
||||
time = ''
|
||||
for msg in tmp:
|
||||
r = re.search(r'[从|至](.*)(开始|结束)', msg)
|
||||
if r:
|
||||
time += r.group(1).strip() + ' - '
|
||||
time = time[:-3]
|
||||
title = time.split(' - ')[0] + 'UP卡池'
|
||||
data['char']['title'] = title
|
||||
data['arms']['title'] = title
|
||||
data['char']['time'] = time
|
||||
data['arms']['time'] = time
|
||||
start_idx = -1
|
||||
end_idx = -1
|
||||
index = 0
|
||||
divs = context.find_all('div')
|
||||
for x in divs:
|
||||
if x.text == '角色':
|
||||
start_idx = index
|
||||
if x.text == '武器':
|
||||
end_idx = index
|
||||
break
|
||||
index += 1
|
||||
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:]:
|
||||
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)
|
||||
except Exception as e:
|
||||
print(f'坎公骑冠剑up更新失败 {type(e)}:{e}')
|
||||
return check_write(data, guardian_up_char, 'guardian')
|
||||
|
||||
@@ -3,8 +3,10 @@ import os
|
||||
import nonebot
|
||||
from nonebot.adapters.cqhttp import MessageSegment
|
||||
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
|
||||
set_list, get_star, format_card_information, UpEvent
|
||||
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, \
|
||||
@@ -12,7 +14,6 @@ from .config import DRAW_PATH, GUARDIAN_ONE_CHAR_P, GUARDIAN_TWO_CHAR_P, GUARDIA
|
||||
GUARDIAN_EXCLUSIVE_ARMS_OTHER_P, GUARDIAN_FLAG
|
||||
from dataclasses import dataclass
|
||||
from .init_card_pool import init_game_pool
|
||||
import asyncio
|
||||
try:
|
||||
import ujson as json
|
||||
except ModuleNotFoundError:
|
||||
@@ -23,6 +24,12 @@ driver: nonebot.Driver = nonebot.get_driver()
|
||||
ALL_CHAR = []
|
||||
ALL_ARMS = []
|
||||
|
||||
_CURRENT_CHAR_POOL_TITLE = ''
|
||||
_CURRENT_ARMS_POOL_TITLE = ''
|
||||
UP_CHAR = []
|
||||
UP_ARMS = []
|
||||
POOL_IMG = ''
|
||||
|
||||
|
||||
@dataclass
|
||||
class GuardianChar(BaseData):
|
||||
@@ -41,12 +48,33 @@ async def guardian_draw(count: int, pool_name):
|
||||
else:
|
||||
cnlist = ['★★★', '★★', '★']
|
||||
star_list = [0, 0, 0]
|
||||
title = ''
|
||||
up_type = []
|
||||
up_list = []
|
||||
if pool_name == 'char' and _CURRENT_CHAR_POOL_TITLE:
|
||||
up_type = UP_CHAR
|
||||
title = _CURRENT_CHAR_POOL_TITLE
|
||||
elif pool_name == 'arms' and _CURRENT_ARMS_POOL_TITLE:
|
||||
up_type = UP_ARMS
|
||||
title = _CURRENT_ARMS_POOL_TITLE
|
||||
tmp = ''
|
||||
if up_type:
|
||||
for x in up_type:
|
||||
for operator in x.operators:
|
||||
up_list.append(operator)
|
||||
if pool_name == 'char':
|
||||
if x.star == 3:
|
||||
tmp += f'三星UP:{" ".join(x.operators)} \n'
|
||||
else:
|
||||
if x.star == 5:
|
||||
tmp += f'五星UP:{" ".join(x.operators)}'
|
||||
obj_list, obj_dict, max_list, star_list, max_index_list = format_card_information(count, star_list,
|
||||
_get_guardian_card, pool_name)
|
||||
rst = init_star_rst(star_list, cnlist, max_list, max_index_list)
|
||||
rst = init_star_rst(star_list, cnlist, max_list, max_index_list, up_list)
|
||||
pool_info = f'当前up池:{title}\n{tmp}' if title else ''
|
||||
if count > 90:
|
||||
obj_list = set_list(obj_list)
|
||||
return MessageSegment.image(
|
||||
return pool_info + '\n' + MessageSegment.image(
|
||||
"base64://" + await generate_img(obj_list, 'guardian', star_list)) \
|
||||
+ '\n' + rst[:-1] + '\n' + max_card(obj_dict)
|
||||
|
||||
@@ -78,41 +106,66 @@ 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()
|
||||
|
||||
|
||||
# 抽取卡池
|
||||
def _get_guardian_card(pool_name: str):
|
||||
global ALL_CHAR, ALL_ARMS
|
||||
if pool_name != 'arms':
|
||||
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])
|
||||
chars = [x for x in ALL_CHAR if x.star == star]
|
||||
return random.choice(chars), 3 - star
|
||||
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])
|
||||
arms = [x for x in ALL_ARMS if x.star == star]
|
||||
return random.choice(arms), 5 - star
|
||||
|
||||
|
||||
# 整理数据
|
||||
def _format_card_information(count: int, pool_name: str):
|
||||
max_star_lst = []
|
||||
max_index_lst = []
|
||||
obj_list = []
|
||||
obj_dict = {}
|
||||
if pool_name == 'arms':
|
||||
star_list = [0, 0, 0, 0]
|
||||
up_lst = UP_ARMS
|
||||
flag = _CURRENT_ARMS_POOL_TITLE
|
||||
_max_star = 5
|
||||
all_data = ALL_ARMS
|
||||
# 是否UP
|
||||
if flag and star == _max_star and pool_name:
|
||||
# 获取up角色列表
|
||||
up_char_lst = [x.operators for x in up_lst if x.star == star][0]
|
||||
# 成功获取up角色
|
||||
if random.random() < 0.5:
|
||||
up_char_name = random.choice(up_char_lst)
|
||||
acquire_char = [x for x in all_data if x.name == up_char_name][0]
|
||||
else:
|
||||
# 无up
|
||||
all_char_lst = [x for x in all_data if x.star == star and x.name not in up_char_lst and not x.limited]
|
||||
acquire_char = random.choice(all_char_lst)
|
||||
else:
|
||||
star_list = [0, 0, 0]
|
||||
for i in range(count):
|
||||
obj, code = _get_guardian_card(pool_name)
|
||||
star_list[code] += 1
|
||||
if code == 0:
|
||||
max_star_lst.append(obj.name)
|
||||
max_index_lst.append(i)
|
||||
try:
|
||||
obj_dict[obj.name] += 1
|
||||
except KeyError:
|
||||
obj_dict[obj.name] = 1
|
||||
obj_list.append(obj)
|
||||
return obj_list, obj_dict, max_star_lst, star_list, max_index_lst
|
||||
chars = [x for x in all_data if x.star == star and not x.limited]
|
||||
acquire_char = random.choice(chars)
|
||||
return acquire_char, _max_star - star
|
||||
|
||||
|
||||
# 获取up和概率
|
||||
async def _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))
|
||||
|
||||
|
||||
async def reload_guardian_pool():
|
||||
await _init_up_char()
|
||||
return f'当前UP池子:{_CURRENT_CHAR_POOL_TITLE} & {_CURRENT_ARMS_POOL_TITLE} {POOL_IMG}'
|
||||
|
||||
@@ -42,7 +42,12 @@ def init_game_pool(game: str, data: dict, Operator: Any):
|
||||
tmp_lst.append(Operator(name=key, star=data[key]['初始星级'], limited=False))
|
||||
if game == 'pretty_card':
|
||||
for key in data.keys():
|
||||
tmp_lst.append(Operator(name=data[key]['中文名'], star=len(data[key]['稀有度']), limited=False))
|
||||
limited = False
|
||||
if '卡池' not in data[key]['获取方式']:
|
||||
limited = True
|
||||
if not data[key]['获取方式']:
|
||||
limited = False
|
||||
tmp_lst.append(Operator(name=data[key]['中文名'], star=len(data[key]['稀有度']), limited=limited))
|
||||
if game in ['guardian', 'guardian_arms']:
|
||||
for key in data.keys():
|
||||
tmp_lst.append(Operator(name=data[key]['名称'], star=int(data[key]['星级']), limited=False))
|
||||
@@ -55,9 +60,10 @@ def init_game_pool(game: str, data: dict, Operator: Any):
|
||||
if game == 'azur':
|
||||
for key in data.keys():
|
||||
limited = False
|
||||
if int(data[key]['星级']) > 4 or key.find('兵装') != -1 or key[-1] == '改' or key.find('布里') != -1:
|
||||
if '可以建造' not in data[key]['获取途径']:
|
||||
limited = True
|
||||
tmp_lst.append(Operator(name=data[key]['名称'], star=int(data[key]['星级']), limited=limited, itype=data[key]['类型']))
|
||||
tmp_lst.append(Operator(name=data[key]['名称'], star=int(data[key]['星级']),
|
||||
limited=limited, itype=data[key]['类型']))
|
||||
if game in ['fgo', 'fgo_card']:
|
||||
for key in data.keys():
|
||||
limited = False
|
||||
@@ -74,5 +80,6 @@ def init_game_pool(game: str, data: dict, Operator: Any):
|
||||
'灶门祢豆子', '灶门炭治郎']:
|
||||
limited = True
|
||||
tmp_lst.append(Operator(name=data[key]['名称'], star=data[key]['星级'], limited=limited))
|
||||
# print(tmp_lst)
|
||||
return tmp_lst
|
||||
|
||||
|
||||
@@ -125,11 +125,17 @@ async def retrieve_char_data(char: bs4.element.Tag, game_name: str, data: dict,
|
||||
if game_name == 'azur':
|
||||
char = char.find('td').find('div')
|
||||
avatar_img = char.find('a').find('img')
|
||||
try:
|
||||
member_dict['名称'] = remove_prohibited_str(str(avatar_img['alt'])[: str(avatar_img['alt']).find('头像')])
|
||||
except TypeError:
|
||||
member_dict['名称'] = char.find('a')['title'][:-4]
|
||||
try:
|
||||
member_dict['头像'] = unquote(str(avatar_img['srcset']).split(' ')[-2])
|
||||
except KeyError:
|
||||
member_dict['头像'] = unquote(str(avatar_img['src']).split(' ')[-2])
|
||||
member_dict['名称'] = remove_prohibited_str(str(avatar_img['alt'])[: str(avatar_img['alt']).find('头像')])
|
||||
except TypeError:
|
||||
member_dict['头像'] = "img link not find..."
|
||||
logger(f'{member_dict["名称"]} 图片缺失....')
|
||||
star = char.find('div').find('img')['alt']
|
||||
if star == '舰娘头像外框普通.png':
|
||||
star = 1
|
||||
@@ -159,15 +165,19 @@ async def _async_update_azur_extra_info(key: str, session: aiohttp.ClientSession
|
||||
try:
|
||||
async with session.get(f'https://wiki.biligame.com/blhx/{key}', timeout=7) as res:
|
||||
soup = BeautifulSoup(await res.text(), 'lxml')
|
||||
construction_time = str(soup.find('table', {'class': 'wikitable sv-general'}).find('tbody'))
|
||||
x = {key: {'获取途径': []}}
|
||||
if construction_time.find('无法建造') != -1:
|
||||
x[key]['获取途径'].append('无法建造')
|
||||
elif construction_time.find('活动已关闭') != -1:
|
||||
x[key]['获取途径'].append('活动限定')
|
||||
else:
|
||||
x[key]['获取途径'].append('可以建造')
|
||||
logger.info(f'碧蓝航线获取额外信息 {key}...{x[key]["获取途径"]}')
|
||||
try:
|
||||
construction_time = str(soup.find('table', {'class': 'wikitable sv-general'}).find('tbody'))
|
||||
x = {key: {'获取途径': []}}
|
||||
if construction_time.find('无法建造') != -1:
|
||||
x[key]['获取途径'].append('无法建造')
|
||||
elif construction_time.find('活动已关闭') != -1:
|
||||
x[key]['获取途径'].append('活动限定')
|
||||
else:
|
||||
x[key]['获取途径'].append('可以建造')
|
||||
logger.info(f'碧蓝航线获取额外信息 {key}...{x[key]["获取途径"]}')
|
||||
except AttributeError:
|
||||
x = {key: {'获取途径': []}}
|
||||
logger.warning(f'碧蓝航线获取额外信息错误 {key}...{[]}')
|
||||
return x
|
||||
except TimeoutError:
|
||||
logger.warning(f'访问 https://wiki.biligame.com/blhx/{key} 第 {i}次 超时...已再次访问')
|
||||
|
||||
Reference in New Issue
Block a user