2015-05-26 15:20:12 -04:00
|
|
|
#
|
2015-06-09 09:33:50 -04:00
|
|
|
# Copyright 2015 (c) Anna Schumaker.
|
2015-05-26 15:20:12 -04:00
|
|
|
#
|
|
|
|
from . import api
|
|
|
|
from . import auth
|
2015-05-26 21:18:50 -04:00
|
|
|
from . import chat
|
2015-06-09 09:33:50 -04:00
|
|
|
from . import threads
|
2015-05-26 16:22:05 -04:00
|
|
|
from . import users
|
2015-05-26 15:20:12 -04:00
|
|
|
|
|
|
|
|
2015-06-09 09:33:50 -04:00
|
|
|
class Channel(threads.Thread):
|
2015-05-26 15:20:12 -04:00
|
|
|
def __init__(self, json):
|
2015-06-09 09:33:50 -04:00
|
|
|
threads.Thread.__init__(self, json)
|
2015-05-26 15:20:12 -04:00
|
|
|
self.__member = json.get("is_member", False)
|
|
|
|
|
2015-06-09 09:56:55 -04:00
|
|
|
def do_fetch_info(self):
|
|
|
|
return info(self.id())
|
2015-05-27 16:37:05 -04:00
|
|
|
|
2015-06-09 10:22:10 -04:00
|
|
|
def do_fetch_messages(self, ts):
|
|
|
|
return history(self.id(), ts)
|
|
|
|
|
|
|
|
def do_mark_messages(self, ts):
|
|
|
|
mark(self.id(), ts)
|
|
|
|
|
2015-05-26 15:20:12 -04:00
|
|
|
def is_member(self):
|
|
|
|
return self.__member
|
|
|
|
|
2015-05-26 16:00:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
def history(channel, timestamp):
|
|
|
|
ret = api.call("channels.history", token = auth.token(), channel = channel, oldest = timestamp)
|
|
|
|
if ret["ok"] == False:
|
|
|
|
return None
|
2015-06-09 10:22:10 -04:00
|
|
|
return ret["messages"]
|
2015-05-26 15:38:47 -04:00
|
|
|
|
|
|
|
def info(channel):
|
|
|
|
ret = api.call("channels.info", token = auth.token(), channel = channel)
|
|
|
|
if ret["ok"] == False:
|
|
|
|
return None
|
|
|
|
return ret["channel"]
|
|
|
|
|
2015-05-26 15:20:12 -04:00
|
|
|
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
|
2015-05-26 17:00:20 -04:00
|
|
|
|
|
|
|
def mark(channel, timestamp):
|
|
|
|
api.call("channels.mark", token = auth.token(), channel = channel, ts = timestamp)
|