diff --git a/README.md b/README.md index 970475b..61f6b41 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,17 @@ There's no easy way to see this from telegram, so you can use the separate utili ### Usage -You can create all config files you want. You will only need to pass it as parameter, but if you don't it will try to grab `config.ini` by default, and it will fail if it doesn't exist: +There only can be one configuration file. This is because it can only be one bot connection, when there's more than one, message are lost. Therefore, for linking more rooms you must "link" them in the configuration. This is done simply by hooking jabber rooms with Telegram: - # it's advisable to use tmux or screen to execute the next order - $ jabbergram.py example.ini + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 + +Thus, the example's muc "exampleMuc@muc.nope.org" syncs with the group "-10293943920" and "segunda@muc.sip.org" with "120 301203". ### License @@ -124,7 +131,7 @@ Clonar el repositorio: ### Configuración -Este programa es simple, no tiene ni un menú de `ayuda`. Lo primero que hay que hacer es crear el bot de `Telegrama`. Para ello, hay que tener una cuenta de `Telegram` y hablar con [BotFather](https://telegram.me/botfather). A continuación, ejecuta: +Este programa es simple, no tiene ni un menú de `ayuda`. Lo primero que hay que hacer es crear el bot de `Telegram`. Para ello, hay que tener una cuenta de `Telegram` y hablar con [BotFather](https://telegram.me/botfather). A continuación, ejecuta: /start /newbot @@ -152,10 +159,17 @@ No hay manera fácil de ver el ID desde `Telegram`, por lo que se puede utilizar ### Uso -Se pueden crear todos los archivos de configuración que se deseen. Sólo tendrás que pasarlo como parámetro al programa, si no se hace se intentará coger el archivo `config.ini` por defecto, y se producirá un error si no existe: +Sólo puede haber un archivo de configuración. Esto es debido a que sólo puede haber una conexión del bot, cuando hay más de una se pierden mensajes. Por lo tanto, para linkear más salas hay que "linkearlas" en la configuración. Esto se hace, simplemente, enganchando las salas de jabber con las de telegram: - # Es recomendable utilizar tmux o la pantalla para ejecutar la siguiente orden - $ jabbergram.py example.ini + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 + +De este modo, el muc "exampleMuc@muc.nope.org" se sincronizará con el grupo "-10293943920", y "segunda@muc.sip.org" con "120301203". ### Licencia diff --git a/README.org b/README.org index bd35b86..4c1c94f 100644 --- a/README.org +++ b/README.org @@ -48,12 +48,19 @@ There's no easy way to see this from telegram, so you can use the separate utility called =seeIdGroups.py=. To execute it, you only need to set the =token= parameter in the config file. You will need that somebody invite the bot to the group. Also, people on that group must send some messages, so the utility can grab it's id. It may take a couple. When you have the group ID you want, just press Ctrl-c, copy it to the config file (even the minus symbol), and the configuration will be done. *** Usage - You can create all config files you want. You will only need to pass it as parameter, but if you don't it will try to grab =config.ini= by default, and it will fail if it doesn't exist: + There only can be one configuration file. This is because it can only be one bot connection, when there's more than one, message are lost. Therefore, for linking more rooms you must "link" them in the configuration. This is done simply by hooking jabber rooms with Telegram: #+BEGIN_SRC sh - # it's advisable to use tmux or screen to execute the next order - $ jabbergram.py example.ini + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 #+END_SRC + + Thus, the example's muc "exampleMuc@muc.nope.org" syncs with the group "-10293943920" and "segunda@muc.sip.org" with "120 301203". *** License #+BEGIN_SRC text This program is free software: you can redistribute it and / or modify @@ -88,7 +95,7 @@ $ su -c "python3 setup.py instalar" #+END_SRC *** Configuración - Este programa es simple, no tiene ni un menú de =ayuda=. Lo primero que hay que hacer es crear el bot de =Telegrama=. Para ello, hay que tener una cuenta de =Telegram= y hablar con [[https://telegram.me/botfather][BotFather]]. A continuación, ejecuta: + Este programa es simple, no tiene ni un menú de =ayuda=. Lo primero que hay que hacer es crear el bot de =Telegram=. Para ello, hay que tener una cuenta de =Telegram= y hablar con [[https://telegram.me/botfather][BotFather]]. A continuación, ejecuta: #+BEGIN_SRC sh /start @@ -118,12 +125,19 @@ No hay manera fácil de ver el ID desde =Telegram=, por lo que se puede utilizar el programa llamado =seeIdGroups.py=. Para ejecutarlo sólo es necesario establecer el parámetro =token= del archivo de configuración. Necesitarás que alguien invite al bot al grupo. Además, las personas de ese grupo deben enviar algunos mensajes, para que el programa pueda coger su ID. Puede llevar unos segundos el que aparezcan los mensajes. Cuando se tenga el ID de grupo que se quiere, sólo hay que pulsar Ctrl-c, copiarlo en el archivo de configuración (incluido el simbolo menos), y la configuración estará terminada. *** Uso - Se pueden crear todos los archivos de configuración que se deseen. Sólo tendrás que pasarlo como parámetro al programa, si no se hace se intentará coger el archivo =config.ini= por defecto, y se producirá un error si no existe: + Sólo puede haber un archivo de configuración. Esto es debido a que sólo puede haber una conexión del bot, cuando hay más de una se pierden mensajes. Por lo tanto, para linkear más salas hay que "linkearlas" en la configuración. Esto se hace, simplemente, enganchando las salas de jabber con las de telegram: - #+BEGIN_SRC sh - # Es recomendable utilizar tmux o la pantalla para ejecutar la siguiente orden - $ jabbergram.py example.ini - #+END_SRC +#+BEGIN_SRC text + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 +#+END_SRC + +De este modo, el muc "exampleMuc@muc.nope.org" se sincronizará con el grupo "-10293943920", y "segunda@muc.sip.org" con "120301203". *** Licencia #+BEGIN_SRC text This program is free software: you can redistribute it and / or modify diff --git a/README.rst b/README.rst index 03c5f4f..4671315 100644 --- a/README.rst +++ b/README.rst @@ -1,250 +1,168 @@ -- `jabbergram <#jabbergram>`__ -- `English <#english>`__ +- `ended in bot, always <#ended-in-bot,-always>`__ +- `+BEGIN\_SRC text <#+begin_src-text>`__ +- `+END\_SRC <#+end_src>`__ - - `About <#about>`__ - - `Installation <#installation>`__ - - `Configuration <#configuration>`__ - - `Usage <#usage>`__ - - `License <#license>`__ - -- `Castellano <#castellano>`__ - - - `Acerca de <#acerca-de>`__ - - `Instalación <#instalación>`__ - - `Configuración <#configuración>`__ - - `Uso <#uso>`__ - - `Licencia <#licencia>`__ - -jabbergram -========== - -English -------- - -About -~~~~~ - -With this program, it's possible to use a MuC ``XMPP`` room to talk to a -group on ``Telegram`` and vice versa. The aim of this program is to be -just a simple gateway, just pass text from one way to the other. Once -it's stable, it probably won't have more improvements, since I don't -need them. - -Installation -~~~~~~~~~~~~ - -As with any program that uses python, it should be used a virtual -environment (virtualenv), but that is user selectable. It's possible to -use one of the next installation methods: - -Install via pip: +ended in bot, always +==================== :: - $ su -c "pip3 install jabbergram" + # then it will show your bot token, save it + /setprivacy + YourNameBot + # now press Disable + #+END_SRC -Clone the repository: + The =/setprivacy= option is to make the bot read all what it's said to him, not only when using commands. It's necessary to make =jabbergram= work. More info on creating =Telegram= bots at their [[https://core.telegram.org/bots][webpage]]. + + Then, you will have to create a config file. We'll call it =config.ini=. In that file, enter the next parameters: + + #+BEGIN_SRC text + [config] + jid = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 + #+END_SRC + + The only thing worth mentioning is the =token= section, which is said to you when creating the bot, and the =group=, that is the =Telegram= group ID. + + There's no easy way to see this from telegram, so you can use the separate utility called =seeIdGroups.py=. To execute it, you only need to set the =token= parameter in the config file. You will need that somebody invite the bot to the group. Also, people on that group must send some messages, so the utility can grab it's id. It may take a couple. When you have the group ID you want, just press Ctrl-c, copy it to the config file (even the minus symbol), and the configuration will be done. + +\*\*\* Usage There only can be one configuration file. This is because +it can only be one bot connection, when there's more than one, message +are lost. Therefore, for linking more rooms you must "link" them in the +configuration. This is done simply by hooking jabber rooms with +Telegram: :: - $ git clone git://daemons.cf/jabbergram - $ cd jabbergram - $ su -c "pip3 install -r requirements.txt" - $ su -c "python3 setup.py install" + #+BEGIN_SRC sh + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 + #+END_SRC -Configuration -~~~~~~~~~~~~~ + Thus, the example's muc "exampleMuc@muc.nope.org" syncs with the group "-10293943920" and "segunda@muc.sip.org" with "120 301203". -This program is simple, it even doesn't have a ``help`` menu. First -thing you need to do is to create ``Telegram`` Bot. To do so, you must -have a telegram account and talk to -`BotFather `__. Then, execute: +\*\*\* License #+BEGIN\_SRC text 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 3 of the License, or (At your option) any later version. :: - /start - /newbot - YourNameBot # ended in bot, always - # then it will show your bot token, save it - /setprivacy - YourNameBot - # now press Disable + 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. -The ``/setprivacy`` option is to make the bot read all what it's said to -him, not only when using commands. It's necessary to make ``jabbergram`` -work. More info on creating ``Telegram`` bots at their -`webpage `__. + You should have received a copy of the GNU General Public License + Along With This Program. If not, see . + #+END_SRC -Then, you will have to create a config file. We'll call it -``config.ini``. In that file, enter the next parameters: - -:: - - [config] - jid = exampleJid@nope.org - password = difficultPassword - muc_room = exampleMuc@muc.nope.org - nick = jabbergram - token = jabbergramBotTokken - group = -10293943920 - -The only thing worth mentioning is the ``token`` section, which is said -to you when creating the bot, and the ``group``, that is the -``Telegram`` group ID. - -There's no easy way to see this from telegram, so you can use the -separate utility called ``seeIdGroups.py``. To execute it, you only need -to set the ``token`` parameter in the config file. You will need that -somebody invite the bot to the group. Also, people on that group must -send some messages, so the utility can grab it's id. It may take a -couple. When you have the group ID you want, just press Ctrl-c, copy it -to the config file (even the minus symbol), and the configuration will -be done. - -Usage -~~~~~ - -You can create all config files you want. You will only need to pass it -as parameter, but if you don't it will try to grab ``config.ini`` by -default, and it will fail if it doesn't exist: - -:: - - # it's advisable to use tmux or screen to execute the next order - $ jabbergram.py example.ini - -License -~~~~~~~ - -:: - - 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 3 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 . - -Castellano ----------- - -Acerca de -~~~~~~~~~ - -Con este programa es posible utilizar una sala ``XMPP`` para hablar con -un grupo de ``Telegram`` y viceversa. El objetivo de este programa es el -de ser sólo una pasarela sencilla, sólo tiene que pasar el texto de un -lado al otro. Una vez que sea estable, probablemente no tendrá más -mejoras, ya que yo no las necesito. - -Instalación -~~~~~~~~~~~ - -Como con cualquier programa escrito en ``Python``, deberia ser usado en -un entorno virtual (virtualenv), pero eso queda a la elección del -usuario. Es posible utilizar uno de los siguientes métodos de +\*\* Castellano \*\*\* Acerca de Con este programa es posible utilizar +una sala =XMPP= para hablar con un grupo de =Telegram= y viceversa. El +objetivo de este programa es el de ser sólo una pasarela sencilla, sólo +tiene que pasar el texto de un lado al otro. Una vez que sea estable, +probablemente no tendrá más mejoras, ya que yo no las necesito. \*\*\* +Instalación Como con cualquier programa escrito en =Python=, deberia ser +usado en un entorno virtual (virtualenv), pero eso queda a la elección +del usuario. Es posible utilizar uno de los siguientes métodos de instalación: -Instalar a través de ``pip``: +:: + + Instalar a través de =pip=: + #+BEGIN_SRC sh + $ su -c "pip3 instalar jabbergram" + #+END_SRC + + Clonar el repositorio: + #+BEGIN_SRC sh + $ git clone git://daemons.cf/jabbergram + $ cd jabbergram + $ su -c "pip3 instalar requirements.txt -r" + $ su -c "python3 setup.py instalar" + #+END_SRC + +\*\*\* Configuración Este programa es simple, no tiene ni un menú de +=ayuda=. Lo primero que hay que hacer es crear el bot de =Telegram=. +Para ello, hay que tener una cuenta de =Telegram= y hablar con +[[https://telegram.me/botfather][BotFather]]. A continuación, ejecuta: :: - $ su -c "pip3 instalar jabbergram" + #+BEGIN_SRC sh + /start + /newbot + NombreDelBot # terminado en bot, siempre + # A continuación, se mostrará el token del bot, hay que guardarlo + /setprivacy + NombreDelBot + # Ahora hay que pulsar desactivar + #+END_SRC -Clonar el repositorio: + La opción =/setprivacy= es para hacer que el robot pueda leer todo lo que se dice en el grupo, no sólo cuando se utilizan los comandos. Es necesario para hacer que =jabbergram= funcione. Más información sobre la creación los bots de =Telegrama= en su [[https://core.telegram.org/bots][página web]]. + + A continuación, hay que crear un archivo de configuración, que llamaremos =config.ini=. En ese archivo, introduce los siguientes parámetros: + + #+BEGIN_SRC text + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org + nick = jabbergram + token = jabbergramBotTokken + group = -10,293,943,920 + #+END_SRC + + La única cosa que vale la pena mencionar es la sección del =token= (que es la que nos da cuando se crea el robot) y el =group=, que es ID del grupo de =Telegram=. + + No hay manera fácil de ver el ID desde =Telegram=, por lo que se puede utilizar el programa llamado =seeIdGroups.py=. Para ejecutarlo sólo es necesario establecer el parámetro =token= del archivo de configuración. Necesitarás que alguien invite al bot al grupo. Además, las personas de ese grupo deben enviar algunos mensajes, para que el programa pueda coger su ID. Puede llevar unos segundos el que aparezcan los mensajes. Cuando se tenga el ID de grupo que se quiere, sólo hay que pulsar Ctrl-c, copiarlo en el archivo de configuración (incluido el simbolo menos), y la configuración estará terminada. + +\*\*\* Uso Sólo puede haber un archivo de configuración. Esto es debido +a que sólo puede haber una conexión del bot, cuando hay más de una se +pierden mensajes. Por lo tanto, para linkear más salas hay que +"linkearlas" en la configuración. Esto se hace, simplemente, enganchando +las salas de jabber con las de telegram: + ++BEGIN\_SRC text +================ :: - $ git clone git://daemons.cf/jabbergram - $ cd jabbergram - $ su -c "pip3 instalar requirements.txt -r" - $ su -c "python3 setup.py instalar" + [Config] + JID = exampleJid@nope.org + password = difficultPassword + muc_room = exampleMuc@muc.nope.org segunda@muc.sip.org + nick = jabbergram + token = jabbergramBotTokken + group = -10293943920 120301203 -Configuración -~~~~~~~~~~~~~ ++END\_SRC +========= -Este programa es simple, no tiene ni un menú de ``ayuda``. Lo primero -que hay que hacer es crear el bot de ``Telegrama``. Para ello, hay que -tener una cuenta de ``Telegram`` y hablar con -`BotFather `__. A continuación, ejecuta: +De este modo, el muc "exampleMuc@muc.nope.org" se sincronizará con el +grupo "-10293943920", y "segunda@muc.sip.org" con "120301203". \*\*\* +Licencia #+BEGIN\_SRC text 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 3 of the License, or (At your option) any later version. :: - /start - /newbot - NombreDelBot # terminado en bot, siempre - # A continuación, se mostrará el token del bot, hay que guardarlo - /setprivacy - NombreDelBot - # Ahora hay que pulsar desactivar + 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. -La opción ``/setprivacy`` es para hacer que el robot pueda leer todo lo -que se dice en el grupo, no sólo cuando se utilizan los comandos. Es -necesario para hacer que ``jabbergram`` funcione. Más información sobre -la creación los bots de ``Telegrama`` en su `página -web `__. - -A continuación, hay que crear un archivo de configuración, que -llamaremos ``config.ini``. En ese archivo, introduce los siguientes -parámetros: - -:: - - [Config] - JID = exampleJid@nope.org - password = difficultPassword - muc_room = exampleMuc@muc.nope.org - nick = jabbergram - token = jabbergramBotTokken - group = -10,293,943,920 - -La única cosa que vale la pena mencionar es la sección del ``token`` -(que es la que nos da cuando se crea el robot) y el ``group``, que es ID -del grupo de ``Telegram``. - -No hay manera fácil de ver el ID desde ``Telegram``, por lo que se puede -utilizar el programa llamado ``seeIdGroups.py``. Para ejecutarlo sólo es -necesario establecer el parámetro ``token`` del archivo de -configuración. Necesitarás que alguien invite al bot al grupo. Además, -las personas de ese grupo deben enviar algunos mensajes, para que el -programa pueda coger su ID. Puede llevar unos segundos el que aparezcan -los mensajes. Cuando se tenga el ID de grupo que se quiere, sólo hay que -pulsar Ctrl-c, copiarlo en el archivo de configuración (incluido el -simbolo menos), y la configuración estará terminada. - -Uso -~~~ - -Se pueden crear todos los archivos de configuración que se deseen. Sólo -tendrás que pasarlo como parámetro al programa, si no se hace se -intentará coger el archivo ``config.ini`` por defecto, y se producirá un -error si no existe: - -:: - - # Es recomendable utilizar tmux o la pantalla para ejecutar la siguiente orden - $ jabbergram.py example.ini - -Licencia -~~~~~~~~ - -:: - - 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 3 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 . + You should have received a copy of the GNU General Public License + Along With This Program. If not, see . + #+END_SRC diff --git a/jabbergram.py b/jabbergram.py index 15859c7..6610cd2 100755 --- a/jabbergram.py +++ b/jabbergram.py @@ -35,7 +35,7 @@ class EchoBot(sleekxmpp.ClientXMPP): self.bot = telegram.Bot(self.token) self.telegram_users = {} - # meter el conecto del tg en un hilo + # meter el conector del tg en un hilo t = Thread(target=self.read_tg) t.daemon = True t.start() @@ -85,6 +85,10 @@ class EchoBot(sleekxmpp.ClientXMPP): except Unauthorized: sleep(1) + except Exception as e: + print(e) + + def start(self, event): self.get_roster() self.send_presence() @@ -119,7 +123,7 @@ class EchoBot(sleekxmpp.ClientXMPP): muc = presence['from'].bare if user != self.nick: - self.xmpp_users[muc].pop(presence['muc']['nick']) + self.xmpp_users[muc].remove(presence['muc']['nick']) def say_users(self, service, muc, group): xmpp_users = "" diff --git a/setup.py b/setup.py index 6a4fdfa..4bffd60 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup -VERSION = '0.1.4' +VERSION = '0.1.5' setup(name='jabbergram', version=VERSION,