Fix the "answer" option and some minor things

This commit is contained in:
drymer 2017-02-22 17:12:11 +00:00
parent d926f974b7
commit 9e4e5d3852
3 changed files with 24 additions and 28 deletions

View File

@ -145,7 +145,7 @@ Este programa es simple, no tiene ni un menú de `ayuda`. Lo primero que hay que
NombreDelBot
# Ahora hay que pulsar desactivar
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](https://core.telegram.org/bots).
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 `Telegram` en su [página web](https://core.telegram.org/bots).
A continuación, hay que crear un archivo de configuración, que llamaremos `config.ini`. En ese archivo, introduce los siguientes parámetros:

View File

@ -111,7 +111,7 @@
# Ahora hay que pulsar desactivar
#+END_SRC
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]].
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 =Telegram= 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:

View File

@ -49,7 +49,6 @@ class Jabbergram(sleekxmpp.ClientXMPP):
self.groups = groups.split()
self.bot = telegram.Bot(self.token)
self.telegram_users = {}
self.group_name = {}
# initialize http upload on a thread since its needed to be connected
# to xmpp
@ -93,9 +92,20 @@ class Jabbergram(sleekxmpp.ClientXMPP):
for update in self.bot.getUpdates(offset=update_id,
timeout=10):
name = ''
size = 0
if update.message.from_user:
user = str(update.message.from_user.username)
# sometimes there's no user. weird, but it happens
if not user:
user = str(update.message.from_user.first_name)
# even weirder is that username or first_name exists
# let's take last_name
if not user:
user = str(update.message.from_user.last_name)
if not self.group_name:
self.group_name = update.message.chat.username
if update.message.audio or update.message.document or \
update.message.photo or update.message.video \
or update.message.voice or update.message.sticker:
@ -121,7 +131,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
d_file = update.message.voice
ext = '.ogg'
size = d_file.file_size
if self.max_size >= size:
if self.max_size >= int(size):
t_file = self.bot.getFile(d_file.file_id)
f_name = '/tmp/' + d_file.file_id + ext
t_file.download(f_name)
@ -139,7 +149,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
message = 'A file has been uploaded to Telegr'\
'am, but is too big.'
else:
message = 'A file has been uploaderd to Telegram,'\
message = 'A file has been uploaded to Telegram,'\
'but the XMPP server doesn\'t support H'\
'TTP Upload.'
@ -161,29 +171,16 @@ class Jabbergram(sleekxmpp.ClientXMPP):
update.message.reply_to_message.text
else:
message = update.message.reply_to_message.text
message = message + ' <- ' + name + ':' + update.\
message.text
else:
message = update.message.text
user = str(update.message.from_user.username)
# sometimes there's no user. weird, but it happens
if not user:
user = str(update.message.from_user.first_name)
# even weirder is that username or first_name exists
# let's take last_name
if not user:
user = str(update.message.from_user.last_name)
# Don't add name first if it's a reply
if name:
msg = message
msg = message + ' <- ' + user + ": " + update.message.text
else:
msg = user + ": " + message
chat = '@' + update.message.chat.username
if chat not in self.groups:
chat = str(update.message.chat_id)
@ -195,15 +192,14 @@ class Jabbergram(sleekxmpp.ClientXMPP):
if user not in self.telegram_users[chat]:
self.telegram_users[chat] += ' ' + user
else:
self.telegram_users[chat] = ' ' + user
if message == '.users':
self.say_users('telegram', muc, chat)
self.say_users('telegram', receiver, chat)
elif message == '.help':
self.say_help('telegram', muc, chat)
self.say_help('telegram', receiver, chat)
elif message == '.where':
self.say_where('telegram', muc, chat)
self.say_where('telegram', receiver, chat)
else:
self.send_message(mto=receiver, mbody=msg,
mtype='groupchat')
@ -292,8 +288,8 @@ class Jabbergram(sleekxmpp.ClientXMPP):
def say_where(self, service, muc, group):
if service == 'xmpp':
if self.group_name:
msg = 'I\'m on http://telegram.me/' + self.group_name + '.'
if '@' in group:
msg = 'I\'m on http://telegram.me/' + group.split('@')[1] + '.'
else:
msg = 'Sorry, I\'m on a private group, you\'ll have to ask fo'\
'r an invitation.'