Replace <@UID> strings with the target user's username

This makes it easier to know who is being spoken to.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-06-08 19:02:15 -04:00
parent 8d38fffaf4
commit c10fff756c
2 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,18 @@ from . import auth
from . import users
from datetime import datetime
import textwrap
import re
def __text_parse_uid(text):
res = text
for uid in re.findall("<@(.*?)>", text):
uid = uid.split("|")[0]
user = slack.users.info(uid)
res = re.sub("<@%s(.*?)>" % uid, "@%s" % user.user(), res)
return res
class Message:
@ -21,6 +33,7 @@ class Message:
def __str__(self):
lines = []
for line in self.__text:
line = __text_parse_uid(line)
lines += [ "" ] + textwrap.wrap(line)
text = "\n ".join(lines)
time = self.__time.strftime("%I:%M:%S %p")

View File

@ -27,6 +27,9 @@ class User:
return self.__user
return ("%s %s" % (self.__first, self.__last)).strip()
def user(self):
return self.__user
def email(self):
return self.__email