Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ARCBOT ECMD
- Update Notes:
- V1 - Initial Release
- V2 - Added ability to do bans
- V3 - Script sends data to ARCbots, as non serialized
- V4 - Updated unserialize to json_decode
- V5 - json_decode second paremeter value set to true
- V6 - Removed outdated commands & level/chatinfo added as received content
- V7 - Added debugging feature debugECMDCode($debug=false), to test web-results directly thru your website
- V8 - Added arcbot-ecmd.log -- For logging of data sent between ARCbot and ECMD client
- V9 - Added command console: cmdconsole
- *********************************************************************************************************************
- This is an example custom coded ARCbot commands page.
- 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):
- --Add the script to your bot's ecmd list: !ecmdlink http://example.com/arcbot-ecmd.php
- -Examples of how it works:
- -- !ecmd copyme test
- -- Make it an easier command while in chat -- !addalias (!ecmd copyme) (!copyme2)
- Example Received Content from ARCbot:
- -------------------------------------------------------------
- [message] => test
- [type] => 0
- [uid] => 367927622
- [command] => copyme
- [info] =>
- [registeredName] => Actavus
- [avatar] => http://img404.imageshack.us/img404/test.png
- [homepage] => http://ARCbots.com/
- [rank] => main
- [status] => afk
- [inChat] => http://xat.com/ARCbot
- 'level' => 5,
- 'chatinfo' => array(
- 'roomid' => 158721424,
- 'roomname' => 'ARCbot',
- ),
- *********************************************************************************************************************
- *Note that this isn't limited to php.
- If your able to convert this into other languages such as python, and it can respond back, you can use it.
- *********************************************************************************************************************
- Additional API methods your webserver could potentially use:
- http://arcbots.com/api-v2.html
- --Command Console (** NOTE ** : You must wait until command is processed before another one is successfully sent):
- &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=sendCmd&xatBotCommand=[URL ENCODED COMMAND/MESSAGE]
- --Restart Bot:
- &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=restart
- --Stop Bot:
- &user=[ARCbots.com Username]&apiToken=[API TOKEN]&botid=[BOTID]&cmd=stop
- *********************************************************************************************************************
- */
- // Useful Optional Utility Functions
- function getBetween($content,$start,$end){$r = explode($start, $content);if(isset($r[1])){$r = explode($end, $r[1]);return$r[0]; }return'';}
- $debugPassValues = debugECMDCode(false);
- if(!empty($debugPassValues)) {
- var_dump(explode('|', base64_decode(sendResponse($debugPassValues))));
- }
- else {
- $passValues = json_decode(base64_decode($_REQUEST['values']), true); //Received Values
- echo sendResponse($passValues); //Send your ARCbot the response
- }
- 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);
- function sendResponse($passValues) {
- $passV['message'] = 'No Message sent'; //Default message if command not found
- $passV['type'] = $passValues['type']; //0=main chat, 1=pc, 2=pm
- $passV['uid'] = $passValues['uid']; //The user's xat id to send the message to
- $passV['minrank'] = 2; //Minimum mod level to use this command -- 0~5
- $passV['arcbot'] = 'isValid'; //Required so the bot can verify this script
- $info = $passValues['info'];
- $command = strtolower($passValues['command']);
- $message = $passValues['message'];
- switch($command) {
- case 'test':
- $passV['message'] = 'test Response';
- break;
- case 'info':
- $passV['message'] = 'Your name is '.$info['registeredName'].' and ur rank is '.$info['rank'];
- break;
- case 'copyme':
- $passV['message'] = $message;
- break;
- case 'fml':
- $data = file_get_contents('http://m.fmylife.com/random');
- $fml = getBetween($data,'<p class="text">','</p>');
- if(strlen($fml) > 200) {
- $info1 = substr($fml, 0, 200);
- $info2 = substr($fml, 200, 400);
- $passV['message'] = $info1;
- }
- else {
- $passV['message'] = $fml;
- }
- break;
- case 'banuser':
- //!banuser XatUserHere banTypeHere ReasonHere
- $values = explode(' ', $passValues['message'],3);
- //bans names can use: regular, snake, space, match, maze, code, reverse, zip, slot, dunce, naughtystep, redcard, badge, sinbin
- $passV['banName'] = trim($values[1]);
- $passV['banLength'] = 3600; //seconds (1 hour = 3600), BADGE does not require a length (so leave it blank)
- $passV['banReason'] = $values[2]; //Sinbin does not require a reason, can leave this blank
- $passV['banWho'] = $values[0]; //Xat User received from command. (EX: !banuser XATUSERHERE)
- $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
- break;
- case 'cmdconsole':
- //MAKE SURE YOU KNOW WHAT YOUR DOING, BEFORE USING THIS COMMAND CONSOLE FEATURE
- //IF YOU CODE IT WRONG, YOU MAY GIVE XAT USERS ABILITIES TO USE COMMANDS THEY SHOULDNT BE USING
- //All commands/messages will come up as if it was from: Premium (381649372)
- //Premium, will have a default level of 5. You may increase his level by doing !cmod Premium 100
- $passV['message'] = 'Command Console Used, using say...';
- $passV['cmdConsole'] = '!say I LIKE PUPPIES -- Command Console Test';
- break;
- }
- foreach($passV as $key => $value) {
- $passV[$key] = str_replace(';','',$value);
- $passV[$key] = str_replace('|','',$value);
- $passV[$key] = $passV[$key] = trim($key.'|'.$value);
- }
- $passV = implode(';', $passV);
- return base64_encode($passV);
- }
- function debugECMDCode($debug=false) {
- if($debug) {
- $info2 = array(
- 'registeredName' => 'Actavus',
- 'avatar' => 155,
- 'homepage' => 'http://ARCbots.com',
- 'rank' => 'main',
- 'status' => 'Use ARCbots.com',
- 'inChat' => 'http://xat.com/ARCbot'
- );
- $passValues = array(
- 'message' => 'test',
- 'type' => 0,
- 'uid' => 367927622,
- 'command' => 'info',
- 'info' => $info2,
- 'level' => 100,
- 'chatinfo' => array(
- 'roomid' => 158721424,
- 'roomname' => 'ARCbot',
- ),
- );
- return $passValues;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment