Merge consecutive messages with the same author
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
7b78e9d785
commit
65e5403165
|
@ -60,7 +60,14 @@ def history(channel, timestamp):
|
||||||
|
|
||||||
m_list = []
|
m_list = []
|
||||||
for message in ret["messages"]:
|
for message in ret["messages"]:
|
||||||
m_list += [ chat.Message(message) ]
|
msg = chat.Message(message)
|
||||||
|
if len(m_list) == 0:
|
||||||
|
m_list += [ msg ]
|
||||||
|
elif m_list[-1].user() == msg.user():
|
||||||
|
m_list[-1].merge(msg)
|
||||||
|
else:
|
||||||
|
m_list += [ msg ]
|
||||||
|
|
||||||
m_list.sort()
|
m_list.sort()
|
||||||
|
|
||||||
if len(m_list) > 0:
|
if len(m_list) > 0:
|
||||||
|
|
|
@ -13,19 +13,28 @@ class Message:
|
||||||
self.__ts = json["ts"]
|
self.__ts = json["ts"]
|
||||||
self.__time = datetime.fromtimestamp(float(self.__ts))
|
self.__time = datetime.fromtimestamp(float(self.__ts))
|
||||||
self.__user = users.info(json["user"])
|
self.__user = users.info(json["user"])
|
||||||
self.__text = json["text"].encode("utf-8").decode("latin-1")
|
self.__text = [ json["text"].encode("utf-8").decode("latin-1") ]
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.__time < other.__time
|
return self.__time < other.__time
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
text = "\n ".join(textwrap.wrap(self.__text))
|
lines = []
|
||||||
|
for line in self.__text:
|
||||||
|
lines += [ "" ] + textwrap.wrap(line)
|
||||||
|
text = "\n ".join(lines)
|
||||||
time = self.__time.strftime("%I:%M:%S %p")
|
time = self.__time.strftime("%I:%M:%S %p")
|
||||||
return "\n%s | %s:\n\n %s\n" % (time, self.__user, text)
|
return "\n%s | %s:\n%s\n" % (time, self.__user, text)
|
||||||
|
|
||||||
def ts(self):
|
def ts(self):
|
||||||
return self.__ts
|
return self.__ts
|
||||||
|
|
||||||
|
def user(self):
|
||||||
|
return self.__user
|
||||||
|
|
||||||
|
def merge(self, msg):
|
||||||
|
self.__text += msg.__text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def postMessage(channel, text):
|
def postMessage(channel, text):
|
||||||
|
|
Loading…
Reference in New Issue