diff --git a/slack/channels.py b/slack/channels.py index 492a663..310bad1 100644 --- a/slack/channels.py +++ b/slack/channels.py @@ -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: diff --git a/slack/chat.py b/slack/chat.py index 7a510e5..4be52f4 100644 --- a/slack/chat.py +++ b/slack/chat.py @@ -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,