Merge branch 'master' of https://github.com/datamachine/tg into datamachine-master
This commit is contained in:
commit
452c30fc88
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
telegram
|
||||
*.o
|
||||
Makefile
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
config.h
|
||||
config.log
|
||||
@ -16,4 +17,5 @@ debian/telegram-cli.[a-z]
|
||||
debian/files
|
||||
debian/telegram-cli/*
|
||||
debian/telegram-cli.debhelper.log
|
||||
debian/telegram-cli.substvars
|
||||
debian/telegram-cli.substvars
|
||||
__pycache__
|
||||
|
@ -9,6 +9,7 @@ install:
|
||||
- sudo apt-get install libreadline6-dev
|
||||
- sudo apt-get install libssl-dev
|
||||
- sudo apt-get install liblua5.2-dev lua5.2
|
||||
- sudo apt-get install python-dev python
|
||||
- sudo apt-get install libevent-dev
|
||||
- sudo apt-get install libjansson-dev
|
||||
|
||||
|
@ -4,10 +4,9 @@ CFLAGS=@CFLAGS@
|
||||
LDFLAGS=@LDFLAGS@ @OPENSSL_LDFLAGS@
|
||||
CPPFLAGS=@CPPFLAGS@ @OPENSSL_INCLUDES@
|
||||
DEFS=@DEFS@
|
||||
COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC
|
||||
|
||||
COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Werror -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC
|
||||
EXTRA_LIBS=@LIBS@ @EXTRA_LIBS@ @OPENSSL_LIBS@
|
||||
LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS}
|
||||
LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS} -ldl -lpthread -lutil
|
||||
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
|
||||
|
||||
DEP=dep
|
||||
@ -19,7 +18,7 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto
|
||||
|
||||
EXE_LIST=${EXE}/telegram-cli
|
||||
|
||||
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o ${OBJ}/json-tg.o
|
||||
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o ${OBJ}/json-tg.o ${OBJ}/python-tg.o ${OBJ}/python-types.o
|
||||
|
||||
INCLUDE=-I. -I${srcdir} -I${srcdir}/tgl
|
||||
CC=@CC@
|
||||
|
95
README-PY
Normal file
95
README-PY
Normal file
@ -0,0 +1,95 @@
|
||||
To use python with client you should write python script. You can specify it from config ("python_script" option) or from command_line [-Z].
|
||||
|
||||
You should set the following callbacks in your script:
|
||||
tgl.on_binlog_replay_end() - it is called when replay of old events end. Any updates prior this call were already received by this client
|
||||
some time ago.
|
||||
|
||||
tgl.on_get_difference_end() - it is called after first get_difference call. So we received all updates after last client execute.
|
||||
|
||||
tgl.on_our_id(our_id) - Informs about id of currently logged in user.
|
||||
|
||||
tgl.on_msg_receive(msg) - it is called when we receive new msg (!! may be called before on_binlog_replay_end, than it is old msg).
|
||||
|
||||
tgl.on_user_update(peer, what_changed) - updated info about user. what_changed is array of strings.
|
||||
tgl.on_chat_update(peer, what_changed) - updated info about user. what_changed is array of strings.
|
||||
tgl.on_secret_chat_update(peer, what_changed) - updated info about user. what_changed is array of strings.
|
||||
|
||||
|
||||
|
||||
Also, you can call several functions. Each this function last two arguments, are callback, which is a python function implementing the callback from the function.
|
||||
These functions may return false immidiately if something is bad with args, or return true and call cb_function in future.
|
||||
The callback function should have one arguments: first success (True or False), and the rest depends on the call.
|
||||
Functions that require a peer type other than what is passed will raise tgl.PeerError.
|
||||
|
||||
|
||||
Function_list (arguments are listed aside from callback, import tgl for access) :
|
||||
tgl.get_contact_list ()
|
||||
tgl.get_dialog_list ()
|
||||
|
||||
tgl.rename_chat (peer, new_name)
|
||||
tgl.chat_set_photo (peer, file)
|
||||
|
||||
tgl.send_typing (peer)
|
||||
tgl.send_typing_abort (peer)
|
||||
|
||||
tgl.send_msg (peer, text)
|
||||
tgl.fwd_msg (peer, msg)
|
||||
|
||||
tgl.send_photo (peer, file)
|
||||
tgl.send_video (peer, file)
|
||||
tgl.send_audio (peer, file)
|
||||
tgl.send_document (peer, file)
|
||||
tgl.send_text (peer, file)
|
||||
|
||||
tgl.load_photo(msg)
|
||||
tgl.load_video(msg)
|
||||
tgl.load_video_thumb(msg)
|
||||
tgl.load_audio(msg)
|
||||
tgl.load_document(msg)
|
||||
tgl.load_document_thumb(msg)
|
||||
|
||||
tgl.info (peer)
|
||||
|
||||
tgl.get_history (peer, limit)
|
||||
|
||||
tgl.chat_add_user (peer, user)
|
||||
tgl.chat_del_user (peer, user)
|
||||
|
||||
tgl.add_contact (phone, first_name, last_name)
|
||||
tgl.rename_contact (phone, first_name, last_name)
|
||||
|
||||
tgl.msg_search (peer, text)
|
||||
tgl.msg_global_search (text)
|
||||
|
||||
tgl.mark_read (peer)
|
||||
|
||||
tgl.set_profile_photo (file)
|
||||
|
||||
tgl.create_secret_chat (user)
|
||||
tgl.create_group_chat (peer, name)
|
||||
|
||||
tgl.delete_msg (msg)
|
||||
tgl.restore_msg (msg_id)
|
||||
|
||||
tgl.status_online ()
|
||||
tgl.status_offline ()
|
||||
|
||||
tgl.send_location (peer, latitude, longitude)
|
||||
|
||||
Additionally, the tgl.Peer object has the following direct methods:
|
||||
peer.rename_chat(new_name)
|
||||
peer.chat_set_photo(file)
|
||||
peer.send_typing()
|
||||
peer.send_typing_abort()
|
||||
peer.send_msg(text)
|
||||
peer.send_photo(file)
|
||||
peer.send_video(file)
|
||||
peer.send_document(file)
|
||||
peer.send_text(file)
|
||||
peer.info()
|
||||
peer.history(limit, offset)
|
||||
peer.add_user(peer)
|
||||
peer.del_user(peer)
|
||||
peer.search(text)
|
||||
peer.mark_read()
|
||||
peer.send_location(latitude, longitude)
|
19
README.md
19
README.md
@ -24,30 +24,35 @@ Clone GitHub Repository
|
||||
|
||||
git clone --recursive https://github.com/vysheng/tg.git && cd tg
|
||||
|
||||
### Python Support
|
||||
|
||||
Python support is currently limited to Python 2.7 or Python 3.1+. Other versions may work but are not tested.
|
||||
|
||||
#### Linux and BSDs
|
||||
|
||||
Install libs: readline, openssl and (if you want to use config) libconfig, liblua and libjansson.
|
||||
If you do not want to use them pass options --disable-libconfig, --disable-liblua and --disable-json respectively.
|
||||
Install libs: readline, openssl and (if you want to use config) libconfig, liblua, python and libjansson.
|
||||
If you do not want to use them pass options --disable-libconfig, --disable-liblua, --disable-python and --disable-json respectively.
|
||||
|
||||
On Ubuntu/Debian use:
|
||||
|
||||
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev make
|
||||
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
|
||||
|
||||
On gentoo:
|
||||
|
||||
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent dev-libs/jansson
|
||||
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent dev-libs/jansson dev-lang/python
|
||||
|
||||
On Fedora:
|
||||
|
||||
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel libjansson-devel
|
||||
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel python-devel
|
||||
|
||||
On FreeBSD:
|
||||
|
||||
pkg install libconfig libexecinfo lua52
|
||||
pkg install libconfig libexecinfo lua52 python
|
||||
|
||||
On OpenBSD:
|
||||
|
||||
pkg_add libconfig libexecinfo lua
|
||||
pkg_add libconfig libexecinfo lua python
|
||||
|
||||
Then,
|
||||
|
||||
@ -69,6 +74,7 @@ If using [Homebrew](http://brew.sh/):
|
||||
brew install libconfig
|
||||
brew install readline
|
||||
brew install lua
|
||||
brew install python
|
||||
brew install libevent
|
||||
export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.3.8/include"
|
||||
export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.3.8/lib"
|
||||
@ -81,6 +87,7 @@ If using [MacPorts](https://www.macports.org):
|
||||
sudo port install libconfig-hr
|
||||
sudo port install readline
|
||||
sudo port install lua51
|
||||
sudo port install python34
|
||||
sudo port install libevent
|
||||
export CFLAGS="-I/usr/local/include -I/opt/local/include -I/opt/local/include/lua-5.1"
|
||||
export LDFLAGS="-L/usr/local/lib -L/opt/local/lib -L/opt/local/lib/lua-5.1"
|
||||
|
109
ax_python.m4
Normal file
109
ax_python.m4
Normal file
@ -0,0 +1,109 @@
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_python.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_PYTHON
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro does a complete Python development environment check.
|
||||
#
|
||||
# It recurses through several python versions (from 2.1 to 2.6 in this
|
||||
# version), looking for an executable. When it finds an executable, it
|
||||
# looks to find the header files and library.
|
||||
#
|
||||
# It sets PYTHON_BIN to the name of the python executable,
|
||||
# PYTHON_INCLUDE_DIR to the directory holding the header files, and
|
||||
# PYTHON_LIB to the name of the Python library.
|
||||
#
|
||||
# This macro calls AC_SUBST on PYTHON_BIN (via AC_CHECK_PROG),
|
||||
# PYTHON_INCLUDE_DIR and PYTHON_LIB.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Michael Tindal
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 14
|
||||
|
||||
AC_DEFUN([AX_PYTHON],
|
||||
[AC_MSG_CHECKING(for python build information)
|
||||
AC_MSG_RESULT([])
|
||||
for python in python3.4 python3.3 python3.2 python3.1 python3 python2.7 python2.6 python2 python; do
|
||||
AC_CHECK_PROGS(PYTHON_BIN, [$python])
|
||||
ax_python_bin=$PYTHON_BIN
|
||||
if test x$ax_python_bin != x; then
|
||||
AC_CHECK_LIB($ax_python_bin, main, ax_python_lib=$ax_python_bin, ax_python_lib=no)
|
||||
if test x$ax_python_lib == xno; then
|
||||
AC_CHECK_LIB(${ax_python_bin}m, main, ax_python_lib=${ax_python_bin}m, ax_python_lib=no)
|
||||
fi
|
||||
if test x$ax_python_lib != xno; then
|
||||
ax_python_header=`$ax_python_bin -c "from distutils.sysconfig import *; print(get_config_var('CONFINCLUDEPY'))"`
|
||||
if test x$ax_python_header != x; then
|
||||
break;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
unset ac_cv_prog_PYTHON_BIN
|
||||
unset PYTHON_BIN
|
||||
done
|
||||
if test x$ax_python_bin = x; then
|
||||
ax_python_bin=no
|
||||
fi
|
||||
if test x$ax_python_header = x; then
|
||||
ax_python_header=no
|
||||
fi
|
||||
if test x$ax_python_lib = x; then
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([ results of the Python check:])
|
||||
AC_MSG_RESULT([ Binary: $ax_python_bin])
|
||||
AC_MSG_RESULT([ Library: $ax_python_lib])
|
||||
AC_MSG_RESULT([ Include Dir: $ax_python_header])
|
||||
|
||||
|
||||
PYTHON_FOUND=yes
|
||||
if test x$ax_python_header != xno; then
|
||||
PYTHON_INCLUDE_DIR=$ax_python_header
|
||||
AC_SUBST(PYTHON_INCLUDE_DIR)
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
|
||||
if test x$ax_python_lib != xno; then
|
||||
PYTHON_LIB=$ax_python_lib
|
||||
AC_SUBST(PYTHON_LIB)
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
AC_SUBST(PYTHON_FOUND)
|
||||
|
||||
])dnl
|
6
bootstrap
Executable file
6
bootstrap
Executable file
@ -0,0 +1,6 @@
|
||||
#! /bin/sh
|
||||
|
||||
aclocal
|
||||
autoheader
|
||||
automake --gnu --add-missing
|
||||
autoconf
|
@ -164,6 +164,9 @@
|
||||
/* use lua */
|
||||
#undef USE_LUA
|
||||
|
||||
/* use python */
|
||||
#undef USE_PYTHON
|
||||
|
||||
/* fixed for correct valgrind work */
|
||||
#undef VALGRIND_FIXES
|
||||
|
||||
|
461
configure
vendored
461
configure
vendored
@ -622,6 +622,12 @@ ac_includes_default="\
|
||||
ac_subst_vars='LTLIBOBJS
|
||||
EXTRA_LIBS
|
||||
LIBOBJS
|
||||
PYTHON_CFLAGS
|
||||
PYTHON_LIBS
|
||||
PYTHON_FOUND
|
||||
PYTHON_LIB
|
||||
PYTHON_INCLUDE_DIR
|
||||
PYTHON_BIN
|
||||
LUA_LIB
|
||||
LUA_INCLUDE
|
||||
pkgluaexecdir
|
||||
@ -694,6 +700,7 @@ with_zlib
|
||||
enable_libconfig
|
||||
enable_extf
|
||||
enable_liblua
|
||||
enable_python
|
||||
enable_json
|
||||
with_progname
|
||||
enable_valgrind
|
||||
@ -1322,6 +1329,7 @@ Optional Features:
|
||||
--enable-libconfig/--disable-libconfig
|
||||
--enable-extf/--disable-extf
|
||||
--enable-liblua/--disable-liblua
|
||||
--enable-python/--disable-python
|
||||
--enable-json/--disable-json
|
||||
--enable-valgrind/--disable-valgrind
|
||||
|
||||
@ -2393,6 +2401,62 @@ ac_config_headers="$ac_config_headers config.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_python.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_PYTHON
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro does a complete Python development environment check.
|
||||
#
|
||||
# It recurses through several python versions (from 2.1 to 2.6 in this
|
||||
# version), looking for an executable. When it finds an executable, it
|
||||
# looks to find the header files and library.
|
||||
#
|
||||
# It sets PYTHON_BIN to the name of the python executable,
|
||||
# PYTHON_INCLUDE_DIR to the directory holding the header files, and
|
||||
# PYTHON_LIB to the name of the Python library.
|
||||
#
|
||||
# This macro calls AC_SUBST on PYTHON_BIN (via AC_CHECK_PROG),
|
||||
# PYTHON_INCLUDE_DIR and PYTHON_LIB.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Michael Tindal
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 2 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 14
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
@ -5867,6 +5931,403 @@ fi
|
||||
fi
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python" >&5
|
||||
$as_echo_n "checking for python... " >&6; }
|
||||
# Check whether --enable-python was given.
|
||||
if test "${enable_python+set}" = set; then :
|
||||
enableval=$enable_python;
|
||||
if test "x$enableval" = "xno" ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
|
||||
$as_echo "disabled" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled" >&5
|
||||
$as_echo "enabled" >&6; }
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python build information" >&5
|
||||
$as_echo_n "checking for python build information... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
|
||||
$as_echo "" >&6; }
|
||||
for python in python3.4 python3.3 python3.2 python3.1 python3 python2.7 python2.6 python2 python; do
|
||||
for ac_prog in $python
|
||||
do
|
||||
# Extract the first word of "$ac_prog", so it can be a program name with args.
|
||||
set dummy $ac_prog; ac_word=$2
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
|
||||
$as_echo_n "checking for $ac_word... " >&6; }
|
||||
if ${ac_cv_prog_PYTHON_BIN+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if test -n "$PYTHON_BIN"; then
|
||||
ac_cv_prog_PYTHON_BIN="$PYTHON_BIN" # Let the user override the test.
|
||||
else
|
||||
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
|
||||
for as_dir in $PATH
|
||||
do
|
||||
IFS=$as_save_IFS
|
||||
test -z "$as_dir" && as_dir=.
|
||||
for ac_exec_ext in '' $ac_executable_extensions; do
|
||||
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
|
||||
ac_cv_prog_PYTHON_BIN="$ac_prog"
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
IFS=$as_save_IFS
|
||||
|
||||
fi
|
||||
fi
|
||||
PYTHON_BIN=$ac_cv_prog_PYTHON_BIN
|
||||
if test -n "$PYTHON_BIN"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_BIN" >&5
|
||||
$as_echo "$PYTHON_BIN" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
|
||||
test -n "$PYTHON_BIN" && break
|
||||
done
|
||||
|
||||
ax_python_bin=$PYTHON_BIN
|
||||
if test x$ax_python_bin != x; then
|
||||
as_ac_Lib=`$as_echo "ac_cv_lib_$ax_python_bin''_main" | $as_tr_sh`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -l$ax_python_bin" >&5
|
||||
$as_echo_n "checking for main in -l$ax_python_bin... " >&6; }
|
||||
if eval \${$as_ac_Lib+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-l$ax_python_bin $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return main ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
eval "$as_ac_Lib=yes"
|
||||
else
|
||||
eval "$as_ac_Lib=no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
eval ac_res=\$$as_ac_Lib
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
|
||||
ax_python_lib=$ax_python_bin
|
||||
else
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
if test x$ax_python_lib == xno; then
|
||||
as_ac_Lib=`$as_echo "ac_cv_lib_${ax_python_bin}m''_main" | $as_tr_sh`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -l${ax_python_bin}m" >&5
|
||||
$as_echo_n "checking for main in -l${ax_python_bin}m... " >&6; }
|
||||
if eval \${$as_ac_Lib+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-l${ax_python_bin}m $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return main ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
eval "$as_ac_Lib=yes"
|
||||
else
|
||||
eval "$as_ac_Lib=no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
eval ac_res=\$$as_ac_Lib
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
|
||||
ax_python_lib=${ax_python_bin}m
|
||||
else
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
fi
|
||||
if test x$ax_python_lib != xno; then
|
||||
ax_python_header=`$ax_python_bin -c "from distutils.sysconfig import *; print(get_config_var('CONFINCLUDEPY'))"`
|
||||
if test x$ax_python_header != x; then
|
||||
break;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
unset ac_cv_prog_PYTHON_BIN
|
||||
unset PYTHON_BIN
|
||||
done
|
||||
if test x$ax_python_bin = x; then
|
||||
ax_python_bin=no
|
||||
fi
|
||||
if test x$ax_python_header = x; then
|
||||
ax_python_header=no
|
||||
fi
|
||||
if test x$ax_python_lib = x; then
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: results of the Python check:" >&5
|
||||
$as_echo " results of the Python check:" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Binary: $ax_python_bin" >&5
|
||||
$as_echo " Binary: $ax_python_bin" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Library: $ax_python_lib" >&5
|
||||
$as_echo " Library: $ax_python_lib" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Include Dir: $ax_python_header" >&5
|
||||
$as_echo " Include Dir: $ax_python_header" >&6; }
|
||||
|
||||
|
||||
PYTHON_FOUND=yes
|
||||
if test x$ax_python_header != xno; then
|
||||
PYTHON_INCLUDE_DIR=$ax_python_header
|
||||
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
|
||||
if test x$ax_python_lib != xno; then
|
||||
PYTHON_LIB=$ax_python_lib
|
||||
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
if test $PYTHON_FOUND = no ; then
|
||||
as_fn_error $? "No supported python lib version found. Try --disable-python" "$LINENO" 5
|
||||
else
|
||||
|
||||
|
||||
EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
|
||||
CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
|
||||
|
||||
$as_echo "#define USE_PYTHON 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled" >&5
|
||||
$as_echo "enabled" >&6; }
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python build information" >&5
|
||||
$as_echo_n "checking for python build information... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
|
||||
$as_echo "" >&6; }
|
||||
for python in python3.4 python3.3 python3.2 python3.1 python3 python2.7 python2.6 python2 python; do
|
||||
for ac_prog in $python
|
||||
do
|
||||
# Extract the first word of "$ac_prog", so it can be a program name with args.
|
||||
set dummy $ac_prog; ac_word=$2
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
|
||||
$as_echo_n "checking for $ac_word... " >&6; }
|
||||
if ${ac_cv_prog_PYTHON_BIN+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if test -n "$PYTHON_BIN"; then
|
||||
ac_cv_prog_PYTHON_BIN="$PYTHON_BIN" # Let the user override the test.
|
||||
else
|
||||
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
|
||||
for as_dir in $PATH
|
||||
do
|
||||
IFS=$as_save_IFS
|
||||
test -z "$as_dir" && as_dir=.
|
||||
for ac_exec_ext in '' $ac_executable_extensions; do
|
||||
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
|
||||
ac_cv_prog_PYTHON_BIN="$ac_prog"
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
IFS=$as_save_IFS
|
||||
|
||||
fi
|
||||
fi
|
||||
PYTHON_BIN=$ac_cv_prog_PYTHON_BIN
|
||||
if test -n "$PYTHON_BIN"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_BIN" >&5
|
||||
$as_echo "$PYTHON_BIN" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
fi
|
||||
|
||||
|
||||
test -n "$PYTHON_BIN" && break
|
||||
done
|
||||
|
||||
ax_python_bin=$PYTHON_BIN
|
||||
if test x$ax_python_bin != x; then
|
||||
as_ac_Lib=`$as_echo "ac_cv_lib_$ax_python_bin''_main" | $as_tr_sh`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -l$ax_python_bin" >&5
|
||||
$as_echo_n "checking for main in -l$ax_python_bin... " >&6; }
|
||||
if eval \${$as_ac_Lib+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-l$ax_python_bin $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return main ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
eval "$as_ac_Lib=yes"
|
||||
else
|
||||
eval "$as_ac_Lib=no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
eval ac_res=\$$as_ac_Lib
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
|
||||
ax_python_lib=$ax_python_bin
|
||||
else
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
if test x$ax_python_lib == xno; then
|
||||
as_ac_Lib=`$as_echo "ac_cv_lib_${ax_python_bin}m''_main" | $as_tr_sh`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -l${ax_python_bin}m" >&5
|
||||
$as_echo_n "checking for main in -l${ax_python_bin}m... " >&6; }
|
||||
if eval \${$as_ac_Lib+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-l${ax_python_bin}m $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return main ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
eval "$as_ac_Lib=yes"
|
||||
else
|
||||
eval "$as_ac_Lib=no"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
eval ac_res=\$$as_ac_Lib
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
|
||||
$as_echo "$ac_res" >&6; }
|
||||
if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
|
||||
ax_python_lib=${ax_python_bin}m
|
||||
else
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
fi
|
||||
if test x$ax_python_lib != xno; then
|
||||
ax_python_header=`$ax_python_bin -c "from distutils.sysconfig import *; print(get_config_var('CONFINCLUDEPY'))"`
|
||||
if test x$ax_python_header != x; then
|
||||
break;
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
unset ac_cv_prog_PYTHON_BIN
|
||||
unset PYTHON_BIN
|
||||
done
|
||||
if test x$ax_python_bin = x; then
|
||||
ax_python_bin=no
|
||||
fi
|
||||
if test x$ax_python_header = x; then
|
||||
ax_python_header=no
|
||||
fi
|
||||
if test x$ax_python_lib = x; then
|
||||
ax_python_lib=no
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: results of the Python check:" >&5
|
||||
$as_echo " results of the Python check:" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Binary: $ax_python_bin" >&5
|
||||
$as_echo " Binary: $ax_python_bin" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Library: $ax_python_lib" >&5
|
||||
$as_echo " Library: $ax_python_lib" >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Include Dir: $ax_python_header" >&5
|
||||
$as_echo " Include Dir: $ax_python_header" >&6; }
|
||||
|
||||
|
||||
PYTHON_FOUND=yes
|
||||
if test x$ax_python_header != xno; then
|
||||
PYTHON_INCLUDE_DIR=$ax_python_header
|
||||
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
|
||||
if test x$ax_python_lib != xno; then
|
||||
PYTHON_LIB=$ax_python_lib
|
||||
|
||||
else
|
||||
PYTHON_FOUND=no
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
if test $PYTHON_FOUND = no ; then
|
||||
as_fn_error $? "No supported python lib version found. Try --disable-python" "$LINENO" 5
|
||||
else
|
||||
|
||||
|
||||
EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
|
||||
CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
|
||||
|
||||
$as_echo "#define USE_PYTHON 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libjansson" >&5
|
||||
$as_echo_n "checking for libjansson... " >&6; }
|
||||
# Check whether --enable-json was given.
|
||||
|
39
configure.ac
39
configure.ac
@ -4,6 +4,7 @@ AC_CONFIG_SRCDIR([config.h.in])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
m4_include([ax_lua.m4])
|
||||
m4_include([ax_python.m4])
|
||||
m4_include([m4_ax_check_openssl.m4])
|
||||
m4_include([m4_ax_check_zlib.m4])
|
||||
m4_include([m4-ax_gcc_builtin.m4])
|
||||
@ -94,6 +95,44 @@ AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
|
||||
])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for python])
|
||||
AC_ARG_ENABLE(python,[--enable-python/--disable-python],
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
AC_MSG_RESULT([disabled])
|
||||
else
|
||||
AC_MSG_RESULT([enabled])
|
||||
|
||||
AX_PYTHON()
|
||||
AC_SUBST([PYTHON_FOUND])
|
||||
if test $PYTHON_FOUND = no ; then
|
||||
AC_MSG_ERROR([No supported python lib version found. Try --disable-python])
|
||||
else
|
||||
AC_SUBST([PYTHON_LIBS])
|
||||
AC_SUBST([PYTHON_CFLAGS])
|
||||
EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
|
||||
CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
|
||||
AC_DEFINE(USE_PYTHON,1,[use python])
|
||||
fi
|
||||
fi
|
||||
],[
|
||||
AC_MSG_RESULT([enabled])
|
||||
|
||||
AX_PYTHON()
|
||||
AC_SUBST([PYTHON_FOUND])
|
||||
if test $PYTHON_FOUND = no ; then
|
||||
AC_MSG_ERROR([No supported python lib version found. Try --disable-python])
|
||||
else
|
||||
AC_SUBST([PYTHON_LIBS])
|
||||
AC_SUBST([PYTHON_CFLAGS])
|
||||
EXTRA_LIBS="${EXTRA_LIBS} -l${PYTHON_LIB}"
|
||||
CPPFLAGS="${CPPFLAGS} -I${PYTHON_INCLUDE_DIR}"
|
||||
AC_DEFINE(USE_PYTHON,1,[use python])
|
||||
fi
|
||||
])
|
||||
|
||||
|
||||
|
||||
AC_MSG_CHECKING([for libjansson])
|
||||
AC_ARG_ENABLE(json,[--enable-json/--disable-json],
|
||||
[
|
||||
|
@ -20,7 +20,9 @@ DEPEND="sys-libs/zlib
|
||||
dev-libs/libconfig
|
||||
dev-libs/openssl
|
||||
dev-libs/libevent
|
||||
lua? ( dev-lang/lua )"
|
||||
lua? ( dev-lang/lua )
|
||||
json? ( dev-lib/jansson )
|
||||
python? ( dev-lang/python )"
|
||||
|
||||
src_unpack() {
|
||||
git-2_src_unpack
|
||||
@ -30,6 +32,8 @@ src_unpack() {
|
||||
|
||||
src_configure() {
|
||||
econf $(use_enable lua liblua )
|
||||
econf $(use_enable python python )
|
||||
econf $(use_enable json json )
|
||||
}
|
||||
|
||||
src_install() {
|
||||
|
32
interface.c
32
interface.c
@ -21,7 +21,13 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#ifdef USE_PYTHON
|
||||
# include "python-tg.h"
|
||||
#endif
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@ -59,6 +65,7 @@
|
||||
# include "lua-tg.h"
|
||||
#endif
|
||||
|
||||
|
||||
//#include "mtproto-common.h"
|
||||
|
||||
#include <tgl/tgl.h>
|
||||
@ -1288,6 +1295,7 @@ extern char *downloads_directory;
|
||||
extern char *config_directory;
|
||||
extern char *binlog_file_name;
|
||||
extern char *lua_file;
|
||||
extern char *python_file;
|
||||
extern struct event *term_ev;
|
||||
|
||||
void do_clear (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
|
||||
@ -1302,6 +1310,7 @@ void do_clear (struct command *command, int arg_num, struct arg args[], struct i
|
||||
free (config_directory);
|
||||
free (binlog_file_name);
|
||||
free (lua_file);
|
||||
free (python_file);
|
||||
clear_history ();
|
||||
event_free (term_ev);
|
||||
struct event_base *ev_base = TLS->ev_base;
|
||||
@ -2332,6 +2341,9 @@ void print_message_gw (struct tgl_state *TLSR, struct tgl_message *M) {
|
||||
#ifdef USE_LUA
|
||||
lua_new_msg (M);
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
py_new_msg (M);
|
||||
#endif
|
||||
if (!binlog_read) { return; }
|
||||
if (tgl_get_peer_type (M->to_id) == TGL_PEER_ENCR_CHAT) {
|
||||
write_secret_chat_file ();
|
||||
@ -2361,6 +2373,9 @@ void our_id_gw (struct tgl_state *TLSR, int id) {
|
||||
#ifdef USE_LUA
|
||||
lua_our_id (id);
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
py_our_id (id);
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_peer_updates (struct in_ev *ev, int flags) {
|
||||
@ -2426,7 +2441,10 @@ void user_update_gw (struct tgl_state *TLSR, struct tgl_user *U, unsigned flags)
|
||||
#ifdef USE_LUA
|
||||
lua_user_update (U, flags);
|
||||
#endif
|
||||
|
||||
#ifdef USE_PYTHON
|
||||
py_user_update (U, flags);
|
||||
#endif
|
||||
|
||||
if (disable_output && !notify_ev) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
struct in_ev *ev = notify_ev;
|
||||
@ -2457,7 +2475,10 @@ void chat_update_gw (struct tgl_state *TLSR, struct tgl_chat *U, unsigned flags)
|
||||
#ifdef USE_LUA
|
||||
lua_chat_update (U, flags);
|
||||
#endif
|
||||
|
||||
#ifdef USE_PYTHON
|
||||
py_chat_update (U, flags);
|
||||
#endif
|
||||
|
||||
if (disable_output && !notify_ev) { return; }
|
||||
if (!binlog_read) { return; }
|
||||
struct in_ev *ev = notify_ev;
|
||||
@ -2488,7 +2509,12 @@ void secret_chat_update_gw (struct tgl_state *TLSR, struct tgl_secret_chat *U, u
|
||||
#ifdef USE_LUA
|
||||
lua_secret_chat_update (U, flags);
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
py_secret_chat_update (U, flags);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if ((flags & TGL_UPDATE_WORKING) || (flags & TGL_UPDATE_DELETED)) {
|
||||
write_secret_chat_file ();
|
||||
}
|
||||
|
21
loop.c
21
loop.c
@ -21,7 +21,13 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if USE_PYTHON
|
||||
#include "python-tg.h"
|
||||
#endif
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#define READLINE_CALLBACKS
|
||||
|
||||
#include <assert.h>
|
||||
@ -56,7 +62,10 @@
|
||||
#include "interface.h"
|
||||
#include "telegram.h"
|
||||
#include "loop.h"
|
||||
#if USE_LUA
|
||||
#include "lua-tg.h"
|
||||
#endif
|
||||
|
||||
#include <tgl/tgl.h>
|
||||
#include <tgl/tgl-binlog.h>
|
||||
#include <tgl/tgl-net.h>
|
||||
@ -215,6 +224,10 @@ void net_loop (void) {
|
||||
lua_do_all ();
|
||||
#endif
|
||||
|
||||
#ifdef USE_PYTHON
|
||||
py_do_all ();
|
||||
#endif
|
||||
|
||||
if (safe_quit && !TLS->active_queries) {
|
||||
printf ("All done. Exit\n");
|
||||
do_halt (0);
|
||||
@ -655,6 +668,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) {
|
||||
@ -710,6 +727,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);
|
||||
|
48
main.c
48
main.c
@ -21,6 +21,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_PYTHON
|
||||
# include "python-tg.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@ -75,6 +79,7 @@
|
||||
# include "lua-tg.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <tgl/tgl.h>
|
||||
|
||||
#define PROGNAME "telegram-cli"
|
||||
@ -107,6 +112,7 @@ char *downloads_directory;
|
||||
char *config_directory;
|
||||
char *binlog_file_name;
|
||||
char *lua_file;
|
||||
char *python_file;
|
||||
int binlog_enabled;
|
||||
extern int log_level;
|
||||
int sync_from_start;
|
||||
@ -381,6 +387,10 @@ void parse_config (void) {
|
||||
parse_config_val (&conf, &lua_file, "lua_script", 0, config_directory);
|
||||
}
|
||||
|
||||
if (!python_file) {
|
||||
parse_config_val (&conf, &python_file, "python_script", 0, config_directory);
|
||||
}
|
||||
|
||||
strcpy (buf + l, "binlog_enabled");
|
||||
config_lookup_bool (&conf, buf, &binlog_enabled);
|
||||
|
||||
@ -484,6 +494,26 @@ void usage (void) {
|
||||
#ifdef USE_JSON
|
||||
printf (" --json prints answers and values in json format\n");
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
printf (" -Z python script file\n");
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
printf (" -Z python script file\n");
|
||||
#endif
|
||||
printf (" -W send dialog_list query and wait for answer before reading input\n");
|
||||
printf (" -C disable color output\n");
|
||||
printf (" -R disable readline\n");
|
||||
printf (" -d daemon mode\n");
|
||||
printf (" -L <log-name> log file name\n");
|
||||
printf (" -U <user-name> change uid after start\n");
|
||||
printf (" -G <group-name> change gid after start\n");
|
||||
printf (" -D disable output\n");
|
||||
printf (" -P <port> port to listen for input commands\n");
|
||||
printf (" -S <socket-name> unix socket to create\n");
|
||||
printf (" -e <commands> make commands end exit\n");
|
||||
printf (" -I use user and chat IDs in updates instead of names\n");
|
||||
printf (" -6 use ipv6 (may be unstable)\n");
|
||||
|
||||
exit (1);
|
||||
}
|
||||
|
||||
@ -643,8 +673,12 @@ void args_parse (int argc, char **argv) {
|
||||
#endif
|
||||
#ifdef USE_LUA
|
||||
"s:"
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
"Z:"
|
||||
#endif
|
||||
, long_options, NULL
|
||||
|
||||
)) != -1) {
|
||||
switch (opt) {
|
||||
case 1000:
|
||||
@ -700,6 +734,11 @@ void args_parse (int argc, char **argv) {
|
||||
case 'W':
|
||||
wait_dialog_list = 1;
|
||||
break;
|
||||
#ifdef USE_PYTHON
|
||||
case 'Z':
|
||||
python_file = strdup (optarg);
|
||||
break;
|
||||
#endif
|
||||
case 'C':
|
||||
disable_colors ++;
|
||||
break;
|
||||
@ -922,6 +961,9 @@ int main (int argc, char **argv) {
|
||||
"This is free software, and you are welcome to redistribute it\n"
|
||||
"under certain conditions; type `show_license' for details.\n"
|
||||
"Telegram-cli uses libtgl version " TGL_VERSION "\n"
|
||||
#ifdef USE_PYTHON
|
||||
"Telegram-cli uses libpython version " PY_VERSION "\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
running_for_first_time ();
|
||||
@ -942,6 +984,12 @@ int main (int argc, char **argv) {
|
||||
lua_init (lua_file);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_PYTHON
|
||||
if (python_file) {
|
||||
py_init (python_file);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inner_main ();
|
||||
|
||||
|
1253
python-tg.c
Normal file
1253
python-tg.c
Normal file
File diff suppressed because it is too large
Load Diff
89
python-tg.h
Normal file
89
python-tg.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
This file is part of telegram-cli.
|
||||
|
||||
Telegram-cli is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Telegram-cli is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this telegram-cli. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright Vitaly Valtman 2013-2015
|
||||
Copyright Vincent Castellano 2015
|
||||
*/
|
||||
#ifndef __PYTHON_TG_H__
|
||||
#define __PYTHON_TG_H__
|
||||
|
||||
#include <Python.h>
|
||||
#include <string.h>
|
||||
#include <tgl/tgl.h>
|
||||
|
||||
// Python functions
|
||||
void py_init (const char *file);
|
||||
void py_new_msg (struct tgl_message *M);
|
||||
void py_our_id (int id);
|
||||
void py_secret_chat_update (struct tgl_secret_chat *U, unsigned flags);
|
||||
void py_user_update (struct tgl_user *U, unsigned flags);
|
||||
void py_chat_update (struct tgl_chat *C, unsigned flags);
|
||||
void py_binlog_end (void);
|
||||
void py_diff_end (void);
|
||||
void py_do_all (void);
|
||||
|
||||
// Binding functions
|
||||
PyObject* py_contact_list(PyObject *self, PyObject *args);
|
||||
PyObject* py_dialog_list(PyObject *self, PyObject *args);
|
||||
PyObject* py_rename_chat(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_msg(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_typing(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_typing_abort(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_photo(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_video(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_audio(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_document(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_file(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_text(PyObject *self, PyObject *args);
|
||||
PyObject* py_chat_set_photo(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_photo(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_video(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_video_thumb(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_audio(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_document(PyObject *self, PyObject *args);
|
||||
PyObject* py_load_document_thumb(PyObject *self, PyObject *args);
|
||||
PyObject* py_fwd(PyObject *self, PyObject *args);
|
||||
PyObject* py_fwd_media(PyObject *self, PyObject *args);
|
||||
PyObject* py_chat_info(PyObject *self, PyObject *args);
|
||||
PyObject* py_user_info(PyObject *self, PyObject *args);
|
||||
PyObject* py_history(PyObject *self, PyObject *args);
|
||||
PyObject* py_chat_add_user(PyObject *self, PyObject *args);
|
||||
PyObject* py_chat_del_user(PyObject *self, PyObject *args);
|
||||
PyObject* py_add_contact(PyObject *self, PyObject *args);
|
||||
PyObject* py_del_contact(PyObject *self, PyObject *args);
|
||||
PyObject* py_rename_contact(PyObject *self, PyObject *args);
|
||||
PyObject* py_search(PyObject *self, PyObject *args);
|
||||
PyObject* py_global_search(PyObject *self, PyObject *args);
|
||||
PyObject* py_mark_read(PyObject *self, PyObject *args);
|
||||
PyObject* py_set_profile_photo(PyObject *self, PyObject *args);
|
||||
PyObject* py_set_profile_name(PyObject *self, PyObject *args);
|
||||
PyObject* py_create_secret_chat(PyObject *self, PyObject *args);
|
||||
PyObject* py_create_group_chat(PyObject *self, PyObject *args);
|
||||
PyObject* py_delete_msg(PyObject *self, PyObject *args);
|
||||
PyObject* py_restore_msg(PyObject *self, PyObject *args);
|
||||
PyObject* py_accept_secret_chat(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_contact(PyObject *self, PyObject *args);
|
||||
PyObject* py_status_online(PyObject *self, PyObject *args);
|
||||
PyObject* py_status_offline(PyObject *self, PyObject *args);
|
||||
PyObject* py_send_location(PyObject *self, PyObject *args);
|
||||
PyObject* py_extf(PyObject *self, PyObject *args);
|
||||
|
||||
|
||||
// Util Functions
|
||||
void py_add_string_field (PyObject* dict, char *name, const char *value);
|
||||
void py_add_string_field_arr (PyObject* list, int num, const char *value);
|
||||
void py_add_num_field (PyObject* dict, const char *name, double value);
|
||||
#endif
|
1422
python-types.c
Normal file
1422
python-types.c
Normal file
File diff suppressed because it is too large
Load Diff
21
python-types.h
Normal file
21
python-types.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef __PYTHON_TYPES_H__
|
||||
#define __PYTHON_TYPES_H__
|
||||
|
||||
#include <Python.h>
|
||||
#include <tgl/tgl.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
tgl_peer_t *peer;
|
||||
} tgl_Peer;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct tgl_message *msg;
|
||||
} tgl_Msg;
|
||||
|
||||
|
||||
PyObject * tgl_Peer_FromTglPeer(tgl_peer_t *peer);
|
||||
PyObject * tgl_Msg_FromTglMsg(struct tgl_message *peer);
|
||||
|
||||
#endif
|
12
test.lua
12
test.lua
@ -57,17 +57,6 @@ function get_title (P, Q)
|
||||
end
|
||||
end
|
||||
|
||||
local lgi = require ('lgi')
|
||||
local notify = lgi.require('Notify')
|
||||
notify.init ("Telegram updates")
|
||||
local icon = os.getenv("HOME") .. "/.telegram-cli/telegram-pics/telegram_64.png"
|
||||
|
||||
function do_notify (user, msg)
|
||||
local n = notify.Notification.new(user, msg, icon)
|
||||
n:show ()
|
||||
end
|
||||
|
||||
-- }}}
|
||||
|
||||
function on_msg_receive (msg)
|
||||
if started == 0 then
|
||||
@ -76,7 +65,6 @@ function on_msg_receive (msg)
|
||||
if msg.out then
|
||||
return
|
||||
end
|
||||
do_notify (get_title (msg.from, msg.to), msg.text)
|
||||
|
||||
if (msg.text == 'ping') then
|
||||
if (msg.to.id == our_id) then
|
||||
|
71
tg-test.py
Normal file
71
tg-test.py
Normal file
@ -0,0 +1,71 @@
|
||||
import tgl
|
||||
import pprint
|
||||
from functools import partial
|
||||
|
||||
|
||||
our_id = 0
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
binlog_done = False;
|
||||
|
||||
def on_binlog_replay_end():
|
||||
binlog_done = True;
|
||||
|
||||
def on_get_difference_end():
|
||||
pass
|
||||
|
||||
def on_our_id(id):
|
||||
our_id = id
|
||||
return "Set ID: " + str(our_id)
|
||||
|
||||
def msg_cb(success, msg):
|
||||
pp.pprint(success)
|
||||
pp.pprint(msg)
|
||||
|
||||
HISTORY_QUERY_SIZE = 100
|
||||
|
||||
def history_cb(msg_list, peer, success, msgs):
|
||||
print(len(msgs))
|
||||
msg_list.extend(msgs)
|
||||
print(len(msg_list))
|
||||
if len(msgs) == HISTORY_QUERY_SIZE:
|
||||
tgl.get_history(peer, len(msg_list), HISTORY_QUERY_SIZE, partial(history_cb, msg_list, peer));
|
||||
|
||||
|
||||
def cb(success):
|
||||
print(success)
|
||||
|
||||
def on_msg_receive(msg):
|
||||
if msg.out and not binlog_done:
|
||||
return;
|
||||
|
||||
if msg.dest.id == our_id: # direct message
|
||||
peer = msg.src
|
||||
else: # chatroom
|
||||
peer = msg.dest
|
||||
|
||||
pp.pprint(msg)
|
||||
if msg.text.startswith("!ping"):
|
||||
print("SENDING PONG")
|
||||
peer.send_msg("PONG!", msg_cb)
|
||||
peer.send_contact(msg.src.phone, msg.src.first_name, msg.src.last_name , cb)
|
||||
|
||||
|
||||
def on_secret_chat_update(peer, types):
|
||||
return "on_secret_chat_update"
|
||||
|
||||
def on_user_update():
|
||||
pass
|
||||
|
||||
def on_chat_update():
|
||||
pass
|
||||
|
||||
# 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)
|
||||
|
Loading…
Reference in New Issue
Block a user