Archived
1
0
Fork 0

Complete rewrite

This commit is contained in:
Dianliang233 2022-01-16 09:44:31 +08:00
parent 8364ef0e0b
commit 70e013d354
No known key found for this signature in database
GPG key ID: 6C56F399D872F19C
4 changed files with 40 additions and 46 deletions

15
modules/mcmod/__init__.py Normal file
View file

@ -0,0 +1,15 @@
from core.component import on_command
from core.elements import MessageSession
from .mcmod import mcmod as m
mcmod = on_command(
bind_prefix='mcmod',
desc='从 MCMOD 获取 Minecraft Mod 信息',
developers=['Dianliang233', 'HornCopper'],
)
@mcmod.handle('<mod_name> {通过模组名获取模组简介及链接,可使用无歧义简写和准确中文。}')
async def main(msg: MessageSession):
message = await m(msg.parsed_msg['<mod_name>'])
await msg.sendMessage(message)

25
modules/mcmod/mcmod.py Normal file
View file

@ -0,0 +1,25 @@
from bs4 import BeautifulSoup
from config import Config
from core.utils import get_url
api = 'https://search.mcmod.cn/s?key='
async def mcmod(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{url}\n{desc}'
else:
return '未找到结果。'

View file

@ -1,23 +0,0 @@
import asyncio
from core.component import on_command, on_option
from core.dirty_check import check
from core.elements import MessageSession
from database import BotDBUtil
from .mod import mcmod as m
mcmod = on_command(
bind_prefix='mod',
desc='Minecraft Mod检索工具使用MCMOD无API支持',
alias='mcmod',
developers=['HornCopper'],
required_admin = False,
base = False,
required_superuser = False
)
@mcmod.handle('<mod_name> {通过模组名获取模组简介及链接与查Wiki类似但无API支持可使用无歧义简写和准确中文。}')
async def main(msg: MessageSession):
message = await m(msg.parsed_msg["<mod_name>"])
await msg.sendMessage(message)

View file

@ -1,23 +0,0 @@
import re
from bs4 import BeautifulSoup
from core.utils import get_url
search_link = "https://search.mcmod.cn/s?key="
async def mcmod(keyword: str):
full_requests_link = search_link + keyword
html = await get_url(full_requests_link)
useful_information = html[int(html.find("<div class=\"search-result-list\">")):int(html.find("<footer>")-1)]+">"
bshtml = BeautifulSoup(useful_information,'html.parser')
more_useful_information = bshtml.div.div.find_all('div')
str0_1 = str(more_useful_information[2])
potato = str0_1[:20]
if potato.find("body"):
desc = re.sub(r"\[(.+?)\]","",str0_1[int(str0_1.find("<div class=\"body\">")+18):int(str0_1.find("</div>"))])
str0_2 = bshtml.div.div.find_all('a')
str3 = str(str0_2[2])
link = str3[int(str3.find("\"")+1):int(str3.find(" target")-1)]
return f"{link}\n{desc}"
else:
return f"Mod不存在检索失败"