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:
parent
8d38fffaf4
commit
c10fff756c
|
@ -6,6 +6,18 @@ from . import auth
|
||||||
from . import users
|
from . import users
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import textwrap
|
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:
|
class Message:
|
||||||
|
@ -21,6 +33,7 @@ class Message:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
lines = []
|
lines = []
|
||||||
for line in self.__text:
|
for line in self.__text:
|
||||||
|
line = __text_parse_uid(line)
|
||||||
lines += [ "" ] + textwrap.wrap(line)
|
lines += [ "" ] + textwrap.wrap(line)
|
||||||
text = "\n ".join(lines)
|
text = "\n ".join(lines)
|
||||||
time = self.__time.strftime("%I:%M:%S %p")
|
time = self.__time.strftime("%I:%M:%S %p")
|
||||||
|
|
|
@ -27,6 +27,9 @@ class User:
|
||||||
return self.__user
|
return self.__user
|
||||||
return ("%s %s" % (self.__first, self.__last)).strip()
|
return ("%s %s" % (self.__first, self.__last)).strip()
|
||||||
|
|
||||||
|
def user(self):
|
||||||
|
return self.__user
|
||||||
|
|
||||||
def email(self):
|
def email(self):
|
||||||
return self.__email
|
return self.__email
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue