bugfix
This commit is contained in:
parent
62f3d298df
commit
026759e76d
2 changed files with 24 additions and 21 deletions
|
@ -1,6 +1,5 @@
|
||||||
from core.component import on_command
|
from core.component import on_command
|
||||||
from core.elements import MessageSession
|
from core.elements import MessageSession
|
||||||
from core.elements import Url
|
|
||||||
|
|
||||||
from .mod_dl import curseforge as d
|
from .mod_dl import curseforge as d
|
||||||
|
|
||||||
|
@ -10,13 +9,14 @@ mod_dl = on_command(
|
||||||
developers=['HornCopper'],
|
developers=['HornCopper'],
|
||||||
recommend_modules=['mcmod'])
|
recommend_modules=['mcmod'])
|
||||||
|
|
||||||
@news.handle('<mod_name> <mcversion> {通过模组名获取模组下载链接,CloudFlare CDN支持。')
|
|
||||||
|
@mod_dl.handle('<mod_name> <mcversion> {通过模组名获取模组下载链接,CloudFlare CDN支持。}')
|
||||||
async def main(msg: MessageSession):
|
async def main(msg: MessageSession):
|
||||||
info = await d(msg.parsed_msg['<mod_name>'], msg.parsed_msg['<mcversion>'])
|
info = await d(msg.parsed_msg['<mod_name>'], msg.parsed_msg['<mcversion>'])
|
||||||
if info['msg'] != '200 OK':
|
if not info['success']:
|
||||||
await msg.sendMessage(info['msg'])
|
return await msg.sendMessage(info['msg'])
|
||||||
link = info["download_link"]
|
link = info["download_link"]
|
||||||
name = info["filename"]
|
name = info["filename"]
|
||||||
status = info["status"]
|
status = info["status"]
|
||||||
message = f'下载链接:{str(Url(link))}\n文件名:{name}\n版本状态:{status}'
|
message = f'下载链接:{link}\n文件名:{name}\n版本状态:{status}'
|
||||||
await msg.sendMessage(message)
|
await msg.sendMessage(message)
|
||||||
|
|
|
@ -8,21 +8,24 @@ search_piece_1 = 'https://files.xmdhs.top/curseforge/s?q='
|
||||||
search_piece_2 = '&type=1'
|
search_piece_2 = '&type=1'
|
||||||
search_step_2 = 'https://files.xmdhs.top/curseforge/history?id='
|
search_step_2 = 'https://files.xmdhs.top/curseforge/history?id='
|
||||||
|
|
||||||
|
|
||||||
def Chinese(string: str):
|
def Chinese(string: str):
|
||||||
for word in string:
|
for word in string:
|
||||||
if u'\u4e00' <= word <= u'\u9fff':
|
if u'\u4e00' <= word <= u'\u9fff':
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def curseforge(mod_name: str, ver: str):
|
async def curseforge(mod_name: str, ver: str):
|
||||||
if Chinese(mod_name):
|
if Chinese(mod_name):
|
||||||
return {'msg':'请不要输入中文,CurseForge暂不支持中文搜索。'}
|
return {'msg': 'CurseForge暂不支持中文搜索。'}
|
||||||
full_url = search_piece_1 + mod_name + search_piece_2
|
full_url = search_piece_1 + mod_name + search_piece_2
|
||||||
html = await get_url(full_url)
|
html = await get_url(full_url)
|
||||||
bs = BeautifulSoup(html, 'html.parser')
|
bs = BeautifulSoup(html, 'html.parser')
|
||||||
try:
|
try:
|
||||||
information = bs.body.div.div.a
|
information = bs.body.div.div.a
|
||||||
except:
|
except Exception:
|
||||||
return {'msg':'未搜索到该Mod。'}
|
return {'msg': '未搜索到该Mod。', 'success': False}
|
||||||
more_specific_html = str(information)
|
more_specific_html = str(information)
|
||||||
id = more_specific_html[int(more_specific_html.find('id=') + 3):int(more_specific_html.find('\" style='))]
|
id = more_specific_html[int(more_specific_html.find('id=') + 3):int(more_specific_html.find('\" style='))]
|
||||||
final_url = search_step_2 + id + '&ver=' + ver
|
final_url = search_step_2 + id + '&ver=' + ver
|
||||||
|
@ -30,14 +33,14 @@ async def curseforge(mod_name: str,ver: str):
|
||||||
bs_2 = BeautifulSoup(html_2, 'html.parser')
|
bs_2 = BeautifulSoup(html_2, 'html.parser')
|
||||||
try:
|
try:
|
||||||
results = bs_2.body.div.div.table.tbody.find_all('tr')
|
results = bs_2.body.div.div.table.tbody.find_all('tr')
|
||||||
except:
|
except Exception:
|
||||||
return {'msg':'请不要尝试搜索不存在的Minecraft版本的Mod。'}
|
return {'msg': f'此Mod没有{ver}的版本。', 'success': False}
|
||||||
information_2 = str(results[1])
|
information_2 = str(results[1])
|
||||||
download_link = information_2[int(information_2.find("\"") + 1):int(information_2.find("\" target="))]
|
download_link = information_2[int(information_2.find("\"") + 1):int(information_2.find("\" target="))]
|
||||||
file_name = information_2[int(information_2.find("_blank\"") + 8):int(information_2.find("</a>"))]
|
file_name = information_2[int(information_2.find("_blank\"") + 8):int(information_2.find("</a>"))]
|
||||||
if bool(information_2.find("Beta")) == True:
|
status = '???'
|
||||||
|
if bool(information_2.find("Beta")):
|
||||||
status = "Release"
|
status = "Release"
|
||||||
if bool(information_2.find("Release")) == True:
|
if bool(information_2.find("Release")):
|
||||||
status = "Beta"
|
status = "Beta"
|
||||||
dict = {"filename":file_name,"download_link":download_link,"status":status,'msg':'200 OK'}
|
return {"filename": file_name, "download_link": download_link, "status": status, "success": True}
|
||||||
return dict
|
|
||||||
|
|
Reference in a new issue