添加节气报告功能 #51

Merged
Passthem merged 4 commits from feature/24-solar-terms-notification into master 2026-02-21 23:54:25 +08:00
Owner

PR Type

Enhancement


Description

  • 添加二十四节气自动播报功能

  • 实现节气查询命令

  • 集成农历日期处理库


Diagram Walkthrough

flowchart LR
  scheduler["定时任务调度器"] -- "每日8点检查" --> check["检查当日节气"]
  check -- "有节气" --> broadcast["广播节气消息"]
  user["用户命令"] -- "查询" --> query["节气查询处理"]
  query --> response["返回节气信息"]

File Walkthrough

Relevant files
Enhancement
__init__.py
实现二十四节气通知与查询功能                                                                                     

konabot/plugins/solar_terms/init.py

  • 新增二十四节气插件模块
  • 实现每日8点自动检查并播报当日节气
  • 添加下一个节气当前节气查询命令
  • 内置24个节气的口号文案
+101/-0 
Dependencies
pyproject.toml
添加农历日期处理依赖                                                                                             

pyproject.toml

  • 添加borax库依赖用于农历日期处理
+1/-0     

### **PR Type** Enhancement ___ ### **Description** - 添加二十四节气自动播报功能 - 实现节气查询命令 - 集成农历日期处理库 ___ ### Diagram Walkthrough ```mermaid flowchart LR scheduler["定时任务调度器"] -- "每日8点检查" --> check["检查当日节气"] check -- "有节气" --> broadcast["广播节气消息"] user["用户命令"] -- "查询" --> query["节气查询处理"] query --> response["返回节气信息"] ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>__init__.py</strong><dd><code>实现二十四节气通知与查询功能</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/plugins/solar_terms/__init__.py <ul><li>新增二十四节气插件模块<br> <li> 实现每日8点自动检查并播报当日节气<br> <li> 添加<code>下一个节气</code>和<code>当前节气</code>查询命令<br> <li> 内置24个节气的口号文案</ul> </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py">+101/-0</a>&nbsp; </td> </tr> </table></td></tr><tr><td><strong>Dependencies</strong></td><td><table> <tr> <td> <details> <summary><strong>pyproject.toml</strong><dd><code>添加农历日期处理依赖</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> pyproject.toml - 添加`borax`库依赖用于农历日期处理 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/pyproject.toml">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
Passthem added 1 commit 2026-02-21 22:43:40 +08:00
Author
Owner

/review

/review
Collaborator

PR Reviewer Guide 🔍

(Review updated until commit ef3404b096)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵
🧪 No relevant tests
🔒 No security concerns identified
 Recommended focus areas for review

无限循环风险

在查询下一个节气和当前节气时,虽然设置了365天的上限,但如果LunarDate库的term属性始终返回None,仍可能导致性能问题。建议添加更严格的边界检查或错误处理机制。

while date.term is None:
    date = date.after(day_delta=1)
    day_counter += 1
    if day_counter > 365:
        await UniMessage.text("哇呀...查询出错了!").send(event)
        return
异常处理缺失

定时任务和命令处理函数中缺少对LunarDate相关操作的异常捕获。如果日期库抛出异常(如日期转换失败),可能导致整个功能崩溃。建议添加try-except块处理潜在异常。

@scheduler.scheduled_job("cron", hour="8")
async def _():
    today = LunarDate.today()
    term: str | None = today.term

    if term is not None:
        slogan = SOLAR_TERM_SLOGANS.get(term, "")
        await broadcast(
            "二十四节气", UniMessage.text(f"【今日节气】今天是 {term} 哦!{slogan}")
        )
硬编码时区

定时任务使用hour="8"但未指定时区,可能在不同服务器环境下产生非预期的触发时间。建议明确指定时区参数或在文档中说明默认时区假设。

