|
《超级QQ机器人插件》使用说明 超级QQ机器人插件使用说明书 https://www.playzhan.com/p/1733
本说明文档是 《超级QQ机器人插件》开发文档,主要是开发者可基于本插件开发属于自己的机器人功能。
开发案例:为机器人增加了 代下载百度文库的功能 http://addon.discuz.com/?@zhanmishu_wenku.plugin
文档说明
一、插件类库
事例插件:zhanmishu_wenku
机器人相关核心类库
source/plugin/zhanmishu_wenku/source/class/zhanmishu_wenku_rob.php
zhanmishu_rob 机器人核心类库
zhanmishu_rob_message 机器人消息功能核心类库
zhanmishu_rob_member 机器人用户功能核心类库
下面中事例中:
属性$plugin内存放插件的基本信息
- responseMessage($message)是核心方法,机器人每次收到消息都会调用这个方法,因此自己的逻辑写道这个方法中就行。 $message是机器人内置收到的消息,您插件只需要根据这个消息内的消息来执行自己的回复逻辑即可。
- getuidbyqq()通过用户QQ号获取用户的uid,如果当前用户没有绑定,则返回false,可跳转到绑定qq号和论坛账号的页面。
- sendMessage($message,$messageReply) 发送消息方法, $message主要是收到的消息,系统会自动提取发送的消息,然后发送的时候通过这个消息发送。
- open()检测机器人是否存在
- check_isplugin_open()检测当前开发的插件是否已经安装了。
- class zhanmishu_wenku_rob extends zhanmishu_wenku
- {
- public $plugin = array(
- 'name'=>'zhanmishu_wenku_rob',
- 'pluginDir'=>'source/plugin/zhanmishu_wenku/source/class',
- 'description'=>'the description of wenku_rob',
- 'pluginId'=>'zhanmishu_wenku_rob',
- 'method'=>'responseMessage',
- 'available'=>1);
- public function responseMessage($message){
- global $_G;
- if ($this->roberHander()->config['debug']) {
- $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$message);
- }
- if (!class_exists('zhanmishu_rob',false)) {
- C::import('zhanmishu_rob','plugin/zhanmishu_rob/source/class');
- }
- $message['message'] = zhanmishu_rob::auto_charset_change($message['message'],'UTF-8',CHARSET);
- $messageText = $message['message'];
- $preg = '/(?:https?:\/\/wenku\.baidu\.com\/view\/[\w.]+)/';
- preg_match($preg,$messageText,$urls);
- if (!$urls[0]) {
- return false;
- }
- //check user
- $uid = $this->getuidbyqq($message['user_id']);
- if (!$this->config['is_rob_score']) {
- $file = $this->get_file_url($urls[0]);
- if ($file['url']) {
- $messageReply = zhanmishu_rob_member::auto_charset_change($file['url']);
- }else{
- $messageReply = zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','system_error'));
- }
- }else if (!$uid) {
- $bind_url = str_replace('/source/plugin/zhanmishu_rob/', '', $_G['siteurl']).'/plugin.php?id=zhanmishu_rob:binding';
- $messageReply = zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','need_bind')."\r\n".$bind_url);
- $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log','user not register');
- }else{
- $c = array();
- $c['url']=$_GET['baidu_url'];
- $c['time']=date('Y-m-d H:i:s',TIMESTAMP);
- $rs = $this->updatemembercount($uid,'-'.$this->config['score'],lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits'),lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits_intro',$c));
- if ($rs) {
- $file = $this->get_file_url($urls[0]);
- if ($file['url']) {
- $messageReply = zhanmishu_rob_member::auto_charset_change($file['url']);
- }else{
- $rs = $this->updatemembercount($_G['uid'],$this->config['score'],lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits_back'),lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits_intro_back',$c));
- $messageReply = zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','system_error'));
- }
- }else{
- $messageReply = zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','credit_is_not_enough')."\r\n".$this->config['charge_url']);
- }
- }
- if ($this->roberHander()->config['debug']) {
- $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$messageReply);
- }
- $this->sendMessage($message,$messageReply);
- }
- public function getuidbyqq($qq){
- return $this->roberHander()->getuidbyqq($qq);
- }
- public function sendMessage($message,$messageReply){
- $robConfig = $this->roberHander()->config;
- if ($this->roberHander()->config['debug']) {
- $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$messageReply);
- }
- zhanmishu_rob_message::sendMessage($robConfig['apiUrl'], $message['message_type'], $message['user_id'], $message['group_id'], $message['discuss_id'], $messageReply, false,$robConfig['token']);
- }
- public function open(){
- $pluginId = $this->plugin['pluginId'];
- $plugins = $this->roberHander()->ZmsGetFromCache('plugins');
- $plugins[$this->plugin['pluginId']] = $this->plugin;
- $this->roberHander()->ZmswriteToCache('plugins',$plugins);
- }
- public function check_rob_exists(){
- $dir = DISCUZ_ROOT.'source/plugin/zhanmishu_rob';
- if (is_dir($dir)) {
- return true;
- }
- return false;
- }
- public function roberHander() {
- return $roberHander = new zhanmishu_rob_member();
- }
- public function check_isplugin_open(){
- if (!$this->check_rob_exists()) {
- return false;
- }
- $plugins = $this->roberHander()->ZmsGetFromCache('plugins');
- if (!empty($plugins) && is_array($plugins)) {
- if (array_key_exists($this->plugin['pluginId'],$plugins) && $plugins[$this->plugin['pluginId']]['available'] == '1') {
- return true;
- }
- }
- return false;
- }
-
- }
复制代码
|
|