const Bot = require('slackbots');
const util = require('util');
const _ = require('lodash');

const RoundpiecesBot = function Constructor(settings) {
  this.settings = settings;
};

RoundpiecesBot.prototype.run = function () {
  RoundpiecesBot.super_.call(this, this.settings);

  this.on('start', this._onStart);
  this.on('message', this._onMessage);
};

RoundpiecesBot.prototype._onStart = function () {
  this.postMessageToUser(this.settings.adminUserName,
      'RoundpiecesBot fully activated! Type help for a full list of commands.');
};

RoundpiecesBot.prototype._onMessage = function (message) {
  if (message.type === 'message') {
    switch (message.text) {
      case 'help':
      case '?':
        this._printHelp(message.user);
        break;
      default:
        console.log(message);
        break;
    }
  }
};

RoundpiecesBot.prototype._printHelp = function (userId) {
  const userName = this._getUserNameFromUserId(userId);
  if (userName) {
    this.postMessageToUser(userName, 'Here is a list of commands:');
  }
  else {
    console.error('Unknown user id', userId);
  }
};

RoundpiecesBot.prototype._getUserNameFromUserId = function (userId) {
  const user = _.find(this.users, (user) => user.id === userId);
  return user ? user.name : null;
};

util.inherits(RoundpiecesBot, Bot);

module.exports = RoundpiecesBot;

@@ -396,24 +396,55 @@
 nction () %7B%0A
+  this.startTime = Date.now();%0A
   this.postM
@@ -529,20 +529,22 @@
 d! Type 
+%60
 help
+%60
  for a f
@@ -663,19 +663,222 @@
 message'
-) %7B
+ && message.user) %7B%0A    const userName = this._getUserNameFromUserId(message.user);%0A    if (!userName) %7B%0A      console.error('Unknown user id', message.user);%0A      console.log(message);%0A      return;%0A    %7D
 %0A    swi
@@ -957,28 +957,97 @@
 intHelp(
-message.user
+userName);%0A        break;%0A      case 'status':%0A        this._printStatus(userName
 );%0A     
@@ -1079,34 +1079,49 @@
         
-console.log(messag
+this._printUnknownCommand(userNam
 e);%0A    
@@ -1201,90 +1201,281 @@
 user
-Id
+Name
 ) %7B%0A  
-const userName = this._getUserNameFromUserId(userId);%0A  if (userName) %7B%0A  
+this.postMessageToUser(userName, %60Here is a list of commands:%0A  %E2%80%A2 %5C%60help%5C%60, %5C%60?%5C%60: Prints this help%0A  %E2%80%A2 %5C%60status%5C%60: Prints how long I've been alive%60);%0A%7D;%0A%0ARoundpiecesBot.prototype._printStatus = function (userName) %7B%0A  const uptime = Date.now() - this.startTime;%0A
   th
@@ -1509,102 +1509,276 @@
 me, 
-'Here is
+%60I have been
  a
- 
 li
-st of commands:');%0A  %7D%0A  else %7B%0A    console.error('Unknown user id', userId);%0A  %7D
+ve for *$%7Buptime%7D ms!*%60);%0A%7D;%0A%0ARoundpiecesBot.prototype._printUnknownCommand = function (userName) %7B%0A  this.postMessageToUser(userName, 'I don%5C't understand what you%5C're asking :disappointed: Type %60help%60 for a full list of commands that I understand.');
 %0A%7D;%0A

Add command to print uptime. Handle unknown commands. Use slack markdown in messages.