Commit f1c8af60 authored by Vincent Castellano's avatar Vincent Castellano

Complete basic API implementation. Callbacks and various functions TODO

parent 96325e2e
......@@ -656,6 +656,10 @@ void on_started (struct tgl_state *TLS) {
lua_diff_end ();
#endif
#ifdef USE_PYTHON
py_diff_end ();
#endif
if (start_command) {
safe_quit = 1;
while (*start_command) {
......@@ -708,6 +712,10 @@ int loop (void) {
lua_binlog_end ();
#endif
#ifdef USE_PYTHON
py_binlog_end ();
#endif
if (sfd >= 0) {
struct event *ev = event_new (TLS->ev_base, sfd, EV_READ | EV_PERSIST, accept_incoming, 0);
event_add (ev, 0);
......
import tgl
import geopy
import pprint
from geopy.geocoders import Nominatim
our_id = 0
pp = pprint.PrettyPrinter(indent=4)
binlog_done = False;
def on_binlog_replay_end():
pass
binlog_done = True;
def on_get_difference_end():
pass
......@@ -16,10 +20,27 @@ def on_our_id(id):
return "Set ID: " + str(our_id)
def on_msg_receive(msg):
if msg["out"]:
if msg["out"] and not binlog_done:
return;
tgl.send_msg(msg["from"]["type"], msg["from"]["id"], "PONG!")
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"]
text = msg["text"]
if text.startswith("!ping"):
tgl.send_msg(ptype, pid, "PONG!")
d
if text.startswith("!location"):
geolocator = Nominatim()
location = geolocator.geocode(msg["text"][9:])
pp.pprint(location)
tgl.send_location(ptype, pid, location.latitude, location.longitude)
def on_secret_chat_update(peer, types):
return "on_secret_chat_update"
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment