Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moving bot name to a variable.

Now the behavior and output are the same as before, but everything
depends on the bot.name property, nothing in bot.on('speak') is
hard-coded.
  • Loading branch information...
commit 8faf19da9239020be301b33849bac981eb1d5b50 1 parent 6fd44ca
Yossef Mendelssohn authored

Showing 1 changed file with 9 additions and 5 deletions. Show diff stats Hide diff stats

  1. +9 5 swingbot.js
14 swingbot.js
@@ -44,19 +44,23 @@ bot.on('registered', function(data){
44 44 }
45 45 });
46 46
  47 +bot.name = 'Houndbot';
  48 +
47 49 bot.on('speak', function (data) {
48 50 // Get the data
49 51 var name = data.name;
50 52 var text = data.text.toLowerCase();
51 53
52   - if (text.match(/^houndbot/)) {
53   - var command = text.replace(/^houndbot\s+/, '');
  54 + var name_pattern = '^' + bot.name.toLowerCase();
  55 +
  56 + if (text.match(new RegExp(name_pattern))) {
  57 + var command = text.replace(new RegExp(name_pattern + '\\s+'), '');
54 58
55 59 //Let Hounddog turn notifications on and off
56 60 if(command == "dj on"){
57 61 if (!bot.isDj()) {
58 62 bot.addDj(function (dummy){
59   - bot.speak("DJing for you! Type \'Houndbot DJ off\' to make me stop, or \'Houndbot skip\' if you don't like my song.");
  63 + bot.speak("DJing for you! Type \'" + bot.name + " DJ off\' to make me stop, or \'" + bot.name + " skip\' if you don't like my song.");
60 64 });
61 65 }
62 66 }
@@ -78,8 +82,8 @@ bot.on('speak', function (data) {
78 82 }
79 83
80 84 if(command == "help"){
81   - bot.speak("AVAILABLE COMMANDS: \'Houndbot DJ on\', \'Houndbot DJ off\', \'Houndbot skip\'," +
82   - "\'Houndbot dance\', \'Houndbot mystats\'");
  85 + bot.speak("AVAILABLE COMMANDS: \'" + bot.name + " DJ on\', \'" + bot.name + " DJ off\', \'" + bot.name + " skip\'," +
  86 + "\'" + bot.name + " dance\', \'" + bot.name + " mystats\'");
83 87 }
84 88
85 89 if(['dance', 'shim sham', 'shimsham', 'swingout', 'california routine', 'shake that thing', 'bust a move'].includes(command)){

0 comments on commit 8faf19d

Please sign in to comment.
Something went wrong with that request. Please try again.