Advertisement
Guest User

Untitled

a guest
May 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
  2. exports.run = async (client, message, args, level) => {
  3. let argu = ""
  4.     for(var i = 0; i < args.length; i++){
  5.         if(i == args.length-1) argu += args[i];
  6.         else if(args[i] === ", ") argu += args[i];
  7.         else argu += args[i] + " ";
  8.     }
  9.  
  10.     let systems = argu.split(", ")
  11.   if(!systems[0] || !systems[1]){
  12.     message.channel.send({embed: {
  13.   color: 0xff6600,
  14.   description: "Incorrect Syntax. Use ``!helpme dist`` for correct usage."}});
  15.     return;
  16.   }
  17.   const msg = await message.channel.send({embed: {
  18.   color: 0xff6600,
  19.   description: "Stand by, CMDR"}});
  20.  
  21.   function httpGet(theUrl)
  22. {
  23.     var xmlHttp = new XMLHttpRequest();
  24.     xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
  25.     xmlHttp.send( null );
  26.     return xmlHttp.responseText;
  27. }
  28. msg.edit({embed: {
  29.   color: 0xff6600,
  30.   description: "Looking at a really big map"}});
  31.  
  32.   function download(system){
  33.     let systemLink = system.replace('+','%2B').replace(' ', '+');
  34.     let uri = `https://www.edsm.net/api-v1/system?sysname=${systemLink}&coords=1`;
  35.     if(httpGet(uri).length <= 2 && systems[0] == system){
  36.       msg.edit({embed: {
  37.   color: 0xff6600,
  38.   description: "No information for" `${systems['0']}`}});
  39.     }
  40.    
  41.     if(httpGet(uri).length <= 2 && systems[1] == system){
  42.       msg.edit({embed: {
  43.   color: 0xff6600,
  44.   description: "No information for" `${systems['1']}`}});
  45.       //("No information for ``" + systems[1] + "``");
  46.     }
  47.     return JSON.parse(httpGet(uri));
  48.   }
  49.    msg.edit({embed: {
  50.   color: 0xff6600,
  51.   description: "Doing a bunch of math"}});
  52.  
  53.   var sys1 = download(systems[0]);
  54.   var sys2 = download(systems[1]);
  55.  
  56.   var distance = Math.sqrt(Math.pow((sys2["coords"]["x"] - sys1["coords"]["x"]), 2)
  57.                           + Math.pow((sys2["coords"]["y"] - sys1["coords"]["y"]), 2)
  58.                           + Math.pow((sys2["coords"]["z"] - sys1["coords"]["z"]), 2)).toFixed(2);
  59.  
  60.   msg.edit({embed: {
  61.     color: 0xff6600,
  62.     title: "Distance",
  63.     fields: [{
  64.         name: "System 1",
  65.         value: `${systems['0']}`
  66.       },
  67.       {
  68.         name: "System 2",
  69.         value: `${systems['1']}`
  70.       },
  71.       {
  72.         name: "Distance",
  73.         value: `${distance} ly`
  74.       }],
  75.     }
  76.   }
  77. );
  78. };
  79.  
  80.  
  81. exports.conf = {
  82.   enabled: true,
  83.   guildOnly: true,
  84.   aliases: [],
  85.   permLevel: "User"
  86. };
  87.  
  88. exports.help = {
  89.   name: "dist",
  90.   category: "Custom Commands",
  91.   description: "Gives the Distance between two systems in the EDSM database.",
  92.   usage: "dist <system1>, <system2>"
  93. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement