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
|
2015-05-23 20:09:08 -04:00
|
|
|
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
|
|
|
|
|
2015-05-20 02:43:08 -04:00
|
|
|
def history_cb(msg_list, peer, success, msgs):
|
2015-05-12 04:51:59 -04:00
|
|
|
print(len(msgs))
|
|
|
|
msg_list.extend(msgs)
|
|
|
|
print(len(msg_list))
|
|
|
|
if len(msgs) == HISTORY_QUERY_SIZE:
|
2015-05-20 02:43:08 -04:00
|
|
|
tgl.get_history(peer, len(msg_list), HISTORY_QUERY_SIZE, partial(history_cb, msg_list, peer));
|
2015-05-12 04:51:59 -04:00
|
|
|
|
2015-05-23 20:09:08 -04:00
|
|
|
|
|
|
|
def cb(success):
|
|
|
|
print(success)
|
2015-05-20 02:09:46 -04:00
|
|
|
|
2015-05-19 04:40:57 -04:00
|
|
|
def on_msg_receive(msg):
|
2015-05-19 20:49:24 -04:00
|
|
|
if msg.out and not binlog_done:
|
2015-05-04 01:42:11 -04:00
|
|
|
return;
|
|
|
|
|
2015-05-20 02:43:08 -04:00
|
|
|
if msg.dest.id == our_id: # direct message
|
|
|
|
peer = msg.src
|
2015-05-07 02:54:31 -04:00
|
|
|
else: # chatroom
|
2015-05-20 02:43:08 -04:00
|
|
|
peer = msg.dest
|
2015-05-07 03:44:39 -04:00
|
|
|
|
2015-05-20 04:28:23 -04:00
|
|
|
pp.pprint(msg)
|
2015-05-20 02:43:08 -04:00
|
|
|
if msg.text.startswith("!ping"):
|
2015-05-10 07:09:39 -04:00
|
|
|
print("SENDING PONG")
|
2015-05-23 20:09:08 -04:00
|
|
|
peer.send_msg("PONG!", msg_cb)
|
|
|
|
peer.send_contact(msg.src.phone, msg.src.first_name, msg.src.last_name , cb)
|
2015-05-20 02:43:08 -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)
|
|
|
|
|