使用llbot-sdk-core快速开发一个防撤回插件

Fuko 发布于 2025-12-21 79 次阅读


在项目目录 src/main/java/com/ifuko/llbotsdkcore/framework/plugin中创建一个新的类AntiRecall

实现BasePluginInterface接口的所有方法

找到 群消息撤回事件,也就是 GroupRecallNoticeEvent方法

这里给你们看一下这个事件传递的对象数据

public class GroupRecallNoticeEventDTO {
    /**
     * 事件时间戳(Unix 时间戳,秒)
     */
    private Long time;
    /**
     * 机器人的 QQ 号
     */
    private Long self_id;
    /**
     * 事件类型
     * 固定值 notice
     */
    private String post_type;
    /**
     * 通知类型
     * 固定值 group_recall
     */
    private String notice_type;
    /**
     * 群号
     */
    private Long group_id;
    /**
     * 原消息发送者
     */
    private Long user_id;
    /**
     * 撤回消息的人
     */
    private Long operator_id;
    /**
     * 被撤回的消息 ID
     */
    private Long message_id;
}

接下来根据这个数据对象来写该事件下的内容

     /**
     * 群消息撤回
     *
     * @param groupRecallNoticeEventDTO
     * @return
     */
    @Override
    public Integer GroupRecallNoticeEvent(GroupRecallNoticeEventDTO groupRecallNoticeEventDTO) {
        //获取撤回消息的messageId
        Long messageId = groupRecallNoticeEventDTO.getMessage_id();
        //调用获取消息详情api getMsg 
        ApiResult<MessageEventDTO> msg = ApiUtil.getMsg(messageId);
        //将我所需要的MessageEventDTO数据从msg中取出来 命名为message
        MessageEventDTO message = msg.getData();
        //设置变量sendMsg 我要发送的消息内容
        String sendMsg ="群号:"+message.getGroup_id()+"\n";
        sendMsg += "群名:"+message.getGroup_name() +"\n";
        sendMsg += "扣扣:"+message.getUser_id()+"\n";
        sendMsg += "昵称:"+message.getSender().getNickname()+"\n";
        sendMsg += "撤回内容:"+message.getMessage();
        //发送给自己 调用sendPrivateMsg接口 
        //groupRecallNoticeEventDTO.getSelf_id() 获取机器人qq
        ApiUtil.sendPrivateMsg(groupRecallNoticeEventDTO.getSelf_id(), sendMsg);

        return 0;
    }

那么还差最后一个步骤,给你的插件打上@Service注解 将插件注入Spring

具体步骤就是在你的类上面加上@Service就行

我们试着运行一下项目
并在某个群发送一条信息然后撤回
结果如下 接收到撤回事件之后 机器人会把撤回内容发送给自己

此作者没有提供个人介绍。
最后更新于 2025-12-21