Skip to content

✨ Add support for msg emoji like api (NapCat)#337

Merged
MisakaTAT merged 1 commit into
MisakaTAT:mainfrom
TinyTsuki:dev
Aug 13, 2025
Merged

✨ Add support for msg emoji like api (NapCat)#337
MisakaTAT merged 1 commit into
MisakaTAT:mainfrom
TinyTsuki:dev

Conversation

@TinyTsuki

@TinyTsuki TinyTsuki commented Aug 13, 2025

Copy link
Copy Markdown
Contributor

Sourcery 总结

通过添加 setMsgEmojiLike API、连接 MESSAGE_EMOJI_LIKE 通知事件处理,并暴露一个插件钩子用于自定义处理,实现对消息表情符号点赞(如 NapCat)的支持。

新特性:

  • 添加 setMsgEmojiLike 动作,允许在消息上添加或移除表情符号反应
  • 引入 MESSAGE_EMOJI_LIKE 通知事件,包括其 DTO、处理程序注解、枚举条目和插件钩子 onMessageEmojiLikeNotice
Original summary in English

Summary by Sourcery

Implement support for message emoji like (NapCat) by adding the setMsgEmojiLike API, wiring up event handling for MESSAGE_EMOJI_LIKE notices, and exposing a plugin hook for custom handling.

New Features:

  • Add setMsgEmojiLike action to allow adding or removing emoji reactions on messages
  • Introduce MESSAGE_EMOJI_LIKE notice event with its DTO, handler annotation, enum entry, and plugin hook onMessageEmojiLikeNotice

@sourcery-ai

sourcery-ai Bot commented Aug 13, 2025

Copy link
Copy Markdown

审阅者指南

此 PR 扩展了机器人 API 和事件框架,通过添加新的动作方法、事件类型、处理管道、插件钩子以及相应的 DTO/注解,以支持 NapCat 风格的消息表情符号反应。

消息表情点赞事件处理的时序图

sequenceDiagram
    participant Bot
    participant EventHandler
    participant NoticeEvent
    participant InjectionHandler
    participant BotPlugin
    participant MessageEmojiLikeNoticeHandler
    Bot->>EventHandler: Receives group_msg_emoji_like event
    EventHandler->>NoticeEvent: Calls messageEmojiLikeMessage()
    NoticeEvent->>InjectionHandler: invokeMessageEmojiLikeNotice()
    InjectionHandler->>MessageEmojiLikeNoticeHandler: invoke()
    NoticeEvent->>BotPlugin: onMessageEmojiLikeNotice()
    BotPlugin-->>NoticeEvent: MESSAGE_IGNORE or MESSAGE_BLOCK
Loading

表情符号反应新 ActionParams 字段的 ER 图

erDiagram
    ACTION_PARAMS {
        STRING EMOJI_ID
        STRING SET
    }
Loading

新 MessageEmojiLikeNoticeEvent DTO 的类图

classDiagram
    class NoticeEvent
    class MessageEmojiLikeNoticeEvent {
        +Long groupId
        +Integer messageId
        +Long operatorId
        +String code
        +Integer count
    }
    MessageEmojiLikeNoticeEvent --|> NoticeEvent
Loading

NapCatExtend 接口更新的类图

classDiagram
    class NapCatExtend {
        +ActionRaw sendFriendPoke(long userId)
        +ActionRaw sendFriendPoke(long userId, long targetId)
        +ActionRaw setMsgEmojiLike(int msgId, String code, boolean isSet)
    }
Loading

包含 onMessageEmojiLikeNotice 的 BotPlugin 更新类图

classDiagram
    class BotPlugin {
        +int onGroupReactionNotice(Bot bot, GroupMessageReactionNoticeEvent event)
        +int onMessageEmojiLikeNotice(Bot bot, MessageEmojiLikeNoticeEvent event)
    }
Loading

新 MessageEmojiLikeNoticeHandler 注解的类图

classDiagram
    class MessageEmojiLikeNoticeHandler {
    }
Loading

文件级变更

