2015-05-03 12:53:29 -04:00
|
|
|
import tgl
|
|
|
|
import pprint
|
2015-05-12 04:51:59 -04:00
|
|
|
from functools import partial
|
|
|
|
|
2015-05-03 00:32:30 -04:00
|
|
|
|
2015-05-03 12:53:29 -04:00
|
|
|
our_id = 0
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
2015-05-07 02:54:31 -04:00
|
|
|
binlog_done = False;
|
|
|
|
|
2015-05-03 00:32:30 -04:00
|
|
|
def on_binlog_replay_end():
|
2015-05-07 02:54:31 -04:00
|
|
|
binlog_done = True;
|
2015-05-03 00:32:30 -04:00
|
|
|
|
|
|
|
def on_get_difference_end():
|
|
|
|
pass
|
|
|
|
|
2015-05-03 12:53:29 -04:00
|
|
|
def on_our_id(id):
|
|
|
|
our_id = id
|
|
|
|
return "Set ID: " + str(our_id)
|
2015-05-03 00:32:30 -04:00
|
|
|
|
2015-05-12 04:04:47 -04:00
|
|
|
def msg_cb(success, msg):
|
|
|
|
pp.pprint(success)
|
|
|
|
pp.pprint(msg)
|
|
|
|
|
2015-05-12 04:51:59 -04:00
|
|
|
HISTORY_QUERY_SIZE = 100
|
|
|
|
|
|
|
|
def history_cb(msg_list, ptype, pid, success, msgs):
|
|
|
|
print(len(msgs))
|
|
|
|
msg_list.extend(msgs)
|
|
|
|
print(len(msg_list))
|
|
|
|
if len(msgs) == HISTORY_QUERY_SIZE:
|
2015-05-15 13:41:58 -04:00
|
|
|
tgl.get_history(ptype, pid, len(msg_list), HISTORY_QUERY_SIZE, partial(history_cb, msg_list, ptype, pid));
|
2015-05-12 04:51:59 -04:00
|
|
|
|
2015-05-19 04:40:57 -04:00
|
|
|
def on_msg_receive(msg):
|
|
|
|
if msg["out"] and not binlog_done:
|
|
|
|
return;
|
|
|
|
|
2015-05-19 20:06:27 -04:00
|
|
|
print(msg["to"].id)
|
2015-05-19 04:40:57 -04:00
|
|
|
|
|
|
|
"""
|
2015-05-03 00:32:30 -04:00
|
|
|
def on_msg_receive(msg):
|
2015-05-07 02:54:31 -04:00
|
|
|
if msg["out"] and not binlog_done:
|
2015-05-04 01:42:11 -04:00
|
|
|
return;
|
|
|
|
|
2015-05-07 02:54:31 -04:00
|
|
|
if msg["to"]["id"] == our_id: # direct message
|
|
|
|
ptype = msg["from"]["type"]
|
|
|
|
pid = msg["from"]["id"]
|
|
|
|
else: # chatroom
|
|
|
|
ptype = msg["to"]["type"]
|
|
|
|
pid = msg["to"]["id"]
|
|
|
|
|
2015-05-07 03:44:39 -04:00
|
|
|
pp.pprint(msg)
|
|
|
|
|
2015-05-07 02:54:31 -04:00
|
|
|
text = msg["text"]
|
|
|
|
|
|
|
|
if text.startswith("!ping"):
|
2015-05-10 07:09:39 -04:00
|
|
|
print("SENDING PONG")
|
2015-05-12 04:04:47 -04:00
|
|
|
tgl.send_msg(ptype, pid, "PONG!", msg_cb)
|
2015-05-07 02:54:31 -04:00
|
|
|
|
2015-05-12 04:51:59 -04:00
|
|
|
if text.startswith("!loadhistory"):
|
|
|
|
msg_list = []
|
|
|
|
tgl.get_history_ext(ptype, pid, 0, HISTORY_QUERY_SIZE, partial(history_cb, msg_list, ptype, pid));
|
2015-05-19 04:40:57 -04:00
|
|
|
"""
|
2015-05-03 00:32:30 -04:00
|
|
|
def on_secret_chat_update(peer, types):
|
|
|
|
return "on_secret_chat_update"
|
|
|
|
|
|
|
|
def on_user_update():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_chat_update():
|
|
|
|
pass
|
|
|
|
|
2015-05-09 05:10:24 -04:00
|
|
|
# Set callbacks
|
|
|
|
tgl.set_on_binlog_replay_end(on_binlog_replay_end)
|
|
|
|
tgl.set_on_get_difference_end(on_get_difference_end)
|
|
|
|
tgl.set_on_our_id(on_our_id)
|
|
|
|
tgl.set_on_msg_receive(on_msg_receive)
|
|
|
|
tgl.set_on_secret_chat_update(on_secret_chat_update)
|
|
|
|
tgl.set_on_user_update(on_user_update)
|
|
|
|
tgl.set_on_chat_update(on_chat_update)
|
|
|
|
|