34 lines
880 B
Python
34 lines
880 B
Python
#
|
|
# Copyright 2015 (c) Anna Schumaker.
|
|
#
|
|
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,
|
|
text = text, as_user = True, parse = "full")
|