Code Monkey home page Code Monkey logo

qqbot's Introduction

QQ机器人

介绍

  • 这个QQ机器人拥有插件系统,可以轻松扩展
  • 语言:C++23

依赖

前置依赖

构建

  1. 安装 cmake vcpkg c++编译器
  2. 执行以下命令
    vcpkg install openssl
    vcpkg install cpp-httplib
    vcpkg install asio
  3. 构建此程序
    cd 此程序的目录
    cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=你的vcpkg的目录/scripts/buildsystems/vcpkg.cmake
    cd build
    cmake --build . --config Release -j8
    1. 配置go-cqhttp
    2. 运行go-cqhttp再运行此程序即可使用

功能

QQ机器人插件系统

创建插件

  • 此机器人只有一个框架,用于插件扩展,所有指令(除了基本的help等基础指令)都是通过插件加入
  • 插件类
#pragma once

#include <string>

#include "command.h"
#include "permission.h"

namespace qqbot
{
    struct PluginInfo
    {
        //插件名称
        std::string name;

        //插件作者名
        std::string author;

        //插件版本
        std::string version;
    };

    class CppPlugin
    {
    public:
        //禁止复制,只能移动
        CppPlugin() = default;
        CppPlugin(const CppPlugin&) = delete;
        ~CppPlugin() = default;

        CppPlugin& operator =(const CppPlugin&) = delete;

        //插件加载
        virtual void onLoad()
        {
        }

        //插件启动
        virtual void onEnable()
        {
        }

        //插件关闭
        virtual void onDisable()
        {
        }

    public:
        //插件信息
        PluginInfo pluginInfo;

    private:

    };
}
#include <httplib.h>
#include <Json.h>
#include <vector>
#include <string>

//最基本的三个库
#include "cppPlugin.h"
#include "pluginLibrary.h"
#include "network.h"

namespace GroupOperator
{
    class GroupOperatorPlugin : public qqbot::CppPlugin //继承插件类
    {
    public:
        GroupOperatorPlugin()
        {
            qqbot::CppPlugin::pluginInfo.author = "quqiOnfree";            //作者名
            qqbot::CppPlugin::pluginInfo.name = "GroupOperator群组管理插件";//插件名称
            qqbot::CppPlugin::pluginInfo.version = "0.0.1";                //插件版本
        }

        ~GroupOperatorPlugin() = default;

        virtual void onLoad()
        {
            //这里是插件加载之前执行
        }

        virtual void onEnable()
        {
            //这里是插件加载完成时启动执行

            //添加指令
            qqbot::ServerInfo::getCommander().addCommand("kick",//命令名称
                [this](long long groupID,
                    long long senderID,
                    const std::string& commandName,
                    std::vector<std::string> Args)              //lambda表达式或符合格式的函数
                {
                    //...
                },
                "kick userid true/false",       //命令格式
                "踢出群成员"                    //命令作用解释
                );

            //设置权限
            qqbot::ServerInfo::getPermission().setGroupDefaultPermission("kick", false);
            //true是普通用户可以访问,false是管理员可以访问
            //这个可以在配置文件里面进行编辑
        }
    };
}

加载插件

需要在register.cpp加入一些代码

//导入插件
#include "pluginName.h" //插件名

namespace qqbot
{
    //修改此函数
    void Register::init()
    {
        //添加插件(以GroupOperator为例)
        //this->addPlugin(std::make_shared<插件命名空间::插件类>());
        this->addPlugin(std::make_shared<GroupOperator::GroupOperatorPlugin>());
    }
    
    //省略下面代码
    //...
}

开发此qqbot

qqbot的各种系统及API

qqbot's People

Contributors

haoerror avatar lsrlyrsc avatar quqionfree avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lsrlyrsc qidouhai

qqbot's Issues

[功能请求]监听控制中心消息并利用bot原文发送

如题
例:控制中心弹出一则消息,qqbot成功收到并获取信息发送到群聊(启用/关闭通知开关)
建议可以分辨单个软件通知,然后针对性发送控制中心消息
可以选择定时监听发送 或者 一监听到弹出消息就发送

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.