Scripting notes
Fylwind edited this page Jan 16, 2016
·
2 revisions
Python scripting cheatsheet
Don't try to block the main. Instead, handle the built-in events such as on_loop:
import tgl
def on_loop():
do_something()
send_a_message()
tgl.set_on_loop(on_loop)To run the script, use bin/telegram-cli -Z my_script.py. See the full API docs for more info. Note that event handlers are set via tgl.set_*, even though the docs don't explicitly mention the set_ prefix.
To check whether a user is online, update the contact list and compare user_status["when"] with the current time. If the status is in the future, the contact is online right now.
then = peer.user_status["when"]
now = datetime.datetime.now()
if then > now:
# peer is online
greet_peer()