Git Product home page Git Product logo

qqrobot's Introduction

QQRobot是一个轻量级,高扩展的QQ机器人的php开源库,

原先的github被封了,

批量发送功能慎用,小心封号

===============

php的运行环境要求PHP7+。

他依赖coolq,如果你不熟悉coolq,我提供了快捷安装

个人实践代码

qqRobot的权限依赖QQ的权限,尽量你的qq机器人在群内或是其他地方有最高权限(管理员),避免某些群管理功能失效

安装

composer require 269995848/qqrobot dev-master

1.消息委托

2.消息代理

3.发送图片,文字

4.消息群发

5.发送音频

6.组件化开发

7.Q群管理,列表获取等

8.自动解析

9.默认异步发送

10.智能对话,图片检黄(内置组件)//图片检黄组件剔除,因为并发性太低了

11.事件监听

HOW TO DO IT

全局配置

 $config=[
    'proxyQQ'       =>'', //消息事件委托转发QQ
    'host'          =>'127.0.0.1:5700', //监听地址+端口,要配置内网地址,一般是ens0,某些服务器是ens33
    'cookies'       =>false,
    'httpOrS'       =>true,
    'isLog'         =>true, //是否开启日志,默认生成在类库 'qqrobot.log'
    'listenQQRobot' =>true, //是否监听
    'token'         =>'',
    'allowFriend'   =>true,  //是否允许加我为好友
    'allowGroup'    =>true,  //是否允许加我入群
    'atParse'       =>true,  //是否解析at我
    'logFile'       =>'',    //日志文件命名,需要有权限
    'self_qq'       =>'2442459484'  //机器人QQ号
];

$server=new Server($config);

动态配置

他是局部配置,优先级比全局配置高,但只存在当前server实例中,应用场景不同

use QQRobot\Server;

$server=new Server();
$server->isLog=false;   //关闭日志记录

接受事件消息

use QQRobot\Server;

$server=new Server();
$response=$server->response();

对事件的产生者回应

对当前的事件者回应,必须依赖当前的server实例

use QQRobot\Server;
use QQRobot\QQRobotConst;
use QQRobot\Client;


$server=new Server();
$response=$server->response();

if(isset($response->notice_type)){
    if(
        $response->user_id!=$server->config->self_qq
        &&
        ($response->sub_type== QQRobotConst::APPROVE)
        &&
        ($response->notice_type==QQRobotConst::GROUP_INCREASE)
    ){
        $msg=<<<EOT
嘿嘿,你好,欢迎来到本群,我是本群小助手,请@我,并输入"帮助"
EOT;
        $client=new Client($response);  //开启clien实例
        $client->on('back',function()use($msg){   
            return [
                [
                'msg'=>$msg, //回应消息,(必填)
                'emoji'=>'128552',  //可以附带emoji,(不必)
                'at'=>'1234567',//是否@qq1234567,如果要@当前事件产生者,则'at'=>'at'.(不必)
                'img'=>'绝对路径.png',  //(不必)如果你安装是cqa,则不支持这个功能
                 'rec'=>'音频绝对路径' //不必 如果你安装是cqa,则不支持这个功能
                 ],
                 [
                 'msg'=>$msg, //回应消息,(必填)
                 'emoji'=>'128552',  //可以附带emoji,(不必)
                 'at'=>'1234567',//是否@qq1234567,如果要@当前事件产生者,则'at'=>'at'.(不必)
                 'img'=>'绝对路径.png',  //(不必)如果你安装是cqa,则不支持这个功能
                  'rec'=>'音频绝对路径' //不必 如果你安装是cqa,则不支持这个功能
                  ],
                 
             ]          
        });
    }
}

组件化开发

组件化不支持动态配置

use QQRobot\Load;

$load=new  Load($config);  //($config 不必) 默认会按照当前server实例的配置进行读取
$load->addObserver(new Leave());
$load->addObserver(new Join());
$load->addObserver(new AtMe());
$load->loader();

主动发送消息

主动发送消息事件,不依赖当前server实例

use QQRobot\Client;


$client=new Client();
$client->on('msg',function(){
    return
        ['msg'=>'你从哪里来?',  //(必填)
         'emoji'=>'128552',   //(不必)
         'group'=>true,    //(必填) true:发送群里,false:私聊某人
         'qq'=>'623582882',  //(必填) 群号/qq号
         'at'=>'623582882'  //(不必)是否@,私聊则无效
         'img'=>'绝对路径.png', //不必,如果你安装是cqa,则不支持这个功能
         'rec'=>'音频绝对路径' //不必,如果你安装是cqa,则不支持这个功能
     ]; 

});

群发

 public function time(){
        $client=new Client($this->config);
        $msg="消息群发啦";

        $qun=['xxxx','xxxx','xxxx'];
        $emoji=rand(128512,128588);;
        $arr=[
            'msg'=>$msg,
            'emoji'=>$emoji,
            'group'=>'true',
            'qq'=>'',
            'img'=>'qqrobot_detail.png'
        ];

        $msg=[];

        foreach($qun as $v){
            $arr['qq']=$v;
            $msg[]=$arr;
        }

        $client->on('msg',function()use($msg){
            return $msg;
        });

    }

server实例应在你的项目入口处调用,比如tp5默认是index/index/index

意思不意思是你的意思,我将会继续去维护下去,目前正在进行微信机器人开发

微信

Image text

支付宝

Image text

感谢捐赠者: 消逝,随心所欲,`andYes,忧愁的程序员,大致*如此,人生搬砖工

qqrobot's People

Contributors

188700679 avatar

Stargazers

 avatar  avatar  avatar wonder avatar IIMKBqHc avatar  avatar luoyong avatar  avatar  avatar  avatar  avatar Haowa_Sai avatar siton avatar SunnyV avatar  avatar 胡泽民 avatar  avatar Keven Drain avatar Kakaz_chen avatar wilbur.yu avatar guanguans avatar Jiang Qinghua avatar  avatar  avatar jry avatar Edward avatar 学习专用 avatar Sakuya-CN avatar sunburst avatar  avatar  avatar 养猪专业户 avatar sailrel avatar 程浩 avatar  avatar BigNiu avatar

Watchers

 avatar 学习专用 avatar siton avatar

qqrobot's Issues

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.