mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-30 01:00:02 +08:00
first_commit .gitignore
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
from nonebot import on_command
|
||||
from services.log import logger
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent
|
||||
from nonebot.typing import T_State
|
||||
from util.utils import scheduler, get_bot
|
||||
from .data_source import get_epic_game
|
||||
from models.group_remind import GroupRemind
|
||||
from nonebot.adapters.cqhttp.exception import ActionFailed
|
||||
|
||||
__plugin_usage__ = 'epic免费游戏提醒'
|
||||
|
||||
|
||||
epic = on_command("epic", priority=5, block=True)
|
||||
|
||||
|
||||
@epic.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
# try:
|
||||
if str(event.get_message()) in ['帮助']:
|
||||
await epic.finish(__plugin_usage__)
|
||||
try:
|
||||
result = await get_epic_game()
|
||||
except:
|
||||
result = '网络出错了!'
|
||||
await epic.send(result)
|
||||
logger.info(
|
||||
f"(USER {event.user_id}, GROUP {event.group_id if event.message_type != 'private' else 'private'})"
|
||||
f" 获取epic免费游戏")
|
||||
# except Exception as e:
|
||||
# logger.error(f'epic 出错 e:{e}')
|
||||
# await epic.finish('网络好像炸了,再试一次?', at_sender=True)
|
||||
|
||||
|
||||
# epic免费游戏
|
||||
@scheduler.scheduled_job(
|
||||
'cron',
|
||||
hour=12,
|
||||
minute=1,
|
||||
)
|
||||
async def _():
|
||||
# try:
|
||||
bot = get_bot()
|
||||
gl = await bot.get_group_list(self_id=bot.self_id)
|
||||
gl = [g['group_id'] for g in gl]
|
||||
for g in gl:
|
||||
if await GroupRemind.get_status(g, 'epic'):
|
||||
result = await get_epic_game()
|
||||
if result == '今天没有游戏可以白嫖了!':
|
||||
return
|
||||
try:
|
||||
await bot.send_group_msg(group_id=g,
|
||||
message=result)
|
||||
except ActionFailed:
|
||||
logger.error(f'{g}群 epic免费游戏推送错误')
|
||||
# except Exception as e:
|
||||
# logger.error(f'epic免费游戏推送错误 e:{e}')
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,46 @@
|
||||
import aiohttp
|
||||
import aiofiles
|
||||
from util.utils import get_local_proxy
|
||||
import feedparser
|
||||
import platform
|
||||
from util.init_result import image
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from util.user_agent import get_user_agent
|
||||
if platform.system() == 'Windows':
|
||||
import asyncio
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
|
||||
url = 'https://rsshub.app/epicgames/freegames'
|
||||
|
||||
|
||||
async def get_epic_game() -> str:
|
||||
result = ''
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(url, proxy=get_local_proxy(), timeout=7) as response:
|
||||
data = feedparser.parse(await response.text())['entries']
|
||||
if len(data) == 0:
|
||||
return result
|
||||
index = 0
|
||||
for item in data:
|
||||
title = item['title']
|
||||
img_url = item['summary'][item['summary'].find('src="')+5: item['summary'].rfind('"')]
|
||||
async with session.get(img_url, proxy=get_local_proxy(), timeout=7) as res:
|
||||
async with aiofiles.open(IMAGE_PATH + f'temp/epic_{index}.jpg', 'wb') as f:
|
||||
await f.write(await res.read())
|
||||
link = item['link']
|
||||
result += image(f'epic_{index}.jpg', 'temp') + f'\n【游戏】| {title}\n【链接】 | {link}\n'
|
||||
index += 1
|
||||
if result != '':
|
||||
result = 'epic限免游戏(速速白嫖):\n' + result
|
||||
else:
|
||||
result = '今天没有游戏可以白嫖了!'
|
||||
print(result)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
# print(asyncio.get_event_loop().run_until_complete(get_epic_game()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user