Skip to content

Bug Fix #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/bye.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ ways_to_say_good_night = [
]

module.exports = (robot) ->
robot.hear /(good night|goodnight|cya|bye|nighty night)/i, (msg) ->
robot.hear /\b(good night|goodnight|cya|bye|nighty night|gn)\b/i, (msg) ->
msg.send msg.random ways_to_say_good_night
26 changes: 20 additions & 6 deletions scripts/leaderboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ module.exports = (robot) ->
updateScore = (word, field, username) ->
posRegex = /\+\+/
negRegex = /\-\-/
users = robot.brain.data.users
names = Object.keys(users).map (key) => users[key].name

# if there is to be `plus` in score
if word.indexOf("++") >= 0
name = word.replace posRegex, ""
if username.toLowerCase() == name.toLowerCase()
unless username.toLowerCase() in names
response = "-2"
else if username.toLowerCase() == name.toLowerCase()
response = "-1"
else
field[name.toLowerCase()] = lastScore(name, field) + 1
Expand All @@ -84,7 +88,9 @@ module.exports = (robot) ->
# if there is to be `minus` in score
else if word.indexOf("--") >= 0
name = word.replace negRegex, ""
if username.toLowerCase() == name.toLowerCase()
unless username.toLowerCase() in names
response = "-2"
else if username.toLowerCase() == name.toLowerCase()
response = "-1"
else
field[name.toLowerCase()] = lastScore(name, field) - 1
Expand Down Expand Up @@ -112,6 +118,7 @@ module.exports = (robot) ->
# index keeping an eye on position, where next replace will be
start = 0
end = 0
shouldSend = true

# for each ++/--
for i in [0...msg.match.length]
Expand All @@ -124,15 +131,22 @@ module.exports = (robot) ->
end = start + testword.length

# generates response message for reply
if result.Response == "-1"
if result.Response == "-2"
if result.Name.toLowerCase() isnt "c"
newmsg = "#{testword} [Sorry, I don't know anything about #{result.Name}.]"
else
shouldSend = false # Do not reply if c++ is encountered
else if result.Response == "-1"
newmsg = "#{testword} [Sorry, You can't give ++ or -- to yourself.]"
else
newmsg = "#{testword} [#{result.Response} #{result.Name} now at #{result.New}] "
oldmsg = oldmsg.substr(0, start) + newmsg + oldmsg.substr(end+1)
start += newmsg.length
if result.Name.toLowerCase() isnt "c"
oldmsg = oldmsg.substr(0, start) + newmsg + oldmsg.substr(end+1)
start += newmsg.length

# reply with updated message
msg.send "#{oldmsg}"
if shouldSend
msg.send "#{oldmsg}"


# response for score status of any <keyword>
Expand Down