2023-03-14 01:27:22 +00:00
|
|
|
from datetime import datetime
|
2024-06-19 08:29:47 +00:00
|
|
|
from typing import Optional, TYPE_CHECKING, List
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2023-07-18 09:29:31 +00:00
|
|
|
from simnet.errors import DataNotPublic
|
2024-07-06 14:11:42 +00:00
|
|
|
from simnet.models.zzz.chronicle.notes import ZZZNoteCardSignState
|
2024-02-19 12:55:13 +00:00
|
|
|
from telegram import InlineKeyboardMarkup, InlineKeyboardButton
|
2022-07-31 05:48:41 +00:00
|
|
|
from telegram.constants import ChatAction
|
2023-07-18 09:29:31 +00:00
|
|
|
from telegram.ext import ConversationHandler, filters
|
2024-02-19 12:55:13 +00:00
|
|
|
from telegram.helpers import create_deep_linked_url
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
from core.plugin import Plugin, handler
|
2023-03-14 01:27:22 +00:00
|
|
|
from core.services.template.models import RenderResult
|
|
|
|
from core.services.template.services import TemplateService
|
2024-06-19 08:29:47 +00:00
|
|
|
from gram_core.plugin.methods.inline_use_data import IInlineUseData
|
2023-08-21 14:42:44 +00:00
|
|
|
from plugins.tools.genshin import GenshinHelper
|
2022-09-08 01:08:37 +00:00
|
|
|
from utils.log import logger
|
2023-08-26 10:19:00 +00:00
|
|
|
from utils.uid import mask_number
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2023-07-18 09:29:31 +00:00
|
|
|
if TYPE_CHECKING:
|
2024-07-04 11:09:48 +00:00
|
|
|
from simnet import ZZZClient
|
2023-07-18 09:29:31 +00:00
|
|
|
from telegram import Update
|
|
|
|
from telegram.ext import ContextTypes
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
__all__ = ("DailyNotePlugin",)
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
|
|
|
|
class DailyNotePlugin(Plugin):
|
2022-07-31 05:48:41 +00:00
|
|
|
"""每日便签"""
|
|
|
|
|
2022-10-10 11:07:28 +00:00
|
|
|
def __init__(
|
2022-10-22 13:54:04 +00:00
|
|
|
self,
|
2023-03-14 01:27:22 +00:00
|
|
|
template: TemplateService,
|
|
|
|
helper: GenshinHelper,
|
2022-10-10 11:07:28 +00:00
|
|
|
):
|
2023-03-14 01:27:22 +00:00
|
|
|
self.template_service = template
|
|
|
|
self.helper = helper
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2024-07-04 11:09:48 +00:00
|
|
|
async def _get_daily_note(self, client: "ZZZClient") -> RenderResult:
|
|
|
|
daily_info = await client.get_zzz_notes(client.player_id)
|
2023-03-14 01:27:22 +00:00
|
|
|
|
|
|
|
day = datetime.now().strftime("%m-%d %H:%M") + " 星期" + "一二三四五六日"[datetime.now().weekday()]
|
2022-10-10 11:07:28 +00:00
|
|
|
resin_recovery_time = (
|
2024-07-04 11:09:48 +00:00
|
|
|
daily_info.stamina_recover_time.strftime("%m-%d %H:%M")
|
|
|
|
if daily_info.max_stamina - daily_info.current_stamina
|
2022-10-10 11:07:28 +00:00
|
|
|
else None
|
|
|
|
)
|
2023-03-14 01:27:22 +00:00
|
|
|
|
|
|
|
render_data = {
|
2023-08-26 10:19:00 +00:00
|
|
|
"uid": mask_number(client.player_id),
|
2022-07-31 05:48:41 +00:00
|
|
|
"day": day,
|
|
|
|
"resin_recovery_time": resin_recovery_time,
|
2024-07-04 11:09:48 +00:00
|
|
|
"current_resin": daily_info.current_stamina,
|
|
|
|
"max_resin": daily_info.max_stamina,
|
|
|
|
"exp_status": daily_info.vhs_sale.sale_state.name,
|
|
|
|
"current_train_score": daily_info.current_train_score,
|
|
|
|
"max_train_score": daily_info.max_train_score,
|
2024-07-06 14:11:42 +00:00
|
|
|
"card_sign_status": daily_info.card_sign == ZZZNoteCardSignState.DONE,
|
2024-08-14 09:13:13 +00:00
|
|
|
"bounty_commission": daily_info.bounty_commission,
|
|
|
|
"survey_points": daily_info.survey_points,
|
2024-11-08 14:51:00 +00:00
|
|
|
"weekly_task": daily_info.weekly_task,
|
2022-07-31 05:48:41 +00:00
|
|
|
}
|
2022-10-22 07:03:59 +00:00
|
|
|
render_result = await self.template_service.render(
|
2024-07-04 11:09:48 +00:00
|
|
|
"zzz/daily_note/daily_note.jinja2",
|
2023-03-14 01:27:22 +00:00
|
|
|
render_data,
|
2024-11-08 14:51:00 +00:00
|
|
|
{"width": 600, "height": 520},
|
2023-03-14 01:27:22 +00:00
|
|
|
full_page=False,
|
|
|
|
ttl=8 * 60,
|
2022-10-10 11:07:28 +00:00
|
|
|
)
|
2022-10-22 07:03:59 +00:00
|
|
|
return render_result
|
2022-07-31 05:48:41 +00:00
|
|
|
|
2024-02-19 12:55:13 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_task_button(bot_username: str) -> InlineKeyboardMarkup:
|
|
|
|
return InlineKeyboardMarkup(
|
|
|
|
[[InlineKeyboardButton(">> 设置状态提醒 <<", url=create_deep_linked_url(bot_username, "daily_note_tasks"))]]
|
|
|
|
)
|
|
|
|
|
2024-03-25 12:48:19 +00:00
|
|
|
@handler.command("dailynote", cookie=True, block=False)
|
|
|
|
@handler.message(filters.Regex("^当前状态(.*)"), cookie=True, block=False)
|
2024-02-19 12:55:13 +00:00
|
|
|
async def command_start(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> Optional[int]:
|
2022-09-18 08:35:37 +00:00
|
|
|
message = update.effective_message
|
2024-03-10 12:40:26 +00:00
|
|
|
user_id = await self.get_real_user_id(update)
|
2024-06-12 11:59:16 +00:00
|
|
|
uid, offset = self.get_real_uid_or_offset(update)
|
2024-03-10 12:40:26 +00:00
|
|
|
self.log_user(update, logger.info, "每日便签命令请求")
|
2023-03-14 01:27:22 +00:00
|
|
|
|
2022-07-31 05:48:41 +00:00
|
|
|
try:
|
2023-03-14 01:27:22 +00:00
|
|
|
# 获取当前用户的 genshin.Client
|
2024-06-12 11:59:16 +00:00
|
|
|
async with self.helper.genshin(user_id, player_id=uid, offset=offset) as client:
|
2023-07-18 09:29:31 +00:00
|
|
|
render_result = await self._get_daily_note(client)
|
2022-07-31 05:48:41 +00:00
|
|
|
except DataNotPublic:
|
2024-03-16 01:44:15 +00:00
|
|
|
reply_message = await message.reply_text(
|
|
|
|
"查询失败惹,可能是便签功能被禁用了?请尝试通过米游社或者 hoyolab 获取一次便签信息后重试。"
|
|
|
|
)
|
2022-07-31 05:48:41 +00:00
|
|
|
if filters.ChatType.GROUPS.filter(message):
|
2023-03-14 01:27:22 +00:00
|
|
|
self.add_delete_message_job(reply_message, delay=30)
|
|
|
|
self.add_delete_message_job(message, delay=30)
|
2022-07-31 05:48:41 +00:00
|
|
|
return ConversationHandler.END
|
2023-03-14 01:27:22 +00:00
|
|
|
|
2022-10-01 08:29:22 +00:00
|
|
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
2024-02-19 12:55:13 +00:00
|
|
|
await render_result.reply_photo(
|
|
|
|
message,
|
|
|
|
filename=f"{client.player_id}.png",
|
|
|
|
reply_markup=self.get_task_button(context.bot.username),
|
|
|
|
)
|
2024-06-19 08:29:47 +00:00
|
|
|
|
|
|
|
async def daily_note_use_by_inline(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE"):
|
|
|
|
callback_query = update.callback_query
|
|
|
|
user = update.effective_user
|
|
|
|
user_id = user.id
|
|
|
|
uid = IInlineUseData.get_uid_from_context(context)
|
|
|
|
self.log_user(update, logger.info, "每日便签命令请求")
|
|
|
|
|
|
|
|
try:
|
|
|
|
async with self.helper.genshin(user_id, player_id=uid) as client:
|
|
|
|
render_result = await self._get_daily_note(client)
|
|
|
|
except DataNotPublic:
|
|
|
|
await callback_query.answer(
|
|
|
|
"查询失败惹,可能是便签功能被禁用了?请尝试通过米游社或者 hoyolab 获取一次便签信息后重试。",
|
|
|
|
show_alert=True,
|
|
|
|
)
|
|
|
|
return ConversationHandler.END
|
|
|
|
|
|
|
|
await render_result.edit_inline_media(callback_query)
|
|
|
|
|
|
|
|
async def get_inline_use_data(self) -> List[Optional[IInlineUseData]]:
|
|
|
|
return [
|
|
|
|
IInlineUseData(
|
|
|
|
text="当前状态",
|
|
|
|
hash="dailynote",
|
|
|
|
callback=self.daily_note_use_by_inline,
|
|
|
|
cookie=True,
|
|
|
|
player=True,
|
|
|
|
)
|
|
|
|
]
|