SHARE
TWEET

ecmd V9

cinos11 Dec 8th, 2012 (edited) 1,898 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     /*
  3.         ARCBOT ECMD
  4.         Update Notes:
  5.             V1 - Initial Release
  6.             V2 - Added ability to do bans
  7.             V3 - Script sends data to ARCbots, as non serialized
  8.             V4 - Updated unserialize to json_decode
  9.             V5 - json_decode second paremeter value set to true
  10.             V6 - Removed outdated commands & level/chatinfo added as received content
  11.             V7 - Added debugging feature debugECMDCode($debug=false), to test web-results directly thru your website
  12.             V8 - Added arcbot-ecmd.log -- For logging of data sent between ARCbot and ECMD client
  13.             V9 - Added command console: cmdconsole
  14.     *********************************************************************************************************************
  15.         This is an example custom coded ARCbot commands page.
  16.         To use it, host it onto any website of your choosing, then give it to your bot like so (Make sure the file name contains arcbot-ecmd):
  17.             --Add the script to your bot's ecmd list: !ecmdlink http://example.com/arcbot-ecmd.php
  18.             -Examples of how it works:
  19.             -- !ecmd copyme test
  20.             -- Make it an easier command while in chat -- !addalias (!ecmd copyme) (!copyme2)
  21.            
  22.         Example Received Content from ARCbot:
  23.         -------------------------------------------------------------
  24.             [message] => test
  25.             [type] => 0
  26.             [uid] => 367927622
  27.             [command] => copyme
  28.             [info] =>
  29.                 [registeredName] => Actavus
  30.                 [avatar] => http://img404.imageshack.us/img404/test.png
  31.                 [homepage] => http://ARCbots.com/
  32.                 [rank] => main
  33.                 [status] => afk
  34.                 [inChat] => http://xat.com/ARCbot
  35.             'level' => 5,
  36.             'chatinfo' => array(
  37.                 'roomid' => 158721424,
  38.                 'roomname' => 'ARCbot',
  39.             ),
  40.     *********************************************************************************************************************
  41.         *Note that this isn't limited to php.
  42.         If your able to convert this into other languages such as python, and it can respond back, you can use it.
  43.     *********************************************************************************************************************
  44.         Additional API methods your webserver could potentially use:
  45.        
  46.         http://arcbots.com/api-v2.html
  47.        
  48.         --Command Console (** NOTE ** : You must wait until command is processed before another one is successfully sent):
  49.             &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=sendCmd&xatBotCommand=[URL ENCODED COMMAND/MESSAGE]
  50.  
  51.         --Restart Bot:
  52.             &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=restart
  53.            
  54.         --Stop Bot:
  55.             &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=stop
  56.     *********************************************************************************************************************
  57.     */
  58.     // Useful Optional Utility Functions
  59.     function getBetween($content,$start,$end){$r = explode($start, $content);if(isset($r[1])){$r = explode($end, $r[1]);return$r[0]; }return'';}
  60.    
  61.    
  62.     $debugPassValues = debugECMDCode(false);
  63.     if(!empty($debugPassValues)) {
  64.         var_dump(explode('|', base64_decode(sendResponse($debugPassValues))));
  65.     }
  66.     else {
  67.         $passValues = json_decode(base64_decode($_REQUEST['values']), true); //Received Values
  68.         echo sendResponse($passValues); //Send your ARCbot the response
  69.     }
  70.    
  71.     file_put_contents('arcbot-ecmd.log', "[Request Data: ".base64_encode(json_encode($_REQUEST))."][Sent to ARCbot Data: ".base64_encode(json_encode($passValues))."][Timestamp: ".time()."]\n", FILE_APPEND | LOCK_EX);
  72.    
  73.     function sendResponse($passValues) {
  74.         $passV['message'] = 'No Message sent'; //Default message if command not found
  75.         $passV['type'] = $passValues['type']; //0=main chat, 1=pc, 2=pm
  76.         $passV['uid'] = $passValues['uid']; //The user's xat id to send the message to
  77.         $passV['minrank'] = 2; //Minimum mod level to use this command -- 0~5
  78.         $passV['arcbot'] = 'isValid'; //Required so the bot can verify this script
  79.        
  80.         $info = $passValues['info'];
  81.         $command = strtolower($passValues['command']);
  82.         $message = $passValues['message'];
  83.        
  84.         switch($command) {
  85.             case 'test':
  86.                 $passV['message'] = 'test Response';
  87.             break;
  88.             case 'info':
  89.                 $passV['message'] = 'Your name is '.$info['registeredName'].' and ur rank is '.$info['rank'];
  90.             break;
  91.             case 'copyme':
  92.                 $passV['message'] = $message;
  93.             break;
  94.             case 'fml':
  95.                 $data = file_get_contents('http://m.fmylife.com/random');
  96.                 $fml = getBetween($data,'<p class="text">','</p>');
  97.                 if(strlen($fml) > 200) {
  98.                     $info1 = substr($fml, 0, 200);
  99.                     $info2 = substr($fml, 200, 400);
  100.                     $passV['message'] = $info1;
  101.                 }
  102.                 else {
  103.                     $passV['message'] = $fml;
  104.                 }
  105.             break;
  106.             case 'banuser':
  107.                 //!banuser XatUserHere banTypeHere ReasonHere
  108.                 $values = explode(' ', $passValues['message'],3);
  109.                 //bans names can use: regular, snake, space, match, maze, code, reverse, zip, slot, dunce, naughtystep, redcard, badge, sinbin
  110.                 $passV['banName'] = trim($values[1]);
  111.                 $passV['banLength'] = 3600; //seconds (1 hour = 3600), BADGE does not require a length (so leave it blank)
  112.                 $passV['banReason'] = $values[2]; //Sinbin does not require a reason, can leave this blank
  113.                 $passV['banWho'] = $values[0]; //Xat User received from command. (EX: !banuser XATUSERHERE)
  114.                
  115.                 $passV['message'] = 'Ecmd command, was used to ban user: '.$values[0].' with: '.$values[1].', Reason: '.$values[2]; //OPTIONAL message to put, for after the ban
  116.             break;
  117.             case 'cmdconsole':
  118.                 //MAKE SURE YOU KNOW WHAT YOUR DOING, BEFORE USING THIS COMMAND CONSOLE FEATURE
  119.                 //IF YOU CODE IT WRONG, YOU MAY GIVE XAT USERS ABILITIES TO USE COMMANDS THEY SHOULDNT BE USING
  120.                 //All commands/messages will come up as if it was from: Premium (381649372)
  121.                 //Premium, will have a default level of 5. You may increase his level by doing !cmod Premium 100
  122.                
  123.                 $passV['message'] = 'Command Console Used, using say...';
  124.                 $passV['cmdConsole'] = '!say I LIKE PUPPIES -- Command Console Test';
  125.             break;
  126.         }
  127.        
  128.         foreach($passV as $key => $value) {
  129.             $passV[$key] = str_replace(';','',$value);
  130.             $passV[$key] = str_replace('|','',$value);
  131.             $passV[$key] = $passV[$key] = trim($key.'|'.$value);
  132.         }
  133.         $passV = implode(';', $passV);
  134.         return base64_encode($passV);
  135.     }
  136.    
  137.     function debugECMDCode($debug=false) {
  138.         if($debug) {
  139.             $info2 = array(
  140.                 'registeredName' => 'Actavus',
  141.                 'avatar' => 155,
  142.                 'homepage' => 'http://ARCbots.com',
  143.                 'rank' => 'main',
  144.                 'status' => 'Use ARCbots.com',
  145.                 'inChat' => 'http://xat.com/ARCbot'
  146.             );
  147.             $passValues = array(
  148.                 'message' => 'test',
  149.                 'type' => 0,
  150.                 'uid' => 367927622,
  151.                 'command' => 'info',
  152.                 'info' => $info2,
  153.                 'level' => 100,
  154.                 'chatinfo' => array(
  155.                     'roomid' => 158721424,
  156.                     'roomname' => 'ARCbot',
  157.                 ),
  158.             );
  159.             return $passValues;
  160.         }
  161.     }
  162.    
  163.    
  164.    
  165.    
  166.    
  167.    
  168.    
  169. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top