Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fixed DailySign. #102

Merged
merged 2 commits into from
Feb 3, 2025
Merged

[Bug] Fixed DailySign. #102

merged 2 commits into from
Feb 3, 2025

Conversation

rong-xiaoli
Copy link
Owner

@rong-xiaoli rong-xiaoli commented Feb 2, 2025

Fixed DailySign not responding to command after turning off and on.
Fixed DailySign signCombo not counting correctly.

Summary by CodeRabbit

  • Bug Fixes
    • 优化每日签到逻辑,通过更精确的日期时间比较,仅在用户真实连续签到时增加计数,确保签到奖励准确。
  • Chores
    • 移除部分冗余调试日志,使后台日志输出更简洁。

@rong-xiaoli rong-xiaoli added the code/bug Something isn't working | 貌似不太对? label Feb 2, 2025
@rong-xiaoli rong-xiaoli self-assigned this Feb 2, 2025
@rong-xiaoli rong-xiaoli linked an issue Feb 2, 2025 that may be closed by this pull request
1 task
Copy link
Contributor

coderabbitai bot commented Feb 2, 2025

Walkthrough

该拉取请求对两个 Java 类进行了修改。首先,DailySign.java 中将日期比较逻辑从基于 LocalDate 改为 LocalDateTime,从而通过比较年、月、日实现更精确的判断签到连续性,同时添加了日志记录以便调试。其次,在 OsuData.java 中删除了 shutdown 方法中用于记录用户数据列表长度的日志语句。两处修改均未改动公共接口声明。

Changes

File(s) Change Summary
src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java 修改签到逻辑:将日期比较从 LocalDate 改为 LocalDateTime(通过比较年、月、日),并增加日志记录以便调试。
src/main/java/top/.../OsuBot/data/OsuData.java 移除 shutdown 方法中关于用户数据列表长度的日志记录,简化日志输出。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DailySign
    participant Logger
    User->>DailySign: 发起签到请求
    DailySign->>DailySign: 计算 temp = oldDate + 1天
    alt temp 与 newDate 年月日相同
        DailySign->>DailySign: 增加连续签到数
        DailySign->>Logger: 记录 temp 和 newDate 的值
    else
        DailySign->>DailySign: 重置连续签到数为1
        DailySign->>Logger: 记录 temp 和 newDate 的值
    end
Loading

Suggested reviewers

  • Moshonne
  • ADU20281028

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6756daf and 9b9f104.

📒 Files selected for processing (1)
  • src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java-kotlin)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rong-xiaoli
Copy link
Owner Author

rong-xiaoli commented Feb 2, 2025

Fixed #101
Fixed #100
Fixed #99

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java (2)

59-65: 建议优化日期比较逻辑

当前的日期比较实现虽然正确,但可以使用更简洁的方法。

建议使用以下实现来简化代码:

-        LocalDateTime oldDate = lastSign.toZonedDateTime().toLocalDateTime(), newDate = newSign.toZonedDateTime().toLocalDateTime();
-        LocalDateTime temp = oldDate.plusDays(1);
-        LOGGER.verbose(temp.toString());
-        LOGGER.verbose(newDate.toString());
-        if (temp.getYear() == newDate.getYear() && temp.getMonth() == newDate.getMonth() && temp.getDayOfMonth() == newDate.getDayOfMonth()) {
-            newCombo = signCombo + 1;
-        } else newCombo = 1;
+        LocalDateTime oldDate = lastSign.toZonedDateTime().toLocalDateTime();
+        LocalDateTime newDate = newSign.toZonedDateTime().toLocalDateTime();
+        LocalDateTime nextExpectedDate = oldDate.plusDays(1).truncatedTo(ChronoUnit.DAYS);
+        LocalDateTime currentDate = newDate.truncatedTo(ChronoUnit.DAYS);
+        LOGGER.verbose("Next expected date: " + nextExpectedDate);
+        LOGGER.verbose("Current date: " + currentDate);
+        newCombo = nextExpectedDate.isEqual(currentDate) ? signCombo + 1 : 1;

这样的改进:

  1. 使用 truncatedTo(ChronoUnit.DAYS) 忽略时分秒
  2. 使用 isEqual() 替代分别比较年月日
  3. 使用三元运算符使逻辑更简洁
  4. 改进了日志信息使其更清晰

61-62: 建议改进日志信息

当前的日志输出缺乏上下文信息,不利于问题排查。

建议添加更多上下文信息:

-        LOGGER.verbose(temp.toString());
-        LOGGER.verbose(newDate.toString());
+        LOGGER.verbose("计算连续签到 - 下一个预期日期:" + temp);
+        LOGGER.verbose("计算连续签到 - 当前签到日期:" + newDate);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa6f05 and 6756daf.

📒 Files selected for processing (2)
  • src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java (2 hunks)
  • src/main/java/top/rongxiaoli/plugins/OsuBot/data/OsuData.java (0 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/top/rongxiaoli/plugins/OsuBot/data/OsuData.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (1)
src/main/java/top/rongxiaoli/plugins/DailySign/DailySign.java (1)

149-149: 验证重载数据时的插件状态管理

reloadData() 中直接调用 enablePlugin() 可能导致意外的状态变化。

建议在启用插件前添加状态检查:

-        enablePlugin();
+        // 仅在插件之前处于启用状态时重新启用
+        if (pluginStatus) {
+            LOGGER.verbose("重新启用插件");
+            enablePlugin();
+        } else {
+            LOGGER.verbose("保持插件禁用状态");
+        }

@rong-xiaoli rong-xiaoli merged commit 96b6929 into dev Feb 3, 2025
6 checks passed
@rong-xiaoli rong-xiaoli deleted the dailysign-not-responding branch February 3, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code/bug Something isn't working | 貌似不太对?
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug]: DailySign not responding sign after restart
1 participant