MrMcShroom

Untitled

Oct 26th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('request');
  2. const hypixelfunctions = require('../hypixelfunctions.js');
  3. const statistics = require('../statistics.js');
  4. const config = require('../config.json');
  5. const MojangAPI = require('mojang-api');
  6.  
  7. exports.run = (client, message, args, Discord,) => {
  8.     let game = args[0];
  9.     const username = args[1];
  10.     var date = new Date();
  11.     let uuid = hypixelfunctions.validateUUID(username);
  12.     if (!username || !game) {
  13.         message.channel.send("Try it like this! `!hypixel [gametype] [username]` :)");
  14.     } else {
  15.         game = game.toLowerCase();
  16.         if (!uuid) {
  17.             MojangAPI.uuidAt(username, date, (err, res) => {
  18.                 if (err) {
  19.                     console.log(err);
  20.                     message.channel.send("There was an error, or that account/UIID doesn't exist!");
  21.                 } else {
  22.                     uuid = res.id;
  23.                     console.log(uuid + " Whut");
  24.                 }
  25.             });
  26.         }
  27.             console.log(uuid);
  28.             request.get("https://api.hypixel.net/player?key=" + config.hypixelkey + "&uuid=" + uuid, function(e, res, data) {
  29.                 console.log(data);
  30.                 console.log("https://api.hypixel.net/player?key=" + config.hypixelkey + "&uuid=" + uuid)
  31.                 if(!e) {
  32.                     if (res && res.statusCode === 200) {
  33.                         var data = JSON.parse(data);
  34.                         if(!data) {
  35.                             message.channel.send("This user has no stats!");
  36.                         } else {
  37.                             switch (game) {
  38.                                 case "bedwars":
  39.                                 case "bw":
  40.                                 try {
  41.                                     statistics.bedwars(data,message,uuid);
  42.                                 }
  43.                                 catch(err) {
  44.                                     message.channel.send("This player has no bedwars Stats!");
  45.                                     console.log(err)
  46.                                 }
  47.                             }
  48.                         }
  49.                     } else {
  50.                         message.channel.send("There was some sort of error. Sorry!")
  51.                     }
  52.                 } else {
  53.                     console.error("Error: " + e.toString());
  54.                     message.channel.send("There was some sort of error. Sorry!")
  55.                 }
  56.             });
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment