From c83f1c0afc84bd40f7c662112bb745899e0c8992 Mon Sep 17 00:00:00 2001 From: zhxy-CN Date: Tue, 1 Nov 2022 22:12:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BFix=20some=20problems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/birthday.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/plugins/genshin/birthday.py b/plugins/genshin/birthday.py index 908a202..cda1e20 100644 --- a/plugins/genshin/birthday.py +++ b/plugins/genshin/birthday.py @@ -15,6 +15,13 @@ from utils.decorators.restricts import restricts from utils.log import logger +def rm_starting_str(string, starting): + """Remove the starting character from a string.""" + while string[0] == str(starting): + string = string[1:] + return string + + class BirthdayPlugin(Plugin, BasePlugin): """Birthday.""" @@ -40,10 +47,15 @@ class BirthdayPlugin(Plugin, BasePlugin): logger.info(f"用户 {user.full_name}[{user.id}] 查询角色生日命令请求 || 参数 {msg}") if re.match(r"\d{1,2}.\d{1,2}", msg): try: - key = re.findall(r"\d+", msg)[0] + "_" + re.findall(r"\d+", msg)[1] + 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}" day_list = self.birthday_list.get(key, []) - date = re.findall(r"\d+", msg)[0] + "月" + re.findall(r"\d+", msg)[1] + "日" - text = f"{date} 是 {'、'.join(day_list)} 的生日哦~" if day_list else f"{date} 没有角色过生日哦~" + date = f"{month}月{day}日" + if key == "6_1": + text = f"{date} 是 派蒙、{'、'.join(day_list)} 的生日哦~" + else: + text = f"{date} 是 {'、'.join(day_list)} 的生日哦~" if day_list else f"{date} 没有角色过生日哦~" except IndexError: text = "请输入正确的日期格式,如1-1,或输入正确的角色名称。" reply_message = await message.reply_text(text) @@ -52,25 +64,30 @@ class BirthdayPlugin(Plugin, BasePlugin): self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id) else: try: - name = roleToName(msg) - aid = str(roleToId(msg)) - birthday = AVATAR_DATA[aid]["birthday"] + if msg == "派蒙": + name = "派蒙" + birthday = [6, 1] + else: + name = roleToName(msg) + aid = str(roleToId(msg)) + birthday = AVATAR_DATA[aid]["birthday"] text = f"{name} 的生日是 {birthday[0]}月{birthday[1]}日 哦~" reply_message = await message.reply_text(text) if filters.ChatType.GROUPS.filter(reply_message): self._add_delete_message_job(context, message.chat_id, message.message_id) self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id) except KeyError: - reply_message = await message.reply_text( - "请输入正确的日期格式,如1-1,或输入正确的角色名称。" - ) + reply_message = await message.reply_text("请输入正确的日期格式,如1-1,或输入正确的角色名称。") if filters.ChatType.GROUPS.filter(reply_message): self._add_delete_message_job(context, message.chat_id, message.message_id) self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id) else: logger.info(f"用户 {user.full_name}[{user.id}] 查询今日角色生日列表") today_list = self.birthday_list.get(key, []) - text = f"今天是 {'、'.join(today_list)} 的生日哦~" if today_list else "今天没有角色过生日哦~" + if key == "6_1": + text = f"今天是 派蒙、{'、'.join(today_list)} 的生日哦~" + else: + text = f"今天是 {'、'.join(today_list)} 的生日哦~" if today_list else "今天没有角色过生日哦~" reply_message = await message.reply_text(text) if filters.ChatType.GROUPS.filter(reply_message): self._add_delete_message_job(context, message.chat_id, message.message_id)