aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2016-09-24 23:17:49 +0200
committerTollef Fog Heen <tfheen@err.no>2016-09-24 23:17:49 +0200
commit85ac81b7c818e01ff38488d82870adbb7f639893 (patch)
treeed8f0ac6c6707a424588324838b6f4440870908a /wee_slack.py
parenteaab2316c50665e3553b1b7257145fef2d5df905 (diff)
downloadwee-slack-85ac81b7c818e01ff38488d82870adbb7f639893.tar.gz
Handle @@ and ## and similar correctly
Make sure we have something that's a well-formed nick before we go ahead and do silly things. Fixes: #237
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 414f6ca..a7c80f2 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -536,16 +536,17 @@ class Channel(object):
def linkify_text(self, message):
message = message.split(' ')
for item in enumerate(message):
- if item[1].startswith('@') and len(item[1]) > 1:
- named = re.match('.*[@#]([\w.]+\w)(\W*)', item[1]).groups()
- if named[0] in ["group", "channel", "here"]:
- message[item[0]] = "<!{}>".format(named[0])
- if self.server.users.find(named[0]):
- message[item[0]] = "<@{}>{}".format(self.server.users.find(named[0]).identifier, named[1])
- if item[1].startswith('#') and self.server.channels.find(item[1]):
- named = re.match('.*[@#](\w+)(\W*)', item[1]).groups()
- if self.server.channels.find(named[0]):
- message[item[0]] = "<#{}|{}>{}".format(self.server.channels.find(named[0]).identifier, named[0], named[1])
+ targets = re.match('.*([@#])([\w.]+\w)(\W*)', item[1])
+ if targets and targets.groups()[0] == '@':
+ named = targets.groups()
+ if named[1] in ["group", "channel", "here"]:
+ message[item[0]] = "<!{}>".format(named[1])
+ if self.server.users.find(named[1]):
+ message[item[0]] = "<@{}>{}".format(self.server.users.find(named[1]).identifier, named[2])
+ if targets and targets.groups()[0] == '#':
+ named = targets.groups()
+ if self.server.channels.find(named[1]):
+ message[item[0]] = "<#{}|{}>{}".format(self.server.channels.find(named[1]).identifier, named[1], named[2])
dbg(message)
return " ".join(message)