变更 详情 文件
引入 setMsgEmojiLike 动作 API
  • 添加了 Bot.setMsgEmojiLike 实现
  • 在 NapCatExtend 接口中声明了 setMsgEmojiLike
  • 在 ActionPathEnum 中注册了新的动作路径
  • 向 ActionParams 添加了 EMOJI_ID 和 SET 参数
src/main/java/com/mikuac/shiro/core/Bot.java
src/main/java/com/mikuac/shiro/action/NapCatExtend.java
src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java
src/main/java/com/mikuac/shiro/constant/ActionParams.java
定义 MESSAGE_EMOJI_LIKE 事件类型
  • 添加了 MESSAGE_EMOJI_LIKE 枚举常量
  • 在 EventHandler 中将传入的 'group_msg_emoji_like' 映射到处理器
src/main/java/com/mikuac/shiro/enums/NoticeEventEnum.java
src/main/java/com/mikuac/shiro/handler/EventHandler.java
扩展表情点赞通知事件处理
  • 在 NoticeEvent.process 中处理 MESSAGE_EMOJI_LIKE
  • 添加了 messageEmojiLikeMessage 分发方法
src/main/java/com/mikuac/shiro/handler/event/NoticeEvent.java
为表情点赞通知添加插件钩子和注入
  • 在 InjectionHandler 中创建了 invokeMessageEmojiLikeNotice
  • 在 BotPlugin 中添加了 onMessageEmojiLikeNotice
  • 定义了 MessageEmojiLikeNoticeHandler 注解
src/main/java/com/mikuac/shiro/handler/injection/InjectionHandler.java
src/main/java/com/mikuac/shiro/core/BotPlugin.java
src/main/java/com/mikuac/shiro/annotation/MessageEmojiLikeNoticeHandler.java
引入 MessageEmojiLikeNoticeEvent DTO
  • 实现了包含 groupId、messageId、operatorId、code、count 字段的新事件类
src/main/java/com/mikuac/shiro/dto/event/notice/MessageEmojiLikeNoticeEvent.java

提示和命令

与 Sourcery 交互

  • 触发新审阅: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub Issue: 通过回复审阅评论,要求 Sourcery 从中创建 Issue。您也可以回复审阅评论 @sourcery-ai issue 来创建 Issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai 即可随时生成标题。您也可以在拉取请求上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写入 @sourcery-ai summary 即可在您希望的位置随时生成 PR 摘要。您也可以在拉取请求上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求上评论 @sourcery-ai guide 即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这会很有用。
  • 驳回所有 Sourcery 审阅: 在拉取请求上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审阅。如果您想从新的审阅开始,这特别有用——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

This PR extends the bot API and event framework to support NapCat-style message emoji reactions by adding a new action method, event type, handling pipeline, plugin hook, and corresponding DTO/annotation.

Sequence diagram for message emoji like event handling

sequenceDiagram
    participant Bot
    participant EventHandler
    participant NoticeEvent
    participant InjectionHandler
    participant BotPlugin
    participant MessageEmojiLikeNoticeHandler
    Bot->>EventHandler: Receives group_msg_emoji_like event
    EventHandler->>NoticeEvent: Calls messageEmojiLikeMessage()
    NoticeEvent->>InjectionHandler: invokeMessageEmojiLikeNotice()
    InjectionHandler->>MessageEmojiLikeNoticeHandler: invoke()
    NoticeEvent->>BotPlugin: onMessageEmojiLikeNotice()
    BotPlugin-->>NoticeEvent: MESSAGE_IGNORE or MESSAGE_BLOCK
Loading

ER diagram for new ActionParams fields for emoji reactions

erDiagram
    ACTION_PARAMS {
        STRING EMOJI_ID
        STRING SET
    }
Loading

Class diagram for new MessageEmojiLikeNoticeEvent DTO

classDiagram
    class NoticeEvent
    class MessageEmojiLikeNoticeEvent {
        +Long groupId
        +Integer messageId
        +Long operatorId
        +String code
        +Integer count
    }
    MessageEmojiLikeNoticeEvent --|> NoticeEvent
Loading

Class diagram for NapCatExtend interface update

