2015-05-26 21:18:50 -04:00
|
|
|
#
|
|
|
|
# Copyright 2015 (c) Anna Schumaker.
|
|
|
|
#
|
|
|
|
from . import api
|
|
|
|
from . import auth
|
2015-05-28 13:24:15 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2015-05-26 21:18:50 -04:00
|
|
|
|
|
|
|
def postMessage(channel, text):
|
|
|
|
api.call("chat.postMessage", token = auth.token(), channel = channel,
|
2015-05-27 11:10:47 -04:00
|
|
|
text = text, as_user = True, parse = "full")
|