mirror of
https://github.com/Brandon-Rozek/Rozbot.git
synced 2024-11-21 20:46:28 -05:00
Took out getters and setters and just relied upon javascript's own functionality
This commit is contained in:
parent
21f8f3c057
commit
1a4fdd041e
3 changed files with 13 additions and 36 deletions
|
@ -36,12 +36,16 @@ module.exports = function() {
|
|||
|
||||
//Gives Rozbot's response
|
||||
this.respond = function(message, user, extra) {
|
||||
|
||||
//Store if it was a private message or not
|
||||
extra = extra || {};
|
||||
extra.privateMessage = extra.privateMessage || false;
|
||||
|
||||
//Store whether or not an app wants to listen to the next message
|
||||
var inAppScope = user.inAppScope
|
||||
//Used to allow apps to get the next message
|
||||
user.listener.emit('message', message);
|
||||
|
||||
if (!inAppScope) {
|
||||
var args = [message, user.send];
|
||||
//Find the right command to run
|
||||
|
@ -54,10 +58,6 @@ module.exports = function() {
|
|||
//Run the command using user's contextual data (app by app basis)
|
||||
if (command !== undefined) {
|
||||
var userData = user.getData(command.name);
|
||||
//Attach whether or not this is a private message
|
||||
userData.privateMessage = extra.privateMessage;
|
||||
//Attach the username
|
||||
userData.username = user.username;
|
||||
command.respond.apply(command, args.concat(userData));
|
||||
}
|
||||
}
|
||||
|
|
25
User.js
25
User.js
|
@ -11,31 +11,8 @@ module.exports = function(username, sendMethod) {
|
|||
//If it doesn't exist, create it
|
||||
if (this.data[commandName] === undefined) {
|
||||
this.data[commandName] = {
|
||||
username: self.username,
|
||||
properties: [],
|
||||
setProperty: function(key, value) {
|
||||
//First make sure it doesn't already exist
|
||||
for (var i = 0; i < this.properties.length; i++) {
|
||||
//If it does then update it
|
||||
if (this.properties[i].key === key) {
|
||||
this.properties[i].value = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//If it doesnt exist then add it to the properties array
|
||||
this.properties.push({key: key, value: value});
|
||||
},
|
||||
getProperty: function(key) {
|
||||
for (var i = 0; i < this.properties.length; i++) {
|
||||
if (this.properties[i].key === key) {
|
||||
return this.properties[i].value;
|
||||
}
|
||||
}
|
||||
//Key does not exist
|
||||
return null;
|
||||
},
|
||||
isset: function(key) {
|
||||
return this.getProperty(key) !== null;
|
||||
},
|
||||
prompt: function(question) {
|
||||
question = question || "is reading your next message";
|
||||
//Inform user that the next input goes to the app
|
||||
|
|
|
@ -33,10 +33,10 @@ module.exports = new Command("Hangman", condition, function(text, send, userData
|
|||
|
||||
//Recursive guessing letters until person loses or wins
|
||||
var guessLetter = function() {
|
||||
var correctLetters = userData.getProperty("correctLetters");
|
||||
var guessedLetters = userData.getProperty("guessedLetters");
|
||||
var word = userData.getProperty("word");
|
||||
var numOfUniqueLetters = userData.getProperty("numOfUniqueLetters");
|
||||
var correctLetters = userData["correctLetters"];
|
||||
var guessedLetters = userData["guessedLetters"];
|
||||
var word = userData["word"];
|
||||
var numOfUniqueLetters = userData["numOfUniqueLetters"];
|
||||
|
||||
if (correctLetters.length === numOfUniqueLetters) {
|
||||
send("You win!!");
|
||||
|
@ -100,10 +100,10 @@ module.exports = new Command("Hangman", condition, function(text, send, userData
|
|||
send("The word is " + word.length + " letters long");
|
||||
|
||||
//Setup game variables
|
||||
userData.setProperty("word", word);
|
||||
userData.setProperty("numOfUniqueLetters", countUniqueLetters(word));
|
||||
userData.setProperty("correctLetters", []);
|
||||
userData.setProperty("guessedLetters", []);
|
||||
userData["word"] = word;
|
||||
userData["numOfUniqueLetters"] = countUniqueLetters(word);
|
||||
userData["correctLetters"] = [];
|
||||
userData["guessedLetters"] = [];
|
||||
|
||||
//start
|
||||
guessLetter();
|
||||
|
|
Loading…
Reference in a new issue