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:
parent
dcd8650e1a
commit
7b78e9d785
|
@ -5,8 +5,6 @@ from . import api
|
||||||
from . import auth
|
from . import auth
|
||||||
from . import chat
|
from . import chat
|
||||||
from . import users
|
from . import users
|
||||||
from datetime import datetime
|
|
||||||
import textwrap
|
|
||||||
|
|
||||||
|
|
||||||
class Channel:
|
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):
|
def history(channel, timestamp):
|
||||||
ret = api.call("channels.history", token = auth.token(), channel = channel, oldest = timestamp)
|
ret = api.call("channels.history", token = auth.token(), channel = channel, oldest = timestamp)
|
||||||
if ret["ok"] == False:
|
if ret["ok"] == False:
|
||||||
|
@ -82,7 +60,7 @@ def history(channel, timestamp):
|
||||||
|
|
||||||
m_list = []
|
m_list = []
|
||||||
for message in ret["messages"]:
|
for message in ret["messages"]:
|
||||||
m_list += [ Message(message) ]
|
m_list += [ chat.Message(message) ]
|
||||||
m_list.sort()
|
m_list.sort()
|
||||||
|
|
||||||
if len(m_list) > 0:
|
if len(m_list) > 0:
|
||||||
|
|
|
@ -3,6 +3,30 @@
|
||||||
#
|
#
|
||||||
from . import api
|
from . import api
|
||||||
from . import auth
|
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):
|
def postMessage(channel, text):
|
||||||
api.call("chat.postMessage", token = auth.token(), channel = channel,
|
api.call("chat.postMessage", token = auth.token(), channel = channel,
|
||||||
|
|
Loading…
Reference in New Issue