@@ -69,11 +69,14 @@ module.exports = (robot) ->
6969 updateScore = (word , field , username ) ->
7070 posRegex = / \+\+ /
7171 negRegex = / \-\- /
72+ names = Object .keys (robot .brain .data .users )
7273
7374 # if there is to be `plus` in score
7475 if word .indexOf (" ++" ) >= 0
7576 name = word .replace posRegex, " "
76- if username .toLowerCase () == name .toLowerCase () or name .toLowerCase () == " c"
77+ unless username .toLowerCase () in names
78+ response = " -2"
79+ else if username .toLowerCase () == name .toLowerCase ()
7780 response = " -1"
7881 else
7982 field[name .toLowerCase ()] = lastScore (name, field) + 1
@@ -84,7 +87,9 @@ module.exports = (robot) ->
8487 # if there is to be `minus` in score
8588 else if word .indexOf (" --" ) >= 0
8689 name = word .replace negRegex, " "
87- if username .toLowerCase () == name .toLowerCase ()
90+ unless username .toLowerCase () in names
91+ response = " -2"
92+ else if username .toLowerCase () == name .toLowerCase ()
8893 response = " -1"
8994 else
9095 field[name .toLowerCase ()] = lastScore (name, field) - 1
@@ -112,6 +117,7 @@ module.exports = (robot) ->
112117 # index keeping an eye on position, where next replace will be
113118 start = 0
114119 end = 0
120+ shouldSend = true
115121
116122 # for each ++/--
117123 for i in [0 ... msg .match .length ]
@@ -124,15 +130,22 @@ module.exports = (robot) ->
124130 end = start + testword .length
125131
126132 # generates response message for reply
127- if result .Response == " -1"
133+ if result .Response == " -2"
134+ if result .Name .toLowerCase () isnt " c"
135+ newmsg = " #{ testword} [Sorry, I don't know anything about #{ result .Name } .]"
136+ else
137+ shouldSend = false # Do not reply if c++ is encountered
138+ else if result .Response == " -1"
128139 newmsg = " #{ testword} [Sorry, You can't give ++ or -- to yourself.]"
129140 else
130141 newmsg = " #{ testword} [#{ result .Response } #{ result .Name } now at #{ result .New } ] "
131- oldmsg = oldmsg .substr (0 , start) + newmsg + oldmsg .substr (end+ 1 )
132- start += newmsg .length
142+ if result .Name .toLowerCase () isnt " c"
143+ oldmsg = oldmsg .substr (0 , start) + newmsg + oldmsg .substr (end+ 1 )
144+ start += newmsg .length
133145
134146 # reply with updated message
135- msg .send " #{ oldmsg} "
147+ if shouldSend
148+ msg .send " #{ oldmsg} "
136149
137150
138151 # response for score status of any <keyword>
0 commit comments