Skip to content

Nova-Committee/McBot

Repository files navigation

title

McBot

✨ 基于 OneBot 协议的 我的世界 QQ机器人✨


issues CurseForge Download License

English | 长期支持版本 | 快速开始

长期支持版本

Forge 1.16.5/1.18.2/1.19.2/1.20.1/1.21
Fabric 1.16.5/1.18.2/1.19.2/1.20.1/1.21

快速开始

使用api进行请求

public class APIDemo {
    static {
        // 事件回调
        McBotEvents.ON_CHAT.register((player, msgId, msg) -> System.out.printf("McBot刚刚转发一条消息。由%s发送了%s (%s)%n", player.getName().getString(), msg, msgId));
    }

    /**
     * 群里发送消息
     * @param groupId 群号
     * @param message 消息
     */
    public static void doSend(long groupId, String message) throws CommandSyntaxException {
        Const.sendGroupMsg(groupId, message)
    }

    /**
     * 撤回消息
     * @param message_id 消息ID
     */
    public static void recallMessage(int message_id) {
        JsonObject json = new Gson().fromJson(
                String.format("{'message_id': %s}", message_id),
                JsonObject.class);
        Const.customRequest(ActionType.DELETE_MSG, json);
    }
}

事件监听示例

public class WebSocketServerTest {
    public static void main(String[] args) throws Exception {
        public static LinkedBlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();//使用队列传输数据
        public static Thread app = new Thread(() -> {
            service = new ConnectFactory(new BotConfig(), blockingQueue);//创建websocket连接
            bot = service.ws.createBot();//创建机器人实例
        }, "BotServer");
        app.start();
        EventBus bus = new EventBus(blockingQueue);//创建事件分发器
        GroupMessageListener groupMessageListener = new GroupMessageListener();
        groupMessageListener.addHandler("天气", new Handler<GroupMessageEvent>() {
            @Override
            public void handle(GroupMessageEvent groupMessage) {
                System.out.println(groupMessage);

            }
        });
        bus.addListener(groupMessageListener);//加入监听
        bus.addListener(new SimpleListener<PrivateMessageEvent>() {//私聊监听
            @Override
            public void onMessage(PrivateMessageEvent privateMessage) {
                System.out.println(privateMessage);
            }
        });

    }
}

支持

McBot 以 OneBot-v11 标准协议进行开发,兼容所有支持正向WebSocket的OneBot协议端

项目地址 核心作者 备注
Overflow MrXiaoM 实现 mirai 的无缝迁移
Lagrange.Core NepPure C#实现 By Konata.Core
OpenShamrock whitechi73 Xposed框架hook实现
Gensokyo Hoshinonyaruko 基于官方api 轻量 原生跨平台
LLOnebot linyuchen 使用LiteLoaderQQNT
NapCatQQ MliKiowa 基于NTQQ的无头Bot框架
OneBot-Mirai cnlimiter Mirai的onebot协议实现

Credits

开源许可

This product is licensed under the GNU General Public License version 3. The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/gpl-3.0.html.

Alternatively, this product is licensed under the GNU Lesser General Public License version 3 for non-commercial use. The license is as published by the Free Software Foundation published at https://www.gnu.org/licenses/lgpl-3.0.html.

Feel free to contact us if you have any questions about licensing or want to use the library in a commercial closed source product.

致谢

感谢 JetBrains 提供了这么好用的软件~

星星(要要)~⭐

Stargazers over time