mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-01 17:49:58 +08:00
first_commit .gitignore
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.cqhttp.permission import PRIVATE
|
||||
from .data_source import from_reimu_get_info
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import Bot, Event
|
||||
from nonebot.typing import T_State
|
||||
from util.utils import is_number, get_message_text, UserExistLimiter, scheduler
|
||||
from models.count_user import UserCount
|
||||
from configs.config import COUNT_PER_DAY_REIMU
|
||||
|
||||
__plugin_name__ = '上车'
|
||||
__plugin_usage__ = r"""
|
||||
* 请各位使用后不要转发 *
|
||||
* 大部分解压密码是⑨ *
|
||||
/ 每人每天仅提供 5 次上车机会(只能私聊)更多次数请向管理员申请(用爱发电)限制小色批乱搜 /
|
||||
/ 并不推荐小色批使用此功能(主要是不够色,目的不够明确) /
|
||||
上车 [目的地]
|
||||
上车 5 [目的地] 该目的地第5页停车场
|
||||
ps: 请尽量提供具体的目的地名称
|
||||
""".strip()
|
||||
|
||||
|
||||
_ulmt = UserExistLimiter()
|
||||
|
||||
reimu = on_command('上车', permission=PRIVATE, block=True, priority=1)
|
||||
|
||||
|
||||
@reimu.args_parser
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
if get_message_text(event.json()) in ['取消', '算了']:
|
||||
await reimu.finish("已取消操作..", at_sender=True)
|
||||
if not get_message_text(event.json()):
|
||||
await reimu.reject('没时间等了!快说你要去哪里?', at_sender=True)
|
||||
state['keyword'] = get_message_text(event.json())
|
||||
state['page'] = 1
|
||||
|
||||
|
||||
@reimu.handle()
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
if str(event.get_message()) in ['帮助']:
|
||||
await reimu.finish(__plugin_usage__)
|
||||
if await UserCount.check_count(event.user_id, 'reimu', COUNT_PER_DAY_REIMU):
|
||||
await reimu.finish('今天已经没车了,请明天再来...', at_sender=True)
|
||||
if _ulmt.check(event.user_id):
|
||||
await reimu.finish('您还没下车呢,请稍等...', at_sender=True)
|
||||
_ulmt.set_True(event.user_id)
|
||||
msg = get_message_text(event.json())
|
||||
args = msg.split(" ")
|
||||
if msg in ['!', '!', '?', '?', ',', ',', '.', '。']:
|
||||
await reimu.finish(__plugin_usage__)
|
||||
if msg:
|
||||
if len(args) > 1 and is_number(args[0]):
|
||||
state['keyword'] = args[1]
|
||||
state['page'] = args[0]
|
||||
else:
|
||||
state['keyword'] = msg
|
||||
state['page'] = 1
|
||||
|
||||
|
||||
@reimu.got('keyword', '你的目的地是哪?')
|
||||
async def _(bot: Bot, event: Event, state: T_State):
|
||||
try:
|
||||
keyword = state['keyword']
|
||||
page = state['page']
|
||||
print(keyword, page)
|
||||
await UserCount.add_count(event.user_id, 'reimu')
|
||||
await reimu.send('已经帮你关好车门了', at_sender=True)
|
||||
reimu_report = await from_reimu_get_info(keyword, page)
|
||||
if reimu_report:
|
||||
await reimu.send(reimu_report)
|
||||
else:
|
||||
logger.error("Not found reimuInfo")
|
||||
await reimu.send("没找着")
|
||||
_ulmt.set_False(event.user_id)
|
||||
except:
|
||||
_ulmt.set_False(event.user_id)
|
||||
|
||||
|
||||
@scheduler.scheduled_job(
|
||||
'cron',
|
||||
# year=None,
|
||||
# month=None,
|
||||
# day=None,
|
||||
# week=None,
|
||||
# day_of_week="mon,tue,wed,thu,fri",
|
||||
hour=0,
|
||||
minute=1,
|
||||
# second=None,
|
||||
# start_date=None,
|
||||
# end_date=None,
|
||||
# timezone=None,
|
||||
)
|
||||
async def _():
|
||||
await UserCount.reset_count()
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,116 @@
|
||||
from lxml import etree
|
||||
import time
|
||||
import aiohttp
|
||||
from services.log import logger
|
||||
from configs.config import MAXINFO_REIMU
|
||||
from util.user_agent import get_user_agent
|
||||
from util.utils import get_local_proxy
|
||||
from asyncio.exceptions import TimeoutError
|
||||
|
||||
|
||||
async def from_reimu_get_info(key_word: str, page: int) -> str:
|
||||
if "miku" in key_word.lower():
|
||||
logger.warning("Taboo words are being triggered")
|
||||
return None
|
||||
repass = ""
|
||||
url = 'https://blog.reimu.net/search/' + key_word + '/page/' + str(page)
|
||||
url_s = 'https://blog.reimu.net/'
|
||||
try:
|
||||
if key_word == "最近的存档":
|
||||
logger.debug("Now starting get the {}".format(url_s))
|
||||
repass = await get_repass(url_s)
|
||||
else:
|
||||
logger.debug("Now starting get the {}".format(url))
|
||||
repass = await get_repass(url)
|
||||
except TimeoutError as e:
|
||||
logger.error("Timeout! {}".format(e))
|
||||
|
||||
return repass
|
||||
|
||||
|
||||
async def get_repass(url: str) -> str:
|
||||
repass = ""
|
||||
info = "[Note]注意大部分资源解压密码为⑨\n"
|
||||
fund = None
|
||||
print(url)
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(url, proxy=get_local_proxy(), timeout=15) as response:
|
||||
html = etree.HTML(await response.text())
|
||||
|
||||
fund_l = html.xpath('//h1[@class="page-title"]/text()')
|
||||
if fund_l:
|
||||
fund = fund_l[0]
|
||||
if fund == "未找到":
|
||||
return "老司机也找不到路了……"
|
||||
else:
|
||||
pass
|
||||
|
||||
headers = html.xpath('//article/header/h2/a/text()')
|
||||
urls = html.xpath('//article/header/h2/a/@href')
|
||||
logger.debug("Now get {} post from search page".format(len(headers)))
|
||||
|
||||
headers_d = []
|
||||
urls_d = []
|
||||
for i, header in enumerate(headers):
|
||||
if check_need_list(header):
|
||||
headers_d.append(headers[i])
|
||||
urls_d.append(urls[i])
|
||||
else:
|
||||
logger.debug("This title {} does not meet the requirements".format(header))
|
||||
|
||||
header_len = len(headers_d)
|
||||
logger.debug("Get {} post after processing".format(header_len))
|
||||
if header_len > MAXINFO_REIMU:
|
||||
headers_d = headers_d[:MAXINFO_REIMU]
|
||||
urls_d = urls_d[:MAXINFO_REIMU]
|
||||
|
||||
for h_s, url_s in zip(headers_d, urls_d):
|
||||
if h_s != "审核结果存档":
|
||||
time.sleep(1.5)
|
||||
putline = await get_son_html_info(h_s, url_s)
|
||||
if putline:
|
||||
if repass:
|
||||
repass = "\n\n- - - - - - - - \n".join([repass, putline])
|
||||
else:
|
||||
repass = putline
|
||||
else:
|
||||
logger.info("审核归档页面已跳过")
|
||||
|
||||
if repass:
|
||||
repass = info + repass
|
||||
return repass
|
||||
|
||||
|
||||
async def get_son_html_info(h_s, url_s) -> str:
|
||||
repass = ""
|
||||
logger.debug("Now starting get the {}".format(url_s))
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(url_s, proxy=get_local_proxy(), timeout=15) as response:
|
||||
html = etree.HTML(await response.text())
|
||||
pres = html.xpath('//div[@class="entry-content"]/pre/text()')
|
||||
a_texts = html.xpath('//div[@class="entry-content"]/pre//a/text()')
|
||||
a_hrefs = html.xpath('//div[@class="entry-content"]/pre//a/@href')
|
||||
|
||||
if pres and a_texts and a_hrefs:
|
||||
while "" in pres:
|
||||
pres.remove("")
|
||||
|
||||
repass = "【资源名称】 {}\n\n{}".format(h_s, pres[0].strip())
|
||||
for i, (a_t_s, a_h_s) in enumerate(zip(a_texts, a_hrefs)):
|
||||
a = "\n {} {} {} ".format(a_t_s, a_h_s, pres[i + 1].strip())
|
||||
repass += a
|
||||
else:
|
||||
logger.warning("Not get putline from {}".format(url_s))
|
||||
|
||||
return repass
|
||||
|
||||
|
||||
def check_need_list(header: str) -> bool:
|
||||
not_need = ['音乐', '御所动态']
|
||||
for nd in not_need:
|
||||
if nd in header:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# print(asyncio.get_event_loop().run_until_complete(from_reimu_get_info('萝莉')))
|
||||
Reference in New Issue
Block a user