From eff60d8294b7aa40134ca842469e006000b14983 Mon Sep 17 00:00:00 2001 From: snowy Date: Tue, 26 Mar 2024 12:20:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=B6=E5=8C=BA=E8=AE=BE=E5=AE=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_user/const.py | 23 +++++++++++++++++++ .../plugins/liteyuki_user/profile_manager.py | 14 +++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 liteyuki/plugins/liteyuki_user/const.py diff --git a/liteyuki/plugins/liteyuki_user/const.py b/liteyuki/plugins/liteyuki_user/const.py new file mode 100644 index 00000000..9228da90 --- /dev/null +++ b/liteyuki/plugins/liteyuki_user/const.py @@ -0,0 +1,23 @@ +representative_timezones_list = [ + "Etc/GMT+12", # 国际日期变更线西 + "Pacific/Honolulu", # 夏威夷标准时间 + "America/Anchorage", # 阿拉斯加标准时间 + "America/Los_Angeles", # 美国太平洋标准时间 + "America/Denver", # 美国山地标准时间 + "America/Chicago", # 美国中部标准时间 + "America/New_York", # 美国东部标准时间 + "Europe/London", # 英国标准时间 + "Europe/Paris", # 中欧标准时间 + "Europe/Moscow", # 莫斯科标准时间 + "Asia/Dubai", # 阿联酋标准时间 + "Asia/Kolkata", # 印度标准时间 + "Asia/Shanghai", # 中国标准时间 + "Asia/Hong_Kong", # 中国香港标准时间 + "Asia/Chongqing", # 中国重庆标准时间 + "Asia/Macau", # 中国澳门标准时间 + "Asia/Taipei", # 中国台湾标准时间 + "Asia/Tokyo", # 日本标准时间 + "Australia/Sydney", # 澳大利亚东部标准时间 + "Pacific/Auckland" # 新西兰标准时间 +] +representative_timezones_list.sort() \ No newline at end of file diff --git a/liteyuki/plugins/liteyuki_user/profile_manager.py b/liteyuki/plugins/liteyuki_user/profile_manager.py index 20621515..abb55610 100644 --- a/liteyuki/plugins/liteyuki_user/profile_manager.py +++ b/liteyuki/plugins/liteyuki_user/profile_manager.py @@ -1,5 +1,6 @@ from typing import Optional +import pytz from nonebot import require from liteyuki.utils.data import LiteModel @@ -7,6 +8,7 @@ from liteyuki.utils.data_manager import User, user_db from liteyuki.utils.language import Language, get_all_lang, get_user_lang from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent from liteyuki.utils.message import Markdown as md, send_markdown +from .const import representative_timezones_list require("nonebot_plugin_alconna") from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna @@ -90,7 +92,8 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot): btn_set = md.button(ulang.get("user.profile.edit"), f"profile set {key}", enter=True if key in enter_attr else False) reply += (f"\n**{key_text}** **{val}**\n" - f"\n > {btn_set} {ulang.get(f'user.profile.{key}.desc')}\n\n***\n") + f"\n> {ulang.get(f'user.profile.{key}.desc')}" + f"\n> {btn_set} \n\n***\n") await send_markdown(reply, bot, event=event) @@ -115,6 +118,10 @@ def get_profile_menu(key: str, ulang: Language) -> Optional[str]: for lang_code, lang_name in get_all_lang().items(): btn_set = md.button(ulang.get('user.profile.set'), f"profile set {key} {lang_code}") reply += f"\n{btn_set} | **{lang_name}** - {lang_code}\n***\n" + elif key == "timezone": + for tz in representative_timezones_list: + btn_set_tz = md.button(tz, f"profile set {key} {tz}") + reply += f"{btn_set_tz}\n" return reply @@ -131,7 +138,6 @@ def set_profile(key: str, value: str) -> bool: if key == 'lang': if value in get_all_lang(): return True - return False elif key == 'timezone': - # TODO 其他个人信息项目的实现 - pass + if value in pytz.all_timezones: + return True