Commit ad904dbd authored by Vincent Castellano's avatar Vincent Castellano

Complete basic API implementation. Callbacks and various functions TODO

parent 30f0a3b1
...@@ -660,6 +660,10 @@ void on_started (struct tgl_state *TLS) { ...@@ -660,6 +660,10 @@ void on_started (struct tgl_state *TLS) {
lua_diff_end (); lua_diff_end ();
#endif #endif
#ifdef USE_PYTHON
py_diff_end ();
#endif
if (start_command) { if (start_command) {
safe_quit = 1; safe_quit = 1;
while (*start_command) { while (*start_command) {
...@@ -715,6 +719,10 @@ int loop (void) { ...@@ -715,6 +719,10 @@ int loop (void) {
lua_binlog_end (); lua_binlog_end ();
#endif #endif
#ifdef USE_PYTHON
py_binlog_end ();
#endif
if (sfd >= 0) { if (sfd >= 0) {
struct event *ev = event_new (TLS->ev_base, sfd, EV_READ | EV_PERSIST, accept_incoming, 0); struct event *ev = event_new (TLS->ev_base, sfd, EV_READ | EV_PERSIST, accept_incoming, 0);
event_add (ev, 0); event_add (ev, 0);
......
import tgl import tgl
import geopy
import pprint import pprint
from geopy.geocoders import Nominatim
our_id = 0 our_id = 0
pp = pprint.PrettyPrinter(indent=4) pp = pprint.PrettyPrinter(indent=4)
binlog_done = False;
def on_binlog_replay_end(): def on_binlog_replay_end():
pass binlog_done = True;
def on_get_difference_end(): def on_get_difference_end():
pass pass
...@@ -16,10 +20,27 @@ def on_our_id(id): ...@@ -16,10 +20,27 @@ def on_our_id(id):
return "Set ID: " + str(our_id) return "Set ID: " + str(our_id)
def on_msg_receive(msg): def on_msg_receive(msg):
if msg["out"]: if msg["out"] and not binlog_done:
return; 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): def on_secret_chat_update(peer, types):
return "on_secret_chat_update" 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