diff --git a/README.md b/README.md index 3f16741..73c5758 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ WIKI:https://github.com/kcn3388/fgogacha/wiki
### 2022 #### ※建议更新后清除全部配置文件并重新生成,每次更新会尽可能兼容之前的配置文件,但是出现问题请先排查配置文件的问题 +- 🚀 **v2.6.4 (2022-12-20)** + - 拆分代码 + - 修复查询没有pickup的从者时的报错 + - 比如活动赠送、友情池限定等 - 🚀 **v2.6.3 (2022-12-20)** - fgo图书馆-从者信息新增国服未来pick up信息 - 食用指南:``[查询fgo从者 + 关键词 + 未来]`` diff --git a/__init__.py b/__init__.py index 7609947..0dfd0f9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,6 @@ import json.encoder import os.path -from hoshino import priv, Service from hoshino.util import DailyNumberLimiter, FreqLimiter from .get.gacha import gacha from .get.getGachaPools import getgachapools @@ -15,50 +14,6 @@ JEWEL_EXCEED_NOTICE = f"您今天已经抽过{jewel_limit.max}石头了,欢迎明早5点后再来!" TENJO_EXCEED_NOTICE = f"您今天已经抽过{tenjo_limit.max}张百连券了,欢迎明早5点后再来!" -height = 194 -width = 178 -dis = 23 -floor = 48 -st1w = 92 -st1h = 200 -st2 = 192 - -boxlist = [] - -box1 = (st1w, st1h) -for box_i in range(6): - boxlist.append(box1) - lst = list(box1) - lst[0] += width + dis - box1 = tuple(lst) - -box2 = (st2, st1h + height + floor) -for box_i in range(5): - boxlist.append(box2) - lst = list(box2) - lst[0] += width + dis - box2 = tuple(lst) - -sv_help = ''' -# 抽卡模拟相关 -[fgo十连] fgo抽卡 -[fgo百连] 100抽 -[获取fgo卡池] 从mooncell获取卡池数据 -[查询fgo卡池] 查询本地缓存的卡池以及本群卡池 -[切换fgo卡池 + 卡池编号] 切换需要的卡池 -[切换fgo日替卡池 + 卡池编号 + 日替卡池编号] 切换需要的日替卡池 -'''.strip() - -sv = Service( - name='fgo抽卡', - help_=sv_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) - @sv.on_fullmatch(("帮助fgo抽卡", "帮助FGO抽卡", "帮助bgo抽卡", "帮助BGO抽卡")) @sv.on_rex(r"(?i)^[fb]go[抽c][卡k][帮b][助z]$") diff --git a/fgo_fetch_all.py b/fgo_fetch_all.py index 400302c..b364f8c 100644 --- a/fgo_fetch_all.py +++ b/fgo_fetch_all.py @@ -1,37 +1,11 @@ from aiocqhttp import ActionFailed -from hoshino import priv, Service, HoshinoBot +from hoshino import HoshinoBot from .download.download_all_res import download_svt, download_cft, download_cmd from .get.get_all_cft import * from .get.get_all_cmd import * from .get.get_all_svt import * -sv_fetch_help = ''' -# 数据管理相关 -[获取全部内容] 获取从者/礼装/纹章的相关内容 -- 从者包括职介和指令卡 -- 礼装/纹章包括技能 -- 子命令: - - [获取全部从者] - - [获取全部礼装] - - [获取全部纹章] -[下载全部卡片资源] 从上述数据中下载对应静态资源 -- 子命令: - - [下载全部从者资源] - - [下载全部礼装资源] - - [下载全部纹章资源] -'''.strip() - -sv_fetch = Service( - name='fgo数据获取', - help_=sv_fetch_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) - @sv_fetch.on_fullmatch(("帮助fgo数据获取", "帮助FGO数据获取", "帮助bgo数据获取", "帮助BGO数据获取")) @sv_fetch.on_rex(r"(?i)^[fb]go[数s][据j][获h][取q][帮b][助z]$") diff --git a/fgo_lib.py b/fgo_lib.py index a09845e..89f3ad8 100644 --- a/fgo_lib.py +++ b/fgo_lib.py @@ -1,56 +1,8 @@ import os.path -from aiocqhttp import ActionFailed - -from hoshino import Service, priv, HoshinoBot -from .lib_online.lib_cft import * -from .lib_online.lib_cmd import * -from .lib_online.lib_svt import * - -sv_lib_help = ''' -# fgo数据库相关 -``[更新fgo图书馆]`` 获取从者/礼装/纹章的相关详细数据,包括属性、白值等 -- 支持附带类型参数以更新指定内容 -- 类型参数:从者/礼装/纹章/最新 - - 当参数含有最新时,只会获取本地不存在的内容 - - 支持种类与最新同时存在 -- **※需要先执行``[获取全部内容]``** - -``[增添fgo图书馆 + 类型 + id]`` 在本地已存在图书馆的情况下,手动增添新数据,以避免每次数据更新都需要重新爬一次全部内容 -- 类型:从者、礼装、纹章 - -``[查询最新图书馆 + 类型]`` 获取最近的内容 - -``[修补fgo图书馆 + 类型 + id]`` 单独修补某张卡片的详细数据 -- 类型为:从者、礼装、纹章 -- **※需要先执行``[更新fgo图书馆]``** - -``[fgo从者查询 + 关键词(至少一个)]`` 通过关键词搜索从者 -- 若关键词大于两个,只会返回同时符合的 -- 可以附带参数``详细``以获取卡面及游戏数据,附带参数``数据``则不显示卡面只显示游戏数据 -- 当输入参数存在id{卡片id}时,直接返回对应id的卡片 - - 例子:``查询fgo从者 id312`` - -``[fgo礼装查询 + 关键词(至少一个)]`` 通过关键词搜索礼装 -- 若关键词大于两个,只会搜索同时符合的 -- 可以附带参数``详细``以获取卡面及游戏数据 -- 查询特定id的礼装同上 - -``[fgo纹章查询 + 关键词(至少一个)]`` 通过关键词搜索礼装 -- 若关键词大于两个,只会搜索同时符合的 -- 可以附带参数``详细``以获取卡面及游戏数据 -- 查询特定id的纹章同上 -'''.strip() - -sv_lib = Service( - name='fgo图书馆', - help_=sv_lib_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) +from .lib_local.svt_local import * +from .lib_local.cft_local import * +from .lib_local.cmd_local import * @sv_lib.on_fullmatch(("帮助fgo图书馆", "帮助FGO图书馆", "帮助bgo图书馆", "帮助BGO图书馆")) @@ -671,1066 +623,14 @@ async def fix_lib(bot: HoshinoBot, ev: CQEvent): @sv_lib.on_rex(r"(?i)^[查c][询x][fb]go([从c][者z]|svt|servant)(\s.+)?$") async def find_svt(bot: HoshinoBot, ev: CQEvent): - msg = ev.message.extract_plain_text().split() - if len(msg) < 2: - await bot.finish(ev, "食用指南:[查询fgo从者 + 从者名字]") - - try: - with open(lib_servant_path, 'r', encoding="utf-8") as f: - svt = json.load(f) - except json.decoder.JSONDecodeError or FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - except FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - - del (msg[0]) - svt_data = [] - is_detail, remove_card, remove_data, \ - remove_info, remove_fool, remove_ultimate, \ - remove_skill, remove_voice, remove_pup = get_keys(msg) - - is_search_id = False - search_id = None - for each_arg in msg: - if re.match(r"id\d+", each_arg): - search_id = each_arg.replace("id", "") - is_search_id = True - - banned_keys = [ - "Hit信息括号内为每hit伤害百分比", - "Quick", - "Arts", - "Buster", - "Extra", - "宝具", - "受击", - "出星率", - "被即死率", - "暴击星分配权重" - ] - - for i in svt: - if is_search_id and i["id"] == search_id: - svt_data.append(i) - break - trans = {} - tmp = [] - for j in i: - if isinstance(i[j], str): - trans[j] = i[j] - - elif isinstance(i[j], list): - if j == "宝具信息": - for index in range(len(i[j])): - for each in i[j][index]: - trans[f"{each}{index}"] = i[j][index][each] - counter = 1 - for k in i[j]: - if isinstance(k, list) or isinstance(k, dict): - continue - trans[f"{j}{counter}"] = k - counter += 1 - - elif isinstance(i[j], dict): - if j == "技能": - for skills in i[j]: - for each in i[j][skills]: - skill_info = i[j][skills][each] - if each == "图标": - continue - if isinstance(i[j][skills][each], list): - skill_info = i[j][skills][each][0] - trans[f"{skills}{each}"] = skill_info - if j == "svt_detail" or j == "cards_url": - continue - for k in i[j]: - if isinstance(i[j][k], list) or isinstance(i[j][k], dict): - continue - if k in banned_keys: - continue - trans[f"{k}"] = i[j][k] - - counter = 1 - for arg in msg: - if re.match(r"^.星$", arg): - arg = re.sub(r"[五⑤伍]", "5", arg) - arg = re.sub(r"[四④肆]", "4", arg) - arg = re.sub(r"[三③叁]", "3", arg) - arg = re.sub(r"[二②贰]", "2", arg) - arg = re.sub(r"[一①壹]", "1", arg) - arg = arg.lower() - for each in trans: - if arg in trans[each].lower(): - if len(msg) == 1: - if i not in svt_data: - svt_data.append(i) - else: - if i not in tmp: - tmp.append(i) - counter += 1 - else: - if counter < len(msg): - tmp.append(i) - counter += 1 - else: - svt_data.append(i) - break - - if len(svt_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each in svt_data: - too_much += f"{counter}:{each['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - crt_file = False - if os.path.exists(config_path): - try: - configs = json.load(open(config_path, encoding="utf-8")) - for each_group in configs["groups"]: - if each_group["group"] == ev.group_id: - if not each_group["crt_path"] == "False": - crt_file = os.path.join(crt_folder_path, each_group["crt_path"]) - break - except json.decoder.JSONDecodeError: - pass - - if len(svt_data) == 0: - await bot.send(ev, "无结果……尝试在线搜索") - for each_msg in msg: - url = "https://fgo.wiki/w/" + each_msg - name, stat = await lib_svt_online(url, crt_file) - if stat == -100: - await bot.finish(ev, f"出错了!\n{name}") - elif not stat: - continue - elif stat: - for i in svt: - if name in i["name_link"]: - if i not in svt_data: - svt_data.append(i) - break - - if len(svt_data) == 0: - await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") - if len(svt_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each_svt_data in svt_data: - too_much += f"{counter}:{each_svt_data['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - if is_detail: - counter = 1 - details = [] - for each in svt_data: - img_path = os.path.join(svt_path, each["svt_icon"]) - if os.path.exists(img_path): - msg_error = "" - if "error" in each: - msg_error += f"从者{each['id']}数据存在错误,请使用[修补fgo图书馆 + 从者 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - if each_error.startswith("svt_info_main"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "主描述数据错误\n" - if each_error.startswith("svt_info"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "描述数据错误\n" - if each_error.startswith("svt_detail"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "描述详情数据错误\n" - - send_error = gen_node(msg_error.strip()) - details.append(send_error) - continue - - if len(svt_data) < 2: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - else: - if counter == 1: - msg_send = f"{counter}:{each['name_link']}\n" - else: - msg_send = "你找的可能是:\n" - msg_send += f"{counter}:{each['name_link']}\n" - counter += 1 - - # # 因为奇奇怪怪的风控,暂时屏蔽职阶图标 - # class_ = os.path.join(class_path, each["class_icon"]) - # if os.path.exists(class_): - # class_img = Image.open(class_) - # pic_card = util.pic2b64(class_img) - # msg_send += f"{MessageSegment.image(pic_card)}\n" - - if os.path.exists(img_path): - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - - msg_send += f"中文名:{each['name_cn']}\n原名:{each['name_jp']}\n稀有度:{each['rare']}\n" \ - f"获取方法:{each['method']}\n职阶:{each['detail']['职阶']}\n" - - send = gen_node(msg_send.strip()) - details.append(send) - - if not remove_card: - msg_card = "" - for cards in each["cards_url"]: - card = await gen_img_from_url(each["cards_url"][cards], crt_file) - if isinstance(card, Exception): - continue - else: - msg_card += f"{card}\n" - - send_card = gen_node(msg_card.strip()) - details.append(send_card) - - if not remove_data: - msg_data = "" - for data in each["detail"]: - if not data == "职阶": - if data == "NP获得率": - np = str(each['detail'][data]).replace(",", ",\n") - msg_data += f"{data}:{np}\n" - else: - msg_data += f"{data}:{each['detail'][data]}\n" - send_data = gen_node(create_img(msg_data.strip())) - details.append(send_data) - - if not remove_info: - for data in each["svt_detail"]: - msg_info = f"{data}:\n{each['svt_detail'][data]['资料']}\n" - send_info = gen_node(create_img(msg_info.strip())) - details.append(send_info) - - if not remove_fool: - if not each['fool']['资料'] == "" and not each['fool']['原文'] == "": - msg_fool = f"愚人节:\n{each['fool']['资料']}\n" - jp = each['fool']['原文'].replace('。', '。\n') - msg_fool += f"原文:\n{jp}\n" - send_fool = gen_node(create_img(msg_fool.strip())) - details.append(send_fool) - - if not remove_ultimate: - msg_ultimate = "" - for index in range(len(each["宝具信息"])): - if len(each["宝具信息"]) > 1: - msg_ultimate += f"宝具{index + 1}:\n" - else: - msg_ultimate += "宝具:\n" - for data in each["宝具信息"][index]: - msg_ultimate += f"\t\t\t\t{data}:{each['宝具信息'][index][data]}\n" - send_ultimate = gen_node(create_img(msg_ultimate.strip())) - details.append(send_ultimate) - - if not remove_skill: - for skills in each["技能"]: - if each["技能"] == {}: - break - msg_skill = f"{skills}\n" - msg_skill_icon = "" - for data in each["技能"][skills]: - if data == "图标": - icon = await gen_img_from_url(each["技能"][skills][data], crt_file) - if not isinstance(icon, Exception): - msg_skill_icon += f"{icon}\n" - continue - if isinstance(each["技能"][skills][data], list): - msg_skill += f'\t\t\t\t{data}:\n' - for each_value in each["技能"][skills][data]: - msg_skill += f'\t\t\t\t\t\t\t\t{each_value}\n' - else: - msg_skill += f'\t\t\t\t{data}:{each["技能"][skills][data]}\n' - - msg_skill = msg_skill_icon + create_img(msg_skill.strip()) - send_skill = gen_node(msg_skill) - details.append(send_skill) - - if not remove_voice: - for each_type in each["语音"]: - msg_voice = f"{each_type}:\n" - for each_voice in each["语音"][each_type]: - msg_voice += f'\t\t\t\t{each_voice}:' \ - f'\n\t\t\t\t\t\t\t\t{each["语音"][each_type][each_voice]["文本"]}\n' - - msg_voice = create_img(msg_voice.strip()) - send_voice = gen_node(msg_voice) - details.append(send_voice) - if not remove_pup: - details.append(gen_node("国服未来Pick Up情况:")) - pool_counter = 1 - for each_pool in each["pup"]: - msg_pup = f"{pool_counter}:{each_pool['title']}\n" \ - f"开放时间:{each_pool['time_start']}\n" \ - f"结束时间:{each_pool['time_end']}\n" \ - f"卡池时长:{each_pool['time_delta']}\n" - pup_img = await gen_img_from_url(each_pool['img_url'], crt_file) - if isinstance(pup_img, Exception): - continue - msg_pup += pup_img - send_pup = gen_node(msg_pup) - details.append(send_pup) - - else: - await bot.finish(ev, "没有本地资源~请先获取本地资源~") - try: - await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定从者,或单独指定内容") - - else: - msg_send = "你找的可能是:\n" - counter = 1 - details = [] - msg_error = "" - for each in svt_data: - if "error" in each: - msg_error += f"从者{each['id']}数据存在错误,请使用[修补fgo图书馆 + 从者 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - if each_error.startswith("svt_info_main"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "主描述数据错误\n" - if each_error.startswith("svt_info"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "描述数据错误\n" - if each_error.startswith("svt_detail"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "描述详情数据错误\n" - send_error = gen_node(msg_error.strip()) - details.append(send_error) - continue - - if counter == 1: - if len(svt_data) == 1: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - else: - msg_send += f"{counter}:{each['name_link']}\n" - else: - msg_send = f"{counter}:{each['name_link']}\n" - counter += 1 - - # # 因为奇奇怪怪的风控,暂时屏蔽职阶图标 - # class_ = os.path.join(class_path, each["class_icon"]) - # if os.path.exists(class_): - # class_img = Image.open(class_) - # pic_card = util.pic2b64(class_img) - # msg_send += f"{MessageSegment.image(pic_card)}\n" - - img_path = os.path.join(svt_path, each["svt_icon"]) - if os.path.exists(img_path): - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - - msg_send += f"中文名:{each['name_cn']}\n原名:{each['name_jp']}\n稀有度:{each['rare']}\n" \ - f"获取方法:{each['method']}\n职阶:{each['detail']['职阶']}\n" - - send = gen_node(msg_send.strip()) - details.append(send) - try: - if len(svt_data) > 1: - await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) - else: - if msg_error: - await bot.send(ev, msg_error.strip()) - else: - await bot.send(ev, msg_send.strip()) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定从者,或单独指定内容") + await local_find_svt(bot, ev) @sv_lib.on_rex(r"(?i)^[查c][询x][fb]go([礼l][装z]|cft|craft)(\s.+)?$") async def find_cft(bot: HoshinoBot, ev: CQEvent): - msg = ev.message.extract_plain_text().split() - if len(msg) < 2: - await bot.finish(ev, "食用指南:[查询fgo礼装 + 礼装名字]") - - try: - with open(lib_craft_path, 'r', encoding="utf-8") as f: - cft = json.load(f) - except json.decoder.JSONDecodeError or FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - except FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - - del (msg[0]) - cft_data = [] - is_detail = False - rule = re.compile(r"(?i)(详细|detail)") - if re.match(rule, msg[-1]): - is_detail = True - msg.pop() - - if "羁绊" in msg: - msg[msg.index("羁绊")] = "牵绊" - - is_search_id = False - search_id = None - for each_arg in msg: - if re.match(r"id\d+", each_arg): - search_id = each_arg.replace("id", "") - is_search_id = True - - for i in cft: - if is_search_id and i["id"] == search_id: - cft_data.append(i) - break - trans = {} - tmp = [] - for j in i: - if isinstance(i[j], str): - trans[j] = i[j] - - elif isinstance(i[j], list): - counter = 1 - for k in i[j]: - if isinstance(k, list) or isinstance(k, dict): - continue - trans[f"{j}{counter}"] = k - counter += 1 - - elif isinstance(i[j], dict): - for k in i[j]: - if isinstance(i[j][k], list) or isinstance(i[j][k], dict): - continue - if not k == "画师" or not k == "持有技能": - continue - trans[f"{k}"] = i[j][k] - - counter = 1 - for arg in msg: - if re.match(r"^.星$", arg): - arg = re.sub(r"[五⑤伍]", "5", arg) - arg = re.sub(r"[四④肆]", "4", arg) - arg = re.sub(r"[三③叁]", "3", arg) - arg = re.sub(r"[二②贰]", "2", arg) - arg = re.sub(r"[一①壹]", "1", arg) - arg = arg.lower() - for each in trans: - if arg in trans[each].lower(): - if len(msg) == 1: - if i not in cft_data: - cft_data.append(i) - else: - if i not in tmp: - tmp.append(i) - counter += 1 - else: - if counter < len(msg): - tmp.append(i) - counter += 1 - else: - cft_data.append(i) - break - - if len(cft_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each in cft_data: - too_much += f"{counter}:{each['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - crt_file = False - if os.path.exists(config_path): - try: - configs = json.load(open(config_path, encoding="utf-8")) - for each in configs["groups"]: - if each["group"] == ev.group_id: - if not each["crt_path"] == "False": - crt_file = os.path.join(crt_folder_path, each["crt_path"]) - break - except json.decoder.JSONDecodeError: - pass - - if len(cft_data) == 0: - await bot.send(ev, "无结果……尝试在线搜索") - for each in msg: - url = "https://fgo.wiki/w/" + each - name, stat = await lib_cft_online(url, crt_file) - if stat == -100: - await bot.finish(ev, f"出错了!\n{name}") - elif not stat: - continue - elif stat: - for i in cft: - if name in i["name_link"]: - if i not in cft_data: - cft_data.append(i) - break - - if len(cft_data) == 0: - await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") - if len(cft_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each in cft_data: - too_much += f"{counter}:{each['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - if is_detail: - counter = 1 - details = [] - for each in cft_data: - img_path = os.path.join(cft_path, each["cft_icon"]) - if os.path.exists(img_path): - msg_error = "" - if "error" in each: - msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - - send_error = gen_node(msg_error.strip()) - details.append(send_error) - continue - - if counter < 2: - msg_send = "你找的可能是:\n" - msg_send += f"{counter}:{each['name_link']}\n" - counter += 1 - else: - msg_send = f"{counter}:{each['name']}\n" - counter += 1 - if len(cft_data) == 1: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n礼装类型:{each['type']}\n\n" - - msg_send += "卡面:\n" - card = await gen_img_from_url(each["cards_url"], crt_file) - if isinstance(card, Exception): - sv_lib.logger.error(f"获取礼装{each['id']}卡面出错") - else: - msg_send += f"{card}\n" - - msg_data = "" - for data in each["detail"]: - # 按需选取,若风控很可能是因为大段日文 - if "解说" in data: - continue - if data == "持有技能": - msg_data += f"{data}:" - skill = os.path.join(skill_path, each["skill_icon"]) - msg_data += f"\n{gen_ms_img(Image.open(skill))}\n" - if isinstance(each['detail'][data], list): - for each_skill in each['detail'][data]: - each_skill = each_skill.replace("\n+", "+").replace("+", "\n") - msg_data += f"{each_skill}\n" - else: - msg_data += f"{each['detail'][data]}\n" - else: - msg_data += f"{data}:{each['detail'][data]}\n" - - msg_info = f"解说:\n{each['detail']['解说']}\n\n日文解说:\n{each['detail']['日文解说']}" - - detail1 = gen_node(msg_send.strip()) - detail2 = gen_node(msg_data.strip()) - detail3 = gen_node(create_img(msg_info.strip())) - details.append(detail1) - details.append(detail2) - details.append(detail3) - else: - await bot.finish(ev, "没有本地资源~请先获取本地资源~") - try: - await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") - - else: - msg_send = "你找的可能是:\n" - counter = 1 - msg_error = "" - for each in cft_data: - if "error" in each: - msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - - continue - - msg_send += f"{counter}:{each['name_link']}\n" - counter += 1 - if len(cft_data) == 1: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - img_path = os.path.join(cft_path, each["cft_icon"]) - if os.path.exists(img_path): - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n礼装类型:{each['type']}\n\n" - else: - await bot.finish(ev, "没有本地资源~请先获取本地资源~") - try: - if msg_error: - await bot.send(ev, msg_error.strip()) - else: - await bot.send(ev, msg_send.strip()) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") + await local_find_cft(bot, ev) @sv_lib.on_rex(r"(?i)^[查c][询x][fb]go([纹w][章z]|cmd|command)(\s.+)?$") async def find_cmd(bot: HoshinoBot, ev: CQEvent): - msg = ev.message.extract_plain_text().split() - if len(msg) < 2: - await bot.finish(ev, "食用指南:[查询fgo纹章 + 纹章名字]") - - try: - with open(lib_command_path, 'r', encoding="utf-8") as f: - cmd = json.load(f) - except json.decoder.JSONDecodeError or FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - except FileNotFoundError: - await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") - - del (msg[0]) - cmd_data = [] - is_detail = False - rule = re.compile(r"(?i)(详细|detail)") - if re.match(rule, msg[-1]): - is_detail = True - msg.pop() - - is_search_id = False - search_id = None - for each_arg in msg: - if re.match(r"id\d+", each_arg): - search_id = each_arg.replace("id", "") - is_search_id = True - - for i in cmd: - if is_search_id and i["id"] == search_id: - cmd_data.append(i) - break - trans = {} - tmp = [] - for j in i: - if isinstance(i[j], str): - trans[j] = i[j] - - elif isinstance(i[j], list): - counter = 1 - for k in i[j]: - if isinstance(k, list) or isinstance(k, dict): - continue - trans[f"{j}{counter}"] = k - counter += 1 - - elif isinstance(i[j], dict): - for k in i[j]: - if isinstance(i[j][k], list) or isinstance(i[j][k], dict): - continue - if not k == "画师" or not k == "持有技能": - continue - trans[f"{k}"] = i[j][k] - - counter = 1 - for arg in msg: - if re.match(r"^.星$", arg): - arg = re.sub(r"[五⑤伍]", "5", arg) - arg = re.sub(r"[四④肆]", "4", arg) - arg = re.sub(r"[三③叁]", "3", arg) - arg = re.sub(r"[二②贰]", "2", arg) - arg = re.sub(r"[一①壹]", "1", arg) - arg = arg.lower() - for each in trans: - if arg in trans[each].lower(): - if len(msg) == 1: - if i not in cmd_data: - cmd_data.append(i) - else: - if i not in tmp: - tmp.append(i) - counter += 1 - else: - if counter < len(msg): - tmp.append(i) - counter += 1 - else: - cmd_data.append(i) - break - - if len(cmd_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each in cmd_data: - too_much += f"{counter}:{each['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - crt_file = False - if os.path.exists(config_path): - try: - configs = json.load(open(config_path, encoding="utf-8")) - for each in configs["groups"]: - if each["group"] == ev.group_id: - if not each["crt_path"] == "False": - crt_file = os.path.join(crt_folder_path, each["crt_path"]) - break - except json.decoder.JSONDecodeError: - pass - - if len(cmd_data) == 0: - await bot.send(ev, "无结果……尝试在线搜索") - for each in msg: - url = "https://fgo.wiki/w/" + each - name, stat = await lib_cmd_online(url, crt_file) - if stat == -100: - await bot.finish(ev, f"出错了!\n{name}") - elif not stat: - continue - elif stat: - for i in cmd: - if name in i["name_link"]: - if i not in cmd_data: - cmd_data.append(i) - break - - if len(cmd_data) == 0: - await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") - if len(cmd_data) > 5: - too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" - counter = 0 - for each in cmd_data: - too_much += f"{counter}:{each['name_link']}\t" - counter += 1 - - await bot.finish(ev, too_much) - - if is_detail: - counter = 1 - details = [] - for each in cmd_data: - img_path = os.path.join(cmd_path, each["cmd_icon"]) - if os.path.exists(img_path): - msg_error = "" - if "error" in each: - msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - - send_error = gen_node(msg_error.strip()) - details.append(send_error) - continue - - if counter < 2: - msg_send = "你找的可能是:\n" - msg_send += f"{counter}:{each['name_link']}\n" - counter += 1 - else: - msg_send = f"{counter}:{each['name']}\n" - counter += 1 - if len(cmd_data) == 1: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n纹章类型:{each['type']}\n\n" - - msg_send += "卡面:\n" - card = await gen_img_from_url(each["cards_url"], crt_file) - if isinstance(card, Exception): - sv_lib.logger.error(f"获取纹章{each['id']}卡面出错") - else: - msg_send += f"{card}\n" - - msg_data = "" - for data in each["detail"]: - # 按需选取,若风控很可能是因为大段日文 - if "解说" in data: - continue - if data == "持有技能": - msg_data += f"{data}:" - skill = os.path.join(skill_path, each["skill_icon"]) - msg_data += f"\n{gen_ms_img(Image.open(skill))}\n" - msg_data += f"{each['detail'][data]}\n" - else: - msg_data += f"{data}:{each['detail'][data]}\n" - - msg_info = f"解说:\n{each['detail']['解说']}\n\n日文解说:\n{each['detail']['日文解说']}" - - detail1 = gen_node(msg_send.strip()) - detail2 = gen_node(msg_data.strip()) - detail3 = gen_node(create_img(msg_info.strip())) - details.append(detail1) - details.append(detail2) - details.append(detail3) - else: - await bot.finish(ev, "没有本地资源~请先获取本地资源~") - try: - await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定纹章") - - else: - msg_send = "你找的可能是:\n" - counter = 1 - msg_error = "" - for each in cmd_data: - if "error" in each: - msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" - error_num = len(each["error"]) - for each_error in each["error"]: - if each_error.startswith("aiorequest"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "基础数据错误\n" - if each_error.startswith("first bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "从者数据错误\n" - if each_error.startswith("find power bs error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "技能/宝具数据错误\n" - if each_error.startswith("get card img error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "卡面数据错误\n" - if each_error.startswith("get star error"): - if not error_num == 1: - msg_error += f'错误{each["error"].index(each_error) + 1}:' - msg_error += "星级数据错误\n" - - continue - - msg_send += f"{counter}:{each['name_link']}\n" - counter += 1 - if len(cmd_data) == 1: - msg_send = f"你找的可能是:\n{each['name_link']}\n" - img_path = os.path.join(cmd_path, each["cmd_icon"]) - if os.path.exists(img_path): - msg_send += f"{gen_ms_img(Image.open(img_path))}\n" - msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n纹章类型:{each['type']}\n\n" - else: - await bot.finish(ev, "没有本地资源~请先获取本地资源~") - try: - if msg_error: - await bot.send(ev, msg_error.strip()) - else: - await bot.send(ev, msg_send.strip()) - except ActionFailed as e: - sv_lib.logger.error(f"转发群消息失败:{e}") - await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") - - -def get_keys(msg) -> Tuple: - is_detail = False - remove_card = False - remove_data = False - remove_info = False - remove_fool = False - remove_ultimate = False - remove_skill = False - remove_voice = False - remove_pup = False - rule = re.compile(r"(?i)(详细|detail)") - if re.match(rule, msg[-1]): - is_detail = True - msg.pop() - rule1 = re.compile(r"(?i)(卡面|card)") - if re.match(rule1, msg[-1]): - is_detail = True - remove_data = True - remove_info = True - remove_fool = True - remove_ultimate = True - remove_skill = True - remove_voice = True - remove_pup = True - msg.pop() - rule2 = re.compile(r"(?i)(数据|data)") - if re.match(rule2, msg[-1]): - is_detail = True - remove_card = True - remove_info = True - remove_fool = True - remove_ultimate = True - remove_skill = True - remove_voice = True - remove_pup = True - msg.pop() - rule3 = re.compile(r"(?i)(资料|info)") - if re.match(rule3, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_fool = True - remove_ultimate = True - remove_skill = True - remove_voice = True - remove_pup = True - msg.pop() - rule4 = re.compile(r"(?i)(愚人节|fool)") - if re.match(rule4, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_info = True - remove_ultimate = True - remove_skill = True - remove_voice = True - remove_pup = True - msg.pop() - rule5 = re.compile(r"(?i)(宝具|bj|ultimate)") - if re.match(rule5, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_info = True - remove_fool = True - remove_skill = True - remove_voice = True - remove_pup = True - msg.pop() - rule6 = re.compile(r"(?i)(技能|skill)") - if re.match(rule6, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_info = True - remove_fool = True - remove_ultimate = True - remove_voice = True - remove_pup = True - msg.pop() - rule7 = re.compile(r"(?i)(语音|voice)") - if re.match(rule7, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_info = True - remove_fool = True - remove_ultimate = True - remove_skill = True - remove_pup = True - msg.pop() - rule8 = re.compile(r"(?i)(未来|pup)") - if re.match(rule8, msg[-1]): - is_detail = True - remove_data = True - remove_card = True - remove_info = True - remove_fool = True - remove_ultimate = True - remove_voice = True - remove_skill = True - msg.pop() - - return ( - is_detail, remove_card, remove_data, - remove_info, remove_fool, remove_ultimate, - remove_skill, remove_voice, remove_pup - ) + await local_find_cmd(bot, ev) diff --git a/fgo_lucky.py b/fgo_lucky.py index 79bc198..2e072c8 100644 --- a/fgo_lucky.py +++ b/fgo_lucky.py @@ -1,10 +1,11 @@ import json.encoder import os.path import re -from aiocqhttp import ActionFailed from typing import List -from hoshino import priv, Service, HoshinoBot +from aiocqhttp import ActionFailed + +from hoshino import HoshinoBot from hoshino.util import DailyNumberLimiter from .get.get_lucky_bag import get_all_lucky_bag, send_lucky_bag, get_lucky_gacha from .path_and_json import * @@ -12,51 +13,6 @@ lucky_limit = DailyNumberLimiter(1) LUCKY_EXCEED_NOTICE = f"您今天已经抽过{lucky_limit.max}次福袋了,欢迎明早5点后再来!" -height = 194 -width = 178 -dis = 23 -floor = 48 -st1w = 92 -st1h = 200 -st2 = 192 - -boxlist = [] - -box1 = (st1w, st1h) -for box_i in range(6): - boxlist.append(box1) - lst = list(box1) - lst[0] += width + dis - box1 = tuple(lst) - -box2 = (st2, st1h + height + floor) -for box_i in range(5): - boxlist.append(box2) - lst = list(box2) - lst[0] += width + dis - box2 = tuple(lst) - -lucky_sv_help = ''' -[更新fgo福袋] 获取福袋信息 -- 初次查询福袋之前务必先执行此命令 -[查询fgo福袋 + 概况] 查询全部福袋的文字概况 -[查询fgo福袋 + 国服/日服] 查询当前存在的福袋数据 -- [查询fgo福袋 + 国服/日服 + 福袋编号] 查询对应顺序的福袋详细数据 -- [查询fgo福袋 + 国服/日服 + 全部] 查询全部福袋详细数据 -[查询fgo福袋 + 未来] 查询国服千里眼福袋数据 -[抽fgo福袋 + 国服/日服 + 福袋编号 + 子池子编号(默认为1)] 抽福袋 -'''.strip() - -lucky_sv = Service( - name='fgo福袋', - help_=lucky_sv_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) - @lucky_sv.on_rex(r"(?i)^[更g][新x][fb]go[福f][袋d]$") async def update_lucky_bag(bot: HoshinoBot, ev: CQEvent): diff --git a/fgo_manage.py b/fgo_manage.py index eeac96a..2cf63e3 100644 --- a/fgo_manage.py +++ b/fgo_manage.py @@ -1,14 +1,11 @@ -import re - -from hoshino import priv, Service, HoshinoBot +from hoshino import HoshinoBot from .download.downloadIcons import downloadicons from .get.getGachaPools import getgachapools +from .get.get_all_cft import * +from .get.get_all_cmd import * +from .get.get_all_svt import * from .get.getnews import get_news -from .get.get_all_svt import get_all_svt -from .get.get_all_cft import get_all_cft -from .get.get_all_cmd import get_all_cmd from .loop import Counter # 借助 use_reloader 实现当模块发生变化时自动重载整个 Python -from .path_and_json import * # 更新时间间隔,单位为秒 flush_second = 0 @@ -31,31 +28,6 @@ except KeyError: pass -sv_manage_help = ''' -# 抽卡管理命令: -[fgo数据初始化] 初始化数据文件及目录,务必安装后先执行此命令! -[fgo数据下载] 下载从者及礼装图标,务必先初始化数据再执行下载! -[跟随最新/剧情卡池] 设置卡池数据更新后跟随最新国服卡池还是国服剧情卡池 -[fgo_enable_crt + crt文件路径] 为下载配置crt文件以规避拒绝访问,留空为默认,False为禁用 -[fgo_check_crt] 检查本群crt文件配置状态 -[重载配置文件] 为本群新建默认配置或还原至默认配置,同时修补其他群的配置 -[切换抽卡样式 + 样式] 切换抽卡样式,可选样式: -- 文字:旧版简约图标 -- 图片:仿真实抽卡 -[设置fgo时间 + 小时 + 分钟 + 秒] 设置自动更新时间间隔,至少输入其中一个参数 -- 例如:``设置fgo时间 1小时60分钟60秒`` -'''.strip() - -sv_manage = Service( - name='fgo管理', - help_=sv_manage_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) - @sv_manage.on_fullmatch(("帮助fgo管理", "帮助FGO管理", "帮助bgo管理", "帮助BGO管理")) @sv_manage.on_rex(r"(?i)^[fb]go[管g][理l][帮b][助z]$") diff --git a/fgo_news.py b/fgo_news.py index 269afa5..150da1e 100644 --- a/fgo_news.py +++ b/fgo_news.py @@ -2,28 +2,11 @@ import shutil from aiocqhttp import ActionFailed -from hoshino import priv, Service, HoshinoBot + +from hoshino import HoshinoBot from .get.getnews import get_news from .path_and_json import * -sv_news_help = ''' -# 新闻相关: -[获取fgo新闻 + 数量] 从官网获取公告新闻,默认6条,置顶的概率公告会去掉 -[查询fgo新闻 + 编号/all] 从本地查询公告具体内容,all代表全部获取 -- 可以在末尾附加参数``pic``不使用截图 -[清除新闻缓存] 移除新闻截图 -'''.strip() - -sv_news = Service( - name='fgo新闻获取', - help_=sv_news_help, - bundle="娱乐", - enable_on_default=True, - visible=True, - use_priv=priv.NORMAL, # 使用权限 - manage_priv=priv.ADMIN, # 管理权限 -) - @sv_news.on_fullmatch(("帮助fgo新闻获取", "帮助FGO新闻获取", "帮助bgo新闻获取", "帮助BGO新闻获取")) @sv_news.on_rex(r"(?i)^[fb]go[新x][闻w][获h][取q][帮b][助z]$") diff --git a/get/gacha.py b/get/gacha.py index 18e68f7..6b8f463 100644 --- a/get/gacha.py +++ b/get/gacha.py @@ -1,7 +1,6 @@ import random - -import hoshino from typing import Tuple, List + from ..path_and_json import * @@ -81,7 +80,7 @@ async def gacha(gid) -> Union[Tuple[int, int, int], Tuple[List, str, Dict]]: try: result = await get_result(pool_data["data"]) except KeyError as e: - hoshino.logger.error(f"{e}") + sv.logger.error(f"{e}") return 13, 0, 0 for each_result in result: card = int(random.choice(each_result[2])) diff --git a/get/getGachaPools.py b/get/getGachaPools.py index b59906f..b8d07cb 100644 --- a/get/getGachaPools.py +++ b/get/getGachaPools.py @@ -226,7 +226,7 @@ async def getgachapools(islatest=True, crt_file=None) -> Union[Exception, int]: return 0 except Exception as e: - logger.warning(f"{e}") + sv.logger.warning(f"{e}") return e diff --git a/get/get_lucky_bag.py b/get/get_lucky_bag.py index 78b2517..bb9f172 100644 --- a/get/get_lucky_bag.py +++ b/get/get_lucky_bag.py @@ -68,7 +68,7 @@ async def get_all_lucky_bag(crt_file=None) -> Union[Exception, Dict]: page["time_end"] = f'{time_end.string.strip()}(JST)' page["time_delta"] = f'{time_delta.string.strip()}(JST)' except Exception as e: - logger.warning(f"{e}") + lucky_sv.logger.warning(f"{e}") try: time_info = time_soup.find(text="日服卡池信息") time_start = time_info.find_next("td") @@ -78,7 +78,7 @@ async def get_all_lucky_bag(crt_file=None) -> Union[Exception, Dict]: page["time_end"] = f'{time_end.string.strip()}(JST)' page["time_delta"] = f'{time_delta.string.strip()}(JST)' except Exception as e: - logger.warning(f"{e}") + lucky_sv.logger.warning(f"{e}") pass detail_msg = await get_lucky_bag_detail(page) @@ -91,7 +91,7 @@ async def get_all_lucky_bag(crt_file=None) -> Union[Exception, Dict]: return lucky_bag except Exception as e: - logger.warning(f"{e}") + lucky_sv.logger.warning(f"{e}") return e @@ -185,7 +185,7 @@ async def get_lucky_bag_image(bag_pools: List) -> List: else: c_counter = 0 - card_msg = f'编号{counter}:' \ + card_msg = f'编号【{counter}】:' \ f'\n{pool_title}包含的五星从者:\n{gen_ms_img(target)}' nodes.append(gen_node(card_msg.strip())) counter += 1 @@ -219,7 +219,7 @@ async def send_lucky_bag(select_lucky: Union[Dict, List], crt_file, is_next=Fals counter = 1 for each_bag in select_lucky: sub_node = [] - lucky_msg = f"编号{counter}:\n" \ + lucky_msg = f"编号【{counter}】:\n" \ f"福袋名称:{each_bag['name']}\n" \ f"关联卡池:{each_bag['title']}\n" \ f"开放时间:{each_bag['time_start']}\n" \ diff --git a/lib_local/__pycache__/cft_local.cpython-38.pyc b/lib_local/__pycache__/cft_local.cpython-38.pyc new file mode 100644 index 0000000..eba3b1b Binary files /dev/null and b/lib_local/__pycache__/cft_local.cpython-38.pyc differ diff --git a/lib_local/__pycache__/cmd_local.cpython-38.pyc b/lib_local/__pycache__/cmd_local.cpython-38.pyc new file mode 100644 index 0000000..9b8491c Binary files /dev/null and b/lib_local/__pycache__/cmd_local.cpython-38.pyc differ diff --git a/lib_local/__pycache__/svt_local.cpython-38.pyc b/lib_local/__pycache__/svt_local.cpython-38.pyc new file mode 100644 index 0000000..2a6a850 Binary files /dev/null and b/lib_local/__pycache__/svt_local.cpython-38.pyc differ diff --git a/lib_local/cft_local.py b/lib_local/cft_local.py new file mode 100644 index 0000000..d0508ee --- /dev/null +++ b/lib_local/cft_local.py @@ -0,0 +1,277 @@ +from aiocqhttp import ActionFailed +from hoshino import HoshinoBot + +from ..lib_online.lib_cft import * +from ..path_and_json import * + + +async def local_find_cft(bot: HoshinoBot, ev: CQEvent): + msg = ev.message.extract_plain_text().split() + if len(msg) < 2: + await bot.finish(ev, "食用指南:[查询fgo礼装 + 礼装名字]") + + try: + with open(lib_craft_path, 'r', encoding="utf-8") as f: + cft = json.load(f) + except json.decoder.JSONDecodeError or FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + except FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + + del (msg[0]) + cft_data = [] + is_detail = False + rule = re.compile(r"(?i)(详细|detail)") + if re.match(rule, msg[-1]): + is_detail = True + msg.pop() + + if "羁绊" in msg: + msg[msg.index("羁绊")] = "牵绊" + + is_search_id = False + search_id = None + for each_arg in msg: + if re.match(r"id\d+", each_arg): + search_id = each_arg.replace("id", "") + is_search_id = True + + for i in cft: + if is_search_id and i["id"] == search_id: + cft_data.append(i) + break + trans = {} + tmp = [] + for j in i: + if isinstance(i[j], str): + trans[j] = i[j] + + elif isinstance(i[j], list): + counter = 1 + for k in i[j]: + if isinstance(k, list) or isinstance(k, dict): + continue + trans[f"{j}{counter}"] = k + counter += 1 + + elif isinstance(i[j], dict): + for k in i[j]: + if isinstance(i[j][k], list) or isinstance(i[j][k], dict): + continue + if not k == "画师" or not k == "持有技能": + continue + trans[f"{k}"] = i[j][k] + + counter = 1 + for arg in msg: + if re.match(r"^.星$", arg): + arg = re.sub(r"[五⑤伍]", "5", arg) + arg = re.sub(r"[四④肆]", "4", arg) + arg = re.sub(r"[三③叁]", "3", arg) + arg = re.sub(r"[二②贰]", "2", arg) + arg = re.sub(r"[一①壹]", "1", arg) + arg = arg.lower() + for each in trans: + if arg in trans[each].lower(): + if len(msg) == 1: + if i not in cft_data: + cft_data.append(i) + else: + if i not in tmp: + tmp.append(i) + counter += 1 + else: + if counter < len(msg): + tmp.append(i) + counter += 1 + else: + cft_data.append(i) + break + + if len(cft_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each in cft_data: + too_much += f"{counter}:{each['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + crt_file = False + if os.path.exists(config_path): + try: + configs = json.load(open(config_path, encoding="utf-8")) + for each in configs["groups"]: + if each["group"] == ev.group_id: + if not each["crt_path"] == "False": + crt_file = os.path.join(crt_folder_path, each["crt_path"]) + break + except json.decoder.JSONDecodeError: + pass + + if len(cft_data) == 0: + await bot.send(ev, "无结果……尝试在线搜索") + for each in msg: + url = "https://fgo.wiki/w/" + each + name, stat = await lib_cft_online(url, crt_file) + if stat == -100: + await bot.finish(ev, f"出错了!\n{name}") + elif not stat: + continue + elif stat: + for i in cft: + if name in i["name_link"]: + if i not in cft_data: + cft_data.append(i) + break + + if len(cft_data) == 0: + await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") + if len(cft_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each in cft_data: + too_much += f"{counter}:{each['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + if is_detail: + counter = 1 + details = [] + for each in cft_data: + img_path = os.path.join(cft_path, each["cft_icon"]) + if os.path.exists(img_path): + msg_error = "" + if "error" in each: + msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + + send_error = gen_node(msg_error.strip()) + details.append(send_error) + continue + + if counter < 2: + msg_send = "你找的可能是:\n" + msg_send += f"{counter}:{each['name_link']}\n" + counter += 1 + else: + msg_send = f"{counter}:{each['name']}\n" + counter += 1 + if len(cft_data) == 1: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n礼装类型:{each['type']}\n\n" + + msg_send += "卡面:\n" + card = await gen_img_from_url(each["cards_url"], crt_file) + if isinstance(card, Exception): + sv_lib.logger.error(f"获取礼装{each['id']}卡面出错") + else: + msg_send += f"{card}\n" + + msg_data = "" + for data in each["detail"]: + # 按需选取,若风控很可能是因为大段日文 + if "解说" in data: + continue + if data == "持有技能": + msg_data += f"{data}:" + skill = os.path.join(skill_path, each["skill_icon"]) + msg_data += f"\n{gen_ms_img(Image.open(skill))}\n" + if isinstance(each['detail'][data], list): + for each_skill in each['detail'][data]: + each_skill = each_skill.replace("\n+", "+").replace("+", "\n") + msg_data += f"{each_skill}\n" + else: + msg_data += f"{each['detail'][data]}\n" + else: + msg_data += f"{data}:{each['detail'][data]}\n" + + msg_info = f"解说:\n{each['detail']['解说']}\n\n日文解说:\n{each['detail']['日文解说']}" + + detail1 = gen_node(msg_send.strip()) + detail2 = gen_node(msg_data.strip()) + detail3 = gen_node(create_img(msg_info.strip())) + details.append(detail1) + details.append(detail2) + details.append(detail3) + else: + await bot.finish(ev, "没有本地资源~请先获取本地资源~") + try: + await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") + + else: + msg_send = "你找的可能是:\n" + counter = 1 + msg_error = "" + for each in cft_data: + if "error" in each: + msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + + continue + + msg_send += f"{counter}:{each['name_link']}\n" + counter += 1 + if len(cft_data) == 1: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + img_path = os.path.join(cft_path, each["cft_icon"]) + if os.path.exists(img_path): + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n礼装类型:{each['type']}\n\n" + else: + await bot.finish(ev, "没有本地资源~请先获取本地资源~") + try: + if msg_error: + await bot.send(ev, msg_error.strip()) + else: + await bot.send(ev, msg_send.strip()) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") diff --git a/lib_local/cmd_local.py b/lib_local/cmd_local.py new file mode 100644 index 0000000..b48b81e --- /dev/null +++ b/lib_local/cmd_local.py @@ -0,0 +1,269 @@ +from aiocqhttp import ActionFailed +from hoshino import HoshinoBot + +from ..lib_online.lib_cmd import * +from ..path_and_json import * + + +async def local_find_cmd(bot: HoshinoBot, ev: CQEvent): + msg = ev.message.extract_plain_text().split() + if len(msg) < 2: + await bot.finish(ev, "食用指南:[查询fgo纹章 + 纹章名字]") + + try: + with open(lib_command_path, 'r', encoding="utf-8") as f: + cmd = json.load(f) + except json.decoder.JSONDecodeError or FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + except FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + + del (msg[0]) + cmd_data = [] + is_detail = False + rule = re.compile(r"(?i)(详细|detail)") + if re.match(rule, msg[-1]): + is_detail = True + msg.pop() + + is_search_id = False + search_id = None + for each_arg in msg: + if re.match(r"id\d+", each_arg): + search_id = each_arg.replace("id", "") + is_search_id = True + + for i in cmd: + if is_search_id and i["id"] == search_id: + cmd_data.append(i) + break + trans = {} + tmp = [] + for j in i: + if isinstance(i[j], str): + trans[j] = i[j] + + elif isinstance(i[j], list): + counter = 1 + for k in i[j]: + if isinstance(k, list) or isinstance(k, dict): + continue + trans[f"{j}{counter}"] = k + counter += 1 + + elif isinstance(i[j], dict): + for k in i[j]: + if isinstance(i[j][k], list) or isinstance(i[j][k], dict): + continue + if not k == "画师" or not k == "持有技能": + continue + trans[f"{k}"] = i[j][k] + + counter = 1 + for arg in msg: + if re.match(r"^.星$", arg): + arg = re.sub(r"[五⑤伍]", "5", arg) + arg = re.sub(r"[四④肆]", "4", arg) + arg = re.sub(r"[三③叁]", "3", arg) + arg = re.sub(r"[二②贰]", "2", arg) + arg = re.sub(r"[一①壹]", "1", arg) + arg = arg.lower() + for each in trans: + if arg in trans[each].lower(): + if len(msg) == 1: + if i not in cmd_data: + cmd_data.append(i) + else: + if i not in tmp: + tmp.append(i) + counter += 1 + else: + if counter < len(msg): + tmp.append(i) + counter += 1 + else: + cmd_data.append(i) + break + + if len(cmd_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each in cmd_data: + too_much += f"{counter}:{each['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + crt_file = False + if os.path.exists(config_path): + try: + configs = json.load(open(config_path, encoding="utf-8")) + for each in configs["groups"]: + if each["group"] == ev.group_id: + if not each["crt_path"] == "False": + crt_file = os.path.join(crt_folder_path, each["crt_path"]) + break + except json.decoder.JSONDecodeError: + pass + + if len(cmd_data) == 0: + await bot.send(ev, "无结果……尝试在线搜索") + for each in msg: + url = "https://fgo.wiki/w/" + each + name, stat = await lib_cmd_online(url, crt_file) + if stat == -100: + await bot.finish(ev, f"出错了!\n{name}") + elif not stat: + continue + elif stat: + for i in cmd: + if name in i["name_link"]: + if i not in cmd_data: + cmd_data.append(i) + break + + if len(cmd_data) == 0: + await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") + if len(cmd_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each in cmd_data: + too_much += f"{counter}:{each['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + if is_detail: + counter = 1 + details = [] + for each in cmd_data: + img_path = os.path.join(cmd_path, each["cmd_icon"]) + if os.path.exists(img_path): + msg_error = "" + if "error" in each: + msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + + send_error = gen_node(msg_error.strip()) + details.append(send_error) + continue + + if counter < 2: + msg_send = "你找的可能是:\n" + msg_send += f"{counter}:{each['name_link']}\n" + counter += 1 + else: + msg_send = f"{counter}:{each['name']}\n" + counter += 1 + if len(cmd_data) == 1: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n纹章类型:{each['type']}\n\n" + + msg_send += "卡面:\n" + card = await gen_img_from_url(each["cards_url"], crt_file) + if isinstance(card, Exception): + sv_lib.logger.error(f"获取纹章{each['id']}卡面出错") + else: + msg_send += f"{card}\n" + + msg_data = "" + for data in each["detail"]: + # 按需选取,若风控很可能是因为大段日文 + if "解说" in data: + continue + if data == "持有技能": + msg_data += f"{data}:" + skill = os.path.join(skill_path, each["skill_icon"]) + msg_data += f"\n{gen_ms_img(Image.open(skill))}\n" + msg_data += f"{each['detail'][data]}\n" + else: + msg_data += f"{data}:{each['detail'][data]}\n" + + msg_info = f"解说:\n{each['detail']['解说']}\n\n日文解说:\n{each['detail']['日文解说']}" + + detail1 = gen_node(msg_send.strip()) + detail2 = gen_node(msg_data.strip()) + detail3 = gen_node(create_img(msg_info.strip())) + details.append(detail1) + details.append(detail2) + details.append(detail3) + else: + await bot.finish(ev, "没有本地资源~请先获取本地资源~") + try: + await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定纹章") + + else: + msg_send = "你找的可能是:\n" + counter = 1 + msg_error = "" + for each in cmd_data: + if "error" in each: + msg_error += f"礼装{each['id']}数据存在错误,请使用[修补fgo图书馆 + 礼装 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + + continue + + msg_send += f"{counter}:{each['name_link']}\n" + counter += 1 + if len(cmd_data) == 1: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + img_path = os.path.join(cmd_path, each["cmd_icon"]) + if os.path.exists(img_path): + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + msg_send += f"名字:{each['name']}\n稀有度:{each['rare']}\n纹章类型:{each['type']}\n\n" + else: + await bot.finish(ev, "没有本地资源~请先获取本地资源~") + try: + if msg_error: + await bot.send(ev, msg_error.strip()) + else: + await bot.send(ev, msg_send.strip()) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定礼装") diff --git a/lib_local/svt_local.py b/lib_local/svt_local.py new file mode 100644 index 0000000..a41443b --- /dev/null +++ b/lib_local/svt_local.py @@ -0,0 +1,549 @@ +from aiocqhttp import ActionFailed +from hoshino import HoshinoBot + +from ..lib_online.lib_svt import * +from ..path_and_json import * + + +async def local_find_svt(bot: HoshinoBot, ev: CQEvent): + msg = ev.message.extract_plain_text().split() + if len(msg) < 2: + await bot.finish(ev, "食用指南:[查询fgo从者 + 从者名字]") + + try: + with open(lib_servant_path, 'r', encoding="utf-8") as f: + svt = json.load(f) + except json.decoder.JSONDecodeError or FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + except FileNotFoundError: + await bot.finish(ev, "本地没有图书馆数据~请先更新图书馆~\n指令:[更新fgo图书馆]") + + del (msg[0]) + svt_data = [] + is_detail, remove_card, remove_data, \ + remove_info, remove_fool, remove_ultimate, \ + remove_skill, remove_voice, remove_pup = get_keys(msg) + + is_search_id = False + search_id = None + for each_arg in msg: + if re.match(r"id\d+", each_arg): + search_id = each_arg.replace("id", "") + is_search_id = True + + banned_keys = [ + "Hit信息括号内为每hit伤害百分比", + "Quick", + "Arts", + "Buster", + "Extra", + "宝具", + "受击", + "出星率", + "被即死率", + "暴击星分配权重" + ] + + for i in svt: + if is_search_id and i["id"] == search_id: + svt_data.append(i) + break + trans = {} + tmp = [] + for j in i: + if isinstance(i[j], str): + trans[j] = i[j] + + elif isinstance(i[j], list): + if j == "宝具信息": + for index in range(len(i[j])): + for each in i[j][index]: + trans[f"{each}{index}"] = i[j][index][each] + counter = 1 + for k in i[j]: + if isinstance(k, list) or isinstance(k, dict): + continue + trans[f"{j}{counter}"] = k + counter += 1 + + elif isinstance(i[j], dict): + if j == "技能": + for skills in i[j]: + for each in i[j][skills]: + skill_info = i[j][skills][each] + if each == "图标": + continue + if isinstance(i[j][skills][each], list): + skill_info = i[j][skills][each][0] + trans[f"{skills}{each}"] = skill_info + if j == "svt_detail" or j == "cards_url": + continue + for k in i[j]: + if isinstance(i[j][k], list) or isinstance(i[j][k], dict): + continue + if k in banned_keys: + continue + trans[f"{k}"] = i[j][k] + + counter = 1 + for arg in msg: + if re.match(r"^.星$", arg): + arg = re.sub(r"[五⑤伍]", "5", arg) + arg = re.sub(r"[四④肆]", "4", arg) + arg = re.sub(r"[三③叁]", "3", arg) + arg = re.sub(r"[二②贰]", "2", arg) + arg = re.sub(r"[一①壹]", "1", arg) + arg = arg.lower() + for each in trans: + if arg in trans[each].lower(): + if len(msg) == 1: + if i not in svt_data: + svt_data.append(i) + else: + if i not in tmp: + tmp.append(i) + counter += 1 + else: + if counter < len(msg): + tmp.append(i) + counter += 1 + else: + svt_data.append(i) + break + + if len(svt_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each in svt_data: + too_much += f"【{counter}】:{each['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + crt_file = False + if os.path.exists(config_path): + try: + configs = json.load(open(config_path, encoding="utf-8")) + for each_group in configs["groups"]: + if each_group["group"] == ev.group_id: + if not each_group["crt_path"] == "False": + crt_file = os.path.join(crt_folder_path, each_group["crt_path"]) + break + except json.decoder.JSONDecodeError: + pass + + if len(svt_data) == 0: + await bot.send(ev, "无结果……尝试在线搜索") + for each_msg in msg: + url = "https://fgo.wiki/w/" + each_msg + name, stat = await lib_svt_online(url, crt_file) + if stat == -100: + await bot.finish(ev, f"出错了!\n{name}") + elif not stat: + continue + elif stat: + for i in svt: + if name in i["name_link"]: + if i not in svt_data: + svt_data.append(i) + break + + if len(svt_data) == 0: + await bot.finish(ev, "嘤嘤嘤,找不到~请重新选择关键词") + if len(svt_data) > 5: + too_much = "描述太模糊,数据太多了qwq,只显示名字,有需要请直接搜索名字~\n" + counter = 0 + for each_svt_data in svt_data: + too_much += f"【{counter}】:{each_svt_data['name_link']}\t" + counter += 1 + + await bot.finish(ev, too_much) + + if is_detail: + counter = 1 + details = [] + for each in svt_data: + img_path = os.path.join(svt_path, each["svt_icon"]) + if os.path.exists(img_path): + msg_error = "" + if "error" in each: + msg_error += f"从者{each['id']}数据存在错误,请使用[修补fgo图书馆 + 从者 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + if each_error.startswith("svt_info_main"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "主描述数据错误\n" + if each_error.startswith("svt_info"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "描述数据错误\n" + if each_error.startswith("svt_detail"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "描述详情数据错误\n" + + send_error = gen_node(msg_error.strip()) + details.append(send_error) + continue + + if len(svt_data) < 2: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + else: + if counter == 1: + msg_send = f"【{counter}】:{each['name_link']}\n" + else: + msg_send = "你找的可能是:\n" + msg_send += f"【{counter}】:{each['name_link']}\n" + counter += 1 + + # # 因为奇奇怪怪的风控,暂时屏蔽职阶图标 + # class_ = os.path.join(class_path, each["class_icon"]) + # if os.path.exists(class_): + # class_img = Image.open(class_) + # pic_card = util.pic2b64(class_img) + # msg_send += f"{MessageSegment.image(pic_card)}\n" + + if os.path.exists(img_path): + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + + msg_send += f"中文名:{each['name_cn']}\n原名:{each['name_jp']}\n稀有度:{each['rare']}\n" \ + f"获取方法:{each['method']}\n职阶:{each['detail']['职阶']}\n" + + send = gen_node(msg_send.strip()) + details.append(send) + + if not remove_card: + msg_card = "" + for cards in each["cards_url"]: + card = await gen_img_from_url(each["cards_url"][cards], crt_file) + if isinstance(card, Exception): + continue + else: + msg_card += f"{card}\n" + + send_card = gen_node(msg_card.strip()) + details.append(send_card) + + if not remove_data: + msg_data = "" + for data in each["detail"]: + if not data == "职阶": + if data == "NP获得率": + np = str(each['detail'][data]).replace(",", ",\n") + msg_data += f"{data}:{np}\n" + else: + msg_data += f"{data}:{each['detail'][data]}\n" + send_data = gen_node(create_img(msg_data.strip())) + details.append(send_data) + + if not remove_info: + for data in each["svt_detail"]: + msg_info = f"{data}:\n{each['svt_detail'][data]['资料']}\n" + send_info = gen_node(create_img(msg_info.strip())) + details.append(send_info) + + if not remove_fool: + if not each['fool']['资料'] == "" and not each['fool']['原文'] == "": + msg_fool = f"愚人节:\n{each['fool']['资料']}\n" + jp = each['fool']['原文'].replace('。', '。\n') + msg_fool += f"原文:\n{jp}\n" + send_fool = gen_node(create_img(msg_fool.strip())) + details.append(send_fool) + + if not remove_ultimate: + msg_ultimate = "" + for index in range(len(each["宝具信息"])): + if len(each["宝具信息"]) > 1: + msg_ultimate += f"宝具{index + 1}:\n" + else: + msg_ultimate += "宝具:\n" + for data in each["宝具信息"][index]: + msg_ultimate += f"\t\t\t\t{data}:{each['宝具信息'][index][data]}\n" + send_ultimate = gen_node(create_img(msg_ultimate.strip())) + details.append(send_ultimate) + + if not remove_skill: + for skills in each["技能"]: + if each["技能"] == {}: + break + msg_skill = f"{skills}\n" + msg_skill_icon = "" + for data in each["技能"][skills]: + if data == "图标": + icon = await gen_img_from_url(each["技能"][skills][data], crt_file) + if not isinstance(icon, Exception): + msg_skill_icon += f"{icon}\n" + continue + if isinstance(each["技能"][skills][data], list): + msg_skill += f'\t\t\t\t{data}:\n' + for each_value in each["技能"][skills][data]: + msg_skill += f'\t\t\t\t\t\t\t\t{each_value}\n' + else: + msg_skill += f'\t\t\t\t{data}:{each["技能"][skills][data]}\n' + + msg_skill = msg_skill_icon + create_img(msg_skill.strip()) + send_skill = gen_node(msg_skill) + details.append(send_skill) + + if not remove_voice: + for each_type in each["语音"]: + msg_voice = f"{each_type}:\n" + for each_voice in each["语音"][each_type]: + msg_voice += f'\t\t\t\t{each_voice}:' \ + f'\n\t\t\t\t\t\t\t\t{each["语音"][each_type][each_voice]["文本"]}\n' + + msg_voice = create_img(msg_voice.strip()) + send_voice = gen_node(msg_voice) + details.append(send_voice) + if not remove_pup: + method = each["method"] + if "圣晶石常驻" not in method and "期间限定" not in method: + if "友情" in method: + details.append(gen_node("该从者只能通过友情池获取")) + else: + details.append(gen_node("该从者是赠送的从者")) + elif not each["pup"]: + details.append(gen_node("该从者国服未来没有Pick Up")) + else: + details.append(gen_node("国服未来Pick Up情况:")) + pool_counter = 1 + for each_pool in each["pup"]: + if len(each["pup"]) == 1: + msg_pup = f"{each_pool['title']}\n" \ + f"开放时间:{each_pool['time_start']}\n" \ + f"结束时间:{each_pool['time_end']}\n" \ + f"卡池时长:{each_pool['time_delta']}\n" + else: + msg_pup = f"【{pool_counter}】:{each_pool['title']}\n" \ + f"开放时间:{each_pool['time_start']}\n" \ + f"结束时间:{each_pool['time_end']}\n" \ + f"卡池时长:{each_pool['time_delta']}\n" + pup_img = await gen_img_from_url(each_pool['img_url'], crt_file) + if isinstance(pup_img, Exception): + continue + pool_counter += 1 + msg_pup += pup_img + send_pup = gen_node(msg_pup) + details.append(send_pup) + + else: + await bot.finish(ev, "没有本地资源~请先获取本地资源~") + try: + await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定从者,或单独指定内容") + + else: + msg_send = "你找的可能是:\n" + counter = 1 + details = [] + msg_error = "" + for each in svt_data: + if "error" in each: + msg_error += f"从者{each['id']}数据存在错误,请使用[修补fgo图书馆 + 从者 + id]修补\n" + error_num = len(each["error"]) + for each_error in each["error"]: + if each_error.startswith("aiorequest"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "基础数据错误\n" + if each_error.startswith("first bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "从者数据错误\n" + if each_error.startswith("find power bs error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "技能/宝具数据错误\n" + if each_error.startswith("get card img error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "卡面数据错误\n" + if each_error.startswith("get star error"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "星级数据错误\n" + if each_error.startswith("svt_info_main"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "主描述数据错误\n" + if each_error.startswith("svt_info"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "描述数据错误\n" + if each_error.startswith("svt_detail"): + if not error_num == 1: + msg_error += f'错误{each["error"].index(each_error) + 1}:' + msg_error += "描述详情数据错误\n" + send_error = gen_node(msg_error.strip()) + details.append(send_error) + continue + + if counter == 1: + if len(svt_data) == 1: + msg_send = f"你找的可能是:\n{each['name_link']}\n" + else: + msg_send += f"{counter}:{each['name_link']}\n" + else: + msg_send = f"{counter}:{each['name_link']}\n" + counter += 1 + + # # 因为奇奇怪怪的风控,暂时屏蔽职阶图标 + # class_ = os.path.join(class_path, each["class_icon"]) + # if os.path.exists(class_): + # class_img = Image.open(class_) + # pic_card = util.pic2b64(class_img) + # msg_send += f"{MessageSegment.image(pic_card)}\n" + + img_path = os.path.join(svt_path, each["svt_icon"]) + if os.path.exists(img_path): + msg_send += f"{gen_ms_img(Image.open(img_path))}\n" + + msg_send += f"中文名:{each['name_cn']}\n原名:{each['name_jp']}\n稀有度:{each['rare']}\n" \ + f"获取方法:{each['method']}\n职阶:{each['detail']['职阶']}\n" + + send = gen_node(msg_send.strip()) + details.append(send) + try: + if len(svt_data) > 1: + await bot.send_group_forward_msg(group_id=ev['group_id'], messages=details) + else: + if msg_error: + await bot.send(ev, msg_error.strip()) + else: + await bot.send(ev, msg_send.strip()) + except ActionFailed as e: + sv_lib.logger.error(f"转发群消息失败:{e}") + await bot.finish(ev, "消息被风控,可能是消息太长,请尝试更精确指定从者,或单独指定内容") + + +def get_keys(msg) -> Tuple: + is_detail = False + remove_card = False + remove_data = False + remove_info = False + remove_fool = False + remove_ultimate = False + remove_skill = False + remove_voice = False + remove_pup = False + rule = re.compile(r"(?i)(详细|detail)") + if re.match(rule, msg[-1]): + is_detail = True + msg.pop() + rule1 = re.compile(r"(?i)(卡面|card)") + if re.match(rule1, msg[-1]): + is_detail = True + remove_data = True + remove_info = True + remove_fool = True + remove_ultimate = True + remove_skill = True + remove_voice = True + remove_pup = True + msg.pop() + rule2 = re.compile(r"(?i)(数据|data)") + if re.match(rule2, msg[-1]): + is_detail = True + remove_card = True + remove_info = True + remove_fool = True + remove_ultimate = True + remove_skill = True + remove_voice = True + remove_pup = True + msg.pop() + rule3 = re.compile(r"(?i)(资料|info)") + if re.match(rule3, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_fool = True + remove_ultimate = True + remove_skill = True + remove_voice = True + remove_pup = True + msg.pop() + rule4 = re.compile(r"(?i)(愚人节|fool)") + if re.match(rule4, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_info = True + remove_ultimate = True + remove_skill = True + remove_voice = True + remove_pup = True + msg.pop() + rule5 = re.compile(r"(?i)(宝具|bj|ultimate)") + if re.match(rule5, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_info = True + remove_fool = True + remove_skill = True + remove_voice = True + remove_pup = True + msg.pop() + rule6 = re.compile(r"(?i)(技能|skill)") + if re.match(rule6, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_info = True + remove_fool = True + remove_ultimate = True + remove_voice = True + remove_pup = True + msg.pop() + rule7 = re.compile(r"(?i)(语音|voice)") + if re.match(rule7, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_info = True + remove_fool = True + remove_ultimate = True + remove_skill = True + remove_pup = True + msg.pop() + rule8 = re.compile(r"(?i)(未来|pup)") + if re.match(rule8, msg[-1]): + is_detail = True + remove_data = True + remove_card = True + remove_info = True + remove_fool = True + remove_ultimate = True + remove_voice = True + remove_skill = True + msg.pop() + + return ( + is_detail, remove_card, remove_data, + remove_info, remove_fool, remove_ultimate, + remove_skill, remove_voice, remove_pup + ) diff --git a/lib_online/lib_cft.py b/lib_online/lib_cft.py index a243229..e6ee0f7 100644 --- a/lib_online/lib_cft.py +++ b/lib_online/lib_cft.py @@ -89,7 +89,7 @@ async def lib_cft(cft_data, crt_file=False) -> Dict: s1[-1] = s1[-1].split("\n\n") # noqa if s2[-1].startswith("以下翻译内容由Mooncell用户贡献。"): s2[-1] = s2[-1].replace("以下翻译内容由Mooncell用户贡献。", "") # noqa - s2[-1] = re.split(r"转载请保留网址 https://fgo.wiki/id/\d+\n\n\n", s2[-1]) + s2[-1] = re.split(r"转载请保留网址 https://fgo.wiki/id/\d+\n\n\n", s2[-1]) # noqa else: s2[-1] = s2[-1].split("\n\n\n") # noqa diff --git a/lib_online/lib_svt.py b/lib_online/lib_svt.py index 57695bf..2a90902 100644 --- a/lib_online/lib_svt.py +++ b/lib_online/lib_svt.py @@ -128,7 +128,7 @@ def get_detail(svts, svt, svt_data): s2.pop() s2.pop(0) s2.pop(0) - result = {} + result: dict = {} for each_stat in s1: if each_stat == "ATK" or each_stat == "职阶补正后" or each_stat == "HP" or each_stat == "能力": result[each_stat] = [] diff --git a/path_and_json.py b/path_and_json.py index 48f5723..fcc823b 100644 --- a/path_and_json.py +++ b/path_and_json.py @@ -9,9 +9,188 @@ from aiocqhttp import MessageSegment from selenium import webdriver -from hoshino import config, util, aiorequests, logger +from hoshino import config, util, aiorequests, logger, Service, priv from hoshino.typing import CQEvent +sv_help = ''' +# 抽卡模拟相关 +[fgo十连] fgo抽卡 +[fgo百连] 100抽 +[获取fgo卡池] 从mooncell获取卡池数据 +[查询fgo卡池] 查询本地缓存的卡池以及本群卡池 +[切换fgo卡池 + 卡池编号] 切换需要的卡池 +[切换fgo日替卡池 + 卡池编号 + 日替卡池编号] 切换需要的日替卡池 +'''.strip() + +sv = Service( + name='fgo抽卡', + help_=sv_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +sv_fetch_help = ''' +# 数据管理相关 +[获取全部内容] 获取从者/礼装/纹章的相关内容 +- 从者包括职介和指令卡 +- 礼装/纹章包括技能 +- 子命令: + - [获取全部从者] + - [获取全部礼装] + - [获取全部纹章] +[下载全部卡片资源] 从上述数据中下载对应静态资源 +- 子命令: + - [下载全部从者资源] + - [下载全部礼装资源] + - [下载全部纹章资源] +'''.strip() + +sv_fetch = Service( + name='fgo数据获取', + help_=sv_fetch_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +sv_lib_help = ''' +# fgo数据库相关 +``[更新fgo图书馆]`` 获取从者/礼装/纹章的相关详细数据,包括属性、白值等 +- 支持附带类型参数以更新指定内容 +- 类型参数:从者/礼装/纹章/最新 + - 当参数含有最新时,只会获取本地不存在的内容 + - 支持种类与最新同时存在 +- **※需要先执行``[获取全部内容]``** + +``[增添fgo图书馆 + 类型 + id]`` 在本地已存在图书馆的情况下,手动增添新数据,以避免每次数据更新都需要重新爬一次全部内容 +- 类型:从者、礼装、纹章 + +``[查询最新图书馆 + 类型]`` 获取最近的内容 + +``[修补fgo图书馆 + 类型 + id]`` 单独修补某张卡片的详细数据 +- 类型为:从者、礼装、纹章 +- **※需要先执行``[更新fgo图书馆]``** + +``[fgo从者查询 + 关键词(至少一个)]`` 通过关键词搜索从者 +- 若关键词大于两个,只会返回同时符合的 +- 可以附带参数``详细``以获取卡面及游戏数据,附带参数``数据``则不显示卡面只显示游戏数据 +- 当输入参数存在id{卡片id}时,直接返回对应id的卡片 + - 例子:``查询fgo从者 id312`` + +``[fgo礼装查询 + 关键词(至少一个)]`` 通过关键词搜索礼装 +- 若关键词大于两个,只会搜索同时符合的 +- 可以附带参数``详细``以获取卡面及游戏数据 +- 查询特定id的礼装同上 + +``[fgo纹章查询 + 关键词(至少一个)]`` 通过关键词搜索礼装 +- 若关键词大于两个,只会搜索同时符合的 +- 可以附带参数``详细``以获取卡面及游戏数据 +- 查询特定id的纹章同上 +'''.strip() + +sv_lib = Service( + name='fgo图书馆', + help_=sv_lib_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +lucky_sv_help = ''' +[更新fgo福袋] 获取福袋信息 +- 初次查询福袋之前务必先执行此命令 +[查询fgo福袋 + 概况] 查询全部福袋的文字概况 +[查询fgo福袋 + 国服/日服] 查询当前存在的福袋数据 +- [查询fgo福袋 + 国服/日服 + 福袋编号] 查询对应顺序的福袋详细数据 +- [查询fgo福袋 + 国服/日服 + 全部] 查询全部福袋详细数据 +[查询fgo福袋 + 未来] 查询国服千里眼福袋数据 +[抽fgo福袋 + 国服/日服 + 福袋编号 + 子池子编号(默认为1)] 抽福袋 +'''.strip() + +lucky_sv = Service( + name='fgo福袋', + help_=lucky_sv_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +sv_manage_help = ''' +# 抽卡管理命令: +[fgo数据初始化] 初始化数据文件及目录,务必安装后先执行此命令! +[fgo数据下载] 下载从者及礼装图标,务必先初始化数据再执行下载! +[跟随最新/剧情卡池] 设置卡池数据更新后跟随最新国服卡池还是国服剧情卡池 +[fgo_enable_crt + crt文件路径] 为下载配置crt文件以规避拒绝访问,留空为默认,False为禁用 +[fgo_check_crt] 检查本群crt文件配置状态 +[重载配置文件] 为本群新建默认配置或还原至默认配置,同时修补其他群的配置 +[切换抽卡样式 + 样式] 切换抽卡样式,可选样式: +- 文字:旧版简约图标 +- 图片:仿真实抽卡 +[设置fgo时间 + 小时 + 分钟 + 秒] 设置自动更新时间间隔,至少输入其中一个参数 +- 例如:``设置fgo时间 1小时60分钟60秒`` +'''.strip() + +sv_manage = Service( + name='fgo管理', + help_=sv_manage_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +sv_news_help = ''' +# 新闻相关: +[获取fgo新闻 + 数量] 从官网获取公告新闻,默认6条,置顶的概率公告会去掉 +[查询fgo新闻 + 编号/all] 从本地查询公告具体内容,all代表全部获取 +- 可以在末尾附加参数``pic``不使用截图 +[清除新闻缓存] 移除新闻截图 +'''.strip() + +sv_news = Service( + name='fgo新闻获取', + help_=sv_news_help, + bundle="娱乐", + enable_on_default=True, + visible=True, + use_priv=priv.NORMAL, # 使用权限 + manage_priv=priv.ADMIN, # 管理权限 +) + +height = 194 +width = 178 +dis = 23 +floor = 48 +st1w = 92 +st1h = 200 +st2 = 192 + +boxlist = [] + +box1 = (st1w, st1h) +for box_i in range(6): + boxlist.append(box1) + lst = list(box1) + lst[0] += width + dis + box1 = tuple(lst) + +box2 = (st2, st1h + height + floor) +for box_i in range(5): + boxlist.append(box2) + lst = list(box2) + lst[0] += width + dis + box2 = tuple(lst) + headers = { "User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.6) ", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", @@ -175,14 +354,14 @@ def getpic(url, save_img_name, _type="") -> bool: # print(link) driver.get(link) k = 1 - height = driver.execute_script(js_height) + window_height = driver.execute_script(js_height) while True: - if k * 500 < height: + if k * 500 < window_height: js_move = "window.scrollTo(0,{})".format(k * 500) # print(js_move) driver.execute_script(js_move) time.sleep(0.2) - height = driver.execute_script(js_height) + window_height = driver.execute_script(js_height) k += 1 else: break