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.

246 lines
7.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. import logging
  5. import random
  6. import pydog
  7. import requests
  8. from telegram import ParseMode
  9. from telegram.ext import Updater, CommandHandler
  10. from coding_love import send_coding_love_gif
  11. from reddit import wrong_dog, hamster, reddit, reddit_img, toggle_four_twenty, four_twenty
  12. from schneiderbot_twitter import toggle_pepito_for_group, check_pepito_and_post_auto, check_pepito_and_post_manually
  13. from db import Db
  14. from mensa import mensa
  15. # Enable logging
  16. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  17. level=logging.INFO)
  18. logger = logging.getLogger(__name__)
  19. with open("res/stoll.txt", "r") as tmp_file:
  20. STOLL = tmp_file.readlines()
  21. with open("res/manta.txt", "r") as tmp_file:
  22. MANTA = tmp_file.readlines()
  23. with open("res/goodlife.txt", "r") as tmp_file:
  24. GOOD_LIFE = tmp_file.readlines()
  25. with open("res/simon.txt", "r") as tmp_file:
  26. SIMON = tmp_file.readlines()
  27. # Define a few command handlers. These usually take the two arguments bot and
  28. # update. Error handlers also receive the raised TelegramError object in error.
  29. def start(bot, update):
  30. """Was ist das hier für eins Bot?"""
  31. update.message.reply_text("""Hallo, ich bin ein Bot.
  32. Ich liefere tolle Informationen über die Mensa. Die Infos kommen von
  33. https://mensa.schneider-hosting.de
  34. Mhmm, lecker. Guten Appetit!""")
  35. def help(bot, update):
  36. """Send a message when the command /help is issued."""
  37. update.message.reply_text("""Commands:
  38. *Mensa*:
  39. /mensa _mensa_ - prints filtered list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used)
  40. /mensa _mensa_ full - prints full list of meals for _mensa_ (if no _mensa_ given, zentralmensa is used)
  41. *Fun*:
  42. /cat - random cat (using thecatapi.com)
  43. /dog - random dog (using dog.ceo/dog-api)
  44. /codinglove - random gif from the coding love (https://thecodinglove.com)
  45. /magie - random Axel Stoll quote
  46. /manta - random Opel Manta joke
  47. /goodlife - random good life quote
  48. /shrug - prints shrug
  49. /kill - kills you
  50. /revive - revives you
  51. /sudo kill/revive - force kill/revive
  52. /graveyard - shows the dead people
  53. /help - this help text""", parse_mode=ParseMode.MARKDOWN)
  54. def send_cat(bot, update):
  55. """CUTE"""
  56. cat_file = requests.get('http://aws.random.cat/meow').json()['file']
  57. bot.send_photo(chat_id=update.message.chat_id, photo=cat_file)
  58. def send_dog(bot, update):
  59. """CUTE 2.0"""
  60. dog = pydog.PyDog()
  61. bot.send_photo(chat_id=update.message.chat_id, photo=dog.get_random_image())
  62. def kill(bot, update, sudocall=False):
  63. """kill me pls"""
  64. db = Db()
  65. user = update.message.from_user.first_name
  66. if db.is_dead(user, update.message.chat_id):
  67. if sudocall:
  68. update.message.reply_text("%s killed again" % user)
  69. return
  70. update.message.reply_text("%s is already dead" % user)
  71. return
  72. message = update.message.from_user.first_name + " died"
  73. if sudocall:
  74. message += " for real"
  75. db.kill(user, update.message.chat_id)
  76. update.message.reply_text(message)
  77. def revive(bot, update, sudocall=False):
  78. """unkill me pls"""
  79. db = Db()
  80. user = update.message.from_user.first_name
  81. if not db.is_dead(user, update.message.chat_id):
  82. update.message.reply_text("Maybe %s should have a litte 'accident' before" % user)
  83. return
  84. if sudocall:
  85. update.message.reply_text("%s is living again, for real" % user)
  86. db.revive(user, update.message.chat_id)
  87. return
  88. update.message.reply_text("You fool! You cannot revive a dead person!")
  89. SUDO_CMDS = {
  90. "kill": kill,
  91. "revive": revive
  92. }
  93. def graveyard(bot, update):
  94. """List the dead"""
  95. db = Db()
  96. update.message.reply_text("Here are the dead people:\n%s" % db.get_dead_bodies(update.message.chat_id))
  97. def sudo(bot, update, args):
  98. """for real"""
  99. if not args:
  100. update.message.reply_text("Unknown command")
  101. return
  102. for arg in args:
  103. if arg in SUDO_CMDS:
  104. SUDO_CMDS[arg](bot, update, True)
  105. else:
  106. update.message.reply_text("Unknown command")
  107. def send_cat_dog(bot, update):
  108. """Best of both worlds!"""
  109. catdog = "https://upload.wikimedia.org/wikipedia/en/6/64/CatDog.jpeg"
  110. bot.send_photo(chat_id=update.message.chat_id, photo=catdog)
  111. def magie(bot, update):
  112. """MAGIEEEEEE"""
  113. rand = random.SystemRandom()
  114. update.message.reply_text(STOLL[rand.randrange(0, len(STOLL), 1)])
  115. def manta(bot, update):
  116. """Boah ey, geile Karre!"""
  117. rand = random.SystemRandom()
  118. update.message.reply_text(MANTA[rand.randrange(0, len(MANTA), 1)])
  119. def goodlife(bot, update):
  120. """GOOD LIFE MY A..."""
  121. rand = random.SystemRandom()
  122. update.message.reply_text(GOOD_LIFE[rand.randrange(0, len(GOOD_LIFE), 1)])
  123. def shrug(bot, update):
  124. """SHRUG"""
  125. update.message.reply_text("¯\_(ツ)_/¯")
  126. def simon(bot, update, args):
  127. "KAUF DIR N HUND"
  128. name = "@thedailysimon"
  129. if len(args) > 0:
  130. name = args[0]
  131. rand = random.SystemRandom()
  132. animal = SIMON[rand.randrange(0, len(SIMON), 1)].replace('\n', '')
  133. update.message.reply_text(
  134. "%s, bitte kauf dir einen Hund, eine Katze oder von mir aus auch %s, du hast zu viel Zeit"
  135. % (name, animal))
  136. def echo(bot, update):
  137. """Echo the user message."""
  138. update.message.reply_text(update.message.text)
  139. def error(bot, update, error):
  140. """Log Errors caused by Updates."""
  141. logger.warning('Update "%s" caused error "%s"', update, error)
  142. def init_commands(dp):
  143. dp.add_handler(CommandHandler("start", start))
  144. dp.add_handler(CommandHandler("help", help))
  145. dp.add_handler(CommandHandler("magie", magie))
  146. dp.add_handler(CommandHandler("manta", manta))
  147. dp.add_handler(CommandHandler("goodlife", goodlife))
  148. dp.add_handler(CommandHandler("mensa", mensa, pass_args=True))
  149. dp.add_handler(CommandHandler("sudo", sudo, pass_args=True))
  150. dp.add_handler(CommandHandler("cat", send_cat))
  151. dp.add_handler(CommandHandler("dog", send_dog))
  152. dp.add_handler(CommandHandler("catdog", send_cat_dog))
  153. dp.add_handler(CommandHandler("shrug", shrug))
  154. dp.add_handler(CommandHandler("kill", kill))
  155. dp.add_handler(CommandHandler("revive", revive))
  156. dp.add_handler(CommandHandler("simon", simon, pass_args=True))
  157. dp.add_handler(CommandHandler("graveyard", graveyard))
  158. dp.add_handler(CommandHandler("codinglove", send_coding_love_gif))
  159. dp.add_handler(CommandHandler("wrongdog", wrong_dog))
  160. dp.add_handler(CommandHandler("hamster", hamster))
  161. dp.add_handler(CommandHandler("reddit", reddit, pass_args=True))
  162. dp.add_handler(CommandHandler("reddit_img", reddit_img, pass_args=True))
  163. dp.add_handler(CommandHandler("pepito", check_pepito_and_post_manually))
  164. dp.add_handler(CommandHandler("tpepito", toggle_pepito_for_group))
  165. dp.add_handler(CommandHandler("lightitup", toggle_four_twenty))
  166. def main():
  167. """Start the bot."""
  168. # Create the EventHandler and pass it your bot's token.
  169. token = open("config/token").read()
  170. # token = open("config/test_token").read()
  171. updater = Updater(token.strip())
  172. jq = updater.job_queue
  173. # Get the dispatcher to register handlers
  174. dp = updater.dispatcher
  175. init_commands(dp)
  176. jq.run_repeating(check_pepito_and_post_auto, interval=180, first=0)
  177. jq.run_daily(four_twenty, datetime.time(4, 20, 0), days=(0, 1, 2, 3, 4, 5, 6))
  178. # on different commands - answer in Telegram
  179. # log all errors
  180. dp.add_error_handler(error)
  181. # Start the Bot
  182. updater.start_polling()
  183. # Run the bot until you press Ctrl-C or the process receives SIGINT,
  184. # SIGTERM or SIGABRT. This should be used most of the time, since
  185. # start_polling() is non-blocking and will stop the bot gracefully.
  186. updater.idle()
  187. if __name__ == '__main__':
  188. main()