text: /**
   *Copyright 2014 Yemasthui
   *Modifications (including forks) of the code to fit personal needs are allowed only for personal use and should refer back to the original source.
   *This software is not for profit, any extension, or unauthorised person providing this software is not authorised to be in a position of any monetary gain from this use of this software. Any and all money gained under the use of the software (which includes donations) must be passed on to the original author.
   */
  (function () {
  
      var kill = function () {
          clearInterval(basicBot.room.autodisableInterval);
          clearInterval(basicBot.room.afkInterval);
          basicBot.status = false;
      };
  
      var storeToStorage = function () {
          localStorage.setItem("basicBotsettings", JSON.stringify(basicBot.settings));
          localStorage.setItem("basicBotRoom", JSON.stringify(basicBot.room));
          var basicBotStorageInfo = {
              time: Date.now(),
              stored: true,
              version: basicBot.version
          };
          localStorage.setItem("basicBotStorageInfo", JSON.stringify(basicBotStorageInfo));
  
      };
  
      var subChat = function(chat, obj){
          if(typeof chat === "undefined"){
              API.chatLog("There is a chat text missing.");
              console.log("There is a chat text missing.");
              return "[Error] No text message found.";
          }
          var lit = '%%';
          for(var prop in obj){
              chat = chat.replace(lit + prop.toUpperCase() + lit, obj[prop]);
          }
          return chat;
      };
  
      var loadChat = function(cb){
          if(!cb) cb = function(){};
          $.get("https://rawgit.com/Club-RevolutionZ/Bar/master/BareTenderDictionary.json", function(json){
              var link = basicBot.chatLink;
              if(json !== null && typeof json !== "undefined"){
                  langIndex = json;
                  link = langIndex[basicBot.settings.language.toLowerCase()];
                  if(basicBot.settings.chatLink !== basicBot.chatLink){
                      link = basicBot.settings.chatLink;
                  }
                  else{
                      if(typeof link === "undefined"){
                          link = basicBot.chatLink;
                      }
                  }
                  $.get(link, function (json) {
                      if (json !== null && typeof json !== "undefined") {
                          if(typeof json === "string") json = JSON.parse(json);
                          basicBot.chat = json;
                          cb();
                      }
                  });
              }
              else{
                  $.get(basicBot.chatLink, function (json) {
                      if (json !== null && typeof json !== "undefined") {
                          if(typeof json === "string") json = JSON.parse(json);
                          basicBot.chat = json;
                          cb();
                      }
                  });
              }
          });
      };
  
      var retrieveSettings = function(){
          var settings = JSON.parse(localStorage.getItem("basicBotsettings"));
          if(settings !== null){
              for (var prop in settings) {
                  basicBot.settings[prop] = settings[prop];
              }
          }
      };
  
      var retrieveFromStorage = function () {
          var info = localStorage.getItem("basicBotStorageInfo");
          if (info === null) API.chatLog(basicBot.chat.nodatafound);
          else {
              var settings = JSON.parse(localStorage.getItem("basicBotsettings"));
              var room = JSON.parse(localStorage.getItem("basicBotRoom"));
              var elapsed = Date.now() - JSON.parse(info).time;
              if ((elapsed < 1 * 60 * 60 * 1000)) {
                  API.chatLog(basicBot.chat.retrievingdata);
                  for (var prop in settings) {
                      basicBot.settings[prop] = settings[prop];
                  }
                  basicBot.room.users = room.users;
                  basicBot.room.afkList = room.afkList;
                  basicBot.room.historyList = room.historyList;
                  basicBot.room.mutedUsers = room.mutedUsers;
                  basicBot.room.autoskip = room.autoskip;
                  basicBot.room.roomstats = room.roomstats;
                  basicBot.room.messages = room.messages;
                  basicBot.room.queue = room.queue;
                  basicBot.room.newBlacklisted = room.newBlacklisted;
                  API.chatLog(basicBot.chat.datarestored);
              }
          }
          var json_sett = null;
          var roominfo = document.getElementById("room-info");
          info = roominfo.textContent;
          var ref_bot = "@basicBot=";
          var ind_ref = info.indexOf(ref_bot);
          if (ind_ref > 0) {
              var link = info.substring(ind_ref + ref_bot.length, info.length);
              var ind_space = null;
              if (link.indexOf(" ") < link.indexOf("\n")) ind_space = link.indexOf(" ");
              else ind_space = link.indexOf("\n");
              link = link.substring(0, ind_space);
              $.get(link, function (json) {
                  if (json !== null && typeof json !== "undefined") {
                      json_sett = JSON.parse(json);
                      for (var prop in json_sett) {
                          basicBot.settings[prop] = json_sett[prop];
                      }
                  }
              });
          }
  
      };
      String.prototype.splitBetween = function(a, b){
          var self = this;
          self = this.split(a);
          for(var i = 0; i < self.length; i++){
              self[i] = self[i].split(b);
          }
          var arr = [];
          for(var i = 0; i < self.length; i++){
              if(Array.isArray(self[i])){
                  for(var j = 0; j < self[i].length; j++){
                      arr.push(self[i][j]);
                  }
              }
              else arr.push(self[i]);
          }
          return arr;
      };
  
      var linkFixer = function(msg){
          var parts = msg.splitBetween('<a href="', '<\/a>');
          for(var i = 1; i < parts.length; i = i+2){
              var link = parts[i].split('"')[0];
              parts[i] = link;
          }
          var m = '';
          for(var i = 0; i < parts.length; i++){
              m += parts[i];
          }
          return m;
      };
  
      var botCreator = "MEH";
      var botCreatorIDs = ["100210101012"];
  
      var basicBot = {
          version: "1.8",// 
          status: true, //false
          name: "BarTender",
          loggedInID: null,
          scriptLink: "https://rawgit.com/Club-RevolutionZ/Bar/master/BareTender.js",
          cmdLink: "https://github.com/Club-RevolutionZ/Bar/blob/master/BartenderJobScope.me",
          chatLink: "https://rawgit.com/Yemasthui/basicBot/master/lang/en.json",
          chat: null,
          loadChat: loadChat,
          retrieveSettings: retrieveSettings,
          settings: {
              botName: "BarTender",
              language: "english",
              chatLink: "https://rawgit.com/Yemasthui/basicBot/master/lang/en.json",
              maximumAfk: 120,
              afkRemoval: true,
              maximumDc: 60,
              bouncerPlus: true,
              lockdownEnabled: false,
              lockGuard: false,
              maximumLocktime: 10,
              cycleGuard: true,
              maximumCycletime: 7,
              timeGuard: true,
              maximumSongLength: 7,
              autodisable: true,
              commandCooldown: 30,
              usercommandsEnabled: true,
              lockskipPosition: 3,
              lockskipReasons: [
                  ["theme", "This song does not fit the room theme.Y "],
                  ["op", "This song is on the OP list.y "],
                  ["history", "This song is in the history.y "],
                  ["mix", "You played a mix, which is against the rules. y"],
                  ["sound", "The song you played had bad sound quality or no sound. y"],
                  ["nsfw", "The song you contained was NSFW (image or sound). y"],
                  ["unavailable", "The song you played was not available for some users. y"]
              ],
              afkpositionCheck: 15,
              afkRankCheck: "ambassador",
              motdEnabled: true, 
              motdInterval: 5,
              motd: "If you do enjoy your stay with Club RevolutionZ, do checkin with us on FaceBook. !order !fb !theme !site What would you like to see in our next event? http://tinyurl.com/ClubRevZFeedback",
              filterChat: true,
              etaRestriction: false,
              welcome: true,
              opLink: null,
              orderLink: " ",
              hiLink: "  ",
              byeLink: " ",
              brbLink: "  ",
              afkLink: "  ",
              rulesLink:" :hammer: http://tinyurl.com/ClubRevolutionZRules",
              themeLink: " :tada: http://tinyurl.com/ClubRevolutionZCurrentEvent",
              fbLink: "https://www.facebook.com/ClubRevolutionZ",
              youtubeLink: null,
              website: " :house: http://tinyurl.com/ClubRevolutionZ",
              intervalMessages: "INT MSG!", //unknown, broken
              messageInterval: null,
              songstats: false, 
              commandLiteral: "!",
              blacklists: {
                  NSFW: "https://rawgit.com/Yemasthui/basicBot-customization/master/blacklists/ExampleNSFWlist.json",
                  OP: "https://rawgit.com/Yemasthui/basicBot-customization/master/blacklists/ExampleOPlist.json"
              }
          },
          room: {
              users: [], //chk this
              afkList: [],
              mutedUsers: [],
              bannedUsers: [],
              skippable: true,
              usercommand: true,
              allcommand: true,
              afkInterval: null,
              autoskip: true, //false
              autoskipTimer: null, //null
              autodisableInterval: null,
              autodisableFunc: function () {
                  if (basicBot.status && basicBot.settings.autodisable) {
                      API.sendChat('!afkdisable');
                      API.sendChat('!joindisable');
                  }
              },
              queueing: 0,
              queueable: true,
              currentDJID: null,
              historyList: [],
              cycleTimer: setTimeout(function () {
              }, 1),
              roomstats: {
                  accountName: null,
                  totalWoots: 0,
                  totalCurates: 0,
                  totalMehs: 0,
                  launchTime: null,
                  songCount: 0,
                  chatmessages: 0
              },
              messages: {
                  from: [],
                  to: [],
                  message: []
              },
              queue: {
                  id: [],
                  position: []
              },
              blacklists: {
              },
              newBlacklisted: [],
              newBlacklistedSongFunction: null,
              roulette: {
                  rouletteStatus: false,
                  participants: [],
                  countdown: null,
                  startRoulette: function () {
                      basicBot.room.roulette.rouletteStatus = true;
                      basicBot.room.roulette.countdown = setTimeout(function () {
                          basicBot.room.roulette.endRoulette();
                      }, 60 * 1000);
                      API.sendChat(basicBot.chat.isopen);
                  },
                  endRoulette: function () {
                      basicBot.room.roulette.rouletteStatus = false;
                      var ind = Math.floor(Math.random() * basicBot.room.roulette.participants.length);
                      var winner = basicBot.room.roulette.participants[ind];
                      basicBot.room.roulette.participants = [];
                      var pos = Math.floor((Math.random() * API.getWaitList().length) + 1);
                      var user = basicBot.userUtilities.lookupUser(winner);
                      var name = user.username;
                      API.sendChat(subChat(basicBot.chat.winnerpicked, {name: name, position: pos}));
                      setTimeout(function (winner, pos) {
                          basicBot.userUtilities.moveUser(winner, pos, false);
                      }, 1 * 1000, winner, pos);
                  }
              }
          },
          User: function (id, name) {
              this.id = id;
              this.username = name;
              this.jointime = Date.now();
              this.lastActivity = Date.now();
              this.votes = {
                  woot: 0,
                  meh: 0,
                  curate: 0
              };
              this.lastEta = null;
              this.afkWarningCount = 0;
              this.afkCountdown = null;
              this.inRoom = true;
              this.isMuted = false;
              this.lastDC = {
                  time: null,
                  position: null,
                  songCount: 0
              };
              this.lastKnownPosition = null;
          },
          userUtilities: {
              getJointime: function (user) {
                  return user.jointime;
              },
              getUser: function (user) {
                  return API.getUser(user.id);
              },
              updatePosition: function (user, newPos) {
                  user.lastKnownPosition = newPos;
              },
              updateDC: function (user) {
                  user.lastDC.time = Date.now();
                  user.lastDC.position = user.lastKnownPosition;
                  user.lastDC.songCount = basicBot.room.roomstats.songCount;
              },
              setLastActivity: function (user) {
                  user.lastActivity = Date.now();
                  user.afkWarningCount = 0;
                  clearTimeout(user.afkCountdown);
              },
              getLastActivity: function (user) {
                  return user.lastActivity;
              },
              getWarningCount: function (user) {
                  return user.afkWarningCount;
              },
              setWarningCount: function (user, value) {
                  user.afkWarningCount = value;
              },
              lookupUser: function (id) {
                  for (var i = 0; i < basicBot.room.users.length; i++) {
                      if (basicBot.room.users[i].id === id) {
                          return basicBot.room.users[i];
                      }
                  }
                  return false;
              },
              lookupUserName: function (name) {
                  for (var i = 0; i < basicBot.room.users.length; i++) {
                      var match = basicBot.room.users[i].username.trim() == name.trim();
                      if (match) {
                          return basicBot.room.users[i];
                      }
                  }
                  return false;
              },
              voteRatio: function (id) {
                  var user = basicBot.userUtilities.lookupUser(id);
                  var votes = user.votes;
                  if (votes.meh === 0) votes.ratio = 1;
                  else votes.ratio = (votes.woot / votes.meh).toFixed(2);
                  return votes;
  
              },
              getPermission: function (obj) { //1 requests
                  var u;
                  if (typeof obj === "object") u = obj;
                  else u = API.getUser(obj);
                  if(botCreatorIDs.indexOf(u.id) > -1) return 10;
                  if (u.gRole < 2) return u.role;
                  else {
                      switch (u.gRole) {
                          case 2:
                              return 7;
                          case 3:
                              return 8;
                          case 4:
                              return 9;
                          case 5:
                              return 10;
                      }
                  }
                  return 0;
              },
              moveUser: function (id, pos, priority) {
                  var user = basicBot.userUtilities.lookupUser(id);
                  var wlist = API.getWaitList();
                  if (API.getWaitListPosition(id) === -1) {
                      if (wlist.length < 50) {
                          API.moderateAddDJ(id);
                          if (pos !== 0) setTimeout(function (id, pos) {
                              API.moderateMoveDJ(id, pos);
                          }, 1250, id, pos);
                      }
                      else {
                          var alreadyQueued = -1;
                          for (var i = 0; i < basicBot.room.queue.id.length; i++) {
                              if (basicBot.room.queue.id[i] === id) alreadyQueued = i;
                          }
                          if (alreadyQueued !== -1) {
                              basicBot.room.queue.position[alreadyQueued] = pos;
                              return API.sendChat(subChat(basicBot.chat.alreadyadding, {position: basicBot.room.queue.position[alreadyQueued]}));
                          }
                          basicBot.roomUtilities.booth.lockBooth();
                          if (priority) {
                              basicBot.room.queue.id.unshift(id);
                              basicBot.room.queue.position.unshift(pos);
                          }
                          else {
                              basicBot.room.queue.id.push(id);
                              basicBot.room.queue.position.push(pos);
                          }
                          var name = user.username;
                          return API.sendChat(subChat(basicBot.chat.adding, {name: name, position: basicBot.room.queue.position.length}));
                      }
                  }
                  else API.moderateMoveDJ(id, pos);
              },
              dclookup: function (id) {
                  var user = basicBot.userUtilities.lookupUser(id);
                  if (typeof user === 'boolean') return basicBot.chat.usernotfound;
                  var name = user.username;
                  if (user.lastDC.time === null) return subChat(basicBot.chat.notdisconnected, {name: name});
                  var dc = user.lastDC.time;
                  var pos = user.lastDC.position;
                  if (pos === null) return basicBot.chat.noposition;
                  var timeDc = Date.now() - dc;
                  var validDC = false;
                  if (basicBot.settings.maximumDc * 60 * 1000 > timeDc) {
                      validDC = true;
                  }
                  var time = basicBot.roomUtilities.msToStr(timeDc);
                  if (!validDC) return (subChat(basicBot.chat.toolongago, {name: basicBot.userUtilities.getUser(user).username, time: time}));
                  var songsPassed = basicBot.room.roomstats.songCount - user.lastDC.songCount;
                  var afksRemoved = 0;
                  var afkList = basicBot.room.afkList;
                  for (var i = 0; i < afkList.length; i++) {
                      var timeAfk = afkList[i][1];
                      var posAfk = afkList[i][2];
                      if (dc < timeAfk && posAfk < pos) {
                          afksRemoved++;
                      }
                  }
                  var newPosition = user.lastDC.position - songsPassed - afksRemoved;
                  if (newPosition <= 0) newPosition = 1;
                  var msg = subChat(basicBot.chat.valid, {name: basicBot.userUtilities.getUser(user).username, time: time, position: newPosition});
                  basicBot.userUtilities.moveUser(user.id, newPosition, true);
                  return msg;
              }
          },
  
          roomUtilities: {
              rankToNumber: function (rankString) {
                  var rankInt = null;
                  switch (rankString) {
                      case "admin":
                          rankInt = 10;
                          break;
                      case "ambassador":
                          rankInt = 7;
                          break;
                      case "host":
                          rankInt = 10; //5
                          break;
                      case "cohost":
                          rankInt = 4;
                          break;
                      case "manager":
                          rankInt = 3;
                          break;
                      case "bouncer":
                          rankInt = 2;
                          break;
                      case "residentdj":
                          rankInt = 1;
                          break;
                      case "user":
                          rankInt = 0;
                          break;
                  }
                  return rankInt;
              },
              msToStr: function (msTime) {
                  var ms, msg, timeAway;
                  msg = '';
                  timeAway = {
                      'days': 0,
                      'hours': 0,
                      'minutes': 0,
                      'seconds': 0
                  };
                  ms = {
                      'day': 24 * 60 * 60 * 1000,
                      'hour': 60 * 60 * 1000,
                      'minute': 60 * 1000,
                      'second': 1000
                  };
                  if (msTime > ms.day) {
                      timeAway.days = Math.floor(msTime / ms.day);
                      msTime = msTime % ms.day;
                  }
                  if (msTime > ms.hour) {
                      timeAway.hours = Math.floor(msTime / ms.hour);
                      msTime = msTime % ms.hour;
                  }
                  if (msTime > ms.minute) {
                      timeAway.minutes = Math.floor(msTime / ms.minute);
                      msTime = msTime % ms.minute;
                  }
                  if (msTime > ms.second) {
                      timeAway.seconds = Math.floor(msTime / ms.second);
                  }
                  if (timeAway.days !== 0) {
                      msg += timeAway.days.toString() + 'd';
                  }
                  if (timeAway.hours !== 0) {
                      msg += timeAway.hours.toString() + 'h';
                  }
                  if (timeAway.minutes !== 0) {
                      msg += timeAway.minutes.toString() + 'm';
                  }
                  if (timeAway.minutes < 1 && timeAway.hours < 1 && timeAway.days < 1) {
                      msg += timeAway.seconds.toString() + 's';
                  }
                  if (msg !== '') {
                      return msg;
                  } else {
                      return false;
                  }
              },
              booth: {
                  lockTimer: setTimeout(function () {
                  }, 1000),
                  locked: false,
                  lockBooth: function () {
                      API.moderateLockWaitList(!basicBot.roomUtilities.booth.locked);
                      basicBot.roomUtilities.booth.locked = false;
                      if (basicBot.settings.lockGuard) {
                          basicBot.roomUtilities.booth.lockTimer = setTimeout(function () {
                              API.moderateLockWaitList(basicBot.roomUtilities.booth.locked);
                          }, basicBot.settings.maximumLocktime * 60 * 1000);
                      }
                  },
                  unlockBooth: function () {
                      API.moderateLockWaitList(basicBot.roomUtilities.booth.locked);
                      clearTimeout(basicBot.roomUtilities.booth.lockTimer);
                  }
              },
              afkCheck: function () {
                  if (!basicBot.status || !basicBot.settings.afkRemoval) return void (0);
                  var rank = basicBot.roomUtilities.rankToNumber(basicBot.settings.afkRankCheck);
                  var djlist = API.getWaitList();
                  var lastPos = Math.min(djlist.length, basicBot.settings.afkpositionCheck);
                  if (lastPos - 1 > djlist.length) return void (0);
                  for (var i = 0; i < lastPos; i++) {
                      if (typeof djlist[i] !== 'undefined') {
                          var id = djlist[i].id;
                          var user = basicBot.userUtilities.lookupUser(id);
                          if (typeof user !== 'boolean') {
                              var plugUser = basicBot.userUtilities.getUser(user);
                              if (rank !== null && basicBot.userUtilities.getPermission(plugUser) <= rank) {
                                  var name = plugUser.username;
                                  var lastActive = basicBot.userUtilities.getLastActivity(user);
                                  var inactivity = Date.now() - lastActive;
                                  var time = basicBot.roomUtilities.msToStr(inactivity);
                                  var warncount = user.afkWarningCount;
                                  if (inactivity > basicBot.settings.maximumAfk * 60 * 1000) {
                                      if (warncount === 0) {
                                          API.sendChat(subChat(basicBot.chat.warning1, {name: name, time: time}));
                                          user.afkWarningCount = 3;
                                          user.afkCountdown = setTimeout(function (userToChange) {
                                              userToChange.afkWarningCount = 1;
                                          }, 90 * 1000, user);
                                      }
                                      else if (warncount === 1) {
                                          API.sendChat(subChat(basicBot.chat.warning2, {name: name}));
                                          user.afkWarningCount = 3;
                                          user.afkCountdown = setTimeout(function (userToChange) {
                                              userToChange.afkWarningCount = 2;
                                          }, 30 * 1000, user);
                                      }
                                      else if (warncount === 2) {
                                          var pos = API.getWaitListPosition(id);
                                          if (pos !== -1) {
                                              pos++;
                                              basicBot.room.afkList.push([id, Date.now(), pos]);
                                              user.lastDC = {
  
                                                  time: null,
                                                  position: null,
                                                  songCount: 0
                                              };
                                              API.moderateRemoveDJ(id);
                                              API.sendChat(subChat(basicBot.chat.afkremove, {name: name, time: time, position: pos, maximumafk: basicBot.settings.maximumAfk}));
                                          }
                                          user.afkWarningCount = 0;
                                      }
                                  }
                              }
                          }
                      }
                  }
              },
              changeDJCycle: function () {
                  var toggle = $(".cycle-toggle");
                  if (toggle.hasClass("disabled")) {
                      toggle.click();
                      if (basicBot.settings.cycleGuard) {
                          basicBot.room.cycleTimer = setTimeout(function () {
                              if (toggle.hasClass("enabled")) toggle.click();
                          }, basicBot.settings.cycleMaxTime * 60 * 1000);
                      }
                  }
                  else {
                      toggle.click();
                      clearTimeout(basicBot.room.cycleTimer);
                  }
              },
              intervalMessage: function () {
                  var interval;
                  if (basicBot.settings.motdEnabled) interval = basicBot.settings.motdInterval;
                  else interval = basicBot.settings.messageInterval;
                  if ((basicBot.room.roomstats.songCount % interval) === 0 && basicBot.status) {
                      var msg;
                      if (basicBot.settings.motdEnabled) {
                          msg = basicBot.settings.motd;
                      }
                      else {
                          if (basicBot.settings.intervalMessages.length === 0) return void (0);
                          var messageNumber = basicBot.room.roomstats.songCount % basicBot.settings.intervalMessages.length;
                          msg = basicBot.settings.intervalMessages[messageNumber];
                      }
                      API.sendChat('/me ' + msg);
                  }
              },
              updateBlacklists: function () {
                  for (var bl in basicBot.settings.blacklists) {
                      basicBot.room.blacklists[bl] = [];
                      if (typeof basicBot.settings.blacklists[bl] === 'function') {
                          basicBot.room.blacklists[bl] = basicBot.settings.blacklists();
                      }
                      else if (typeof basicBot.settings.blacklists[bl] === 'string') {
                          if (basicBot.settings.blacklists[bl] === '') {
                              continue;
                          }
                          try {
                              (function(l){
                                  $.get(basicBot.settings.blacklists[l], function (data) {
                                      if (typeof data === 'string') {
                                          data = JSON.parse(data);
                                      }
                                      var list = [];
                                      for (var prop in data) {
                                          if(typeof data[prop].mid !== 'undefined'){
                                              list.push(data[prop].mid);
                                          }
                                      }
                                      basicBot.room.blacklists[l] = list;
                                  })
                              })(bl);
                          }
                          catch (e) {
                              API.chatLog('Error setting' + bl + 'blacklist.');
                              console.log('Error setting' + bl + 'blacklist.');
                              console.log(e);
                          }
                      }
                  }
              },
              logNewBlacklistedSongs: function () {
                  if (typeof console.table !== 'undefined') {
                      console.table(basicBot.room.newBlacklisted);
                  }
                  else {
                      console.log(basicBot.room.newBlacklisted);
                  }
              },
              exportNewBlacklistedSongs: function () {
                  var list = {};
                  for (var i = 0; i < basicBot.room.newBlacklisted.length; i++) {
                      var track = basicBot.room.newBlacklisted[i];
                      list[track.list] = [];
                      list[track.list].push({
                          title: track.title,
                          author: track.author,
                          mid: track.mid
                      });
                  }
                  return list;
              }
          },
          eventChat: function (chat) {
              chat.message = linkFixer(chat.message);
              chat.message = chat.message.trim();
              for (var i = 0; i < basicBot.room.users.length; i++) {
                  if (basicBot.room.users[i].id === chat.uid) {
                      basicBot.userUtilities.setLastActivity(basicBot.room.users[i]);
                      if (basicBot.room.users[i].username !== chat.un) {
                          basicBot.room.users[i].username = chat.un;
                      }
                  }
              }
              if (basicBot.chatUtilities.chatFilter(chat)) return void (0);
              if (!basicBot.chatUtilities.commandCheck(chat))
                  basicBot.chatUtilities.action(chat);
          },
          eventUserjoin: function (user) {
              var known = false;
              var index = null;
              for (var i = 0; i < basicBot.room.users.length; i++) {
                  if (basicBot.room.users[i].id === user.id) {
                      known = true;
                      index = i;
                  }
              }
              var greet = true;
              var welcomeback = null;
              if (known) {
                  basicBot.room.users[index].inRoom = true;
                  var u = basicBot.userUtilities.lookupUser(user.id);
                  var jt = u.jointime;
                  var t = Date.now() - jt;
                  if (t < 10 * 1000) greet = false;
                  else welcomeback = true;
              }
              else {
                  basicBot.room.users.push(new basicBot.User(user.id, user.username));
                  welcomeback = false;
              }
              for (var j = 0; j < basicBot.room.users.length; j++) {
                  if (basicBot.userUtilities.getUser(basicBot.room.users[j]).id === user.id) {
                      basicBot.userUtilities.setLastActivity(basicBot.room.users[j]);
                      basicBot.room.users[j].jointime = Date.now();
                  }
  
              }
              if (basicBot.settings.welcome && greet) {
                  welcomeback ?
                      setTimeout(function (user) {
                          API.sendChat(subChat(basicBot.chat.welcomeback, {name: user.username}));
                      }, 1 * 1000, user)
                  :
                      setTimeout(function (user) {
                          API.sendChat(subChat(basicBot.chat.welcome, {name: user.username}));
                      }, 1 * 1000, user);
              }
          },
          eventUserleave: function (user) {
              for (var i = 0; i < basicBot.room.users.length; i++) {
                  if (basicBot.room.users[i].id === user.id) {
                      basicBot.userUtilities.updateDC(basicBot.room.users[i]);
                      basicBot.room.users[i].inRoom = false;
                  }
              }
          },
          eventVoteupdate: function (obj) {
              for (var i = 0; i < basicBot.room.users.length; i++) {
                  if (basicBot.room.users[i].id === obj.user.id) {
                      if (obj.vote === 1) {
                          basicBot.room.users[i].votes.woot++;
                      }
                      else {
                          basicBot.room.users[i].votes.meh++;
                      }
                  }
              }
          },
          eventCurateupdate: function (obj) {
              for (var i = 0; i < basicBot.room.users.length; i++) {
                  if (basicBot.room.users[i].id === obj.user.id) {
                      basicBot.room.users[i].votes.curate++;
                  }
              }
          },
          eventDjadvance: function (obj) {
              var lastplay = obj.lastPlay;
              if (typeof lastplay === 'undefined') return void (0);
              if (basicBot.settings.songstats){
                  if(typeof basicBot.chat.songstatistics === "undefined"){
                      API.sendChat("/me " + lastplay.media.author + " - " + lastplay.media.title + ": " + lastplay.score.positive + "W/" + lastplay.score.grabs + "G/" + lastplay.score.negative + "M.")
                  }
                  else{
                      API.sendChat(subChat(basicBot.chat.songstatistics, {artist: lastplay.media.author, title: lastplay.media.title, woots: lastplay.score.positive, grabs: lastplay.score.grabs, mehs: lastplay.score.negative}))
                  }
              }
              basicBot.room.roomstats.totalWoots += lastplay.score.positive;
              basicBot.room.roomstats.totalMehs += lastplay.score.negative;
              basicBot.room.roomstats.totalCurates += lastplay.score.grabs;
              basicBot.room.roomstats.songCount++;
              basicBot.roomUtilities.intervalMessage();
              basicBot.room.currentDJID = obj.dj.id;
              var mid = obj.media.format + ':' + obj.media.cid;
              for (var bl in basicBot.room.blacklists) {
                  if (basicBot.room.blacklists[bl].indexOf(mid) > -1) {
                      API.sendChat(subChat(basicBot.chat.isblacklisted, {blacklist: bl}));
                      return API.moderateForceSkip();
                  }
              }
              var alreadyPlayed = false;
              for (var i = 0; i < basicBot.room.historyList.length; i++) {
                  if (basicBot.room.historyList[i][0] === obj.media.cid) {
                      var firstPlayed = basicBot.room.historyList[i][1];
                      var plays = basicBot.room.historyList[i].length - 1;
                      var lastPlayed = basicBot.room.historyList[i][plays];
                      //API.sendChat(subChat(basicBot.chat.songknown, {plays: plays, timetotal: basicBot.roomUtilities.msToStr(Date.now() - firstPlayed), lasttime: basicBot.roomUtilities.msToStr(Date.now() - lastPlayed)}));
                      basicBot.room.historyList[i].push(+new Date());
                      alreadyPlayed = true;
                  }
              }
              if (!alreadyPlayed) {
                  basicBot.room.historyList.push([obj.media.cid, +new Date()]);
              }
              var newMedia = obj.media;
              if (basicBot.settings.timeGuard && newMedia.duration > basicBot.settings.maximumSongLength * 60 && !basicBot.room.roomevent) {
                  var name = obj.dj.username;
                  API.sendChat(subChat(basicBot.chat.timelimit, {name: name, maxlength: basicBot.settings.maximumSongLength}));
                  API.moderateForceSkip();
              }
              var user = basicBot.userUtilities.lookupUser(obj.dj.id);
              if (user.ownSong) {
                  API.sendChat(subChat(basicBot.chat.permissionownsong, {name: user.username}));
                  user.ownSong = false;
              }
              user.lastDC = {
                  time: null,
                  position: null,
                  songCount: 0
              };
              clearTimeout(basicBot.room.autoskipTimer);
              if (basicBot.room.autoskip) {
                  var remaining = obj.media.duration * 1000;
                  basicBot.room.autoskipTimer = setTimeout(function () {
                      API.moderateForceSkip();
                  }, remaining + 1000);
              }
              storeToStorage();
  
          },
          eventWaitlistupdate: function (users) {
              if (users.length < 50) {
                  if (basicBot.room.queue.id.length > 0 && basicBot.room.queueable) {
                      basicBot.room.queueable = false;
                      setTimeout(function () {
                          basicBot.room.queueable = true;
                      }, 500);
                      basicBot.room.queueing++;
                      var id, pos;
                      setTimeout(
                          function () {
                              id = basicBot.room.queue.id.splice(0, 1)[0];
                              pos = basicBot.room.queue.position.splice(0, 1)[0];
                              API.moderateAddDJ(id, pos);
                              setTimeout(
                                  function (id, pos) {
                                      API.moderateMoveDJ(id, pos);
                                      basicBot.room.queueing--;
                                      if (basicBot.room.queue.id.length === 0) setTimeout(function () {
                                          basicBot.roomUtilities.booth.unlockBooth();
                                      }, 1000);
                                  }, 1000, id, pos);
                          }, 1000 + basicBot.room.queueing * 2500);
                  }
              }
              for (var i = 0; i < users.length; i++) {
                  var user = basicBot.userUtilities.lookupUser(users[i].id);
                  basicBot.userUtilities.updatePosition(user, API.getWaitListPosition(users[i].id) + 1);
              }
          },
          chatcleaner: function (chat) {
              if (!basicBot.settings.filterChat) return false;
              if (basicBot.userUtilities.getPermission(chat.uid) > 1) return false;
              var msg = chat.message;
              var containsLetters = false;
              for (var i = 0; i < msg.length; i++) {
                  ch = msg.charAt(i);
                  if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch === ':' || ch === '^') containsLetters = true;
              }
              if (msg === '') {
                  return true;
              }
              if (!containsLetters && (msg.length === 1 || msg.length > 3)) return true;
              msg = msg.replace(/[ ,;.:\/=~+%^*\-\\"'&@#]/g, '');
              var capitals = 0;
              var ch;
              for (var i = 0; i < msg.length; i++) {
                  ch = msg.charAt(i);
                  if (ch >= 'A' && ch <= 'Z') capitals++;
              }
              if (capitals >= 40) {
                  API.sendChat(subChat(basicBot.chat.caps, {name: chat.un}));
                  return true;
              }
              msg = msg.toLowerCase();
              if (msg === 'skip') {
                  API.sendChat(subChat(basicBot.chat.askskip, {name: chat.un}));
                  return true;
              }
              for (var j = 0; j < basicBot.chatUtilities.spam.length; j++) {
                  if (msg === basicBot.chatUtilities.spam[j]) {
                      API.sendChat(subChat(basicBot.chat.spam, {name: chat.un}));
                      return true;
                  }
              }
              return false;
          },
          chatUtilities: {
              chatFilter: function (chat) {
                  var msg = chat.message;
                  var perm = basicBot.userUtilities.getPermission(chat.uid);
                  var user = basicBot.userUtilities.lookupUser(chat.uid);
                  var isMuted = false;
                  for (var i = 0; i < basicBot.room.mutedUsers.length; i++) {
                      if (basicBot.room.mutedUsers[i] === chat.uid) isMuted = true;
                  }
                  if (isMuted) {
                      API.moderateDeleteChat(chat.cid);
                      return true;
                  }
                  if (basicBot.settings.lockdownEnabled) {
                      if (perm === 0) {
                          API.moderateDeleteChat(chat.cid);
                          return true;
                      }
                  }
                  if (basicBot.chatcleaner(chat)) {
                      API.moderateDeleteChat(chat.cid);
                      return true;
                  }
                  /**
                  var plugRoomLinkPatt = /(\bhttps?:\/\/(www.)?plug\.dj[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
                  if (plugRoomLinkPatt.exec(msg)) {
                      if (perm === 0) {
                          API.sendChat(subChat(basicBot.chat.roomadvertising, {name: chat.un}));
                          API.moderateDeleteChat(chat.cid);
                          return true;
                      }
                  }
                   **/
                  if (msg.indexOf('http://adf.ly/') > -1) {
                      API.moderateDeleteChat(chat.cid);
                      API.sendChat(subChat(basicBot.chat.adfly, {name: chat.un}));
                      return true;
                  }
                  if (msg.indexOf('autojoin was not enabled') > 0 || msg.indexOf('AFK message was not enabled') > 0 || msg.indexOf('!afkdisable') > 0 || msg.indexOf('!joindisable') > 0 || msg.indexOf('autojoin disabled') > 0 || msg.indexOf('AFK message disabled') > 0) {
                      API.moderateDeleteChat(chat.cid);
                      return true;
                  }
                  var rlJoinChat = basicBot.chat.roulettejoin;
                  var rlLeaveChat = basicBot.chat.rouletteleave;
  
                  var joinedroulette = rlJoinChat.split('%%NAME%%');
                  if(joinedroulette[1].length > joinedroulette[0].length) joinedroulette = joinedroulette[1];
                  else joinedroulette = joinedroulette[0];
  
                  var leftroulette = rlLeaveChat.split('%%NAME%%');
                  if(leftroulette[1].length > leftroulette[0].length) leftroulette = leftroulette[1];
                  else leftroulette = leftroulette[0];
  
                  if ((msg.indexOf(joinedroulette) > -1 || msg.indexOf(leftroulette) > -1) && chat.uid === basicBot.loggedInID) {
                      setTimeout(function (id) {
                          API.moderateDeleteChat(id);
                      }, 2 * 1000, chat.cid);
                      return true;
                  }
                  return false;
              },
              commandCheck: function (chat) {
                  var cmd;
                  if (chat.message.charAt(0) === '!') {
                      var space = chat.message.indexOf(' ');
                      if (space === -1) {
                          cmd = chat.message;
                      }
                      else cmd = chat.message.substring(0, space);
                  }
                  else return false;
                  var userPerm = basicBot.userUtilities.getPermission(chat.uid);
                  //console.log("name: " + chat.un + ", perm: " + userPerm);
                  if (chat.message !== "!join" && chat.message !== "!leave") {
                      if (userPerm === 0 && !basicBot.room.usercommand) return void (0);
                      if (!basicBot.room.allcommand) return void (0);
                  }
                  if (chat.message === '!eta' && basicBot.settings.etaRestriction) {
                      if (userPerm < 2) {
                          var u = basicBot.userUtilities.lookupUser(chat.uid);
                          if (u.lastEta !== null && (Date.now() - u.lastEta) < 1 * 60 * 60 * 1000) {
                              API.moderateDeleteChat(chat.cid);
                              return void (0);
                          }
                          else u.lastEta = Date.now();
                      }
                  }
                  var executed = false;
  
                  for (var comm in basicBot.commands) {
                      var cmdCall = basicBot.commands[comm].command;
                      if(!Array.isArray(cmdCall)){cmdCall = [cmdCall]}
                      for(var i = 0; i < cmdCall.length; i++){
                          if (basicBot.settings.commandLiteral + cmdCall[i] === cmd) {
                              basicBot.commands[comm].functionality(chat, basicBot.settings.commandLiteral + cmdCall[i]);
                              executed = true;
                              break;
                          }
                      }
                  }
  
                  if (executed && userPerm === 0) {
                      basicBot.room.usercommand = false;
                      setTimeout(function () {
                          basicBot.room.usercommand = true;
                      }, basicBot.settings.commandCooldown * 1000);
                  }
                  if (executed) {
                      API.moderateDeleteChat(chat.cid);
                      basicBot.room.allcommand = false;
                      setTimeout(function () {
                          basicBot.room.allcommand = true;
                      }, 5 * 1000);
                  }
                  return executed;
              },
              action: function (chat) {
                  var user = basicBot.userUtilities.lookupUser(chat.uid);
                  if (chat.type === 'message') {
                      for (var j = 0; j < basicBot.room.users.length; j++) {
                          if (basicBot.userUtilities.getUser(basicBot.room.users[j]).id === chat.uid) {
                              basicBot.userUtilities.setLastActivity(basicBot.room.users[j]);
                          }
  
                      }
                  }
                  basicBot.room.roomstats.chatmessages++;
              },
              spam: [
                  'hueh', 'hu3', 'brbr', 'heu', 'brbr', 'kkkk', 'spoder', 'mafia', 'zuera', 'zueira',
                  'zueria', 'aehoo', 'aheu', 'alguem', 'algum', 'brazil', 'zoeira', 'fuckadmins', 'affff', 'vaisefoder', 'huenaarea',
                  'hitler', 'ashua', 'ahsu', 'ashau', 'lulz', 'huehue', 'hue', 'huehuehue', 'merda', 'pqp', 'puta', 'mulher', 'pula', 'retarda', 'caralho', 'filha', 'ppk',
                  'gringo', 'fuder', 'foder', 'hua', 'ahue', 'modafuka', 'modafoka', 'mudafuka', 'mudafoka', 'ooooooooooooooo', 'foda'
              ],
              curses: [
                  'nigger', 'faggot', 'nigga', 'niqqa', 'motherfucker', 'modafocka'
              ]
          },
          connectAPI: function () {
              this.proxy = {
                  eventChat: $.proxy(this.eventChat, this),
                  eventUserskip: $.proxy(this.eventUserskip, this),
                  eventUserjoin: $.proxy(this.eventUserjoin, this),
                  eventUserleave: $.proxy(this.eventUserleave, this),
                  eventUserfan: $.proxy(this.eventUserfan, this),
                  eventFriendjoin: $.proxy(this.eventFriendjoin, this),
                  eventFanjoin: $.proxy(this.eventFanjoin, this),
                  eventVoteupdate: $.proxy(this.eventVoteupdate, this),
                  eventCurateupdate: $.proxy(this.eventCurateupdate, this),
                  eventRoomscoreupdate: $.proxy(this.eventRoomscoreupdate, this),
                  eventDjadvance: $.proxy(this.eventDjadvance, this),
                  eventDjupdate: $.proxy(this.eventDjupdate, this),
                  eventWaitlistupdate: $.proxy(this.eventWaitlistupdate, this),
                  eventVoteskip: $.proxy(this.eventVoteskip, this),
                  eventModskip: $.proxy(this.eventModskip, this),
                  eventChatcommand: $.proxy(this.eventChatcommand, this),
                  eventHistoryupdate: $.proxy(this.eventHistoryupdate, this)
  
              };
              API.on(API.CHAT, this.proxy.eventChat);
              API.on(API.USER_SKIP, this.proxy.eventUserskip);
              API.on(API.USER_JOIN, this.proxy.eventUserjoin);
              API.on(API.USER_LEAVE, this.proxy.eventUserleave);
              API.on(API.USER_FAN, this.proxy.eventUserfan);
              API.on(API.VOTE_UPDATE, this.proxy.eventVoteupdate);
              API.on(API.GRAB_UPDATE, this.proxy.eventCurateupdate);
              API.on(API.ROOM_SCORE_UPDATE, this.proxy.eventRoomscoreupdate);
              API.on(API.ADVANCE, this.proxy.eventDjadvance);
              API.on(API.WAIT_LIST_UPDATE, this.proxy.eventWaitlistupdate);
              API.on(API.MOD_SKIP, this.proxy.eventModskip);
              API.on(API.CHAT_COMMAND, this.proxy.eventChatcommand);
              API.on(API.HISTORY_UPDATE, this.proxy.eventHistoryupdate);
          },
          disconnectAPI: function () {
              API.off(API.CHAT, this.proxy.eventChat);
              API.off(API.USER_SKIP, this.proxy.eventUserskip);
              API.off(API.USER_JOIN, this.proxy.eventUserjoin);
              API.off(API.USER_LEAVE, this.proxy.eventUserleave);
              API.off(API.USER_FAN, this.proxy.eventUserfan);
              API.off(API.VOTE_UPDATE, this.proxy.eventVoteupdate);
              API.off(API.CURATE_UPDATE, this.proxy.eventCurateupdate);
              API.off(API.ROOM_SCORE_UPDATE, this.proxy.eventRoomscoreupdate);
              API.off(API.ADVANCE, this.proxy.eventDjadvance);
              API.off(API.WAIT_LIST_UPDATE, this.proxy.eventWaitlistupdate);
              API.off(API.MOD_SKIP, this.proxy.eventModskip);
              API.off(API.CHAT_COMMAND, this.proxy.eventChatcommand);
              API.off(API.HISTORY_UPDATE, this.proxy.eventHistoryupdate);
          },
          startup: function () {
              Function.prototype.toString = function(){return 'Function.'};
              var u = API.getUser();
              if (basicBot.userUtilities.getPermission(u) < 2) return API.chatLog(basicBot.chat.greyuser);
              if (basicBot.userUtilities.getPermission(u) === 2) API.chatLog(basicBot.chat.bouncer);
              basicBot.connectAPI();
              basicBot.connectAPI();
              API.moderateDeleteChat = function(cid){
                  $.ajax({
                      url: "https://plug.dj/_/chat/"+cid,
                      type: "DELETE"
                  })
              };
              //retrieveSettings();
              //retrieveFromStorage();
              window.bot = basicBot;
              basicBot.roomUtilities.updateBlacklists();
              setInterval(basicBot.roomUtilities.updateBlacklists, 60*60*1000);
              basicBot.getNewBlacklistedSongs = basicBot.roomUtilities.exportNewBlacklistedSongs;
              basicBot.logNewBlacklistedSongs = basicBot.roomUtilities.logNewBlacklistedSongs;
              if (basicBot.room.roomstats.launchTime === null) {
                  basicBot.room.roomstats.launchTime = Date.now();
              }
  
              for (var j = 0; j < basicBot.room.users.length; j++) {
                  basicBot.room.users[j].inRoom = false;
              }
              var userlist = API.getUsers();
              for (var i = 0; i < userlist.length; i++) {
                  var known = false;
                  var ind = null;
                  for (var j = 0; j < basicBot.room.users.length; j++) {
                      if (basicBot.room.users[j].id === userlist[i].id) {
                          known = true;
                          ind = j;
                      }
                  }
                  if (known) {
                      basicBot.room.users[ind].inRoom = true;
                  }
                  else {
                      basicBot.room.users.push(new basicBot.User(userlist[i].id, userlist[i].username));
                      ind = basicBot.room.users.length - 1;
                  }
                  var wlIndex = API.getWaitListPosition(basicBot.room.users[ind].id) + 1;
                  basicBot.userUtilities.updatePosition(basicBot.room.users[ind], wlIndex);
              }
              basicBot.room.afkInterval = setInterval(function () {
                  basicBot.roomUtilities.afkCheck()
              }, 10 * 1000);
              basicBot.room.autodisableInterval = setInterval(function () {
                  basicBot.room.autodisableFunc();
              }, 60 * 60 * 1000);
              basicBot.loggedInID = API.getUser().id;
              basicBot.status = true;
              API.sendChat('/cap 1');
              API.setVolume(0);
              var emojibutton = $(".icon-emoji-on");
              if(emojibutton.length > 0){
                  emojibutton[0].click();
              }
              loadChat(API.sendChat(subChat(basicBot.chat.online, {botname: basicBot.settings.botName, version: basicBot.version})));
              window.bot = basicBot;
          },
          commands: {
              executable: function (minRank, chat) {
                  var id = chat.uid;
                  var perm = basicBot.userUtilities.getPermission(id);
                  var minPerm;
                  switch (minRank) {
                      case 'admin':
                          minPerm = 10;
                          break;
                      case 'ambassador':
                          minPerm = 7;
                          break;
                      case 'host':
                          minPerm = 10; //5
                          break;
                      case 'cohost':
                          minPerm = 4;
                          break;
                      case 'manager':
                          minPerm = 3;
                          break;
                      case 'mod':
                          if (basicBot.settings.bouncerPlus) {
                              minPerm = 2;
                          }
                          else {
                              minPerm = 3;
                          }
                          break;
                      case 'bouncer':
                          minPerm = 2;
                          break;
                      case 'residentdj':
                          minPerm = 1;
                          break;
                      case 'user':
                          minPerm = 0;
                          break;
                      default:
                          API.chatLog('error assigning minimum permission');
                  }
                  return perm >= minPerm;
  
              },
              /**
               command: {
                          command: 'cmd',
                          rank: 'user/bouncer/mod/manager',
                          type: 'startsWith/exact',
                          functionality: function(chat, cmd){
                                  if(this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                                  if( !basicBot.commands.executable(this.rank, chat) ) return void (0);
                                  else{
                                  
                                  }
                          }
                  },
               **/
  
              activeCommand: {
                  command: 'active',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var now = Date.now();
                          var chatters = 0;
                          var time;
                          if (msg.length === cmd.length) time = 60;
                          else {
                              time = msg.substring(cmd.length + 1);
                              if (isNaN(time)) return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                          }
                          for (var i = 0; i < basicBot.room.users.length; i++) {
                              userTime = basicBot.userUtilities.getLastActivity(basicBot.room.users[i]);
                              if ((now - userTime) <= (time * 60 * 1000)) {
                                  chatters++;
                              }
                          }
                          API.sendChat(subChat(basicBot.chat.activeusersintime, {name: chat.un, amount: chatters, time: time}));
                      }
                  }
              },
  
              addCommand: {
                  command: 'add',
                  rank: 'mod',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substr(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (msg.length > cmd.length + 2) {
                              if (typeof user !== 'undefined') {
                                  if (basicBot.room.roomevent) {
                                      basicBot.room.eventArtists.push(user.id);
                                  }
                                  API.moderateAddDJ(user.id);
                              } else API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          }
                      }
                  }
              },
  
              afklimitCommand: {
                  command: 'afklimit',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nolimitspecified, {name: chat.un}));
                          var limit = msg.substring(cmd.length + 1);
                          if (!isNaN(limit)) {
                              basicBot.settings.maximumAfk = parseInt(limit, 10);
                              API.sendChat(subChat(basicBot.chat.maximumafktimeset, {name: chat.un, time: basicBot.settings.maximumAfk}));
                          }
                          else API.sendChat(subChat(basicBot.chat.invalidlimitspecified, {name: chat.un}));
                      }
                  }
              },
  
              afkremovalCommand: {
                  command: 'afkremoval',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.afkRemoval) {
                              basicBot.settings.afkRemoval = !basicBot.settings.afkRemoval;
                              clearInterval(basicBot.room.afkInterval);
                              API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.afkremoval}));
                          }
                          else {
                              basicBot.settings.afkRemoval = !basicBot.settings.afkRemoval;
                              basicBot.room.afkInterval = setInterval(function () {
                                  basicBot.roomUtilities.afkCheck()
                              }, 2 * 1000);
                              API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.afkremoval}));
                          }
                      }
                  }
              },
  
              afkresetCommand: {
                  command: 'afkreset',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substring(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          basicBot.userUtilities.setLastActivity(user);
                          API.sendChat(subChat(basicBot.chat.afkstatusreset, {name: chat.un, username: name}));
                      }
                  }
              },
  
              afktimeCommand: {
                  command: 'afktime',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substring(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var lastActive = basicBot.userUtilities.getLastActivity(user);
                          var inactivity = Date.now() - lastActive;
                          var time = basicBot.roomUtilities.msToStr(inactivity);
                          API.sendChat(subChat(basicBot.chat.inactivefor, {name: chat.un, username: name, time: time}));
                      }
                  }
              },
  
              autoskipCommand: {
                  command: 'autoskip',
                  rank: 'bouncer', //mod
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.room.autoskip) {
                              basicBot.room.autoskip = !basicBot.room.autoskip;
                              clearTimeout(basicBot.room.autoskipTimer);
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.autoskip}));
                          }
                          else {
                              basicBot.room.autoskip = !basicBot.room.autoskip;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.autoskip}));
                          }
                      }
                  }
              },
  
              autowootCommand: {
                  command: ['autowoot','woot'],
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(basicBot.chat.autowoot);
                      }
                  }
              },
  
              baCommand: {
                  command: 'ba',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(basicBot.chat.brandambassador);
                      }
                  }
              },
  
              banCommand: {
                  command: 'ban',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substr(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          API.moderateBanUser(user.id, 1, API.BAN.DAY);
                      }
                  }
              },
              
              blacklistCommand: {
                  command: ['blacklist', 'bl'],
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nolistspecified, {name: chat.un}));
                          var list = msg.substr(cmd.length + 1);
                          if (typeof basicBot.room.blacklists[list] === 'undefined') return API.sendChat(subChat(basicBot.chat.invalidlistspecified, {name: chat.un}));
                          else {
                              var media = API.getMedia();
                              var track = {
                                  list: list,
                                  author: media.author,
                                  title: media.title,
                                  mid: media.format + ':' + media.cid
                              };
                              basicBot.room.newBlacklisted.push(track);
                              basicBot.room.blacklists[list].push(media.format + ':' + media.cid);
                              API.sendChat(subChat(basicBot.chat.newblacklisted, {name: chat.un, blacklist: list, author: media.author,title: media.title, mid: media.format + ':' + media.cid}));
                              API.moderateForceSkip();
                              if(typeof basicBot.room.newBlacklistedSongFunction === 'function'){
                                  basicBot.room.newBlacklistedSongFunction(track);
                              }
                          }
                      }
                  }
              },
  
              bouncerPlusCommand: {
                  command: ['bouncer+','bouncer'],
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (basicBot.settings.bouncerPlus) {
                              basicBot.settings.bouncerPlus = false;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': 'Bouncer+'}));
                          }
                          else {
                              if (!basicBot.settings.bouncerPlus) {
                                  var id = chat.uid;
                                  var perm = basicBot.userUtilities.getPermission(id);
                                  if (perm > 2) {
                                      basicBot.settings.bouncerPlus = true;
                                      return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': 'Bouncer+'}));
                                  }
                              }
                              else return API.sendChat(subChat(basicBot.chat.bouncerplusrank, {name: chat.un}));
                          }
                      }
                  }
              },
  
              clearchatCommand: {
                  command: ['clearchat','clear'],
                  rank: 'manager',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var currentchat = $('#chat-messages').children();
                          for (var i = 0; i < currentchat.length; i++) {
                              API.moderateDeleteChat(currentchat[i].getAttribute("data-cid"));
                          }
                          return API.sendChat(subChat(basicBot.chat.chatcleared,{name: chat.un}));
                      }
                  }
              },
  
              commandsCommand: {
                  command: ['commands','cmd','command'],
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(subChat(basicBot.chat.commandslink, {botname: basicBot.settings.botName, link: basicBot.cmdLink}));
                      }
                  }
              },
              
              cookieCommand: {
                  command: ['cookie','cookies'],
                  rank: 'cohost',
                  type: 'startsWith',
                  cookies: ['has bought you a chocolate chip cookie!',
                      'has bought you a soft homemade oatmeal cookie!',
                      'has bought you a plain, dry, old cookie. It was the last one in the bag. Gross.',
                      'bought you a sugar cookie. What, no frosting and sprinkles? 0/10 would not touch.',
                      'bought you a chocolate chip cookie. Oh wait, those are raisins. Bleugh!',
                      'bought you an enormous cookie. Poking it gives you more cookies. Weird.',
                      'bought you a fortune cookie. It reads "Why are you not working on any projects?"',
                      'bought you a fortune cookie. It reads "Give that special someone a compliment"',
                      'bought you a fortune cookie. It reads "Take a risk!"',
                      'bought you a fortune cookie. It reads "Go outside."',
                      'bought you a fortune cookie. It reads "Do not forget to eat your veggies!"',
                      'bought you a fortune cookie. It reads "Do you even lift?"',
                      'bought you a fortune cookie. It reads "m808 pls"',
                      'bought you a fortune cookie. It reads "If you move your hips, you will get all the ladies."',
                      'bought you a fortune cookie. It reads "I love you."',
                      'bought you a Golden Cookie. You cannot eat it because it is made of gold. Dammit.',
                      'bought you an Oreo cookie!',
                      'bought you a rainbow cookie made with love :heart:',
                      'bought you an old cookie that was left out in the rain, its moldy.',
                      'bought you fresh cookies, it smells amazing.'
                  ],
                  getCookie: function () {
                      var c = Math.floor(Math.random() * this.cookies.length);
                      return this.cookies[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else  {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatcookie);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nousercookie, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfcookie, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.cookie, {nameto: user.username, namefrom: chat.un, cookie: this.getCookie()}));
                              }
                          }
                      }
                  }
              },
              
              alcoholCommand: {
                  command: ['alcohol','alcohols'],
                  rank: 'cohost',
                  type: 'startsWith',
                  alcohols: ['has bought you a pint of Johny Walker!',
                      'has bought you a glass of Vodka!',
                      'has bought you an empty glass...',
                      'has bought you a bottle of Budweiser beer.',
                      'has bought you a bottle of Bud Light beer.',
                      'has bought you a bottle of Heineken beer.',
                      'has bought you a bottle of Guinness Stout beer.',
                      'has bought you a bottle of Sam Adams beer.',
                      'has bought you a bottle of Becks beer.',
                      'has bought you a bottle of Corana beer.',
                      'has bought you a pint of scotch, cause he is classy mofo.',
                      'has bought you nothing, cause he is too cheap.'
                  ],
                  getAlcohol: function () {
                      var c = Math.floor(Math.random() * this.alcohols.length);
                      return this.alcohols[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatalcohol);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouseralcohol, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfalcohol, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.alcohol, {nameto: user.username, namefrom: chat.un, alcohol: this.getAlcohol()}));
                              }
                          }
                      }
                  }
              },
              
              donutCommand: {
                  command: ['donut','donuts','doughnuts','doughnut'],
                  rank: 'user',
                  type: 'startsWith',
                  donuts: ['has bought you a Chocolate Iced glazed donut!',
                      'has bought you a sugar coated donut!',
                      'has bought you a half eaten donut.',
                      'has bought you a fat free donut.',
                      'has bought you a Glazed donut.',
                      'has bought you a Chocolate donut with sprinkles.',
                      'has bought you nothing, cause he is too cheap.',
                      'has bought you the famous Boston cream donut!',
                      'has bought you a Coconut donut!'
                  ],
                  getDonut: function () {
                      var c = Math.floor(Math.random() * this.donuts.length);
                      return this.donuts[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatdonut);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserdonut, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfdonut, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.donut, {nameto: user.username, namefrom: chat.un, donut: this.getDonut()}));
                              }
                          }
                      }
                  }
              },
              
              pizzaCommand: {
                  command: ['pizza','pizzas'],
                  rank: 'residentdj',
                  type: 'startsWith',
                  pizzas: ['has bought you a mini Chicken pizza!',
                      'has bought you a pan of Hawaiian pizza!',
                      'has bought you a half eaten pizza.',
                      'has bought you a pan of Meat lovers pizza.',
                      'has bought you a pan of Neapolitan pizza.',
                      'has bought you a pan of Pepperoni and Cheese pizza.',
                      'has bought you a pan of Double Cheese pizza.',
                      'has bought you a pan of BBQ Chicken pizza.',
                      'has bought you a pan of Chicken Delight',
                      'has bought you a pizza base. "Now go make your own pizza!"',
                      'has bought you nothing, cause he is too cheap.'
                  ],
                  getPizza: function () {
                      var c = Math.floor(Math.random() * this.pizzas.length);
                      return this.pizzas[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatpizza);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserpizza, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfpizza, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.pizza, {nameto: user.username, namefrom: chat.un, pizza: this.getPizza()}));
                              }
                          }
                      }
                  }
              },
              
              icecreamCommand: {
                  command: ['icecream','icecreams'],
                  rank: 'user',
                  type: 'startsWith',
                  icecreams: ['has bought you a Chocolate flavored icecream in cone.',
                      'has bought you a Sprinkle coated Vanilla flavored icecream in a cone.',
                      'has bought you a half licked icecream in a cone.',
                      'has bought you a Strawberry flavored icecream in cone.',
                      'has bought you a Vanilla with chocolate chip flavored icecream in cone.',
                      'has bought you a  Mint with Chocolate chip  flavored icecream in cone.',
                      'has bought you a Coffee flavored icecream in cone.',
                      'has bought you a tub of Chocoalte ice cream!',
                      'has bought you a tub of Vanilla ice cream!',
                      'has bought you a tub of Strawberry ice cream!',
                      'has bought you a tub of Napolean ice cream',
                      'has bought you a half eatten tub of ice cream',
                      'has bought you an empty cone.'
                  ],
                  getIcecream: function () {
                      var c = Math.floor(Math.random() * this.icecreams.length);
                      return this.icecreams[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eaticecream);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nousericecream, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selficecream, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.icecream, {nameto: user.username, namefrom: chat.un, icecream: this.getIcecream()}));
                              }
                          }
                      }
                  }
              },
              
              chocolateCommand: {
                  command: ['chocolate','choc','choco','chocolates'],
                  rank: 'residentdj',
                  type: 'startsWith',
                  chocolates: ['has bought you a chocolate chip chocolate!',
                  'has bought you a bar of Kit Kat chocolate!',
                  'has bought you a bar of Mars chocolate!',
                  'has bought you a bar of Cadbury chocolate!',
                  'has bought you a bar of Toblerone chocolate!',
                  'has bought you a bar of Lindt chocolate!',
                  'has bought you a box of Ferrero Rocher chocolate!!!',
                  'has bought you a bar of 3 Musketeers chocolate!',
                  'has bought you a bar of Milky Way chocolate!',
                  'has bought you a bar of Hershey chocolate!',
                  'has bought you a bar of Snickers chocolate!'
                  ],
                  getChocolate: function () {
                      var c = Math.floor(Math.random() * this.chocolates.length);
                      return this.chocolates[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatchocolate);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserchocolate, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfchocolate, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.chocolate, {nameto: user.username, namefrom: chat.un, chocolate: this.getChocolate()}));
                              }
                          }
                      }
                  }
              },
              
              riceCommand: {
                  command: 'rice',
                  rank: 'user',
                  type: 'startsWith',
                  rices: ['has bought you a plate of Chicken Fried Rice.',
                      'has bought you a plate of Spicy Chicken Fried Fried Rice.',
                      'has bought you a plate of Beef Fried Rice.',
                      'has bought you a plate of Spicy Beef Fried Rice.',
                      'has bought you a plate of Pork Fried Rice.',
                      'has bought you a plate of Spicy Fried Rice.',
                      'has bought you a cup of rice grains. "Now go cook your own rice." ',
                      'has bought you a plate of Curry Rice.',
                      'has bought you a plate of Spicy Curry Rice.',
                      'has bought you a bowl of porridge',
                      'has bought you a plate of Briyani Rice.',
                      'has bought you a plate of Mexican Red Rice.',
                      'has bought you a plate of Mexican Green Rice.',
                      'has bought you a plate of Spicy Vegetable Fried Rice.',
                      'has bought you a plate of Vegetable Fried Rice.',
                      'has bought you a plate of Brown Rice.',
                      'has bought you a small Rice Ball.',
                      'has bought you a Rice Ball.',
                      'has bought you a GIANT Rice Ball !!!',
                      'has bought you a plate of Lemon Rice.'
                  ],
                  getRice: function () {
                      var c = Math.floor(Math.random() * this.rices.length);
                      return this.rices[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatrice);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserrice, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfrice, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.rice, {nameto: user.username, namefrom: chat.un, rice: this.getRice()}));
                              }
                          }
                      }
                  }
              },
              
              friesCommand: {
                  command: ['fries','french fries','frenchfries'],
                  rank: 'user',
                  type: 'startsWith',
                  friess: ['has bought you a small box of french fries.',
                      'has bought you a medium box of french fries.',
                      'has bought you a large box of french fries!',
                      'has bought you a GIANT box of french fries!!!',
                      'has bought you a soggy box of french fries.',
                      'has bought you a damp box of french fries.',
                      'has bought you a half eatten box of french fries.',
                      'has bought you a over cooked box of french fries.',
                      'has bought you a potato. "Now go cook your own fries!" ',
                      'has bought you a small box of curly fries.',
                      'has bought you a medium box of curly fries.',
                      'has bought you a large box of curly fries!',
                      'has bought you a GIANT box of curly fries!!!',
                      'has bought you a soggy box of curly fries.',
                      'has bought you a damp box of curly fries.',
                      'has bought you a half eatten box of curly fries.',
                      'has bought you a over cooked box of curly fries.',
                      'has bought you a small box of carrot fries.',
                      'has bought you a medium box of carrot fries.',
                      'has bought you a large box of carrot fries!',
                      'has bought you a GIANT box of carrot fries!!!',
                      'has bought you a half eatten box of carrot fries.',
                      'has bought you a small box of sweet potato fries.',
                      'has bought you a medium box of sweet potato fries.',
                      'has bought you a large box of sweet potato fries!',
                      'has bought you a GIANT box of sweet potato fries!!!',
                      'has bought you a soggy box of sweet potato fries.',
                      'has bought you a damp box of sweet potato fries.',
                      'has bought you a half eatten box of sweet potato fries.',
                      'has bought you a over cooked box of sweet potato fries.',
                      'has bought you a small box of waffle fries.',
                      'has bought you a medium box of waffle fries.',
                      'has bought you a large box of waffle fries!',
                      'has bought you a soggy box of waffle fries.',
                      'has bought you a damp box of waffle fries.',
                      'has bought you a half eatten box of waffle fries.',
                      'has bought you a over cooked box of waffle fries.'
                  ],
                  getFries: function () {
                      var c = Math.floor(Math.random() * this.friess.length);
                      return this.friess[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatfries);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserfries, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selffries, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.fries, {nameto: user.username, namefrom: chat.un, fries: this.getFries()}));
                              }
                          }
                      }
                  }
              },
              
              bunCommand: {
                  command: ['bun','buns'],
                  rank: 'user',
                  type: 'startsWith',
                  buns: ['has bought you a Chocolate flavored bun!',
                      'has bought you a soft homemade Oatmeal bun!',
                      'has bought you a Chicken filling bun.',
                      'has bought you a Pork filling bun.',
                      'has bought you a Beef filling bun.',
                      'has bought you a Vegetable filling bun.',
                      'has bought you a Chilli filling bun.',
                      'has bought you a Strawberry jam filling bun.',
                      'has bought you a blueberry jam filling bun.',
                      'has bought you a Nutella jam filling bun.',
                      'has bought you a Chocolate jam filling bun.',
                      'has bought you a Cinnamon bun.',
                      'has bought you a dough. "Now go make your own bun!" ',
                      'has bought you a Cream bun! "It looks like cream...but is it actually cream?" ',
                      'has bought you a fresh Honey bun! "Dont mind the bees in it." ',
                      'has bought you a hotdog bun!'
                  ],
                  getBun: function () {
                      var c = Math.floor(Math.random() * this.buns.length);
                      return this.buns[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatbun);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserbun, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfbun, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.bun, {nameto: user.username, namefrom: chat.un, bun: this.getBun()}));
                              }
                          }
                      }
                  }
              },
              
              chipsCommand: {
                  command: ['chips','chip','potato chips','potatochips'],
                  rank: 'user',
                  type: 'startsWith',
                  chipss: ['has bought you a small bag of Potato chips!',
                      'has bought you a large bag of BBQ flavored Potato chips!',
                      'has bought youa a tube of Pringles Potato chips!',
                      'has bought youa a bag of Ruffles Potato chips!',
                      'has bought youa a bag of Lays Potato chips!',
                      'has bought youa a bag of Doritos Potato chips!',
                      'has bought youa a bag of Cheetos Potato chips!',
                      'has bought youa a bag of opened Potato chips.'
                  ],
                  getChips: function () {
                      var c = Math.floor(Math.random() * this.chipss.length);
                      return this.chipss[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatchips);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserchips, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfchips, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.chips, {nameto: user.username, namefrom: chat.un, chips: this.getChips()}));
                              }
                          }
                      }
                  }
              },
              
              cupcakeCommand: {
                  command: ['cupcake','cup cake','cupcakes'],
                  rank: 'bouncer',
                  type: 'startsWith',
                  cupcakes: ['has bought you a Chocolate cupcake!',
                      'has bought you a Vanilla flavored cupcake with strawberry creame topping!',
                      'has bought you a Vanilla flavored cupcake!',
                      'has bought you a Pumpkin flavored cupcake!',
                      'has bought you a Banana flavored cupcake!',
                      'has bought you a Coffee flavored cupcake!',
                      'has bought you a Lemon flavored cupcake!',
                      'has bought you a Peanut Butter flavored cupcake!',
                      'has bought you a Chocolate flavored cupcake with Vanilla creame topping!',
                      'has bought you a Vanilla flavored cupcake with Chocolate creame topping!',
                      'has bought you a Vanilla flavored cupcake with a cherry topping!',
                      'has bought you a Chocolate flavored cupcake with a cherry topping!',
                      'has bought you a cupcake with a worm dancing! "I think that is a real worm."'
                  ],
                  getCupcake: function () {
                      var c = Math.floor(Math.random() * this.cupcakes.length);
                      return this.cupcakes[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatcupcake);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nousercupcake, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfcupcake, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.cupcake, {nameto: user.username, namefrom: chat.un, cupcake: this.getCupcake()}));
                              }
                          }
                      }
                  }
              },
              
              burgerCommand: {
                  command: ['burger','burgers'],
                  rank: 'bouncer',
                  type: 'startsWith',
                  burgers: ['has bought you a Chicken burger! ',
                      'has bought you a Cajun Chicken burger! ',
                      'has bought you a Beef burger! ',
                      'has bought you a Angus burger! ',
                      'has bought you a Fish burger! ',
                      'has bought you a Vegetarian burger! ',
                      'has bought you a Prawn burger! ',
                      'has bought you a Crab burger! ',
                      'has bought you a Rice burger! ',
                      'has bought you a Hamburger! ',
                      'has bought you a Cheeseburger! ',
                      'has bought you a Teriyaki burger! ',
                      'has bought you a Krusty burger! ',
                      'has bought you a Cartman burger! ',
                      'has bought you a Burger King burger! ',
                      'has bought you a MacDonalds burger! ',
                      'has bought you a KFC burger! ',
                      'has bought you a Wendys burger! ',
                      'has bought you a White Castle burger! ',
                      'has bought you a  Beef Deluxe burger. "Would you like fries with that heart-attack?" '
                  ],
                  getBurger: function () {
                      var c = Math.floor(Math.random() * this.burgers.length);
                      return this.burgers[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatburger);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserburger, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfburger, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.burger, {nameto: user.username, namefrom: chat.un, burger: this.getBurger()}));
                              }
                          }
                      }
                  }
              },
              
              drinkCommand: {
                  command: ['drink','drinks'],
                  rank: 'user',
                  type: 'startsWith',
                  drinks: ['has bought you a cup of Apple juice! ',
                      'has bought you a glass of chilled Cola!!',
                      'has bought you a cup of Cranberry juice!',
                      'has bought you a cup of Chocolate Milk!',
                      'has bought you a glass of Sprite!',
                      'has bought you a glass of freshly squeezed Orange juice!',
                      'has bought you a glass of freshly squeezed Lemon juice!',
                      'has bought you a glass of plain water. Although it seems to be fizzy....',
                      'has bought you a glass of expired Milk. Oh well, its yoghurt now.',
                      'has bought you an empty glass...'
                  ],
                  getDrink: function () {
                      var c = Math.floor(Math.random() * this.drinks.length);
                      return this.drinks[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatdrink);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserdrink, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfdrink, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.drink, {nameto: user.username, namefrom: chat.un, drink: this.getDrink()}));
                              }
                          }
                      }
                  }
              },
              
              profileCommand: {
                  command: ['stalk','stalker','profile'],
                  rank: 'user',
                  type: 'startsWith',
                  profiles: [' https://plug.dj/@/'
                  ],
                  getProfile: function () {
                      var c = Math.floor(Math.random() * this.profiles.length);
                      return this.profiles[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatprofile);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserprofile, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfprofile, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.profile, {nameto: user.username.toLowerCase().replace(/ /g, "-").replace(/_/g, "-"), namefrom: chat.un, profile: this.getProfile()}));
                              }
                          }
                      }
                  }
              },
              
              punishCommand: {
                  command: ['punish','slap','kick'],
                  rank: 'bouncer',
                  type: 'startsWith',
                  punishs: ['HAI-YAH!!!!',
                      'misserably failing to kick you https://imageshack.com/a/img540/9347/VeTD8u.gif',
                      'shaking you like a baby in the air! https://imageshack.com/a/img913/9183/0y41Gv.gif',
                      'clobbering your shin! https://imageshack.com/a/img631/4016/VU3ax3.gif',
                      'tying you up onto a railtrack! https://imageshack.com/a/img904/6752/6e8GnE.gif',
                      'throwing a pie to your face! https://imageshack.com/a/img901/1997/sTW9Av.gif',
                      'missing to shoot you at point blank range. What a FAIL! https://imageshack.com/a/img537/4028/9S7ZyR.gif',
                      'bravely slapping you in the face, like a Gentleman! https://imageshack.com/a/img746/5395/7VupRH.gif',
                      'shooting himself in the face, at the very last msecond... https://imageshack.com/a/img908/5887/bij6vR.gif',
                      'punching you in the face. https://imageshack.com/a/img673/9980/X8jND1.gif'
                  ],
                  getPunish: function () {
                      var c = Math.floor(Math.random() * this.punishs.length);
                      return this.punishs[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              API.sendChat(basicBot.chat.eatpunish);
                              return false;
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserpunish, {name: name}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfpunish, {name: name}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.punish, {nameto: user.username, namefrom: chat.un, punish: this.getPunish()}));
                              }
                          }
                      }
                  }
              },
              
              diceCommand: {
                  command: ['roll_dice','dice','roll'],
                  rank: 'user',
                  type: 'startsWith',
                  dices: ['has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled an One. https://imageshack.com/a/img538/9612/nkX6X3.gif',
                      'has rolled a Two. https://imageshack.com/a/img540/8616/pzrH5R.gif',
                      'has rolled a Two. https://imageshack.com/a/img540/8616/pzrH5R.gif',
                      'has rolled a Two. https://imageshack.com/a/img540/8616/pzrH5R.gif',
                      'has rolled a Two. https://imageshack.com/a/img540/8616/pzrH5R.gif',
                      'has rolled a Two. https://imageshack.com/a/img540/8616/pzrH5R.gif',
                      'has rolled a Three. https://imageshack.com/a/img674/7615/FCpxMK.gif',
                      'has rolled a Three. https://imageshack.com/a/img674/7615/FCpxMK.gif',
                      'has rolled a Three. https://imageshack.com/a/img674/7615/FCpxMK.gif',
                      'has rolled a Three. https://imageshack.com/a/img674/7615/FCpxMK.gif',
                      'has rolled a Four. https://imageshack.com/a/img661/6979/xqWXgG.gif',
                      'has rolled a Four. https://imageshack.com/a/img661/6979/xqWXgG.gif',
                      'has rolled a Four. https://imageshack.com/a/img661/6979/xqWXgG.gif',
                      'has rolled a Five! https://imageshack.com/a/img901/2489/2kDsyq.gif',
                      'has rolled a Five! https://imageshack.com/a/img901/2489/2kDsyq.gif',
                      'has rolled a SIX !!! Contact the Host or Co-host for a prize! https://imageshack.com/a/img538/9670/EohWHp.gif'
                  ],
                  getDice: function () {
                      var c = Math.floor(Math.random() * this.dices.length);
                      return this.dices[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              return API.sendChat(subChat(basicBot.chat.eatdice, {namefrom: chat.un, dice: this.getDice()}));
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserdice, {namefrom: chat.un, dice: this.getDice()}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfdice, {namefrom: chat.un, dice: this.getDice()}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.dice, {nameto: user.username, namefrom: chat.un, dice: this.getDice()}));
                              }
                          }
                      }
                  }
              },
              
              prizeCommand: {
                  command: 'prize',
                  rank: 'cohost',
                  type: 'startsWith',
                  prizes: ['http://38.media.tumblr.com/47989f8687222cdac6d110c83f5f7479/tumblr_n9kgddpyhw1r6i0nlo1_1280.gif'
                  ],
                  getDice: function () {
                      var c = Math.floor(Math.random() * this.prizes.length);
                      return this.prizes[c];
                  },
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
  
                          var space = msg.indexOf(' ');
                          if (space === -1) {
                              return API.sendChat(subChat(basicBot.chat.eatprize, {namefrom: chat.un, prize: this.getPrize()}));
                          }
                          else {
                              var name = msg.substring(space + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (user === false || !user.inRoom) {
                                  return API.sendChat(subChat(basicBot.chat.nouserprize, {namefrom: chat.un, prize: this.getPrize()}));
                              }
                              else if (user.username === chat.un) {
                                  return API.sendChat(subChat(basicBot.chat.selfprize, {namefrom: chat.un, prize: this.getPrize()}));
                              }
                              else {
                                  return API.sendChat(subChat(basicBot.chat.prize, {nameto: user.username, namefrom: chat.un, prize: this.getPrize()}));
                              }
                          }
                      }
                  }
              },
              
              cycleguardCommand: {
                  command: 'cycleguard',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.cycleGuard) {
                              basicBot.settings.cycleGuard = !basicBot.settings.cycleGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.cycleguard}));
                          }
                          else {
                              basicBot.settings.cycleGuard = !basicBot.settings.cycleGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.cycleguard}));
                          }
  
                      }
                  }
              },
  
              cycletimerCommand: {
                  command: 'cycletimer',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var cycleTime = msg.substring(cmd.length + 1);
                          if (!isNaN(cycleTime) && cycleTime !== "") {
                              basicBot.settings.maximumCycletime = cycleTime;
                              return API.sendChat(subChat(basicBot.chat.cycleguardtime, {name: chat.un, time: basicBot.settings.maximumCycletime}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
  
                      }
                  }
              },
  
              dclookupCommand: {
                  command: ['dclookup','dc'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var name;
                          if (msg.length === cmd.length) name = chat.un;
                          else {
                              name = msg.substring(cmd.length + 2);
                              var perm = basicBot.userUtilities.getPermission(chat.uid);
                              if (perm < 2) return API.sendChat(subChat(basicBot.chat.dclookuprank, {name: chat.un}));
                          }
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var toChat = basicBot.userUtilities.dclookup(user.id);
                          API.sendChat(toChat);
                      }
                  }
              },
              
              deletechatCommand: {
                  command: 'deletechat',
                  rank: 'mod',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substring(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var chats = $('.from');
                          for(var i = 0; i < chats.length; i++){
                              var n = chats[i].textContent;
                              if(name.trim() === n.trim()){
                                  var cid = $(chats[i]).parent()[0].getAttribute('data-cid');
                                  API.moderateDeleteChat(cid);
                              }
                          }
                          API.sendChat(subChat(basicBot.chat.deletechat,{name: chat.un, username: name}));
                      }
                  }
              },
  
              emojiCommand: {
                  command: 'emoji',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var link = 'http://www.emoji-cheat-sheet.com/';
                          API.sendChat(subChat(basicBot.chat.emojilist, {link: link}));
                      }
                  }
              },
  
              etaCommand: {
                  command: 'eta',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var perm = basicBot.userUtilities.getPermission(chat.uid);
                          var msg = chat.message;
                          var name;
                          if (msg.length > cmd.length) {
                              if (perm < 2) return void (0);
                              name = msg.substring(cmd.length + 2);
                          } else name = chat.un;
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var pos = API.getWaitListPosition(user.id);
                          if (pos < 0) return API.sendChat(subChat(basicBot.chat.notinwaitlist, {name: name}));
                          var timeRemaining = API.getTimeRemaining();
                          var estimateMS = ((pos + 1) * 4 * 60 + timeRemaining) * 1000;
                          var estimateString = basicBot.roomUtilities.msToStr(estimateMS);
                          API.sendChat(subChat(basicBot.chat.eta, {name: name, time: estimateString}));
                      }
                  }
              },
              fbCommand: {
                  command: ['fb','facebook'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.fbLink);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              orderCommand: {
                  command: ['order','food'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('This should help you get started. http://tinyurl.com/CRevZorder ' /*+ basicBot.settings.hiLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              hiCommand: {
                  command: ['hi','hello'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('HI !!! https://imageshack.com/a/img537/1306/6blhxN.gif ' /*+ basicBot.settings.hiLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              byeCommand: {
                  command: ['bye','by'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('Bye... https://imageshack.com/a/img661/2023/D8kn6q.gif ' /* + basicBot.settings.byeLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              brbCommand: {
                  command: 'brb',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('B.R.B https://imageshack.com/a/img745/7239/Z0KJQb.gif '/* + basicBot.settings.brbLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              afkCommand: {
                  command: 'afk',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('A.F.K https://imageshack.com/a/img661/4941/8XIWfa.gif ' /*+ basicBot.settings.afkLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              
              jalbaCommand: {
                  command: 'jessica_alba',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('Jessica Alba says, "Im taken and in a relationship with Lord_Tryzalot" https://imageshack.com/a/img904/9496/WAEX9h.gif ' /*+ basicBot.settings.afkLink*/);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
  
              filterCommand: {
                  command: 'filter',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.filterChat) {
                              basicBot.settings.filterChat = !basicBot.settings.filterChat;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.chatfilter}));
                          }
                          else {
                              basicBot.settings.filterChat = !basicBot.settings.filterChat;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.chatfilter}));
                          }
                      }
                  }
              },
  
              helpCommand: {
                  command: 'help',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var link = "http://i.imgur.com/SBAso1N.jpg";
                          API.sendChat(subChat(basicBot.chat.starterhelp, {link: link}));
                      }
                  }
              },
  
              joinCommand: {
                  command: 'join',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.room.roulette.rouletteStatus && basicBot.room.roulette.participants.indexOf(chat.uid) < 0) {
                              basicBot.room.roulette.participants.push(chat.uid);
                              API.sendChat(subChat(basicBot.chat.roulettejoin, {name: chat.un}));
                          }
                      }
                  }
              },
  
              jointimeCommand: {
                  command: 'jointime',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substring(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var join = basicBot.userUtilities.getJointime(user);
                          var time = Date.now() - join;
                          var timeString = basicBot.roomUtilities.msToStr(time);
                          API.sendChat(subChat(basicBot.chat.jointime, {namefrom: chat.un, username: name, time: timeString}));
                      }
                  }
              },
  
              kickCommand: {
                  command: 'kick',
                  rank: 'host',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var lastSpace = msg.lastIndexOf(' ');
                          var time;
                          var name;
                          if (lastSpace === msg.indexOf(' ')) {
                              time = 0.25;
                              name = msg.substring(cmd.length + 2);
                          }
                          else {
                              time = msg.substring(lastSpace + 1);
                              name = msg.substring(cmd.length + 2, lastSpace);
                          }
  
                          var user = basicBot.userUtilities.lookupUserName(name);
                          var from = chat.un;
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
  
                          var permFrom = basicBot.userUtilities.getPermission(chat.uid);
                          var permTokick = basicBot.userUtilities.getPermission(user.id);
  
                          if (permFrom <= permTokick)
                              return API.sendChat(subChat(basicBot.chat.kickrank, {name: chat.un}));
  
                          if (!isNaN(time)) {
                              API.sendChat(subChat(basicBot.chat.kick, {name: chat.un, username: name, time: time}));
                              if (time > 24 * 60 * 60) API.moderateBanUser(user.id, 1, API.BAN.PERMA);
                              else API.moderateBanUser(user.id, 1, API.BAN.DAY);
                              setTimeout(function (id, name) {
                                  API.moderateUnbanUser(id);
                                  console.log('Unbanned @' + name + '. ('+id+')');
                              }, time * 60 * 1000, user.id, name);
                          }
                          else API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                      }
                  }
              },
  
              killCommand: {
                  command: 'kill',
                  rank: 'host',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          storeToStorage();
                          API.sendChat(basicBot.chat.kill);
                          basicBot.disconnectAPI();
                          setTimeout(function () {
                              kill();
                          }, 1000);
                      }
                  }
              },
  
              leaveCommand: {
                  command: 'leave',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var ind = basicBot.room.roulette.participants.indexOf(chat.uid);
                          if (ind > -1) {
                              basicBot.room.roulette.participants.splice(ind, 1);
                              API.sendChat(subChat(basicBot.chat.rouletteleave, {name: chat.un}));
                          }
                      }
                  }
              },
  
              linkCommand: {
                  command: ['link','song'],
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var media = API.getMedia();
                          var from = chat.un;
                          var user = basicBot.userUtilities.lookupUser(chat.uid);
                          var perm = basicBot.userUtilities.getPermission(chat.uid);
                          var dj = API.getDJ().id;
                          var isDj = false;
                          if (dj === chat.uid) isDj = true;
                          if (perm >= 1 || isDj) {
                              if (media.format === 1) {
                                  var linkToSong = "https://www.youtube.com/watch?v=" + media.cid;
                                  API.sendChat(subChat(basicBot.chat.songlink, {name: from, link: linkToSong}));
                              }
                              if (media.format === 2) {
                                  SC.get('/tracks/' + media.cid, function (sound) {
                                      API.sendChat(subChat(basicBot.chat.songlink, {name: from, link: sound.permalink_url}));
                                  });
                              }
                          }
                      }
                  }
              },
  
              lockCommand: {
                  command: 'lock',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          basicBot.roomUtilities.booth.lockBooth();
                      }
                  }
              },
  
              lockdownCommand: {
                  command: 'lockdown',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var temp = basicBot.settings.lockdownEnabled;
                          basicBot.settings.lockdownEnabled = !temp;
                          if (basicBot.settings.lockdownEnabled) {
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.lockdown}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.lockdown}));
                      }
                  }
              },
  
              lockguardCommand: {
                  command: 'lockguard',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.lockGuard) {
                              basicBot.settings.lockGuard = !basicBot.settings.lockGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.lockdown}));
                          }
                          else {
                              basicBot.settings.lockGuard = !basicBot.settings.lockGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.lockguard}));
                          }
                      }
                  }
              },
  
              lockskipCommand: {
                  command: 'lockskip',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.room.skippable) {
                              var dj = API.getDJ();
                              var id = dj.id;
                              var name = dj.username;
                              var msgSend = '@' + name + ': ';
                              basicBot.room.queueable = false;
  
                              if (chat.message.length === cmd.length) {
                                  API.sendChat(subChat(basicBot.chat.usedlockskip, {name: chat.un}));
                                  basicBot.roomUtilities.booth.lockBooth();
                                  setTimeout(function (id) {
                                      API.moderateForceSkip();
                                      basicBot.room.skippable = false;
                                      setTimeout(function () {
                                          basicBot.room.skippable = true
                                      }, 5 * 1000);
                                      setTimeout(function (id) {
                                          basicBot.userUtilities.moveUser(id, basicBot.settings.lockskipPosition, false);
                                          basicBot.room.queueable = true;
                                          setTimeout(function () {
                                              basicBot.roomUtilities.booth.unlockBooth();
                                          }, 1000);
                                      }, 1500, id);
                                  }, 1000, id);
                                  return void (0);
                              }
                              var validReason = false;
                              var msg = chat.message;
                              var reason = msg.substring(cmd.length + 1);
                              for (var i = 0; i < basicBot.settings.lockskipReasons.length; i++) {
                                  var r = basicBot.settings.lockskipReasons[i][0];
                                  if (reason.indexOf(r) !== -1) {
                                      validReason = true;
                                      msgSend += basicBot.settings.lockskipReasons[i][1];
                                  }
                              }
                              if (validReason) {
                                  API.sendChat(subChat(basicBot.chat.usedlockskip, {name: chat.un}));
                                  basicBot.roomUtilities.booth.lockBooth();
                                  setTimeout(function (id) {
                                      API.moderateForceSkip();
                                      basicBot.room.skippable = false;
                                      API.sendChat(msgSend);
                                      setTimeout(function () {
                                          basicBot.room.skippable = true
                                      }, 5 * 1000);
                                      setTimeout(function (id) {
                                          basicBot.userUtilities.moveUser(id, basicBot.settings.lockskipPosition, false);
                                          basicBot.room.queueable = true;
                                          setTimeout(function () {
                                              basicBot.roomUtilities.booth.unlockBooth();
                                          }, 1000);
                                      }, 1500, id);
                                  }, 1000, id);
                                  return void (0);
                              }
                          }
                      }
                  }
              },
  
              lockskipposCommand: {
                  command: 'lockskippos',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var pos = msg.substring(cmd.length + 1);
                          if (!isNaN(pos)) {
                              basicBot.settings.lockskipPosition = pos;
                              return API.sendChat(subChat(basicBot.chat.lockskippos, {name: chat.un, position: basicBot.settings.lockskipPosition}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.invalidpositionspecified, {name: chat.un}));
                      }
                  }
              },
  
              locktimerCommand: {
                  command: 'locktimer',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var lockTime = msg.substring(cmd.length + 1);
                          if (!isNaN(lockTime) && lockTime !== "") {
                              basicBot.settings.maximumLocktime = lockTime;
                              return API.sendChat(subChat(basicBot.chat.lockguardtime, {name: chat.un, time: basicBot.settings.maximumLocktime}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                      }
                  }
              },
  
              maxlengthCommand: {
                  command: 'maxlength',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var maxTime = msg.substring(cmd.length + 1);
                          if (!isNaN(maxTime)) {
                              basicBot.settings.maximumSongLength = maxTime;
                              return API.sendChat(subChat(basicBot.chat.maxlengthtime, {name: chat.un, time: basicBot.settings.maximumSongLength}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                      }
                  }
              },
  
              motdCommand: {
                  command: 'motd',
                  rank: 'cohost',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me MotD: ' + basicBot.settings.motd);
                          var argument = msg.substring(cmd.length + 1);
                          if (!basicBot.settings.motdEnabled) basicBot.settings.motdEnabled = !basicBot.settings.motdEnabled;
                          if (isNaN(argument)) {
                              basicBot.settings.motd = argument;
                              API.sendChat(subChat(basicBot.chat.motdset, {msg: basicBot.settings.motd}));
                          }
                          else {
                              basicBot.settings.motdInterval = argument;
                              API.sendChat(subChat(basicBot.chat.motdintervalset, {interval: basicBot.settings.motdInterval}));
                          }
                      }
                  }
              },
  
              moveCommand: {
                  command: 'move',
                  rank: 'mod',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var firstSpace = msg.indexOf(' ');
                          var lastSpace = msg.lastIndexOf(' ');
                          var pos;
                          var name;
                          if (isNaN(parseInt(msg.substring(lastSpace + 1)))) {
                              pos = 1;
                              name = msg.substring(cmd.length + 2);
                          }
                          else {
                              pos = parseInt(msg.substring(lastSpace + 1));
                              name = msg.substring(cmd.length + 2, lastSpace);
                          }
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          if (user.id === basicBot.loggedInID) return API.sendChat(subChat(basicBot.chat.addbotwaitlist, {name: chat.un}));
                          if (!isNaN(pos)) {
                              API.sendChat(subChat(basicBot.chat.move, {name: chat.un}));
                              basicBot.userUtilities.moveUser(user.id, pos, false);
                          } else return API.sendChat(subChat(basicBot.chat.invalidpositionspecified, {name: chat.un}));
                      }
                  }
              },
  
              muteCommand: {
                  command: 'mute',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var lastSpace = msg.lastIndexOf(' ');
                          var time = null;
                          var name;
                          if (lastSpace === msg.indexOf(' ')) {
                              name = msg.substring(cmd.length + 2);
                              time = 45;
                          }
                          else {
                              time = msg.substring(lastSpace + 1);
                              if (isNaN(time) || time == "" || time == null || typeof time == "undefined") {
                                  return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                              }
                              name = msg.substring(cmd.length + 2, lastSpace);
                          }
                          var from = chat.un;
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var permFrom = basicBot.userUtilities.getPermission(chat.uid);
                          var permUser = basicBot.userUtilities.getPermission(user.id);
                          if (permFrom > permUser) {
                              /*
                              basicBot.room.mutedUsers.push(user.id);
                              if (time === null) API.sendChat(subChat(basicBot.chat.mutednotime, {name: chat.un, username: name}));
                              else {
                                  API.sendChat(subChat(basicBot.chat.mutedtime, {name: chat.un, username: name, time: time}));
                                  setTimeout(function (id) {
                                      var muted = basicBot.room.mutedUsers;
                                      var wasMuted = false;
                                      var indexMuted = -1;
                                      for (var i = 0; i < muted.length; i++) {
                                          if (muted[i] === id) {
                                              indexMuted = i;
                                              wasMuted = true;
                                          }
                                      }
                                      if (indexMuted > -1) {
                                          basicBot.room.mutedUsers.splice(indexMuted);
                                          var u = basicBot.userUtilities.lookupUser(id);
                                          var name = u.username;
                                          API.sendChat(subChat(basicBot.chat.unmuted, {name: chat.un, username: name}));
                                      }
                                  }, time * 60 * 1000, user.id);
                              }
                              */
                              if(time > 45){
                                  API.sendChat(subChat(basicBot.chat.mutedmaxtime, {name: chat.un, time: "45"}));
                                  API.moderateMuteUser(user.id, 1, API.MUTE.LONG);
                              }
                              else if(time === 45){
                                  API.moderateMuteUser(user.id, 1, API.MUTE.LONG);
                                  API.sendChat(subChat(basicBot.chat.mutedtime, {name: chat.un, username: name, time: time}));
  
                              }
                              else if(time > 30){
                                  API.moderateMuteUser(user.id, 1, API.MUTE.MEDIUM);
                                  API.sendChat(subChat(basicBot.chat.mutedtime, {name: chat.un, username: name, time: time}));
                                  setTimeout(function(id){
                                      API.moderateUnmuteUser(id);
                                  }, time * 60 * 1000, user.id);
                              }
                              else {
                                  API.moderateMuteUser(user.id, 1, API.MUTE.SHORT);
                                  API.sendChat(subChat(basicBot.chat.mutedtime, {name: chat.un, username: name, time: time}));
                                  setTimeout(function(id){
                                      API.moderateUnmuteUser(id);
                                  }, time * 60 * 1000, user.id);
                              }
                          }
                          else API.sendChat(subChat(basicBot.chat.muterank, {name: chat.un}));
                      }
                  }
              },
              opCommand: {
                  command: 'op',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.opLink);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
  
              pingCommand: {
                  command: ['ping','test'],
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(basicBot.chat.pong)
                      }
                  }
              },
  
              refreshCommand: {
                  command: 'refresh',
                  rank: 'host',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          storeToStorage();
                          basicBot.disconnectAPI();
                          setTimeout(function () {
                              window.location.reload(false);
                          }, 1000);
  
                      }
                  }
              },
  
              reloadCommand: {
                  command: 'reload',
                  rank: 'cohost',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(basicBot.chat.reload);
                          storeToStorage();
                          basicBot.disconnectAPI();
                          kill();
                          setTimeout(function () {
                              $.getScript(basicBot.scriptLink);
                          }, 2000);
                      }
                  }
              },
  
              removeCommand: {
                  command: 'remove',
                  rank: 'mod',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length > cmd.length + 2) {
                              var name = msg.substr(cmd.length + 2);
                              var user = basicBot.userUtilities.lookupUserName(name);
                              if (typeof user !== 'boolean') {
                                  user.lastDC = {
                                      time: null,
                                      position: null,
                                      songCount: 0
                                  };
                                  if(API.getDJ().id === user.id){
                                      API.moderateForceSkip();
                                      setTimeout(function(){
                                          API.moderateRemoveDJ(user.id);
                                      }, 1*1000, user);
                                  }
                                  else API.moderateRemoveDJ(user.id);
                              } else API.sendChat(subChat(basicBot.chat.removenotinwl, {name: chat.un, username: name}));
                          } else API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                      }
                  }
              },
  
              restrictetaCommand: {
                  command: 'restricteta',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.etaRestriction) {
                              basicBot.settings.etaRestriction = !basicBot.settings.etaRestriction;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.etarestriction}));
                          }
                          else {
                              basicBot.settings.etaRestriction = !basicBot.settings.etaRestriction;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.etarestriction}));
                          }
                      }
                  }
              },
  
              rouletteCommand: {
                  command: 'roulette',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (!basicBot.room.roulette.rouletteStatus) {
                              basicBot.room.roulette.startRoulette();
                          }
                      }
                  }
              },
              
              rulesCommand: {
                  command: ['rules','rule'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.rulesLink);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
  
              sessionstatsCommand: {
                  command: 'sessionstats',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var from = chat.un;
                          var woots = basicBot.room.roomstats.totalWoots;
                          var mehs = basicBot.room.roomstats.totalMehs;
                          var grabs = basicBot.room.roomstats.totalCurates;
                          API.sendChat(subChat(basicBot.chat.sessionstats, {name: from, woots: woots, mehs: mehs, grabs: grabs}));
                      }
                  }
              },
  
              skipCommand: {
                  command: 'skip',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat(subChat(basicBot.chat.skip, {name: chat.un}));
                          API.moderateForceSkip();
                          basicBot.room.skippable = false;
                          setTimeout(function () {
                              basicBot.room.skippable = true
                          }, 5 * 1000);
  
                      }
                  }
              },
  
              songstatsCommand: {
                  command: 'songstats',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.songstats) {
                              basicBot.settings.songstats = !basicBot.settings.songstats;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.songstats}));
                          }
                          else {
                              basicBot.settings.songstats = !basicBot.settings.songstats;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.songstats}));
                          }
                      }
                  }
              },
  
              sourceCommand: {
                  command: 'source',
                  rank: 'user',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          API.sendChat('/me This bot was made by ' + botCreator + '.');
                      }
                  }
              },
  
              statusCommand: {
                  command: 'status',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var from = chat.un;
                          var msg = '/me [@' + from + '] ';
  
                          msg += basicBot.chat.afkremoval + ': ';
                          if (basicBot.settings.afkRemoval) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
                          msg += basicBot.chat.afksremoved + ": " + basicBot.room.afkList.length + '. ';
                          msg += basicBot.chat.afklimit + ': ' + basicBot.settings.maximumAfk + '. ';
  
                          msg += 'Bouncer+: ';
                          if (basicBot.settings.bouncerPlus) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
  
                          msg += basicBot.chat.lockguard + ': ';
                          if (basicBot.settings.lockGuard) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
  
                          msg += basicBot.chat.cycleguard + ': ';
                          if (basicBot.settings.cycleGuard) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
  
                          msg += basicBot.chat.timeguard + ': ';
                          if (basicBot.settings.timeGuard) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
  
                          msg += basicBot.chat.chatfilter + ': ';
                          if (basicBot.settings.filterChat) msg += 'ON';
                          else msg += 'OFF';
                          msg += '. ';
  
                          var launchT = basicBot.room.roomstats.launchTime;
                          var durationOnline = Date.now() - launchT;
                          var since = basicBot.roomUtilities.msToStr(durationOnline);
                          msg += subChat(basicBot.chat.activefor, {time: since});
  
                          return API.sendChat(msg);
                      }
                  }
              },
  
              swapCommand: {
                  command: 'swap',
                  rank: 'mod',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var firstSpace = msg.indexOf(' ');
                          var lastSpace = msg.lastIndexOf(' ');
                          var name1 = msg.substring(cmd.length + 2, lastSpace);
                          var name2 = msg.substring(lastSpace + 2);
                          var user1 = basicBot.userUtilities.lookupUserName(name1);
                          var user2 = basicBot.userUtilities.lookupUserName(name2);
                          if (typeof user1 === 'boolean' || typeof user2 === 'boolean') return API.sendChat(subChat(basicBot.chat.swapinvalid, {name: chat.un}));
                          if (user1.id === basicBot.loggedInID || user2.id === basicBot.loggedInID) return API.sendChat(subChat(basicBot.chat.addbottowaitlist, {name: chat.un}));
                          var p1 = API.getWaitListPosition(user1.id) +1;
                          var p2 = API.getWaitListPosition(user2.id) +1;
                          if (p1 < 0 || p2 < 0) return API.sendChat(subChat(basicBot.chat.swapwlonly, {name: chat.un}));
                          API.sendChat(subChat(basicBot.chat.swapping, {'name1': name1, 'name2': name2}));
                          if (p1 < p2) {
                              basicBot.userUtilities.moveUser(user2.id, p1, false);
                              setTimeout(function (user1, p2) {
                                  basicBot.userUtilities.moveUser(user1.id, p2, false);
                              }, 2000, user1, p2);
                          }
                          else {
                              basicBot.userUtilities.moveUser(user1.id, p2, false);
                              setTimeout(function (user2, p1) {
                                  basicBot.userUtilities.moveUser(user2.id, p1, false);
                              }, 2000, user2, p1);
                          }
                      }
                  }
              },
              themeCommand: {
                  command: ['theme','genre'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.themeLink);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
  
              timeguardCommand: {
                  command: 'timeguard',
                  rank: 'bouncer',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.timeGuard) {
                              basicBot.settings.timeGuard = !basicBot.settings.timeGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.timeguard}));
                          }
                          else {
                              basicBot.settings.timeGuard = !basicBot.settings.timeGuard;
                              return API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.timeguard}));
                          }
  
                      }
                  }
              },
  
              togglemotdCommand: {
                  command: 'togglemotd',
                  rank: 'cohost',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.motdEnabled) {
                              basicBot.settings.motdEnabled = !basicBot.settings.motdEnabled;
                              API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.motd}));
                          }
                          else {
                              basicBot.settings.motdEnabled = !basicBot.settings.motdEnabled;
                              API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.motd}));
                          }
                      }
                  }
              },
  
              unbanCommand: {
                  command: 'unban',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          $(".icon-population").click();
                          $(".icon-ban").click();
                          setTimeout(function (chat) {
                              var msg = chat.message;
                              if (msg.length === cmd.length) return API.sendChat();
                              var name = msg.substring(cmd.length + 2);
                              var bannedUsers = API.getBannedUsers();
                              var found = false;
                              for (var i = 0; i < bannedUsers.length; i++) {
                                  var user = bannedUsers[i];
                                  if (user.username === name) {
                                      bannedUser = user;
                                      found = true;
                                  }
                              }
                              if (!found) {
                                  $(".icon-chat").click();
                                  return API.sendChat(subChat(basicBot.chat.notbanned, {name: chat.un}));
                              }
                              API.moderateUnbanUser(bannedUser.id);
                              console.log("Unbanned " + name);
                              setTimeout(function () {
                                  $(".icon-chat").click();
                              }, 1000);
                          }, 1000, chat);
                      }
                  }
              },
  
              unlockCommand: {
                  command: 'unlock',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          basicBot.roomUtilities.booth.unlockBooth();
                      }
                  }
              },
  
              unmuteCommand: {
                  command: 'unmute',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var permFrom = basicBot.userUtilities.getPermission(chat.uid);
                          /**
                          if (msg.indexOf('@') === -1 && msg.indexOf('all') !== -1) {
                              if (permFrom > 2) {
                                  basicBot.room.mutedUsers = [];
                                  return API.sendChat(subChat(basicBot.chat.unmutedeveryone, {name: chat.un}));
                              }
                              else return API.sendChat(subChat(basicBot.chat.unmuteeveryonerank, {name: chat.un}));
                          }
                          **/
                          var from = chat.un;
                          var name = msg.substr(cmd.length + 2);
  
                          var user = basicBot.userUtilities.lookupUserName(name);
  
                          if (typeof user === 'boolean') return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
  
                          var permUser = basicBot.userUtilities.getPermission(user.id);
                          if (permFrom > permUser) {
                              /*
                              var muted = basicBot.room.mutedUsers;
                              var wasMuted = false;
                              var indexMuted = -1;
                              for (var i = 0; i < muted.length; i++) {
                                  if (muted[i] === user.id) {
                                      indexMuted = i;
                                      wasMuted = true;
                                  }
  
                              }
                              if (!wasMuted) return API.sendChat(subChat(basicBot.chat.notmuted, {name: chat.un}));
                              basicBot.room.mutedUsers.splice(indexMuted);
                              API.sendChat(subChat(basicBot.chat.unmuted, {name: chat.un, username: name}));
                              */
                              try{
                                  API.moderateUnmuteUser(user.id);
                                  API.sendChat(subChat(basicBot.chat.unmuted, {name: chat.un, username: name}));
                              }
                              catch(e){
                                  API.sendChat(subChat(basicBot.chat.notmuted, {name: chat.un}));
                              }
                          }
                          else API.sendChat(subChat(basicBot.chat.unmuterank, {name: chat.un}));
                      }
                  }
              },
  
              usercmdcdCommand: {
                  command: 'usercmdcd',
                  rank: 'manager',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          var cd = msg.substring(cmd.length + 1);
                          if (!isNaN(cd)) {
                              basicBot.settings.commandCooldown = cd;
                              return API.sendChat(subChat(basicBot.chat.commandscd, {name: chat.un, time: basicBot.settings.commandCooldown}));
                          }
                          else return API.sendChat(subChat(basicBot.chat.invalidtime, {name: chat.un}));
                      }
                  }
              },
  
              usercommandsCommand: {
                  command: 'usercommands',
                  rank: 'manager',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.usercommandsEnabled) {
                              API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.usercommands}));
                              basicBot.settings.usercommandsEnabled = !basicBot.settings.usercommandsEnabled;
                          }
                          else {
                              API.sendChat(subChat(basicBot.chat.toggleon, {name: chat.un, 'function': basicBot.chat.usercommands}));
                              basicBot.settings.usercommandsEnabled = !basicBot.settings.usercommandsEnabled;
                          }
                      }
                  }
              },
  
              voteratioCommand: {
                  command: 'voteratio',
                  rank: 'bouncer',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length === cmd.length) return API.sendChat(subChat(basicBot.chat.nouserspecified, {name: chat.un}));
                          var name = msg.substring(cmd.length + 2);
                          var user = basicBot.userUtilities.lookupUserName(name);
                          if (user === false) return API.sendChat(subChat(basicBot.chat.invaliduserspecified, {name: chat.un}));
                          var vratio = user.votes;
                          var ratio = vratio.woot / vratio.meh;
                          API.sendChat(subChat(basicBot.chat.voteratio, {name: chat.un, username: name, woot: vratio.woot, mehs: vratio.meh, ratio: ratio.toFixed(2)}));
                      }
                  }
              },
  
              welcomeCommand: {
                  command: 'welcome',
                  rank: 'mod',
                  type: 'exact',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          if (basicBot.settings.welcome) {
                              basicBot.settings.welcome = !basicBot.settings.welcome;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.welcomemsg}));
                          }
                          else {
                              basicBot.settings.welcome = !basicBot.settings.welcome;
                              return API.sendChat(subChat(basicBot.chat.toggleoff, {name: chat.un, 'function': basicBot.chat.welcomemsg}));
                          }
                      }
                  }
              },
              
              websiteCommand: {
                  command: ['site','website'],
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.website);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
              
              youtubeCommand: {
                  command: 'youtube',
                  rank: 'user',
                  type: 'startsWith',
                  functionality: function (chat, cmd) {
                      if (this.type === 'exact' && chat.message.length !== cmd.length) return void (0);
                      if (!basicBot.commands.executable(this.rank, chat)) return void (0);
                      else {
                          var msg = chat.message;
                          if (msg.length <= cmd.length + 1) return API.sendChat('/me ' + basicBot.settings.youtubeLink);
                          var argument = msg.substring(cmd.length + 1);
                          
                      }
                  }
              },
          }
      };
  
      loadChat(basicBot.startup);
  }).call(this);
  