# # Copyright 2015 (c) Anna Schumaker. # from . import api from . import auth from . import chat from . import threads from . import users class Channel(threads.Thread): def __init__(self, json): threads.Thread.__init__(self, json) self.__member = json.get("is_member", False) def do_fetch_info(self): return info(self.id()) def do_fetch_messages(self, ts): return history(self.id(), ts) def do_mark_messages(self, ts): mark(self.id(), ts) def is_member(self): return self.__member def post(self, text): chat.postMessage(self.__id, text) def history(channel, timestamp): ret = api.call("channels.history", token = auth.token(), channel = channel, oldest = timestamp) if ret["ok"] == False: return None return ret["messages"] def info(channel): ret = api.call("channels.info", token = auth.token(), channel = channel) if ret["ok"] == False: return None return ret["channel"] def list(): ret = api.call("channels.list", token = auth.token()) if ret["ok"] == False: return None ch_list = [] for channel in ret["channels"]: ch_list += [ Channel(channel) ] return ch_list def mark(channel, timestamp): api.call("channels.mark", token = auth.token(), channel = channel, ts = timestamp)