Jeanzinh0

tempoCommand.js

Dec 27th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. O comando é !tempo <id do jogo>
  4. Baixe esse arquivo e renomeia para tempoCommand.js
  5. Coloque o arquivo em scripts/commands
  6. Troque o STEAM_ID64 para o seu Steam ID
  7.  
  8. */
  9.  
  10. (function() {
  11.    
  12.     var STEAM_ID64 = '76561198080168165';
  13.    
  14.     function _getJSON(url){
  15.         var HttpRequest = Packages.com.gmt2001.HttpRequest;
  16.         var HashMap = Packages.java.util.HashMap;
  17.         var h = new HashMap();
  18.  
  19.         var responseData = HttpRequest.getData(HttpRequest.RequestType.GET, encodeURI(url), '', h);
  20.         return responseData.content;
  21.     }
  22.    
  23.     /*
  24.      * @event command
  25.      */
  26.     $.bind('command', function(event) {
  27.         var sender = event.getSender(),
  28.             command = event.getCommand(),
  29.             args = event.getArgs(),
  30.             target = args[0],
  31.             date;
  32.  
  33.         if (command.equalsIgnoreCase('tempo')) {
  34.             if (target === undefined)
  35.             {
  36.                 $.say($.whisperPrefix(sender) + "Modo de usar: !tempo <id do jogo na Steam>");
  37.                 return;
  38.             }
  39.            
  40.             var jsonGameInfo = JSON.parse(_getJSON("https://store.steampowered.com/api/appdetails/?appids="+target));
  41.             var getUserItem  = _getJSON("https://decapi.me/steam/hours/"+ STEAM_ID64 +"/"+target+"/readable"); 
  42.            
  43.             var finalMessage;
  44.            
  45.             if(jsonGameInfo[""+ target +""]["success"] == false)
  46.             {
  47.                 $.say("Esse jogo não existe na Steam!");
  48.                 return;
  49.             }  
  50.             else if(getUserItem.startsWith("The "))
  51.             {
  52.                 $.say("Opa! Eu não tenho o " + jsonGameInfo[""+ target +""]["data"]["name"]);
  53.                 return;
  54.             }          
  55.             else
  56.             {
  57.                 $.say("No jogo " + jsonGameInfo[""+ target +""]["data"]["name"] + " eu tenho " + getUserItem.replace('week', 'semana').replace('day', 'dia').replace('hour', 'hora').replace('minute', 'minuto'));
  58.                 return;
  59.             }            
  60.         }
  61.     });
  62.  
  63.     /*
  64.      * @event initReady
  65.      */
  66.     $.bind('initReady', function() {
  67.         $.registerChatCommand('./commands/tempoCommand.js', 'tempo', 7);
  68.     });
  69. })();
Advertisement
Add Comment
Please, Sign In to add comment