From 74052594c326b155baa1f2ac55568fa7d180406c Mon Sep 17 00:00:00 2001 From: passthem Date: Sat, 21 Feb 2026 23:36:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8A=82=E6=B0=94=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konabot/plugins/solar_terms/__init__.py | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/konabot/plugins/solar_terms/__init__.py b/konabot/plugins/solar_terms/__init__.py index cb34105..83891ed 100644 --- a/konabot/plugins/solar_terms/__init__.py +++ b/konabot/plugins/solar_terms/__init__.py @@ -1,4 +1,6 @@ from borax.calendars import LunarDate +from nonebot import on_command +from nonebot.internal.adapter.event import Event from nonebot_plugin_alconna import UniMessage from nonebot_plugin_apscheduler import scheduler @@ -29,3 +31,35 @@ async def _(): await broadcast("二十四节气", UniMessage.text(f"【今日节气】今天是 {term} 哦!{result}")) + +cmd_next_term = on_command("下一个节气") + +@cmd_next_term.handle() +async def _(event: Event): + date = LunarDate.today() + day_counter = 0 + + while date.term is None: + date = date.after(day_delta=1) + day_counter += 1 + + d_cn_format = date.strftime("%M月%D") # 相当于正月初一这样的格式 + date_solar = date.to_solar_date() + d_glob_format = f"{date_solar.month} 月 {date_solar.day} 日" + msg = UniMessage.text( + f"下一个节气是{date.term},在 {day_counter} 天后的 {d_glob_format}(农历{d_cn_format})" + ) + await msg.send(event) + + +cmd_current_term = on_command("当前节气", aliases={"获取节气", "节气"}) + +@cmd_current_term.handle() +async def _(event: Event): + date = LunarDate.today() + while date.term is None: + date = date.before(day_delta=1) + + msg = UniMessage.text(f"现在的节气是{date.term}") + await msg.send(event) +