make handles case insensitive when it comes to assigning karma

remove one of the responses to bot snacks
This commit is contained in:
Morgan McMillian 2017-11-13 21:10:11 -08:00
parent eb49ac41c5
commit d57848d4e1

View file

@ -20,7 +20,6 @@ def botsnack_cb(room, event):
"That makes me happy",
"How kind!",
"Sweet.",
"Sorry, but I can't handle more right now.",
"*burp*",
"Ah.. Hiccup!"
]
@ -43,7 +42,7 @@ def karma_cb(room, event):
members = room.get_joined_members()
msender = re.search('@([\w]+_)?([^:]+)', event['sender'])
sender = msender.group(2)
tokens = re.search("([\w]+)(\-\-|\+\+)", event['content']['body'])
tokens = re.search("([\w]+)\s?(\-\-|\+\+)", event['content']['body'])
handle = tokens.group(1)
sign = tokens.group(2)
reply = ""
@ -84,11 +83,11 @@ def karma_cb(room, event):
def _set_karma(room, room_id, handle, sign):
if sign == '++':
rs.incr("partybot:k_" + room_id + "@" + handle)
rs.incr("partybot:k_" + room_id + "@" + handle.lower())
elif sign == '--':
rs.decr("partybot:k_" + room_id + "@" + handle)
rs.decr("partybot:k_" + room_id + "@" + handle.lower())
k = int(rs.get("partybot:k_" + room_id + "@" + handle))
k = int(rs.get("partybot:k_" + room_id + "@" + handle.lower()))
reply = handle + " has " + str(k) + " karma in this channel."
room.send_notice(reply)
@ -115,7 +114,7 @@ if __name__ == "__main__":
rs = redis.StrictRedis()
bot = MatrixBotAPI(config['username'], config['password'], config['url'])
bot.add_handler(MRegexHandler("([\w]+)(\-\-|\+\+)", karma_cb))
bot.add_handler(MRegexHandler("([\w]+)\s?(\-\-|\+\+)", karma_cb))
bot.add_handler(MCommandHandler("karma", show_karma_cb))
bot.add_handler(MCommandHandler("botsnack", botsnack_cb))