diff --git a/Genshin All Char.xlsx b/Genshin All Char.xlsx new file mode 100644 index 00000000..8f67b55c Binary files /dev/null and b/Genshin All Char.xlsx differ diff --git a/__init__.py b/__init__.py index 7b01b304..24fe9a54 100644 --- a/__init__.py +++ b/__init__.py @@ -18,6 +18,23 @@ FILE_PATH = os.path.join(os.path.dirname(__file__), 'mys') INDEX_PATH = os.path.join(FILE_PATH, 'index') Texture_PATH = os.path.join(FILE_PATH, 'texture2d') +@sv.on_regex('[\u4e00-\u9fa5]+(用什么|能用啥|怎么养)') +async def send_char_adv(bot: HoshinoBot, ev: CQEvent): + try: + name = str(ev.message).strip().replace(" ","")[:-3] + im = await char_adv(name) + await bot.send(im) + except Exception as e: + logger.exception("获取建议失败。") + +@sv.on_regex('[\u4e00-\u9fa5]+(能给谁|给谁用|要给谁|谁能用)') +async def send_weapon_adv(bot: HoshinoBot, ev: CQEvent): + try: + name = str(ev.message).strip().replace(" ","")[:-3] + im = await weapon_adv(name) + await bot.send(im) + except Exception as e: + logger.exception("获取建议失败。") @sv.on_prefix('语音') async def send_audio(bot: HoshinoBot, ev: CQEvent): @@ -26,8 +43,12 @@ async def send_audio(bot: HoshinoBot, ev: CQEvent): message = message.replace(' ', "") name = ''.join(re.findall('[\u4e00-\u9fa5]', message)) im = await audio_wiki(name, message) - await bot.send(ev, im) + if name == "列表": + await bot.send(ev, f"[CQ:image,file={im}]") + else: + await bot.send(ev, f"[CQ:recode,file={im}]") except ActionFailed as e: + logger.exception("获取语音失败") await bot.send(ev, "机器人发送消息失败:{}".format(e)) except Exception as e: logger.exception("获取语音失败") diff --git a/get_mihoyo_bbs_data.py b/get_mihoyo_bbs_data.py index 38814437..fcb49bc6 100644 --- a/get_mihoyo_bbs_data.py +++ b/get_mihoyo_bbs_data.py @@ -5,6 +5,7 @@ import random import re import sqlite3 from base64 import b64encode +from openpyxl import load_workbook from io import BytesIO import requests @@ -150,6 +151,90 @@ audio_json = '''{ "1020000":["1020000_01"] }''' +char_adv_im = '''【{}】 +【五星武器】:{} +【四星武器】:{} +【三星武器】:{} +【圣遗物】: +{}''' + +async def weapon_adv(name): + char_adv_path = os.path.join(FILE_PATH,"Genshin All Char.xlsx") + wb = load_workbook(char_adv_path) + ws = wb.active + + weapon_name = "" + char_list = [] + for c in range(2,5): + for r in range(2,300): + if ws.cell(r,c).value: + #if all(i in ws.cell(r,c).value for i in name): + if name in ws.cell(r,c).value: + weapon_name = ws.cell(r,c).value + char_list.append(ws.cell(2+((r-2)//5)*5,1).value) + + if char_list != []: + im = ','.join(char_list) + im = im + "可能会用到【{}】".format(weapon_name) + else: + im = "没有角色能使用【{}】".format(weapon_name) + return im + +async def char_adv(name): + char_adv_path = os.path.join(FILE_PATH,"Genshin All Char.xlsx") + wb = load_workbook(char_adv_path) + ws = wb.active + char_list = ws["A"] + index = None + for i in char_list: + if i.value: + if all(g in i.value for g in name): + #if name in i.value: + index = i.row + char_name = i.value + if index: + weapon_5star = "" + for i in range(index,index+5): + if ws.cell(i,2).value: + weapon_5star += ws.cell(i,2).value + ">" + if weapon_5star != "": + weapon_5star = weapon_5star[:-1] + else: + weapon_5star = "无推荐" + + weapon_4star = "" + for i in range(index,index+5): + if ws.cell(i,3).value: + weapon_4star += ws.cell(i,3).value + ">" + if weapon_4star != "": + weapon_4star = weapon_4star[:-1] + else: + weapon_4star = "无推荐" + + weapon_3star = "" + for i in range(index,index+5): + if ws.cell(i,4).value: + weapon_3star += ws.cell(i,4).value + ">" + if weapon_3star != "": + weapon_3star = weapon_3star[:-1] + else: + weapon_3star = "无推荐" + + artifacts = "" + for i in range(index,index+5): + if ws.cell(i,5).value: + if ws.cell(i,6).value: + artifacts += ws.cell(i,5).value + "*2" + ws.cell(i,6).value + "*2" + "\n" + else: + artifacts += ws.cell(i,5).value + "*4" + "\n" + + if artifacts != "": + artifacts = artifacts[:-1] + else: + artifacts = "无推荐" + + im = char_adv_im.format(char_name,weapon_5star,weapon_4star,weapon_3star,artifacts) + return im async def deal_ck(mes, qid): aid = re.search(r"account_id=(\d*)", mes) @@ -218,8 +303,8 @@ async def audio_wiki(name, message): tmp_json[_audioid].remove(audioid1) if name == "列表": - im = f'[CQ:image,file=file://{os.path.join(INDEX_PATH, "语音.png")}]' - return im + imgmes = 'base64://' + b64encode(open(os.path.join(INDEX_PATH, "语音.png"), "rb").read()).decode() + return imgmes elif name == "": return "角色名不正确。" else: @@ -230,7 +315,7 @@ async def audio_wiki(name, message): return "语音获取失败" if audio: audios = 'base64://' + b64encode(audio.getvalue()).decode() - return f"[CQ:record,file={audios}]" + return audios async def artifacts_wiki(name): diff --git a/requirements.txt b/requirements.txt index f729b207..6329bb9f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ Pillow>=8.3.1 wordcloud>=1.8.1 numpy~=1.22.2 beautifulsoup4>=4.10.0 -lxml>=4.7.1 \ No newline at end of file +lxml>=4.7.1 +openpyxl>=3.0.9 \ No newline at end of file