🎨 Update url, run repeat job interval and log in post.py

This commit is contained in:
洛水居室 2022-12-07 10:29:00 +08:00
parent 62e932d8a5
commit efc3dedc74
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -51,7 +51,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
self.last_post_id_list: List[int] = []
if config.channels and len(config.channels) > 0:
logger.success("文章定时推送处理已经开启")
bot.app.job_queue.run_repeating(self.task, 60 * 3)
bot.app.job_queue.run_repeating(self.task, 60)
async def task(self, context: CallbackContext):
temp_post_id_list: List[int] = []
@ -60,7 +60,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
try:
official_recommended_posts = await self.bbs.get_official_recommended_posts(2)
except APIHelperException as exc:
logger.error(f"获取首页推荐信息失败 {repr(exc)}")
logger.error("获取首页推荐信息失败 %s", str(exc))
return
for data_list in official_recommended_posts["list"]:
@ -84,13 +84,13 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
try:
post_info = await self.bbs.get_post_info(2, post_id)
except APIHelperException as exc:
logger.error(f"获取文章信息失败 {repr(exc)}")
text = f"获取 post_id[{post_id}] 文章信息失败 {repr(exc)}"
logger.error("获取文章信息失败 %s", str(exc))
text = f"获取 post_id[{post_id}] 文章信息失败 {str(exc)}"
for user in config.admins:
try:
await context.bot.send_message(user.user_id, text)
except BadRequest as _exc:
logger.error(f"发送消息失败 {repr(_exc)}")
logger.error("发送消息失败 %s", str(_exc))
return
buttons = [
[
@ -98,7 +98,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
InlineKeyboardButton("取消", callback_data=f"post_admin|cancel|{post_info.post_id}"),
]
]
url = f"https://bbs.mihoyo.com/ys/article/{post_info.post_id}"
url = f"https://www.miyoushe.com/ys/article/{post_info.post_id}"
text = f"发现官网推荐文章 <a href='{url}'>{post_info.subject}</a>\n是否开始处理"
for user in config.admins:
try:
@ -106,7 +106,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
user.user_id, text, parse_mode=ParseMode.HTML, reply_markup=InlineKeyboardMarkup(buttons)
)
except BadRequest as exc:
logger.error(f"发送消息失败 {repr(exc)}")
logger.error("发送消息失败 %s", exc.message)
@conversation.entry_point
@handler.callback_query(pattern=r"^post_admin\|", block=False)
@ -120,13 +120,13 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
callback_query = update.callback_query
user = callback_query.from_user
message = callback_query.message
logger.info(f"用户 {user.full_name}[{user.id}] POST命令请求")
logger.info("用户 %s[%s] POST命令请求", user.full_name, user.id)
async def get_post_admin_callback(callback_query_data: str) -> Tuple[str, int]:
_data = callback_query_data.split("|")
_result = _data[1]
_post_id = int(_data[2])
logger.debug(f"callback_query_data函数返回 result[{_result}] post_id[{_post_id}]")
logger.debug("callback_query_data函数返回 result[%s] post_id[%s]", _result, _post_id)
return _result, _post_id
result, post_id = await get_post_admin_callback(callback_query.data)
@ -151,7 +151,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
async def command_start(self, update: Update, context: CallbackContext) -> int:
user = update.effective_user
message = update.effective_message
logger.info(f"用户 {user.full_name}[{user.id}] POST命令请求")
logger.info("用户 %s[%s] POST命令请求", user.full_name, user.id)
post_handler_data = context.chat_data.get("post_handler_data")
if post_handler_data is None:
post_handler_data = PostHandlerData()
@ -187,10 +187,10 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
post_text = f"*{escape_markdown(post_subject, version=2)}*\n" f"\n"
for p in post_p:
post_text += f"{escape_markdown(p.get_text(), version=2)}\n"
post_text += f"[source](https://bbs.mihoyo.com/ys/article/{post_id})"
post_text += f"[source](https://www.miyoushe.com/ys/article/{post_id})"
if len(post_text) >= MessageLimit.CAPTION_LENGTH:
await message.reply_markdown_v2(post_text)
post_text = post_text[: MessageLimit.CAPTION_LENGTH]
post_text = post_text[: MessageLimit.CAPTION_LENGTH - 16 * 3] # 预留一些字
await message.reply_text(f"警告!图片字符描述已经超过 {MessageLimit.CAPTION_LENGTH} 个字,已经切割并发送原文本")
try:
if len(post_images) > 1:
@ -204,7 +204,7 @@ class Post(Plugin.Conversation, BasePlugin.Conversation):
image = post_images[0]
await message.reply_photo(image.data, caption=post_text, parse_mode=ParseMode.MARKDOWN_V2)
else:
await message.reply_text("图片获取错误", reply_markup=ReplyKeyboardRemove()) # excuse?
await message.reply_text(post_text, reply_markup=ReplyKeyboardRemove())
return ConversationHandler.END
except (BadRequest, TypeError) as exc:
await message.reply_text("发送图片时发生错误,错误信息已经写到日记", reply_markup=ReplyKeyboardRemove())