@scheduler.scheduled_job("cron", hour="8")
## PR Reviewer Guide 🔍 #### (Review updated until commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/ef3404b0968a2c9bf680ac575a0020876f547890) Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>No relevant tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L68-L73'><strong>无限循环风险</strong></a> 在查询下一个节气和当前节气时,虽然设置了365天的上限,但如果`LunarDate`库的`term`属性始终返回`None`,仍可能导致性能问题。建议添加更严格的边界检查或错误处理机制。 </summary> ```python while date.term is None: date = date.after(day_delta=1) day_counter += 1 if day_counter > 365: await UniMessage.text("哇呀...查询出错了!").send(event) return ``` </details> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L48-L57'><strong>异常处理缺失</strong></a> 定时任务和命令处理函数中缺少对`LunarDate`相关操作的异常捕获。如果日期库抛出异常(如日期转换失败),可能导致整个功能崩溃。建议添加try-except块处理潜在异常。 </summary> ```python @scheduler.scheduled_job("cron", hour="8") async def _(): today = LunarDate.today() term: str | None = today.term if term is not None: slogan = SOLAR_TERM_SLOGANS.get(term, "") await broadcast( "二十四节气", UniMessage.text(f"【今日节气】今天是 {term} 哦!{slogan}") ) ``` </details> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L48-L48'><strong>硬编码时区</strong></a> 定时任务使用`hour="8"`但未指定时区,可能在不同服务器环境下产生非预期的触发时间。建议明确指定时区参数或在文档中说明默认时区假设。 </summary> ```python @scheduler.scheduled_job("cron", hour="8") ``` </details> </td></tr> </table>
Author
Owner

/improve

/improve
Collaborator

PR Code Suggestions

Latest suggestions up to ef3404b
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
修正循环边界检查逻辑

day_counter 达到 365 时,循环会继续执行一次(因为先执行 day_counter += 1 再检查),导致实际迭代 366
次。应该在递增前检查计数器,或者使用 >= 比较来避免额外迭代。

konabot/plugins/solar_terms/init.py [68-73]

 while date.term is None:
-    date = date.after(day_delta=1)
     day_counter += 1
     if day_counter > 365:
         await UniMessage.text("哇呀...查询出错了!").send(event)
         return
+    date = date.after(day_delta=1)
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a logic issue where the loop executes one extra iteration (366 times instead of 365). Moving the counter increment and check before date.after() prevents the unnecessary extra iteration and improves efficiency. The same issue exists in the second function (lines 92-97) but this suggestion only addresses the first occurrence.

Medium

Previous suggestions

Suggestions up to commit ef3404b
CategorySuggestion                                                                                                                                    Impact
Possible issue
添加LLM调用异常处理


LLM调用可能失败或抛出异常,但代码没有异常处理机制。如果llm.chat()失败,整个定时任务会崩溃,导致节气消息无法发送。应该添加异常处理,确保即使LLM失败也能发送基本的节气通知。

konabot/plugins/solar_terms/init.py [23-30]

-result = await llm.chat([{
-    "role": "user", "content": prompt,
-}])
-result = result.content
-if result is None:
+try:
+    result = await llm.chat([{
+        "role": "user", "content": prompt,
+    }])
+    result = result.content if result.content else ""
+except Exception:
     result = ""
 
 await broadcast("二十四节气", UniMessage.text(f"【今日节气】今天是 {term} 哦!{result}"))
Suggestion importance[1-10]: 7

__

Why: Valid suggestion addressing error handling for llm.chat() which could fail and crash the scheduled task. Adding try-except ensures the broadcast still happens even if LLM fails, improving robustness. However, this is standard error handling rather than a critical bug fix.

Medium
General
优化定时任务执行逻辑


定时任务每天8点都会执行,但只有当天是节气时才发送消息。这会导致大量无效的执行和LLM调用。应该使用更精确的调度策略,或者在检查节气之前先判断是否为节气日期,避免不必要的资源消耗。

konabot/plugins/solar_terms/init.py [15-20]

 @scheduler.scheduled_job("cron", hour="8")
 async def _():
     today = LunarDate.today()
     term: str | None = today.term
 
-    if term is not None:
+    if term is None:
+        return
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that the task runs daily but only acts on solar term days. However, the logic change is minimal (early return vs nested if), and the original code already avoids the LLM call when term is None. The optimization impact is negligible since checking term is lightweight.