classDiagram
    class NapCatExtend {
        +ActionRaw sendFriendPoke(long userId)
        +ActionRaw sendFriendPoke(long userId, long targetId)
        +ActionRaw setMsgEmojiLike(int msgId, String code, boolean isSet)
    }
Loading

Class diagram for BotPlugin update with onMessageEmojiLikeNotice

classDiagram
    class BotPlugin {
        +int onGroupReactionNotice(Bot bot, GroupMessageReactionNoticeEvent event)
        +int onMessageEmojiLikeNotice(Bot bot, MessageEmojiLikeNoticeEvent event)
    }
Loading

Class diagram for new MessageEmojiLikeNoticeHandler annotation

classDiagram
    class MessageEmojiLikeNoticeHandler {
    }
Loading

File-Level Changes

Change Details Files
Introduce setMsgEmojiLike action API
  • Added Bot.setMsgEmojiLike implementation
  • Declared setMsgEmojiLike in NapCatExtend interface
  • Registered new action path in ActionPathEnum
  • Added EMOJI_ID and SET params to ActionParams
src/main/java/com/mikuac/shiro/core/Bot.java
src/main/java/com/mikuac/shiro/action/NapCatExtend.java
src/main/java/com/mikuac/shiro/enums/ActionPathEnum.java
src/main/java/com/mikuac/shiro/constant/ActionParams.java
Define MESSAGE_EMOJI_LIKE event type
  • Added MESSAGE_EMOJI_LIKE enum constant
  • Mapped incoming 'group_msg_emoji_like' to handler in EventHandler
src/main/java/com/mikuac/shiro/enums/NoticeEventEnum.java
src/main/java/com/mikuac/shiro/handler/EventHandler.java
Extend notice event processing for emoji likes
  • Handle MESSAGE_EMOJI_LIKE in NoticeEvent.process
  • Added messageEmojiLikeMessage dispatch method
src/main/java/com/mikuac/shiro/handler/event/NoticeEvent.java
Add plugin hook and injection for emoji-like notices
  • Created invokeMessageEmojiLikeNotice in InjectionHandler
  • Added onMessageEmojiLikeNotice in BotPlugin
  • Defined MessageEmojiLikeNoticeHandler annotation
src/main/java/com/mikuac/shiro/handler/injection/InjectionHandler.java
src/main/java/com/mikuac/shiro/core/BotPlugin.java
src/main/java/com/mikuac/shiro/annotation/MessageEmojiLikeNoticeHandler.java
Introduce MessageEmojiLikeNoticeEvent DTO
  • Implemented new event class with groupId, messageId, operatorId, code, count fields
src/main/java/com/mikuac/shiro/dto/event/notice/MessageEmojiLikeNoticeEvent.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@TinyTsuki - 我已审阅了你的更改,它们看起来很棒!

AI 代理提示
请处理此代码审查中的评论:
## 个人评论

