const discord = require('discord.js');
const https = require('https');
const http = require('http');
const config = require('../inc/config.js');
const lang = require('../inc/lang.js');
const logger = require('../basic/logger.js');

function pushMojangStatus(message, callback) {
    let options = {
        host: 'api.kuvus.pl',
        port: 80,
        path: '/?t=status&s=mojang'
    };
    http.get(options).on('response', function (response) {
        let reply = '';
        response.on('data', function (chunk) {
            reply += chunk;
        });
        response.on('end', function () {
            const embed = new discord.RichEmbed()
                .setTitle(config.settings.bot_name)
                .setColor(config.settings.color.default)
                .setFooter(config.settings.footer)
                .setThumbnail(config.settings.bot_thumbnail)
                .setURL(config.settings.website)
                .addField(lang.pl_PL.commands.status.mojang_status + ': \n', reply)
            message.channel.sendEmbed(embed, {disableEveryone: true});
            callback();
        });
    });
}

function pushServerStatus(message, ip, callback) {
    let options = {
        host: 'api.skript.pl',
        port: 443,
        path: '/server/' + encodeURIComponent(ip) + '/'
    };

    https.get(options).on('response', function (response) {
        let reply = '';
        response.on('data', function (chunk) {
            reply += chunk;
        });
        response.on('end', function () {
            let json = JSON.parse(reply);
            if (json.online) {
                const embed = new discord.RichEmbed()
                    .setTitle(config.settings.bot_name)
                    .setColor(config.settings.color.default)
                    .setFooter(config.settings.footer)
                    .setThumbnail(config.settings.bot_thumbnail)
                    .setURL(config.settings.website)
                    .addField('' + lang.pl_PL.commands.status.status + ':', json.address)
                    .addField('➭ ' + lang.pl_PL.commands.status.status + ': ', lang.pl_PL.commands.status.on)
                    .addField('➭ ' + lang.pl_PL.commands.status.ping + ': ', parseInt(json.latency) + ' ms')
                    .addField('➭ ' + lang.pl_PL.commands.status.players + ': ', json.players.online + '/' + json.players.max)
                    .addField('➭ ' + lang.pl_PL.commands.status.version + ': ', json.version.name)
                    .addField('➭ ' + lang.pl_PL.commands.status.motd + ': ', json.description)
                message.channel.sendEmbed(embed, {disableEveryone: true});
            } else {
                message.reply(lang.pl_PL.commands.status.server_offline);
            }
            callback();
        });
    });
}

var status = {};

status.get = function (message) {
    try {
        message.channel.startTyping();
        let args = message.content.split(" ").slice(1);
        if (args[0] != undefined) {
            let arg = args[0].toLowerCase();
            switch (arg) {
                case 'mojang':
                    pushMojangStatus(message, function () {
                        return message.channel.stopTyping(true);
                    });
                    break;
                default:
                    pushServerStatus(message, arg, function () {
                        return message.channel.stopTyping(true);
                    });
            }
        } else {
            message.channel.sendMessage(`<@${message.author.id}> ⚠️ **` + lang.pl_PL.valid_usage + `**: \`.status <mojang/ip>\``);
        }
    } catch (e) {
        message.reply("error!");
        logger.log(e);
    } finally {
        message.channel.stopTyping(true);
    }
}

module.exports = status;
@@ -68,38 +68,8 @@
 ');%0A
-const http = require('http');%0A
 cons
@@ -234,32 +234,46 @@
 ge, callback) %7B%0A
+    try %7B%0A    
     let options 
@@ -284,26 +284,30 @@
         
+  
+  
 host: '
-api
+bot
 .kuvus.p
@@ -322,18 +322,27 @@
     
+    
 port: 
-80,%0A
+443,%0A    
     
@@ -357,43 +357,49 @@
 : '/
-?t=status&s=mojang'%0A
+api/mojang.php'%0A   
     
+ 
 %7D;%0A
+%0A 
     
+   
 http
+s
 .get
@@ -437,32 +437,36 @@
 on (response) %7B%0A
+    
         let repl
@@ -473,32 +473,36 @@
 y = '';%0A        
+    
 response.on('dat
@@ -516,32 +516,36 @@
 ction (chunk) %7B%0A
+    
             repl
@@ -556,36 +556,44 @@
  chunk;%0A        
-%7D);%0A
+    %7D);%0A    
         response
@@ -621,32 +621,36 @@
 ) %7B%0A            
+    
 const embed = ne
@@ -679,32 +679,36 @@
                 
+   
+ 
 .setTitle(config
@@ -719,32 +719,36 @@
 tings.bot_name)%0A
+    
                 
@@ -796,32 +796,36 @@
                 
+   
+ 
 .setFooter(confi
@@ -835,32 +835,36 @@
 ettings.footer)%0A
+    
                 
@@ -916,32 +916,36 @@
                 
+  
+  
 .setURL(config.s
@@ -953,32 +953,36 @@
 ttings.website)%0A
+    
                 
@@ -1053,32 +1053,36 @@
 ly)%0A            
+    
 message.channel.
@@ -1089,47 +1089,21 @@
 send
-Embed
 (embed
-, %7BdisableEveryone: true%7D);%0A
+);%0A    
     
@@ -1126,32 +1126,36 @@
 ();%0A        
+  
+  
 %7D);%0A    
 %7D);%0A%7D%0A%0Afunct
@@ -1142,20 +1142,108 @@
 %7D);%0A    
+  
+  
 %7D);%0A
+    %7D%0A    catch (e) %7B%0A        message.reply(%22error!%22);%0A        logger.log(e);%0A    %7D%0A
 %7D%0A%0Afunct
@@ -2720,44 +2720,14 @@
 send
-Embed
 (embed
-, %7BdisableEveryone: true%7D
 );%0A 
@@ -3599,15 +3599,8 @@
 send
-Message
 (%60%3C@
@@ -3862,8 +3862,9 @@
  status;
+%0A

Update .status command