2022-10-29 17:00:13 +00:00
|
|
|
|
import re
|
2023-07-23 15:46:11 +00:00
|
|
|
|
from typing import TYPE_CHECKING
|
2022-10-29 17:00:13 +00:00
|
|
|
|
|
2024-03-04 08:12:20 +00:00
|
|
|
|
from telegram.ext import filters
|
2022-10-29 17:00:13 +00:00
|
|
|
|
|
|
|
|
|
from core.plugin import Plugin, handler
|
2023-03-14 01:27:22 +00:00
|
|
|
|
from core.services.cookies import CookiesService
|
2023-07-23 15:46:11 +00:00
|
|
|
|
from core.services.task.services import TaskCardServices
|
|
|
|
|
from core.services.users.services import UserService, UserAdminService
|
2022-10-29 17:00:13 +00:00
|
|
|
|
from metadata.genshin import AVATAR_DATA
|
|
|
|
|
from metadata.shortname import roleToId, roleToName
|
2023-07-23 15:46:11 +00:00
|
|
|
|
from plugins.tools.birthday_card import (
|
|
|
|
|
BirthdayCardSystem,
|
|
|
|
|
rm_starting_str,
|
|
|
|
|
)
|
2024-03-04 08:12:20 +00:00
|
|
|
|
from plugins.tools.genshin import GenshinHelper
|
2022-10-29 17:00:13 +00:00
|
|
|
|
from utils.log import logger
|
2023-02-13 05:13:32 +00:00
|
|
|
|
|
2023-07-18 09:29:31 +00:00
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from telegram import Update
|
|
|
|
|
from telegram.ext import ContextTypes
|
|
|
|
|
|
2022-11-01 14:12:18 +00:00
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
|
class BirthdayPlugin(Plugin):
|
2022-10-29 17:00:13 +00:00
|
|
|
|
"""Birthday."""
|
|
|
|
|
|
2023-02-13 05:13:32 +00:00
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
2023-03-14 01:27:22 +00:00
|
|
|
|
user_service: UserService,
|
|
|
|
|
helper: GenshinHelper,
|
|
|
|
|
cookie_service: CookiesService,
|
2023-07-23 15:46:11 +00:00
|
|
|
|
card_system: BirthdayCardSystem,
|
|
|
|
|
user_admin_service: UserAdminService,
|
|
|
|
|
card_service: TaskCardServices,
|
2023-02-13 05:13:32 +00:00
|
|
|
|
):
|
2022-10-29 17:00:13 +00:00
|
|
|
|
"""Load Data."""
|
2023-02-13 05:13:32 +00:00
|
|
|
|
self.user_service = user_service
|
|
|
|
|
self.cookie_service = cookie_service
|
2023-03-14 01:27:22 +00:00
|
|
|
|
self.helper = helper
|
2023-07-23 15:46:11 +00:00
|
|
|
|
self.card_system = card_system
|
|
|
|
|
self.user_admin_service = user_admin_service
|
|
|
|
|
self.card_service = card_service
|
2022-10-29 17:00:13 +00:00
|
|
|
|
|
2023-03-14 01:27:22 +00:00
|
|
|
|
@handler.command(command="birthday", block=False)
|
2023-07-18 09:29:31 +00:00
|
|
|
|
async def command_start(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> None:
|
2022-10-29 17:00:13 +00:00
|
|
|
|
message = update.effective_message
|
2023-03-14 04:19:09 +00:00
|
|
|
|
args = self.get_args(context)
|
2022-10-29 17:00:13 +00:00
|
|
|
|
if len(args) >= 1:
|
|
|
|
|
msg = args[0]
|
2024-03-10 12:40:26 +00:00
|
|
|
|
self.log_user(update, logger.info, "查询角色生日命令请求 || 参数 %s", msg)
|
2022-10-29 17:00:13 +00:00
|
|
|
|
if re.match(r"\d{1,2}.\d{1,2}", msg):
|
|
|
|
|
try:
|
2022-11-01 14:12:18 +00:00
|
|
|
|
month = rm_starting_str(re.findall(r"\d+", msg)[0], "0")
|
|
|
|
|
day = rm_starting_str(re.findall(r"\d+", msg)[1], "0")
|
|
|
|
|
key = f"{month}_{day}"
|
2023-07-23 15:46:11 +00:00
|
|
|
|
day_list = self.card_system.birthday_list.get(key, [])
|
2022-11-01 14:12:18 +00:00
|
|
|
|
date = f"{month}月{day}日"
|
2023-02-28 14:15:48 +00:00
|
|
|
|
text = f"{date} 是 {'、'.join(day_list)} 的生日哦~" if day_list else f"{date} 没有角色过生日哦~"
|
2022-10-29 17:00:13 +00:00
|
|
|
|
except IndexError:
|
|
|
|
|
text = "请输入正确的日期格式,如1-1,或输入正确的角色名称。"
|
|
|
|
|
reply_message = await message.reply_text(text)
|
2023-03-14 01:27:22 +00:00
|
|
|
|
|
2022-10-29 17:00:13 +00:00
|
|
|
|
else:
|
|
|
|
|
try:
|
2022-11-01 14:12:18 +00:00
|
|
|
|
if msg == "派蒙":
|
2023-03-13 14:47:36 +00:00
|
|
|
|
text = "派蒙的生日是6月1日哦~"
|
|
|
|
|
elif roleToName(msg) == "旅行者":
|
|
|
|
|
text = "喂,旅行者!你该不会忘掉自己的生日了吧?"
|
2022-11-01 14:12:18 +00:00
|
|
|
|
else:
|
|
|
|
|
name = roleToName(msg)
|
|
|
|
|
aid = str(roleToId(msg))
|
|
|
|
|
birthday = AVATAR_DATA[aid]["birthday"]
|
2023-03-13 14:47:36 +00:00
|
|
|
|
text = f"{name} 的生日是 {birthday[0]}月{birthday[1]}日 哦~"
|
2022-10-29 17:00:13 +00:00
|
|
|
|
reply_message = await message.reply_text(text)
|
|
|
|
|
except KeyError:
|
2022-11-01 14:12:18 +00:00
|
|
|
|
reply_message = await message.reply_text("请输入正确的日期格式,如1-1,或输入正确的角色名称。")
|
2022-10-29 17:00:13 +00:00
|
|
|
|
else:
|
2024-03-10 12:40:26 +00:00
|
|
|
|
self.log_user(update, logger.info, "查询今日角色生日列表")
|
2023-07-23 15:46:11 +00:00
|
|
|
|
today_list = self.card_system.get_today_birthday()
|
2023-02-28 14:15:48 +00:00
|
|
|
|
text = f"今天是 {'、'.join(today_list)} 的生日哦~" if today_list else "今天没有角色过生日哦~"
|
2022-10-29 17:00:13 +00:00
|
|
|
|
reply_message = await message.reply_text(text)
|
2023-03-14 01:27:22 +00:00
|
|
|
|
|
|
|
|
|
if filters.ChatType.GROUPS.filter(reply_message):
|
|
|
|
|
self.add_delete_message_job(message)
|
|
|
|
|
self.add_delete_message_job(reply_message)
|