From 1a4fdd041ea60b4d0ba6f7f06574730aec830d0e Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Thu, 18 Aug 2016 17:18:48 -0400 Subject: [PATCH] Took out getters and setters and just relied upon javascript's own functionality --- Rozbot.js | 8 ++++---- User.js | 25 +------------------------ lib/commands/Hangman.js | 16 ++++++++-------- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/Rozbot.js b/Rozbot.js index 30fabef..85c09f0 100644 --- a/Rozbot.js +++ b/Rozbot.js @@ -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)); } } diff --git a/User.js b/User.js index 1f0a4f3..02efb7f 100644 --- a/User.js +++ b/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 diff --git a/lib/commands/Hangman.js b/lib/commands/Hangman.js index f3c6278..9b4d0d3 100644 --- a/lib/commands/Hangman.js +++ b/lib/commands/Hangman.js @@ -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();