Move Message class into the chat namespace

It makes more sense to put it here, since it's related to chatting.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-28 13:24:15 -04:00
parent dcd8650e1a
commit 7b78e9d785
2 changed files with 25 additions and 23 deletions

View File

@ -5,8 +5,6 @@ from . import api
from . import auth
from . import chat
from . import users
from datetime import datetime
import textwrap
class Channel:
@ -55,26 +53,6 @@ class Channel:
class Message:
def __init__(self, json):
self.__ts = json["ts"]
self.__time = datetime.fromtimestamp(float(self.__ts))
self.__user = users.info(json["user"])
self.__text = json["text"].encode("utf-8").decode("latin-1")
def __lt__(self, other):
return self.__time < other.__time
def __str__(self):
text = "\n ".join(textwrap.wrap(self.__text))
time = self.__time.strftime("%I:%M:%S %p")
return "\n%s | %s:\n\n %s\n" % (time, self.__user, text)
def ts(self):
return self.__ts
def history(channel, timestamp):
ret = api.call("channels.history", token = auth.token(), channel = channel, oldest = timestamp)
if ret["ok"] == False:
@ -82,7 +60,7 @@ def history(channel, timestamp):
m_list = []
for message in ret["messages"]:
m_list += [ Message(message) ]
m_list += [ chat.Message(message) ]
m_list.sort()
if len(m_list) > 0:

View File

@ -3,6 +3,30 @@
#
from . import api
from . import auth
from . import users
from datetime import datetime
import textwrap
class Message:
def __init__(self, json):
self.__ts = json["ts"]
self.__time = datetime.fromtimestamp(float(self.__ts))
self.__user = users.info(json["user"])
self.__text = json["text"].encode("utf-8").decode("latin-1")
def __lt__(self, other):
return self.__time < other.__time
def __str__(self):
text = "\n ".join(textwrap.wrap(self.__text))
time = self.__time.strftime("%I:%M:%S %p")
return "\n%s | %s:\n\n %s\n" % (time, self.__user, text)
def ts(self):
return self.__ts
def postMessage(channel, text):
api.call("chat.postMessage", token = auth.token(), channel = channel,