fix: 修复远古时期残留的epic推送问题

This commit is contained in:
AkashiCoin 2022-02-19 14:57:23 +08:00 committed by GitHub
parent 164f6af30c
commit 44a80f89da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -33,13 +33,15 @@ Config.add_plugin_config(
default_value=True, default_value=True,
) )
epic = on_command("epic", priority=5, block=True) epic = on_command("epic", priority=5, block=True)
@epic.handle() @epic.handle()
async def handle(bot: Bot, event: MessageEvent, state: T_State): 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: if code == 404:
await epic.send(msg_list) await epic.send(msg_list)
elif isinstance(event, GroupMessageEvent): elif isinstance(event, GroupMessageEvent):
@ -63,11 +65,13 @@ async def _():
bot = get_bot() bot = get_bot()
gl = await bot.get_group_list() gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl] gl = [g["group_id"] for g in gl]
msg_list, code = await get_epic_free(bot, "Group")
for g in gl: for g in gl:
if await group_manager.check_group_task_status(g, "epic_free_game"): if await group_manager.check_group_task_status(g, "epic_free_game"):
try: try:
msg_list, code = await get_epic_free(bot, GroupMessageEvent)
if msg_list and code == 200: if msg_list and code == 200:
await bot.send_group_forward_msg(group_id=g, messages=msg_list) 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: except Exception as e:
logger.error(f"GROUP {g} epic免费游戏推送错误 {type(e)}: {e}") logger.error(f"GROUP {g} epic免费游戏推送错误 {type(e)}: {e}")

View File

@ -1,11 +1,7 @@
from httpx import AsyncClient from httpx import AsyncClient
from datetime import datetime from datetime import datetime
from nonebot.log import logger from nonebot.log import logger
from nonebot.adapters.cqhttp import ( from nonebot.adapters.cqhttp import Bot
Bot,
Event,
GroupMessageEvent,
)
from configs.config import NICKNAME 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 # https://github.com/DIYgod/RSSHub/blob/master/lib/routes/epicgames/index.js
async def get_epic_game(): async def get_epic_game():
# 现在没用 graphql 辣 # 现在没用 graphql 辣
""" prv_graphql Code """prv_graphql Code
epic_url = "https://www.epicgames.com/store/backend/graphql-proxy" epic_url = "https://www.epicgames.com/store/backend/graphql-proxy"
headers = { headers = {
"Referer": "https://www.epicgames.com/store/zh-CN/", "Referer": "https://www.epicgames.com/store/zh-CN/",
@ -33,14 +29,14 @@ async def get_epic_game():
"withPrice": True, "withPrice": True,
"withPromotions": True, "withPromotions": True,
}, },
} }
""" """
epic_url = "https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=zh-CN&country=CN&allowCountries=CN" epic_url = "https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=zh-CN&country=CN&allowCountries=CN"
headers = { headers = {
"Referer": "https://www.epicgames.com/store/zh-CN/", "Referer": "https://www.epicgames.com/store/zh-CN/",
"Content-Type": "application/json; charset=utf-8", "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: async with AsyncClient(headers=headers) as client:
try: try:
@ -56,7 +52,7 @@ async def get_epic_game():
# 获取 Epic Game Store 免费游戏信息 # 获取 Epic Game Store 免费游戏信息
# 处理免费游戏的信息方法借鉴 pip 包 epicstore_api 示例 # 处理免费游戏的信息方法借鉴 pip 包 epicstore_api 示例
# https://github.com/SD4RK/epicstore_api/blob/master/examples/free_games_example.py # 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() games = await get_epic_game()
if not games: if not games:
return "Epic 可能又抽风啦,请稍后再试(", 404 return "Epic 可能又抽风啦,请稍后再试(", 404
@ -85,7 +81,7 @@ async def get_epic_free(bot: Bot, event: Event):
end_date = datetime.fromisoformat(end_date_iso).strftime( end_date = datetime.fromisoformat(end_date_iso).strftime(
"%b.%d %H:%M" "%b.%d %H:%M"
) )
if isinstance(event, GroupMessageEvent): if Type_Event == "Group":
_message = "\n{} 公司发行的游戏 {} ({}) 在 UTC 时间 {} 即将推出免费游玩,预计截至 {}".format( _message = "\n{} 公司发行的游戏 {} ({}) 在 UTC 时间 {} 即将推出免费游玩,预计截至 {}".format(
game_corp, game_name, game_price, start_date, end_date 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 = "https://www.epicgames.com/store/zh-CN/p/{}".format(
game_url_part game_url_part
) )
if isinstance(event, GroupMessageEvent): if Type_Event == "Group":
_message = "[CQ:image,file={}]\n\nFREE now :: {} ({})\n{}\n此游戏由 {} 开发、{} 发行,将在 UTC 时间 {} 结束免费游玩,戳链接速度加入你的游戏库吧~\n{}\n".format( _message = "[CQ:image,file={}]\n\nFREE now :: {} ({})\n{}\n此游戏由 {} 开发、{} 发行,将在 UTC 时间 {} 结束免费游玩,戳链接速度加入你的游戏库吧~\n{}\n".format(
game_thumbnail, game_thumbnail,
game_name, game_name,