Permalink
Browse files

Merge pull request #8 from ymendel/dynamic_name

Dynamic name
  • Loading branch information...
2 parents 3044a37 + 282f129 commit 0fc3f5d908c780b43488f2fc700434ca83807002 @Houndie committed Apr 7, 2012
Showing with 14 additions and 5 deletions.
  1. +14 −5 swingbot.js
View
19 swingbot.js
@@ -46,20 +46,29 @@ bot.on('registered', function(data){
}
});
+bot.name = 'Houndbot';
+bot.on('ready', function(data) {
+ bot.userInfo(function(data) {
+ bot.name = data.name;
+ });
+});
+
bot.on('speak', function (data) {
// Get the data
var name = data.name;
var text = data.text.toLowerCase();
- if (text.match(/^houndbot/)) {
- var command = text.replace(/^houndbot\s+/, '');
+ var name_pattern = '^' + bot.name.toLowerCase();
+
+ if (text.match(new RegExp(name_pattern))) {
+ var command = text.replace(new RegExp(name_pattern + '\\s+'), '');
//Let Hounddog turn notifications on and off
if(command == "dj on"){
bot.isDj(function(result) {
if(!result){
bot.addDj(function (dummy){
- bot.speak("DJing for you! Type \'Houndbot DJ off\' to make me stop, or \'Houndbot skip\' if you don't like my song.");
+ 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.");
});
}
});
@@ -86,8 +95,8 @@ bot.on('speak', function (data) {
}
if(command == "help"){
- bot.speak("AVAILABLE COMMANDS: \'Houndbot DJ on\', \'Houndbot DJ off\', \'Houndbot skip\'," +
- "\'Houndbot dance\', \'Houndbot mystats\'");
+ bot.speak("AVAILABLE COMMANDS: \'" + bot.name + " DJ on\', \'" + bot.name + " DJ off\', \'" + bot.name + " skip\'," +
+ "\'" + bot.name + " dance\', \'" + bot.name + " mystats\'");
}
if(['dance', 'shim sham', 'shimsham', 'swingout', 'california routine', 'shake that thing', 'bust a move'].contains(command)){

0 comments on commit 0fc3f5d

Please sign in to comment.