找回密码
 立即注册

只需一扫,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 65372|回复: 2

[教程分享] 《超级QQ机器人插件》扩展开发文档

  [复制链接]

8万

主题

431

回帖

9万

积分

管理员

积分
94368
QQ
发表于 2018-7-26 14:09:46 | 显示全部楼层 |阅读模式
《超级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()检测当前开发的插件是否已经安装了。
  1. class zhanmishu_wenku_rob extends zhanmishu_wenku
  2. {
  3.     public $plugin = array(
  4.         'name'=>'zhanmishu_wenku_rob',
  5.         'pluginDir'=>'source/plugin/zhanmishu_wenku/source/class',
  6.         'description'=>'the description of wenku_rob',
  7.         'pluginId'=>'zhanmishu_wenku_rob',
  8.         'method'=>'responseMessage',
  9.         'available'=>1);

  10.     public  function responseMessage($message){
  11.         global $_G;
  12.         if ($this->roberHander()->config['debug']) {
  13.             $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$message);
  14.         }
  15.         if (!class_exists('zhanmishu_rob',false)) {
  16.             C::import('zhanmishu_rob','plugin/zhanmishu_rob/source/class');
  17.         }
  18.         $message['message'] = zhanmishu_rob::auto_charset_change($message['message'],'UTF-8',CHARSET);
  19.         $messageText = $message['message'];

  20.         $preg = '/(?:https?:\/\/wenku\.baidu\.com\/view\/[\w.]+)/';
  21.         preg_match($preg,$messageText,$urls);

  22.         if (!$urls[0]) {
  23.             return false;
  24.         }

  25.         //check user
  26.         $uid = $this->getuidbyqq($message['user_id']);
  27.         if (!$this->config['is_rob_score']) {
  28.             $file = $this->get_file_url($urls[0]);
  29.                 if ($file['url']) {
  30.                     $messageReply = zhanmishu_rob_member::auto_charset_change($file['url']);
  31.                 }else{
  32.                     $messageReply =  zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','system_error'));
  33.                 }
  34.         }else if (!$uid) {
  35.             $bind_url = str_replace('/source/plugin/zhanmishu_rob/', '', $_G['siteurl']).'/plugin.php?id=zhanmishu_rob:binding';
  36.             $messageReply = zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','need_bind')."\r\n".$bind_url);
  37.             $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log','user not register');
  38.         }else{

  39.             $c = array();
  40.             $c['url']=$_GET['baidu_url'];
  41.             $c['time']=date('Y-m-d H:i:s',TIMESTAMP);

  42.             $rs = $this->updatemembercount($uid,'-'.$this->config['score'],lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits'),lang('plugin/zhanmishu_wenku','paytype_baidu_extcredits_intro',$c));
  43.             if ($rs) {
  44.                 $file = $this->get_file_url($urls[0]);
  45.                 if ($file['url']) {
  46.                     $messageReply = zhanmishu_rob_member::auto_charset_change($file['url']);
  47.                 }else{
  48.                     $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));
  49.                     $messageReply =  zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','system_error'));

  50.                 }
  51.             }else{
  52.                 $messageReply =  zhanmishu_rob_member::auto_charset_change(lang('plugin/zhanmishu_wenku','credit_is_not_enough')."\r\n".$this->config['charge_url']);
  53.             }
  54.         }
  55.         if ($this->roberHander()->config['debug']) {
  56.             $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$messageReply);
  57.         }      
  58.         $this->sendMessage($message,$messageReply);
  59.     }

  60.     public  function getuidbyqq($qq){
  61.         return $this->roberHander()->getuidbyqq($qq);
  62.     }

  63.     public function sendMessage($message,$messageReply){
  64.         $robConfig = $this->roberHander()->config;
  65.         if ($this->roberHander()->config['debug']) {
  66.             $this->roberHander()->log_result(DISCUZ_ROOT.'data/qq.log',$messageReply);
  67.         }   
  68.         zhanmishu_rob_message::sendMessage($robConfig['apiUrl'], $message['message_type'], $message['user_id'], $message['group_id'], $message['discuss_id'], $messageReply, false,$robConfig['token']);
  69.     }

  70.     public function open(){
  71.         $pluginId = $this->plugin['pluginId'];
  72.         $plugins = $this->roberHander()->ZmsGetFromCache('plugins');
  73.         $plugins[$this->plugin['pluginId']] = $this->plugin;
  74.         $this->roberHander()->ZmswriteToCache('plugins',$plugins);

  75.     }

  76.     public function check_rob_exists(){
  77.         $dir = DISCUZ_ROOT.'source/plugin/zhanmishu_rob';

  78.         if (is_dir($dir)) {
  79.             return true;
  80.         }
  81.         return false;
  82.     }

  83.     public function roberHander() {
  84.         return $roberHander = new zhanmishu_rob_member();
  85.     }

  86.     public function check_isplugin_open(){
  87.         if (!$this->check_rob_exists()) {
  88.             return false;
  89.         }
  90.         $plugins = $this->roberHander()->ZmsGetFromCache('plugins');
  91.         if (!empty($plugins) && is_array($plugins)) {
  92.             if (array_key_exists($this->plugin['pluginId'],$plugins) && $plugins[$this->plugin['pluginId']]['available'] == '1') {
  93.                     return true;
  94.                 }
  95.         }
  96.         return false;
  97.     }
  98.    
  99. }
复制代码









回复

使用道具 举报

0

主题

38

回帖

55

积分

菜鸟站长

积分
55
发表于 2019-4-11 11:59:17 来自手机 | 显示全部楼层
ahhahahh...  
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册   

本版积分规则

QQ|Archiver|手机版|小黑屋|站秘书 ( 蜀ICP备15034504号-3 )

GMT+8, 2024-4-20 11:07 , Processed in 0.088910 second(s), 32 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表