2015-05-03 12:53:29 -04:00
|
|
|
import tgl
|
2015-05-07 02:54:31 -04:00
|
|
|
import geopy
|
2015-05-03 12:53:29 -04:00
|
|
|
import pprint
|
2015-05-07 02:54:31 -04:00
|
|
|
from geopy.geocoders import Nominatim
|
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
|
|
|
|
|
|
|
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"):
|
|
|
|
tgl.send_msg(ptype, pid, "PONG!")
|
|
|
|
|
|
|
|
if text.startswith("!location"):
|
|
|
|
geolocator = Nominatim()
|
|
|
|
location = geolocator.geocode(msg["text"][9:])
|
|
|
|
pp.pprint(location)
|
|
|
|
tgl.send_location(ptype, pid, location.latitude, location.longitude)
|
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
|
|
|
|
|