mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
fix: 修复远古时期残留的epic推送问题
This commit is contained in:
parent
164f6af30c
commit
44a80f89da
@ -33,13 +33,15 @@ Config.add_plugin_config(
|
||||
default_value=True,
|
||||
)
|
||||
|
||||
|
||||
epic = on_command("epic", priority=5, block=True)
|
||||
|
||||
|
||||
@epic.handle()
|
||||
async def handle(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg_list, code = await get_epic_free(bot, event)
|
||||
Type_Event = "Private"
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
Type_Event = "Group"
|
||||
msg_list, code = await get_epic_free(bot, Type_Event)
|
||||
if code == 404:
|
||||
await epic.send(msg_list)
|
||||
elif isinstance(event, GroupMessageEvent):
|
||||
@ -63,11 +65,13 @@ async def _():
|
||||
bot = get_bot()
|
||||
gl = await bot.get_group_list()
|
||||
gl = [g["group_id"] for g in gl]
|
||||
msg_list, code = await get_epic_free(bot, "Group")
|
||||
for g in gl:
|
||||
if await group_manager.check_group_task_status(g, "epic_free_game"):
|
||||
try:
|
||||
msg_list, code = await get_epic_free(bot, GroupMessageEvent)
|
||||
if msg_list and code == 200:
|
||||
await bot.send_group_forward_msg(group_id=g, messages=msg_list)
|
||||
else:
|
||||
bot.send_group_msg(group_id=g, messages=msg_list)
|
||||
except Exception as e:
|
||||
logger.error(f"GROUP {g} epic免费游戏推送错误 {type(e)}: {e}")
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
from httpx import AsyncClient
|
||||
from datetime import datetime
|
||||
from nonebot.log import logger
|
||||
from nonebot.adapters.cqhttp import (
|
||||
Bot,
|
||||
Event,
|
||||
GroupMessageEvent,
|
||||
)
|
||||
from nonebot.adapters.cqhttp import Bot
|
||||
from configs.config import NICKNAME
|
||||
|
||||
|
||||
@ -14,7 +10,7 @@ from configs.config import NICKNAME
|
||||
# https://github.com/DIYgod/RSSHub/blob/master/lib/routes/epicgames/index.js
|
||||
async def get_epic_game():
|
||||
# 现在没用 graphql 辣
|
||||
""" prv_graphql Code
|
||||
"""prv_graphql Code
|
||||
epic_url = "https://www.epicgames.com/store/backend/graphql-proxy"
|
||||
headers = {
|
||||
"Referer": "https://www.epicgames.com/store/zh-CN/",
|
||||
@ -40,7 +36,7 @@ async def get_epic_game():
|
||||
headers = {
|
||||
"Referer": "https://www.epicgames.com/store/zh-CN/",
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36"
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36",
|
||||
}
|
||||
async with AsyncClient(headers=headers) as client:
|
||||
try:
|
||||
@ -56,7 +52,7 @@ async def get_epic_game():
|
||||
# 获取 Epic Game Store 免费游戏信息
|
||||
# 处理免费游戏的信息方法借鉴 pip 包 epicstore_api 示例
|
||||
# https://github.com/SD4RK/epicstore_api/blob/master/examples/free_games_example.py
|
||||
async def get_epic_free(bot: Bot, event: Event):
|
||||
async def get_epic_free(bot: Bot, Type_Event: str):
|
||||
games = await get_epic_game()
|
||||
if not games:
|
||||
return "Epic 可能又抽风啦,请稍后再试(", 404
|
||||
@ -85,7 +81,7 @@ async def get_epic_free(bot: Bot, event: Event):
|
||||
end_date = datetime.fromisoformat(end_date_iso).strftime(
|
||||
"%b.%d %H:%M"
|
||||
)
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
if Type_Event == "Group":
|
||||
_message = "\n由 {} 公司发行的游戏 {} ({}) 在 UTC 时间 {} 即将推出免费游玩,预计截至 {}。".format(
|
||||
game_corp, game_name, game_price, start_date, end_date
|
||||
)
|
||||
@ -131,7 +127,7 @@ async def get_epic_free(bot: Bot, event: Event):
|
||||
game_url = "https://www.epicgames.com/store/zh-CN/p/{}".format(
|
||||
game_url_part
|
||||
)
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
if Type_Event == "Group":
|
||||
_message = "[CQ:image,file={}]\n\nFREE now :: {} ({})\n{}\n此游戏由 {} 开发、{} 发行,将在 UTC 时间 {} 结束免费游玩,戳链接速度加入你的游戏库吧~\n{}\n".format(
|
||||
game_thumbnail,
|
||||
game_name,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user