Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
- exports.run = async (client, message, args, level) => {
- let argu = ""
- for(var i = 0; i < args.length; i++){
- if(i == args.length-1) argu += args[i];
- else if(args[i] === ", ") argu += args[i];
- else argu += args[i] + " ";
- }
- let systems = argu.split(", ")
- if(!systems[0] || !systems[1]){
- message.channel.send({embed: {
- color: 0xff6600,
- description: "Incorrect Syntax. Use ``!helpme dist`` for correct usage."}});
- return;
- }
- const msg = await message.channel.send({embed: {
- color: 0xff6600,
- description: "Stand by, CMDR"}});
- function httpGet(theUrl)
- {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
- xmlHttp.send( null );
- return xmlHttp.responseText;
- }
- msg.edit({embed: {
- color: 0xff6600,
- description: "Looking at a really big map"}});
- function download(system){
- let systemLink = system.replace('+','%2B').replace(' ', '+');
- let uri = `https://www.edsm.net/api-v1/system?sysname=${systemLink}&coords=1`;
- if(httpGet(uri).length <= 2 && systems[0] == system){
- msg.edit({embed: {
- color: 0xff6600,
- description: "No information for" `${systems['0']}`}});
- }
- if(httpGet(uri).length <= 2 && systems[1] == system){
- msg.edit({embed: {
- color: 0xff6600,
- description: "No information for" `${systems['1']}`}});
- //("No information for ``" + systems[1] + "``");
- }
- return JSON.parse(httpGet(uri));
- }
- msg.edit({embed: {
- color: 0xff6600,
- description: "Doing a bunch of math"}});
- var sys1 = download(systems[0]);
- var sys2 = download(systems[1]);
- var distance = Math.sqrt(Math.pow((sys2["coords"]["x"] - sys1["coords"]["x"]), 2)
- + Math.pow((sys2["coords"]["y"] - sys1["coords"]["y"]), 2)
- + Math.pow((sys2["coords"]["z"] - sys1["coords"]["z"]), 2)).toFixed(2);
- msg.edit({embed: {
- color: 0xff6600,
- title: "Distance",
- fields: [{
- name: "System 1",
- value: `${systems['0']}`
- },
- {
- name: "System 2",
- value: `${systems['1']}`
- },
- {
- name: "Distance",
- value: `${distance} ly`
- }],
- }
- }
- );
- };
- exports.conf = {
- enabled: true,
- guildOnly: true,
- aliases: [],
- permLevel: "User"
- };
- exports.help = {
- name: "dist",
- category: "Custom Commands",
- description: "Gives the Distance between two systems in the EDSM database.",
- usage: "dist <system1>, <system2>"
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement