Skip to content

Commit 452c30f

Browse files
author
vvaltman
committed
Merge branch 'master' of https://github.com/datamachine/tg into datamachine-master
2 parents 8ba66a8 + d594d71 commit 452c30f

20 files changed

+3692
-27
lines changed

‎.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
telegram
22
*.o
33
Makefile
4+
aclocal.m4
45
autom4te.cache
56
config.h
67
config.log
@@ -16,4 +17,5 @@ debian/telegram-cli.[a-z]
1617
debian/files
1718
debian/telegram-cli/*
1819
debian/telegram-cli.debhelper.log
19-
debian/telegram-cli.substvars
20+
debian/telegram-cli.substvars
21+
__pycache__

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ install:
99
- sudo apt-get install libreadline6-dev
1010
- sudo apt-get install libssl-dev
1111
- sudo apt-get install liblua5.2-dev lua5.2
12+
- sudo apt-get install python-dev python
1213
- sudo apt-get install libevent-dev
1314
- sudo apt-get install libjansson-dev
1415

‎Makefile.in

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ CFLAGS=@CFLAGS@
44
LDFLAGS=@LDFLAGS@ @OPENSSL_LDFLAGS@
55
CPPFLAGS=@CPPFLAGS@ @OPENSSL_INCLUDES@
66
DEFS=@DEFS@
7-
COMPILE_FLAGS=${CFLAGS} ${CPFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter -fPIC
8-
7+
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
98
EXTRA_LIBS=@LIBS@ @EXTRA_LIBS@ @OPENSSL_LIBS@
10-
LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS}
9+
LOCAL_LDFLAGS=-rdynamic -ggdb -levent ${EXTRA_LIBS} -ldl -lpthread -lutil
1110
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
1211

1312
DEP=dep
@@ -19,7 +18,7 @@ DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${LIB} ${DEP}/auto ${OBJ}/auto
1918

2019
EXE_LIST=${EXE}/telegram-cli
2120

22-
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/lua-tg.o ${OBJ}/json-tg.o
21+
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
2322

2423
INCLUDE=-I. -I${srcdir} -I${srcdir}/tgl
2524
CC=@CC@

‎README-PY

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
To use python with client you should write python script. You can specify it from config ("python_script" option) or from command_line [-Z].
2+
3+
You should set the following callbacks in your script:
4+
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
5+
some time ago.
6+
7+
tgl.on_get_difference_end() - it is called after first get_difference call. So we received all updates after last client execute.
8+
9+
tgl.on_our_id(our_id) - Informs about id of currently logged in user.
10+
11+
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).
12+
13+
tgl.on_user_update(peer, what_changed) - updated info about user. what_changed is array of strings.
14+
tgl.on_chat_update(peer, what_changed) - updated info about user. what_changed is array of strings.
15+
tgl.on_secret_chat_update(peer, what_changed) - updated info about user. what_changed is array of strings.
16+
17+
18+
19+
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.
20+
These functions may return false immidiately if something is bad with args, or return true and call cb_function in future.
21+
The callback function should have one arguments: first success (True or False), and the rest depends on the call.
22+
Functions that require a peer type other than what is passed will raise tgl.PeerError.
23+
24+
25+
Function_list (arguments are listed aside from callback, import tgl for access) :
26+
tgl.get_contact_list ()
27+
tgl.get_dialog_list ()
28+
29+
tgl.rename_chat (peer, new_name)
30+
tgl.chat_set_photo (peer, file)
31+
32+
tgl.send_typing (peer)
33+
tgl.send_typing_abort (peer)
34+
35+
tgl.send_msg (peer, text)
36+
tgl.fwd_msg (peer, msg)
37+
38+
tgl.send_photo (peer, file)
39+
tgl.send_video (peer, file)
40+
tgl.send_audio (peer, file)
41+
tgl.send_document (peer, file)
42+
tgl.send_text (peer, file)
43+
44+
tgl.load_photo(msg)
45+
tgl.load_video(msg)
46+
tgl.load_video_thumb(msg)
47+
tgl.load_audio(msg)
48+
tgl.load_document(msg)
49+
tgl.load_document_thumb(msg)
50+
51+
tgl.info (peer)
52+
53+
tgl.get_history (peer, limit)
54+
55+
tgl.chat_add_user (peer, user)
56+
tgl.chat_del_user (peer, user)
57+
58+
tgl.add_contact (phone, first_name, last_name)
59+
tgl.rename_contact (phone, first_name, last_name)
60+
61+
tgl.msg_search (peer, text)
62+
tgl.msg_global_search (text)
63+
64+
tgl.mark_read (peer)
65+
66+
tgl.set_profile_photo (file)
67+
68+
tgl.create_secret_chat (user)
69+
tgl.create_group_chat (peer, name)
70+
71+
tgl.delete_msg (msg)
72+
tgl.restore_msg (msg_id)
73+
74+
tgl.status_online ()
75+
tgl.status_offline ()
76+
77+
tgl.send_location (peer, latitude, longitude)
78+
79+
Additionally, the tgl.Peer object has the following direct methods:
80+
peer.rename_chat(new_name)
81+
peer.chat_set_photo(file)
82+
peer.send_typing()
83+
peer.send_typing_abort()
84+
peer.send_msg(text)
85+
peer.send_photo(file)
86+
peer.send_video(file)
87+
peer.send_document(file)
88+
peer.send_text(file)
89+
peer.info()
90+
peer.history(limit, offset)
91+
peer.add_user(peer)
92+
peer.del_user(peer)
93+
peer.search(text)
94+
peer.mark_read()
95+
peer.send_location(latitude, longitude)

‎README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,35 @@ Clone GitHub Repository
2424

2525
git clone --recursive https://github.com/vysheng/tg.git && cd tg
2626

27+
### Python Support
28+
29+
Python support is currently limited to Python 2.7 or Python 3.1+. Other versions may work but are not tested.
30+
2731
#### Linux and BSDs
2832

29-
Install libs: readline, openssl and (if you want to use config) libconfig, liblua and libjansson.
30-
If you do not want to use them pass options --disable-libconfig, --disable-liblua and --disable-json respectively.
33+
Install libs: readline, openssl and (if you want to use config) libconfig, liblua, python and libjansson.
34+
If you do not want to use them pass options --disable-libconfig, --disable-liblua, --disable-python and --disable-json respectively.
3135

3236
On Ubuntu/Debian use:
3337

34-
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev make
38+
sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
3539

3640
On gentoo:
3741

38-
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent dev-libs/jansson
42+
sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent dev-libs/jansson dev-lang/python
3943

4044
On Fedora:
4145

4246
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel libjansson-devel
47+
sudo yum install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel python-devel
4348

4449
On FreeBSD:
4550

46-
pkg install libconfig libexecinfo lua52
51+
pkg install libconfig libexecinfo lua52 python
4752

4853
On OpenBSD:
4954

50-
pkg_add libconfig libexecinfo lua
55+
pkg_add libconfig libexecinfo lua python
5156

5257
Then,
5358

@@ -69,6 +74,7 @@ If using [Homebrew](http://brew.sh/):
6974
brew install libconfig
7075
brew install readline
7176
brew install lua
77+
brew install python
7278
brew install libevent
7379
export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.3.8/include"
7480
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):
8187
sudo port install libconfig-hr
8288
sudo port install readline
8389
sudo port install lua51
90+
sudo port install python34
8491
sudo port install libevent
8592
export CFLAGS="-I/usr/local/include -I/opt/local/include -I/opt/local/include/lua-5.1"
8693
export LDFLAGS="-L/usr/local/lib -L/opt/local/lib -L/opt/local/lib/lua-5.1"

‎ax_python.m4

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# ===========================================================================
2+
# http://www.gnu.org/software/autoconf-archive/ax_python.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_PYTHON
8+
#
9+
# DESCRIPTION
10+
#
11+
# This macro does a complete Python development environment check.
12+
#
13+
# It recurses through several python versions (from 2.1 to 2.6 in this
14+
# version), looking for an executable. When it finds an executable, it
15+
# looks to find the header files and library.
16+
#
17+
# It sets PYTHON_BIN to the name of the python executable,
18+
# PYTHON_INCLUDE_DIR to the directory holding the header files, and
19+
# PYTHON_LIB to the name of the Python library.
20+
#
21+
# This macro calls AC_SUBST on PYTHON_BIN (via AC_CHECK_PROG),
22+
# PYTHON_INCLUDE_DIR and PYTHON_LIB.
23+
#
24+
# LICENSE
25+
#
26+
# Copyright (c) 2008 Michael Tindal
27+
#
28+
# This program is free software; you can redistribute it and/or modify it
29+
# under the terms of the GNU General Public License as published by the
30+
# Free Software Foundation; either version 2 of the License, or (at your
31+
# option) any later version.
32+
#
33+
# This program is distributed in the hope that it will be useful, but
34+
# WITHOUT ANY WARRANTY; without even the implied warranty of
35+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
36+
# Public License for more details.
37+
#
38+
# You should have received a copy of the GNU General Public License along
39+
# with this program. If not, see <http://www.gnu.org/licenses/>.
40+
#
41+
# As a special exception, the respective Autoconf Macro's copyright owner
42+
# gives unlimited permission to copy, distribute and modify the configure
43+
# scripts that are the output of Autoconf when processing the Macro. You
44+
# need not follow the terms of the GNU General Public License when using
45+
# or distributing such scripts, even though portions of the text of the
46+
# Macro appear in them. The GNU General Public License (GPL) does govern
47+
# all other use of the material that constitutes the Autoconf Macro.
48+
#
49+
# This special exception to the GPL applies to versions of the Autoconf
50+
# Macro released by the Autoconf Archive. When you make and distribute a
51+
# modified version of the Autoconf Macro, you may extend this special
52+
# exception to the GPL to apply to your modified version as well.
53+
54+
#serial 14
55+
56+
AC_DEFUN([AX_PYTHON],
57+
[AC_MSG_CHECKING(for python build information)
58+
AC_MSG_RESULT([])
59+
for python in python3.4 python3.3 python3.2 python3.1 python3 python2.7 python2.6 python2 python; do
60+
AC_CHECK_PROGS(PYTHON_BIN, [$python])
61+
ax_python_bin=$PYTHON_BIN
62+
if test x$ax_python_bin != x; then
63+
AC_CHECK_LIB($ax_python_bin, main, ax_python_lib=$ax_python_bin, ax_python_lib=no)
64+
if test x$ax_python_lib == xno; then
65+
AC_CHECK_LIB(${ax_python_bin}m, main, ax_python_lib=${ax_python_bin}m, ax_python_lib=no)
66+
fi
67+
if test x$ax_python_lib != xno; then
68+
ax_python_header=`$ax_python_bin -c "from distutils.sysconfig import *; print(get_config_var('CONFINCLUDEPY'))"`
69+
if test x$ax_python_header != x; then
70+
break;
71+
fi
72+
fi
73+
fi
74+
unset ac_cv_prog_PYTHON_BIN
75+
unset PYTHON_BIN
76+
done
77+
if test x$ax_python_bin = x; then
78+
ax_python_bin=no
79+
fi
80+
if test x$ax_python_header = x; then
81+
ax_python_header=no
82+
fi
83+
if test x$ax_python_lib = x; then
84+
ax_python_lib=no
85+
fi
86+
87+
AC_MSG_RESULT([ results of the Python check:])
88+
AC_MSG_RESULT([ Binary: $ax_python_bin])
89+
AC_MSG_RESULT([ Library: $ax_python_lib])
90+
AC_MSG_RESULT([ Include Dir: $ax_python_header])
91+
92+
93+
PYTHON_FOUND=yes
94+
if test x$ax_python_header != xno; then
95+
PYTHON_INCLUDE_DIR=$ax_python_header
96+
AC_SUBST(PYTHON_INCLUDE_DIR)
97+
else
98+
PYTHON_FOUND=no
99+
fi
100+
101+
if test x$ax_python_lib != xno; then
102+
PYTHON_LIB=$ax_python_lib
103+
AC_SUBST(PYTHON_LIB)
104+
else
105+
PYTHON_FOUND=no
106+
fi
107+
AC_SUBST(PYTHON_FOUND)
108+
109+
])dnl

‎bootstrap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh
2+
3+
aclocal
4+
autoheader
5+
automake --gnu --add-missing
6+
autoconf

‎config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
/* use lua */
165165
#undef USE_LUA
166166

167+
/* use python */
168+
#undef USE_PYTHON
169+
167170
/* fixed for correct valgrind work */
168171
#undef VALGRIND_FIXES
169172

0 commit comments

Comments
 (0)