tg/tgl-test.py

61 lines
1.2 KiB
Python
Raw Normal View History

import tgl
import pprint
2015-05-02 21:32:30 -07:00
our_id = 0
pp = pprint.PrettyPrinter(indent=4)
binlog_done = False;
2015-05-02 21:32:30 -07:00
def on_binlog_replay_end():
binlog_done = True;
2015-05-02 21:32:30 -07:00
def on_get_difference_end():
pass
def on_our_id(id):
our_id = id
return "Set ID: " + str(our_id)
2015-05-02 21:32:30 -07:00
2015-05-12 01:04:47 -07:00
def msg_cb(success, msg):
pp.pprint(success)
pp.pprint(msg)
2015-05-02 21:32:30 -07:00
def on_msg_receive(msg):
if msg["out"] and not binlog_done:
2015-05-03 22:42:11 -07:00
return;
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"]
pp.pprint(msg)
text = msg["text"]
if text.startswith("!ping"):
print("SENDING PONG")
2015-05-12 01:04:47 -07:00
tgl.send_msg(ptype, pid, "PONG!", msg_cb)
2015-05-02 21:32:30 -07: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 02:10:24 -07: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)