예제 #1
0
파일: bot.py 프로젝트: Paco1994/sportbot
commands = { # command description used in the "help" command
 'start': 'Empieza a usar el bot. Recibirás notificaciones globales cuando se actualice el bot.',
 'help': 'Muestra el menú de ayuda.'
}

def listener(messages):
    for m in messages:
        cid = m.chat.id
        mensaje = ""
        if m.content_type == 'text': # Sólo saldrá en el log los mensajes tipo texto
            if cid > 0:
                mensaje = str(m.chat.first_name) + "[" + str(cid) + "]: " + m.text
                #f = open('sources/log.txt', 'a')
                #f.write(mensaje + "\n")
                #f.close()
                print mensaje
            else:
                if m.text[0] == '/':
                    mensaje = str(m.from_user.first_name) + "[" + str(cid) + "]: " + m.text
                    #f = open('sources/log.txt', 'a')
                    #f.write(mensaje + "\n")
                    #f.close()
                    print mensaje

bot.set_update_listener(listener) # Así, le decimos al bot que utilice como función escuchadora nuestra función 'listener' declarada arriba.

bot.polling(none_stop=True) # Con esto, le decimos al bot que siga funcionando incluso si encuentra algún fallo.
while True: # Ahora le decimos al programa que no se cierre haciendo un bucle que siempre se ejecutará.
    #listadoURLs = ini2urls("sources/url.ini",0)    # Lectura de URL desde fichero de INICIO
    time.sleep(300)
예제 #2
0
#!/usr/bin/env python3
import os
import sys

#if sys.version_info.major < 3:
    #raise Exception("Must be using Python 3")

# Add vendor directory to module search path
parent_dir = os.path.abspath(os.path.dirname(__file__))
vendor_dir = os.path.join(parent_dir, 'dist')

sys.path.append(vendor_dir)

from sportbot import bot
bot.polling()