'use strict';
exports.info = {
  name: 'mc',
  desc: 'Posts stats and online user list of a Nodecraft MC server',
  usage: 'mc',
};

const nodecraft = require('nodecraft-api');
const config = require('../../config');
const utils = require('../utilities');
const logger = require('winston');

// Set Nodecraft API credentials
const nodecraftAPI = nodecraft(config.nodecraft.username, config.nodecraft.api_key);

exports.run = (discord, msg) => {
  // Get server stats
  nodecraftAPI.services.stats(config.nodecraft.server_id, (err, results) => {
    if (err) {
      msg.channel.sendMessage('There was an error getting data for the subscriber server.');
    } else {
      logger.debug(JSON.stringify(results));
      const status = utils.capitalize(results.stats.status);
      let str = `\`\`\`Minecraft Subscriber Server Statistics\`\`\`Status: **${status}**`;
      const uptime = results.stats.time;
      const players = results.stats.players;
      if (status === 'Online') {
        str += ` - Uptime: **${uptime}** - Players Online: **${players.length}**`;
        const names = players
          .map(x => {
            return { name: x.username, modified: x.username.toLowerCase() };
          }).sort((a, b) => {
            if (a.modified < b.modified) {
              return -1;
            } else if (a.modified > b.modified) {
              return 1;
            } else {
              return 0;
            }
          });
        str += '\n\n';
        names.forEach(n => {
          str += n.name.replace(/_/gm, '\\_');
          if (names.indexOf(n) < names.length - 1) {
            str += ' | ';
          }
        });
      }
      msg.channel.sendMessage(str);
    }
  });
};

@@ -122,16 +122,31 @@
 : 'mc',%0A
+  aliases: %5B%5D,%0A
 %7D;%0A%0Acons
@@ -300,16 +300,34 @@
 ton');%0A%0A
+let nodecraftAPI;%0A
 // Set N
@@ -351,21 +351,92 @@
 entials%0A
-const
+if (config.nodecraft.username !== '' && config.nodecraft.api_key !== '') %7B%0A 
  nodecra
@@ -506,16 +506,18 @@
 pi_key);
+%0A%7D
 %0A%0Aexport
@@ -529,15 +529,14 @@
  = (
-discord
+client
 , ms
@@ -543,16 +543,108 @@
 g) =%3E %7B%0A
+  // Exit if we never connected to the nodecraft API%0A  if (!nodecraftAPI) %7B%0A    return;%0A  %7D%0A
   // Get
@@ -843,35 +843,40 @@
 ver.');%0A    
-%7D else %7B
+  return;
 %0A  
+  %7D%0A
     logger.d
@@ -906,26 +906,24 @@
 ults));%0A    
- 
- 
 const status
@@ -965,18 +965,16 @@
 tatus);%0A
-  
     let 
@@ -1054,26 +1054,24 @@
 us%7D**%60;%0A    
- 
- 
 const uptime
@@ -1093,18 +1093,16 @@
 s.time;%0A
-  
     cons
@@ -1136,26 +1136,24 @@
 layers;%0A    
- 
- 
 if (status =
@@ -1163,26 +1163,24 @@
 'Online') %7B%0A
-  
       str +=
@@ -1254,18 +1254,16 @@
 ;%0A      
- 
- 
 const na
@@ -1284,18 +1284,16 @@
         
-  
 .map(x =
@@ -1292,26 +1292,24 @@
 .map(x =%3E %7B%0A
-  
           re
@@ -1379,18 +1379,16 @@
         
-  
 %7D).sort(
@@ -1405,26 +1405,24 @@
 %7B%0A          
- 
- 
 if (a.modifi
@@ -1448,26 +1448,24 @@
             
-  
 return -1;%0A 
@@ -1469,26 +1469,24 @@
 ;%0A          
- 
- 
 %7D else if (a
@@ -1519,26 +1519,24 @@
             
-  
 return 1;%0A  
@@ -1539,26 +1539,24 @@
 ;%0A          
- 
- 
 %7D else %7B%0A   
@@ -1552,18 +1552,16 @@
  else %7B%0A
-  
         
@@ -1580,30 +1580,26 @@
 ;%0A          
-  %7D%0A  
+%7D%0A
         %7D);%0A
@@ -1600,26 +1600,24 @@
   %7D);%0A      
- 
- 
 str += '%5Cn%5Cn
@@ -1619,18 +1619,16 @@
 '%5Cn%5Cn';%0A
-  
       na
@@ -1650,26 +1650,24 @@
 %3E %7B%0A        
- 
- 
 str += n.nam
@@ -1687,26 +1687,24 @@
 gm, '%5C%5C_');%0A
-  
         if (
@@ -1748,26 +1748,24 @@
 %7B%0A          
- 
- 
 str += ' %7C '
@@ -1770,34 +1770,32 @@
  ';%0A        
-  
 %7D%0A      
   %7D);%0A      
@@ -1782,26 +1782,24 @@
 %7D%0A      
- 
- 
 %7D);%0A    
   %7D%0A    
@@ -1790,26 +1790,22 @@
 %7D);%0A    
-  
 %7D%0A    
- 
- 
 msg.chan
@@ -1826,22 +1826,16 @@
 e(str);%0A
-    %7D%0A
   %7D);%0A%7D;

Handle not giving Nodecraft credentials for MC command