Telegram version of schneiderbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.9 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """Simple Bot to reply to Telegram messages.
  4. This program is dedicated to the public domain under the CC0 license.
  5. This Bot uses the Updater class to handle the bot.
  6. First, a few handler functions are defined. Then, those functions are passed to
  7. the Dispatcher and registered at their respective places.
  8. Then, the bot is started and runs until we press Ctrl-C on the command line.
  9. Usage:
  10. Basic Echobot example, repeats messages.
  11. Press Ctrl-C on the command line or send a signal to the process to stop the
  12. bot.
  13. """
  14. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
  15. import logging
  16. import random
  17. # Enable logging
  18. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  19. level=logging.INFO)
  20. logger = logging.getLogger(__name__)
  21. with open("stoll.txt", "r") as tmp_file:
  22. STOLL = tmp_file.readlines()
  23. with open("manta.txt", "r") as tmp_file:
  24. MANTA = tmp_file.readlines()
  25. # Define a few command handlers. These usually take the two arguments bot and
  26. # update. Error handlers also receive the raised TelegramError object in error.
  27. def start(bot, update):
  28. """Was ist das hier für eins Bot?"""
  29. update.message.reply_text("""Hallo, ich bin ein Bot.
  30. Ich liefere tolle Informationen über die Mensa. Die Infos kommen von
  31. https://mensa.schneider-hosting.de
  32. Mhmm, lecker. Guten Appetit!""")
  33. def help(bot, update):
  34. """Send a message when the command /help is issued."""
  35. update.message.reply_text('Help!')
  36. def magie(bot, update):
  37. """MAGIEEEEEE"""
  38. rand = random.SystemRandom()
  39. update.message.reply_text(STOLL[rand.randrange(0, len(STOLL), 1)])
  40. def manta(bot, update):
  41. """Boah ey, geile Karre!"""
  42. rand = random.SystemRandom()
  43. update.message.reply_text(MANTA[rand.randrange(0, len(MANTA), 1)])
  44. def echo(bot, update):
  45. """Echo the user message."""
  46. update.message.reply_text(update.message.text)
  47. def error(bot, update, error):
  48. """Log Errors caused by Updates."""
  49. logger.warning('Update "%s" caused error "%s"', update, error)
  50. def main():
  51. """Start the bot."""
  52. # Create the EventHandler and pass it your bot's token.
  53. token = open("token").read()
  54. updater = Updater(token.strip())
  55. # Get the dispatcher to register handlers
  56. dp = updater.dispatcher
  57. # on different commands - answer in Telegram
  58. dp.add_handler(CommandHandler("start", start))
  59. dp.add_handler(CommandHandler("help", help))
  60. dp.add_handler(CommandHandler("magie", magie))
  61. dp.add_handler(CommandHandler("manta", manta))
  62. # log all errors
  63. dp.add_error_handler(error)
  64. # Start the Bot
  65. updater.start_polling()
  66. # Run the bot until you press Ctrl-C or the process receives SIGINT,
  67. # SIGTERM or SIGABRT. This should be used most of the time, since
  68. # start_polling() is non-blocking and will stop the bot gracefully.
  69. updater.idle()
  70. if __name__ == '__main__':
  71. main()