Low
## PR Code Suggestions ✨ <!-- ef3404b --> Latest suggestions up to ef3404b Explore these optional code suggestions: <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>General</td> <td> <details><summary>修正循环边界检查逻辑</summary> ___ **当 <code>day_counter</code> 达到 365 时,循环会继续执行一次(因为先执行 <code>day_counter += 1</code> 再检查),导致实际迭代 366 <br>次。应该在递增前检查计数器,或者使用 <code>>=</code> 比较来避免额外迭代。** [konabot/plugins/solar_terms/__init__.py [68-73]](https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L68-L73) ```diff while date.term is None: - date = date.after(day_delta=1) day_counter += 1 if day_counter > 365: await UniMessage.text("哇呀...查询出错了!").send(event) return + date = date.after(day_delta=1) ``` <details><summary>Suggestion importance[1-10]: 7</summary> __ Why: The suggestion correctly identifies a logic issue where the loop executes one extra iteration (366 times instead of 365). Moving the counter increment and check before `date.after()` prevents the unnecessary extra iteration and improves efficiency. The same issue exists in the second function (lines 92-97) but this suggestion only addresses the first occurrence. </details></details></td><td align=center>Medium </td></tr></tr></tbody></table> ___ #### Previous suggestions <details><summary>Suggestions up to commit ef3404b</summary> <br><table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>Possible issue</td> <td> <details><summary>添加LLM调用异常处理</summary> ___ **<br>LLM调用可能失败或抛出异常,但代码没有异常处理机制。如果<code>llm.chat()</code>失败,整个定时任务会崩溃,导致节气消息无法发送。应该添加异常处理,确保即使LLM失败也能发送基本的节气通知。** [konabot/plugins/solar_terms/__init__.py [23-30]](https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L23-L30) ```diff -result = await llm.chat([{ - "role": "user", "content": prompt, -}]) -result = result.content -if result is None: +try: + result = await llm.chat([{ + "role": "user", "content": prompt, + }]) + result = result.content if result.content else "" +except Exception: result = "" await broadcast("二十四节气", UniMessage.text(f"【今日节气】今天是 {term} 哦!{result}")) ``` <details><summary>Suggestion importance[1-10]: 7</summary> __ Why: Valid suggestion addressing error handling for `llm.chat()` which could fail and crash the scheduled task. Adding try-except ensures the broadcast still happens even if LLM fails, improving robustness. However, this is standard error handling rather than a critical bug fix. </details></details></td><td align=center>Medium </td></tr><tr><td rowspan=1>General</td> <td> <details><summary>优化定时任务执行逻辑</summary> ___ **<br>定时任务每天8点都会执行,但只有当天是节气时才发送消息。这会导致大量无效的执行和LLM调用。应该使用更精确的调度策略,或者在检查节气之前先判断是否为节气日期,避免不必要的资源消耗。** [konabot/plugins/solar_terms/__init__.py [15-20]](https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feature/24-solar-terms-notification/konabot/plugins/solar_terms/__init__.py#L15-L20) ```diff @scheduler.scheduled_job("cron", hour="8") async def _(): today = LunarDate.today() term: str | None = today.term - if term is not None: + if term is None: + return ``` <details><summary>Suggestion importance[1-10]: 4</summary> __ Why: The suggestion correctly identifies that the task runs daily but only acts on solar term days. However, the logic change is minimal (early return vs nested if), and the original code already avoids the LLM call when `term` is `None`. The optimization impact is negligible since checking `term` is lightweight. </details></details></td><td align=center>Low </td></tr></tr></tbody></table> </details>
Passthem added 1 commit 2026-02-21 23:36:55 +08:00
Author
Owner

/review

/review
Collaborator

Persistent review updated to latest commit ef3404b096

**[Persistent review](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/51#issuecomment-249)** updated to latest commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/ef3404b0968a2c9bf680ac575a0020876f547890
Passthem added 1 commit 2026-02-21 23:45:04 +08:00
Author
Owner

/describe

/describe
Collaborator

PR Description updated to latest commit (ef3404b096)

**[PR Description](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/51)** updated to latest commit (https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/ef3404b0968a2c9bf680ac575a0020876f547890)
Author
Owner

/review

/review
Collaborator

Persistent review updated to latest commit ef3404b096

**[Persistent review](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/51#issuecomment-249)** updated to latest commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/ef3404b0968a2c9bf680ac575a0020876f547890
Passthem added 1 commit 2026-02-21 23:51:07 +08:00
Collaborator

Persistent review updated to latest commit ef3404b096

**[Persistent review](https://gitea.service.jazzwhom.top/mttu-developers/konabot/pulls/51#issuecomment-249)** updated to latest commit https://gitea.service.jazzwhom.top/mttu-developers/konabot/commit/ef3404b0968a2c9bf680ac575a0020876f547890
Passthem merged commit 32cabc9452 into master 2026-02-21 23:54:25 +08:00
Sign in to join this conversation.
No description provided.