mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-23 08:10:56 +00:00
🐛 Fix post code
This commit is contained in:
parent
1841e60f6d
commit
b4c98bb2ce
@ -237,8 +237,8 @@ class Hyperion(HyperionBase):
|
||||
for code_data in exchange_group.get("bonuses", []):
|
||||
codes.append(LiveCodeHoYo(**code_data))
|
||||
break
|
||||
for _ in range(len(codes), 3):
|
||||
codes.append(LiveCodeHoYo(exchange_code="", offline_at=guess_offline_at))
|
||||
# for _ in range(len(codes), 3):
|
||||
# codes.append(LiveCodeHoYo(exchange_code="", offline_at=guess_offline_at))
|
||||
return codes
|
||||
|
||||
async def close(self):
|
||||
|
@ -185,7 +185,7 @@ class LiveCodeHoYo(BaseModel):
|
||||
|
||||
@staticmethod
|
||||
def guess_offline_at() -> datetime:
|
||||
return datetime.now().replace(hour=12, minute=0, second=0, microsecond=0) + timedelta(days=1)
|
||||
return datetime.now().replace(hour=23, minute=59, second=59, microsecond=59) + timedelta(days=1)
|
||||
|
||||
|
||||
class PostTypeEnum(str, Enum):
|
||||
|
60
pdm.lock
60
pdm.lock
@ -414,7 +414,7 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "black"
|
||||
version = "24.4.2"
|
||||
version = "24.8.0"
|
||||
requires_python = ">=3.8"
|
||||
summary = "The uncompromising code formatter."
|
||||
groups = ["default"]
|
||||
@ -428,28 +428,28 @@ dependencies = [
|
||||
"typing-extensions>=4.0.1; python_version < \"3.11\"",
|
||||
]
|
||||
files = [
|
||||
{file = "black-24.4.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dd1b5a14e417189db4c7b64a6540f31730713d173f0b63e55fabd52d61d8fdce"},
|
||||
{file = "black-24.4.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8e537d281831ad0e71007dcdcbe50a71470b978c453fa41ce77186bbe0ed6021"},
|
||||
{file = "black-24.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaea3008c281f1038edb473c1aa8ed8143a5535ff18f978a318f10302b254063"},
|
||||
{file = "black-24.4.2-cp310-cp310-win_amd64.whl", hash = "sha256:7768a0dbf16a39aa5e9a3ded568bb545c8c2727396d063bbaf847df05b08cd96"},
|
||||
{file = "black-24.4.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:257d724c2c9b1660f353b36c802ccece186a30accc7742c176d29c146df6e474"},
|
||||
{file = "black-24.4.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:bdde6f877a18f24844e381d45e9947a49e97933573ac9d4345399be37621e26c"},
|
||||
{file = "black-24.4.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e151054aa00bad1f4e1f04919542885f89f5f7d086b8a59e5000e6c616896ffb"},
|
||||
{file = "black-24.4.2-cp311-cp311-win_amd64.whl", hash = "sha256:7e122b1c4fb252fd85df3ca93578732b4749d9be076593076ef4d07a0233c3e1"},
|
||||
{file = "black-24.4.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:accf49e151c8ed2c0cdc528691838afd217c50412534e876a19270fea1e28e2d"},
|
||||
{file = "black-24.4.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:88c57dc656038f1ab9f92b3eb5335ee9b021412feaa46330d5eba4e51fe49b04"},
|
||||
{file = "black-24.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:be8bef99eb46d5021bf053114442914baeb3649a89dc5f3a555c88737e5e98fc"},
|
||||
{file = "black-24.4.2-cp312-cp312-win_amd64.whl", hash = "sha256:415e686e87dbbe6f4cd5ef0fbf764af7b89f9057b97c908742b6008cc554b9c0"},
|
||||
{file = "black-24.4.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:bf10f7310db693bb62692609b397e8d67257c55f949abde4c67f9cc574492cc7"},
|
||||
{file = "black-24.4.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:98e123f1d5cfd42f886624d84464f7756f60ff6eab89ae845210631714f6db94"},
|
||||
{file = "black-24.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a85f2cb5e6799a9ef05347b476cce6c182d6c71ee36925a6c194d074336ef8"},
|
||||
{file = "black-24.4.2-cp38-cp38-win_amd64.whl", hash = "sha256:b1530ae42e9d6d5b670a34db49a94115a64596bc77710b1d05e9801e62ca0a7c"},
|
||||
{file = "black-24.4.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:37aae07b029fa0174d39daf02748b379399b909652a806e5708199bd93899da1"},
|
||||
{file = "black-24.4.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:da33a1a5e49c4122ccdfd56cd021ff1ebc4a1ec4e2d01594fef9b6f267a9e741"},
|
||||
{file = "black-24.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef703f83fc32e131e9bcc0a5094cfe85599e7109f896fe8bc96cc402f3eb4b6e"},
|
||||
{file = "black-24.4.2-cp39-cp39-win_amd64.whl", hash = "sha256:b9176b9832e84308818a99a561e90aa479e73c523b3f77afd07913380ae2eab7"},
|
||||
{file = "black-24.4.2-py3-none-any.whl", hash = "sha256:d36ed1124bb81b32f8614555b34cc4259c3fbc7eec17870e8ff8ded335b58d8c"},
|
||||
{file = "black-24.4.2.tar.gz", hash = "sha256:c872b53057f000085da66a19c55d68f6f8ddcac2642392ad3a355878406fbd4d"},
|
||||
{file = "black-24.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6"},
|
||||
{file = "black-24.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb"},
|
||||
{file = "black-24.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42"},
|
||||
{file = "black-24.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a"},
|
||||
{file = "black-24.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1"},
|
||||
{file = "black-24.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af"},
|
||||
{file = "black-24.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4"},
|
||||
{file = "black-24.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af"},
|
||||
{file = "black-24.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368"},
|
||||
{file = "black-24.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed"},
|
||||
{file = "black-24.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018"},
|
||||
{file = "black-24.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2"},
|
||||
{file = "black-24.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd"},
|
||||
{file = "black-24.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2"},
|
||||
{file = "black-24.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e"},
|
||||
{file = "black-24.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920"},
|
||||
{file = "black-24.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c"},
|
||||
{file = "black-24.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e"},
|
||||
{file = "black-24.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47"},
|
||||
{file = "black-24.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb"},
|
||||
{file = "black-24.8.0-py3-none-any.whl", hash = "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed"},
|
||||
{file = "black-24.8.0.tar.gz", hash = "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2487,7 +2487,7 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.30.4"
|
||||
version = "0.30.5"
|
||||
requires_python = ">=3.8"
|
||||
summary = "The lightning-fast ASGI server."
|
||||
groups = ["default"]
|
||||
@ -2497,13 +2497,13 @@ dependencies = [
|
||||
"typing-extensions>=4.0; python_version < \"3.11\"",
|
||||
]
|
||||
files = [
|
||||
{file = "uvicorn-0.30.4-py3-none-any.whl", hash = "sha256:06b00e3087e58c6865c284143c0c42f810b32ff4f265ab19d08c566f74a08728"},
|
||||
{file = "uvicorn-0.30.4.tar.gz", hash = "sha256:00db9a9e3711a5fa59866e2b02fac69d8dc70ce0814aaec9a66d1d9e5c832a30"},
|
||||
{file = "uvicorn-0.30.5-py3-none-any.whl", hash = "sha256:b2d86de274726e9878188fa07576c9ceeff90a839e2b6e25c917fe05f5a6c835"},
|
||||
{file = "uvicorn-0.30.5.tar.gz", hash = "sha256:ac6fdbd4425c5fd17a9fe39daf4d4d075da6fdc80f653e5894cdc2fd98752bee"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uvicorn"
|
||||
version = "0.30.4"
|
||||
version = "0.30.5"
|
||||
extras = ["standard"]
|
||||
requires_python = ">=3.8"
|
||||
summary = "The lightning-fast ASGI server."
|
||||
@ -2513,14 +2513,14 @@ dependencies = [
|
||||
"httptools>=0.5.0",
|
||||
"python-dotenv>=0.13",
|
||||
"pyyaml>=5.1",
|
||||
"uvicorn==0.30.4",
|
||||
"uvicorn==0.30.5",
|
||||
"uvloop!=0.15.0,!=0.15.1,>=0.14.0; (sys_platform != \"cygwin\" and sys_platform != \"win32\") and platform_python_implementation != \"PyPy\"",
|
||||
"watchfiles>=0.13",
|
||||
"websockets>=10.4",
|
||||
]
|
||||
files = [
|
||||
{file = "uvicorn-0.30.4-py3-none-any.whl", hash = "sha256:06b00e3087e58c6865c284143c0c42f810b32ff4f265ab19d08c566f74a08728"},
|
||||
{file = "uvicorn-0.30.4.tar.gz", hash = "sha256:00db9a9e3711a5fa59866e2b02fac69d8dc70ce0814aaec9a66d1d9e5c832a30"},
|
||||
{file = "uvicorn-0.30.5-py3-none-any.whl", hash = "sha256:b2d86de274726e9878188fa07576c9ceeff90a839e2b6e25c917fe05f5a6c835"},
|
||||
{file = "uvicorn-0.30.5.tar.gz", hash = "sha256:ac6fdbd4425c5fd17a9fe39daf4d4d075da6fdc80f653e5894cdc2fd98752bee"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -21,7 +21,7 @@ from utils.log import logger
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Update, Message
|
||||
from telegram.ext import ContextTypes, Job
|
||||
from modules.apihelper.models.genshin.hyperion import LiveCode, LiveCodeHoYo
|
||||
from modules.apihelper.models.genshin.hyperion import LiveCode, LiveCodeHoYo, PostInfo
|
||||
|
||||
|
||||
class PostCodeHandlerData:
|
||||
@ -92,22 +92,14 @@ class PostCodeHandlerData:
|
||||
|
||||
|
||||
SEND_POST, CHECK_COMMAND, GET_POST_CHANNEL = range(10900, 10903)
|
||||
POST_TEMPLATE = """<b>《原神》%s 版本前瞻特别节目兑换码</b>
|
||||
POST_TEMPLATE = """<b>《绝区零》%s 版本前瞻特别节目兑换码</b>
|
||||
|
||||
国服:
|
||||
<code>%s</code> - 原石 ×100,精锻用魔矿 x10
|
||||
<code>%s</code> - 原石 ×100,大英雄的经验 x5
|
||||
<code>%s</code> - 原石 ×100,摩拉 x50000
|
||||
|
||||
国际服:
|
||||
<code>%s</code> - 原石 ×100,精锻用魔矿 x10
|
||||
<code>%s</code> - 原石 ×100,大英雄的经验 x5
|
||||
<code>%s</code> - 原石 ×100,摩拉 x50000
|
||||
<code>%s</code> - 复色菲林 x300, 资深调查员记录 x2, 音擎能源模块 x3, 丁尼 x30000
|
||||
|
||||
兑换码过期时间 %s UTC+8,请尽快领取。"""
|
||||
UPDATE_TEMPLATE = """可能的兑换码发放时间:
|
||||
|
||||
%s、%s、%s
|
||||
%s
|
||||
|
||||
更新可能延迟三到五分钟,请耐心等待。"""
|
||||
|
||||
@ -115,13 +107,13 @@ UPDATE_TEMPLATE = """可能的兑换码发放时间:
|
||||
class PostCode(Plugin.Conversation):
|
||||
"""版本前瞻特别节目兑换码推送"""
|
||||
|
||||
MENU_KEYBOARD = ReplyKeyboardMarkup([["推送频道", "推送并且定时更新"], ["退出"]], True, True)
|
||||
SUBJECT_RE = re.compile(r"一起来看《原神》(\d+\.\d+)版本前瞻特别节目吧!")
|
||||
MENU_KEYBOARD = ReplyKeyboardMarkup([["推送频道"], ["退出"]], True, True)
|
||||
SUBJECT_RE = re.compile(r"》(\d+\.\d+)版本.*?前瞻讨论活动开启")
|
||||
ACT_RE = re.compile(r"act_id=(.*?)&")
|
||||
|
||||
def __init__(self):
|
||||
self.gids = 2
|
||||
self.type_id = 3
|
||||
self.gids = 8
|
||||
self.type_id = 2
|
||||
|
||||
@staticmethod
|
||||
def get_bbs_client() -> Hyperion:
|
||||
@ -146,8 +138,8 @@ class PostCode(Plugin.Conversation):
|
||||
return match[0], post
|
||||
return None, None
|
||||
|
||||
def init_act_id(self, post: Dict) -> Optional[str]:
|
||||
structured_content = post.get("structured_content")
|
||||
def init_act_id(self, post: "PostInfo") -> Optional[str]:
|
||||
structured_content = post["post"]["post"]["structured_content"]
|
||||
if not structured_content:
|
||||
return None
|
||||
structured_data = json.loads(structured_content)
|
||||
@ -169,17 +161,18 @@ class PostCode(Plugin.Conversation):
|
||||
version, final_post = self.init_version(news.get("list", []))
|
||||
if not final_post:
|
||||
raise ValueError("未找到版本前瞻特别节目文章")
|
||||
act_id = self.init_act_id(final_post)
|
||||
if not act_id:
|
||||
raise ValueError("未找到文章中的 act_id")
|
||||
live_info = await client.get_live_info(act_id)
|
||||
ver_code = live_info.code_ver
|
||||
# final_post_info = await client.get_post_info(self.gids, final_post.get("post_id"))
|
||||
# act_id = self.init_act_id(final_post_info)
|
||||
# if not act_id:
|
||||
# raise ValueError("未找到文章中的 act_id")
|
||||
# live_info = await client.get_live_info(act_id)
|
||||
# ver_code = live_info.code_ver
|
||||
post_code_handler_data.version = version
|
||||
post_code_handler_data.act_id = act_id
|
||||
post_code_handler_data.ver_code = ver_code
|
||||
post_code_handler_data.mys_code = await client.get_live_code(act_id, ver_code)
|
||||
# post_code_handler_data.act_id = act_id
|
||||
# post_code_handler_data.ver_code = ver_code
|
||||
# post_code_handler_data.mys_code = await client.get_live_code(act_id, ver_code)
|
||||
post_code_handler_data.hoyo_code = await client.get_live_code_hoyo(self.gids)
|
||||
if len(post_code_handler_data.mys_code) != 3:
|
||||
if len(post_code_handler_data.hoyo_code) != 1:
|
||||
raise ValueError("获取兑换码数据成功,但是数量不对")
|
||||
return True
|
||||
finally:
|
||||
@ -218,15 +211,15 @@ class PostCode(Plugin.Conversation):
|
||||
return ConversationHandler.END
|
||||
if message.text == "推送频道":
|
||||
return await self.get_channel(update, context)
|
||||
if message.text == "推送并且定时更新":
|
||||
if not post_code_handler_data.real_need_update():
|
||||
await message.reply_text(
|
||||
"所有兑换码已发放,无需创建更新任务,将直接推送。", reply_markup=ReplyKeyboardRemove()
|
||||
)
|
||||
return await self.get_channel(update, context)
|
||||
post_code_handler_data.need_update = True
|
||||
await message.reply_text(post_code_handler_data.get_need_update_text())
|
||||
return await self.get_channel(update, context)
|
||||
# if message.text == "推送并且定时更新":
|
||||
# if not post_code_handler_data.real_need_update():
|
||||
# await message.reply_text(
|
||||
# "所有兑换码已发放,无需创建更新任务,将直接推送。", reply_markup=ReplyKeyboardRemove()
|
||||
# )
|
||||
# return await self.get_channel(update, context)
|
||||
# post_code_handler_data.need_update = True
|
||||
# await message.reply_text(post_code_handler_data.get_need_update_text())
|
||||
# return await self.get_channel(update, context)
|
||||
return ConversationHandler.END
|
||||
|
||||
async def get_channel(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> int:
|
||||
@ -279,7 +272,7 @@ class PostCode(Plugin.Conversation):
|
||||
await message.reply_text("正在推送", reply_markup=ReplyKeyboardRemove())
|
||||
channel_id, channel_username = post_code_handler_data.channel_id, post_code_handler_data.channel_username
|
||||
post_text = post_code_handler_data.get_text()
|
||||
post_text += f"\n\n@{channel_username}"
|
||||
post_text += f"\n\n@{channel_username} #前瞻特别节目兑换码"
|
||||
try:
|
||||
msg = await context.bot.send_message(channel_id, post_text, parse_mode=ParseMode.HTML)
|
||||
if post_code_handler_data.need_update:
|
||||
@ -318,7 +311,7 @@ class PostCode(Plugin.Conversation):
|
||||
post_code_handler_data.mys_code = mys_code
|
||||
post_code_handler_data.hoyo_code = hoyo_code
|
||||
post_text = post_code_handler_data.get_text()
|
||||
post_text += f"\n\n@{channel_username}"
|
||||
post_text += f"\n\n@{channel_username} #前瞻特别节目兑换码"
|
||||
await post_code_handler_data.channel_msg.edit_text(post_text, parse_mode=ParseMode.HTML)
|
||||
logger.success("PostCode 兑换码发生变化,已更新频道消息")
|
||||
else:
|
||||
|
@ -19,7 +19,7 @@ asyncmy==0.2.9
|
||||
attrs==23.2.0
|
||||
backports-zoneinfo==0.2.1; python_version < "3.9"
|
||||
beautifulsoup4==4.12.3
|
||||
black==24.4.2
|
||||
black==24.8.0
|
||||
cachetools==5.3.3
|
||||
certifi==2024.7.4
|
||||
cffi==1.16.0; platform_python_implementation != "PyPy"
|
||||
@ -104,8 +104,8 @@ tzdata==2024.1; platform_system == "Windows"
|
||||
tzlocal==5.2
|
||||
ujson==5.10.0
|
||||
urllib3==2.2.2
|
||||
uvicorn==0.30.4
|
||||
uvicorn[standard]==0.30.4
|
||||
uvicorn==0.30.5
|
||||
uvicorn[standard]==0.30.5
|
||||
uvloop==0.19.0; (sys_platform != "cygwin" and sys_platform != "win32") and platform_python_implementation != "PyPy"
|
||||
watchfiles==0.22.0
|
||||
websockets==12.0
|
||||
|
Loading…
Reference in New Issue
Block a user