Advertisement
xgerhard

XgDestinyCommand.js - Phantombot

Apr 5th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.     /**
  3.      * Add !destiny command through chat:
  4.      * !addcom !destiny (customapi https://2g.be/twitch/destinyv2.php?query=(echo)&user=(sender)&channel=(channelname)&defaultconsole=xbox&bot=phantombot)
  5.      *
  6.      * Add !destiny command as script:
  7.      */
  8.     $.bind('command', function(event) {
  9.         var defaultConsole = 'xbox'; // Change this to xbox or ps
  10.         var command = event.getCommand();
  11.         var args = event.getArgs();
  12.  
  13.         if (command.equalsIgnoreCase('destiny')) {
  14.  
  15.             try {
  16.                 var errorCode = 0;
  17.                 var HttpRequest = Packages.com.gmt2001.HttpRequest;
  18.                 var HashMap = Packages.java.util.HashMap;
  19.                 var h = new HashMap(1);
  20.                 var r = HttpRequest.getData(HttpRequest.RequestType.GET, 'https://2g.be/twitch/destinyv2.php?query=' + args.join("%20") + '&user=' + event.getSender() + '&channel=' + $.channelName + '&defaultconsole=' + defaultConsole + '&bot=phantombot', '', h);
  21.                 if (r.success) {
  22.                     $.say(r.content);
  23.                 } else {
  24.                     if (r.httpCode == 0) {
  25.                         errorCode = 'http 0';
  26.                     } else {
  27.                         errorCode = 'http ' + r.httpCode;
  28.                     }
  29.                 }
  30.             } catch (e) {
  31.                 errorCode = 2;
  32.             }
  33.             if (errorCode != 0)  $.say('Failed to connect to the server, please contact Xgerhard on twitch or tweet at @gerhardoh, error code: ' + errorCode);
  34.         }
  35.     });
  36.  
  37.     /**
  38.      * @event initReady
  39.      */
  40.     $.bind('initReady', function() {
  41.         if ($.bot.isModuleEnabled('./commands/XgDestinyCommand.js')) {
  42.             $.registerChatCommand('./commands/XgDestinyCommand.js', 'destiny');
  43.         }  
  44.     });
  45. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement