@@ -69,11 +69,14 @@ module.exports = (robot) ->
69
69
updateScore = (word , field , username ) ->
70
70
posRegex = / \+\+ /
71
71
negRegex = / \-\- /
72
+ names = Object .keys (robot .brain .data .users )
72
73
73
74
# if there is to be `plus` in score
74
75
if word .indexOf (" ++" ) >= 0
75
76
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 ()
77
80
response = " -1"
78
81
else
79
82
field[name .toLowerCase ()] = lastScore (name, field) + 1
@@ -84,7 +87,9 @@ module.exports = (robot) ->
84
87
# if there is to be `minus` in score
85
88
else if word .indexOf (" --" ) >= 0
86
89
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 ()
88
93
response = " -1"
89
94
else
90
95
field[name .toLowerCase ()] = lastScore (name, field) - 1
@@ -112,6 +117,7 @@ module.exports = (robot) ->
112
117
# index keeping an eye on position, where next replace will be
113
118
start = 0
114
119
end = 0
120
+ shouldSend = true
115
121
116
122
# for each ++/--
117
123
for i in [0 ... msg .match .length ]
@@ -124,15 +130,22 @@ module.exports = (robot) ->
124
130
end = start + testword .length
125
131
126
132
# 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"
128
139
newmsg = " #{ testword} [Sorry, You can't give ++ or -- to yourself.]"
129
140
else
130
141
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
133
145
134
146
# reply with updated message
135
- msg .send " #{ oldmsg} "
147
+ if shouldSend
148
+ msg .send " #{ oldmsg} "
136
149
137
150
138
151
# response for score status of any <keyword>
0 commit comments