### 评论 1
<location> `src/main/java/com/mikuac/shiro/core/Bot.java:1578` </location>
<code_context>
+     * @return result {@link ActionRaw}
+     */
+    @Override
+    public ActionRaw setMsgEmojiLike(int msgId, String code, boolean isSet) {
+        Map<String, Object> params = new HashMap<>();
+        params.put(ActionParams.MESSAGE_ID, msgId);
</code_context>

<issue_to_address>
考虑支持 long 类型作为消息 ID 以保持一致性。

其他方法使用 long 类型作为消息 ID。如果 ID 可能超过 Integer.MAX_VALUE,将 msgId 更新为 long 类型将确保一致性并防止未来出现问题。

建议的实现:

```java
     * @param msgId 消息 ID (long)

```

```java
    public ActionRaw setMsgEmojiLike(long msgId, String code, boolean isSet) {
        Map<String, Object> params = new HashMap<>();
        params.put(ActionParams.MESSAGE_ID, msgId);
        params.put(ActionParams.EMOJI_ID, code);
        params.put(ActionParams.SET, isSet);
        JsonObjectWrapper result = actionHandler.action(session, ActionPathEnum.SET_MSG_EMOJI_LIKE, params);
        return result != null ? result.to(ActionRaw.class) : null;
    }

```

如果代码库中其他地方有任何对 `setMsgEmojiLike` 的调用,它们的 `msgId` 参数类型应更新为 `long` 以保持一致性。
</issue_to_address>

Sourcery 对开源免费 - 如果您喜欢我们的评论,请考虑分享 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将利用这些反馈来改进您的评论。
Original comment in English

Hey @TinyTsuki - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/main/java/com/mikuac/shiro/core/Bot.java:1578` </location>
<code_context>
+     * @return result {@link ActionRaw}
+     */
+    @Override
+    public ActionRaw setMsgEmojiLike(int msgId, String code, boolean isSet) {
+        Map<String, Object> params = new HashMap<>();
+        params.put(ActionParams.MESSAGE_ID, msgId);
</code_context>

<issue_to_address>
Consider supporting long type for message ID for consistency.

Other methods use long for message IDs. If IDs may exceed Integer.MAX_VALUE, updating msgId to long will ensure consistency and prevent future issues.

Suggested implementation:

```java
     * @param msgId 消息 ID (long)

```

```java
    public ActionRaw setMsgEmojiLike(long msgId, String code, boolean isSet) {
        Map<String, Object> params = new HashMap<>();
        params.put(ActionParams.MESSAGE_ID, msgId);
        params.put(ActionParams.EMOJI_ID, code);
        params.put(ActionParams.SET, isSet);
        JsonObjectWrapper result = actionHandler.action(session, ActionPathEnum.SET_MSG_EMOJI_LIKE, params);
        return result != null ? result.to(ActionRaw.class) : null;
    }

```

If there are any calls to `setMsgEmojiLike` elsewhere in the codebase, their `msgId` argument type should be updated to `long` for consistency.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* @return result {@link ActionRaw}
*/
@Override
public ActionRaw setMsgEmojiLike(int msgId, String code, boolean isSet) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: 考虑支持 long 类型作为消息 ID 以保持一致性。

其他方法使用 long 类型作为消息 ID。如果 ID 可能超过 Integer.MAX_VALUE,将 msgId 更新为 long 类型将确保一致性并防止未来出现问题。

建议的实现:

     * @param msgId 消息 ID (long)
    public ActionRaw setMsgEmojiLike(long msgId, String code, boolean isSet) {
        Map<String, Object> params = new HashMap<>();
        params.put(ActionParams.MESSAGE_ID, msgId);
        params.put(ActionParams.EMOJI_ID, code);
        params.put(ActionParams.SET, isSet);
        JsonObjectWrapper result = actionHandler.action(session, ActionPathEnum.SET_MSG_EMOJI_LIKE, params);
        return result != null ? result.to(ActionRaw.class) : null;
    }

如果代码库中其他地方有任何对 setMsgEmojiLike 的调用,它们的 msgId 参数类型应更新为 long 以保持一致性。

Original comment in English

suggestion: Consider supporting long type for message ID for consistency.

Other methods use long for message IDs. If IDs may exceed Integer.MAX_VALUE, updating msgId to long will ensure consistency and prevent future issues.

Suggested implementation:

     * @param msgId 消息 ID (long)
    public ActionRaw setMsgEmojiLike(long msgId, String code, boolean isSet) {
        Map<String, Object> params = new HashMap<>();
        params.put(ActionParams.MESSAGE_ID, msgId);
        params.put(ActionParams.EMOJI_ID, code);
        params.put(ActionParams.SET, isSet);
        JsonObjectWrapper result = actionHandler.action(session, ActionPathEnum.SET_MSG_EMOJI_LIKE, params);
        return result != null ? result.to(ActionRaw.class) : null;
    }

If there are any calls to setMsgEmojiLike elsewhere in the codebase, their msgId argument type should be updated to long for consistency.

@MisakaTAT

Copy link
Copy Markdown
Owner

LGTM, Thanks!

@MisakaTAT
MisakaTAT merged commit 4dc2ff2 into MisakaTAT:main Aug 13, 2025
@TinyTsuki
TinyTsuki deleted the dev branch September 5, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants