parent
047e82226a
commit
e9ffcf51c5
@ -0,0 +1,5 @@
|
||||
# Simple configuration example
|
||||
|
||||
config = {
|
||||
"TOKEN": "Your telegram bot token goes here"
|
||||
}
|
@ -1,5 +1,61 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
import logging
|
||||
import BeautifulSoup
|
||||
from telegram.ext import Updater, Dispatcher, Handler
|
||||
import requests
|
||||
import sys
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from telegram.ext import Updater, Handler, CommandHandler, MessageHandler
|
||||
|
||||
from config import config
|
||||
|
||||
# Enable logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Define a few command handlers. These usually take the two arguments bot and
|
||||
# update. Error handlers also receive the raised TelegramError object in error.
|
||||
def start(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Traigo las cervezas, vosotros los telescopios. ¡Vamos allá!')
|
||||
|
||||
|
||||
def help(bot, update):
|
||||
bot.sendMessage(update.message.chat_id, text='Aquí debería ir un mensaje de ayuda, pero voy algo pedo.')
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.warn('Update "%s" caused error "%s"' % (update, error))
|
||||
|
||||
|
||||
def main():
|
||||
token = config.get('TOKEN')
|
||||
|
||||
if token is None:
|
||||
print("Please, configure your token first")
|
||||
sys.exit(1)
|
||||
|
||||
updater = Updater(token)
|
||||
dispatcher = updater.dispatcher
|
||||
|
||||
# on different commands - answer in Telegram
|
||||
dispatcher.add_handler(CommandHandler("start", start))
|
||||
dispatcher.add_handler(CommandHandler("help", help))
|
||||
|
||||
# log all errors
|
||||
dispatcher.add_error_handler(error)
|
||||
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
|
||||
# Run the bot until the you presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT. This should be used most of the time, since
|
||||
# start_polling() is non-blocking and will stop the bot gracefully.
|
||||
updater.idle()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Starting AstroBeerBot")
|
||||
main()
|
||||
|
Loading…
Reference in new issue