add new module: moddetails
This commit is contained in:
parent
b6dfc0702a
commit
c101d92e10
2 changed files with 43 additions and 0 deletions
16
modules/moddetails/__init__.py
Normal file
16
modules/moddetails/__init__.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from core.component import on_command
|
||||
from core.elements import MessageSession
|
||||
|
||||
from .moddetails import moddetails as m
|
||||
|
||||
moddetails = on_command(
|
||||
bind_prefix='moddetails',
|
||||
desc='从 MCMOD 获取 Minecraft Mod 内容的有关资料',
|
||||
developers=['Dianliang233', 'HornCopper', 'DrLee_lihr'],
|
||||
)
|
||||
|
||||
|
||||
@moddetails.handle('<content> {通过 Mod 内容的名称获取模组简介及链接,可使用物品/方块/实体的 ID 或准确中文。}')
|
||||
async def main(msg: MessageSession):
|
||||
message = await m(msg.parsed_msg['<content>'])
|
||||
await msg.sendMessage(message)
|
27
modules/moddetails/moddetails.py
Normal file
27
modules/moddetails/moddetails.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from bs4 import BeautifulSoup
|
||||
|
||||
from config import Config
|
||||
from core.elements import Url
|
||||
from core.utils import get_url
|
||||
|
||||
api = 'https://search.mcmod.cn/s?filter=3&key='
|
||||
|
||||
|
||||
async def moddetails(keyword: str):
|
||||
search_url = api + keyword
|
||||
webrender = Config('web_render')
|
||||
if webrender:
|
||||
search_url = webrender + 'source?url=' + search_url
|
||||
html = await get_url(search_url)
|
||||
print(html)
|
||||
bs = BeautifulSoup(html, 'html.parser')
|
||||
results = bs.find_all('div', class_='result-item')
|
||||
if results is not None:
|
||||
res = results[0]
|
||||
a = res.find('div', class_='head').find('a', recursive=False)
|
||||
name = a.text
|
||||
url = a['href']
|
||||
desc = res.find('div', class_='body').text
|
||||
return f'{name}\n{str(Url(url))}\n{desc}'
|
||||
else:
|
||||
return '未找到结果。'
|
Reference in a new issue