mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-06-03 05:59:51 +08:00
同步语音重试:PR #81
This commit is contained in:
parent
02ee0427b8
commit
76b010a1bb
37
getMes.py
37
getMes.py
@ -1,4 +1,4 @@
|
|||||||
import math,sqlite3,re,os,random,requests
|
import math,sqlite3,re,os,random,requests,json
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ food_im = '''【{}】
|
|||||||
【材料】:{}
|
【材料】:{}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
audio_json = {
|
audio_json = '''{
|
||||||
"357":["357_01","357_02","357_03"],
|
"357":["357_01","357_02","357_03"],
|
||||||
"1000000":["1000000_01","1000000_02","1000000_03","1000000_04","1000000_05","1000000_06","1000000_07"],
|
"1000000":["1000000_01","1000000_02","1000000_03","1000000_04","1000000_05","1000000_06","1000000_07"],
|
||||||
"1000001":["1000001_01","1000001_02","1000001_03"],
|
"1000001":["1000001_01","1000001_02","1000001_03"],
|
||||||
@ -142,7 +142,7 @@ audio_json = {
|
|||||||
"1010301":["1010301_01","1010301_02","1010301_03","1010301_04","1010301_05"],
|
"1010301":["1010301_01","1010301_02","1010301_03","1010301_04","1010301_05"],
|
||||||
"1010400":["1010400_01","1010400_02","1010400_03"],
|
"1010400":["1010400_01","1010400_02","1010400_03"],
|
||||||
"1020000":["1020000_01"]
|
"1020000":["1020000_01"]
|
||||||
}
|
}'''
|
||||||
|
|
||||||
async def deal_ck(mes,qid):
|
async def deal_ck(mes,qid):
|
||||||
aid = re.search(r"account_id=(\d*)", mes)
|
aid = re.search(r"account_id=(\d*)", mes)
|
||||||
@ -192,19 +192,36 @@ async def award(uid):
|
|||||||
return im
|
return im
|
||||||
|
|
||||||
async def audio_wiki(name,message):
|
async def audio_wiki(name,message):
|
||||||
|
async def get(audioid):
|
||||||
|
tmp_json=json.loads(audio_json)
|
||||||
|
for _ in range(3):#重试3次
|
||||||
|
if audioid in tmp_json:
|
||||||
|
if not tmp_json[audioid]:
|
||||||
|
return
|
||||||
|
audioid1 = random.choice(tmp_json[audioid])
|
||||||
|
else:
|
||||||
|
audioid1=audioid
|
||||||
|
url = await GetAudioInfo(name,audioid1)
|
||||||
|
req=requests.get(url)
|
||||||
|
if req.headers["Content-Type"].startswith("audio"):
|
||||||
|
return BytesIO(req.content)
|
||||||
|
else:
|
||||||
|
if audioid in tmp_json:
|
||||||
|
tmp_json[audioid].remove(audioid1)
|
||||||
if name == "列表":
|
if name == "列表":
|
||||||
im = f'[CQ:image,file=file://{os.path.join(INDEX_PATH,"语音.png")}]'
|
im = f'[CQ:image,file=file://{os.path.join(INDEX_PATH,"语音.png")}]'
|
||||||
|
return im
|
||||||
elif name == "":
|
elif name == "":
|
||||||
return "角色名不正确。"
|
return "角色名不正确。"
|
||||||
else:
|
else:
|
||||||
audioid = re.findall(r"[0-9]+", message)[0]
|
audioid = re.findall(r"[0-9]+", message)[0]
|
||||||
if audioid in audio_json:
|
try:
|
||||||
audioid = random.choice(audio_json[audioid])
|
audio=await get(audioid)
|
||||||
url = await GetAudioInfo(name,audioid)
|
except:
|
||||||
audio = BytesIO(requests.get(url).content)
|
return "语音获取失败"
|
||||||
audios = 'base64://' + b64encode(audio.getvalue()).decode()
|
if audio:
|
||||||
im = f"[CQ:record,file={audios}]"
|
audios = 'base64://' + b64encode(audio.getvalue()).decode()
|
||||||
return im
|
return (f"[CQ:record,file={audios}]")
|
||||||
|
|
||||||
async def artifacts_wiki(name):
|
async def artifacts_wiki(name):
|
||||||
data = await GetMiscInfo("artifacts",name)
|
data = await GetMiscInfo("artifacts",name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user