Skip to content

Nova-Committee/McBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title

McBot

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


issues CurseForge Download License

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

长期支持版本

Forge-all
Fabric-all

快速开始

使用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协议客户端

项目地址 平台 核心作者 备注
koishijs/koishi koishi shigma
onebot-walle/walle-q abrahum
Yiwen-Chan/OneBot-YaYa 先驱 kanri
richardchien/coolq-http-api CKYU richardchien 可在 Mirai 平台使用 mirai-native 加载
Mrs4s/go-cqhttp MiraiGo Mrs4s
yyuueexxiinngg/OneBot-Mirai Mirai yyuueexxiinngg
takayama-lily/onebot OICQ takayama

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