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.

53 lines
1.4 KiB

  1. import praw
  2. import requests
  3. def get_post_type(url):
  4. header = requests.head(url).headers
  5. if 'Content-Type' in header:
  6. return header['Content-Type']
  7. else:
  8. return ''
  9. def get_reddit_instance():
  10. reddit_config = {}
  11. with open("reddit_config") as tmp_file:
  12. for line in tmp_file:
  13. (key, val) = line.split(';')
  14. reddit_config[key] = val.replace('\n', '')
  15. return praw.Reddit(
  16. user_agent=reddit_config['user_agent'],
  17. client_id=reddit_config['client_id'],
  18. client_secret=reddit_config['client_secret']
  19. )
  20. def wrong_dog(bot, update):
  21. reddit_instance = get_reddit_instance()
  22. sub = reddit_instance.subreddit('whatswrongwithyourdog')
  23. post = sub.random()
  24. update.message.reply_text("This dog has serious issues: %s" % post.url)
  25. def hamster(bot, update):
  26. reddit_instance = get_reddit_instance()
  27. sub = reddit_instance.subreddit('hamsters')
  28. post = sub.random()
  29. while "image" not in get_post_type(post.url):
  30. post = sub.random()
  31. bot.send_photo(chat_id=update.message.chat_id, photo=post.url)
  32. def reddit(bot, update, args):
  33. if not args:
  34. update.message.reply_text("Geile, sag sub")
  35. return
  36. sub = args[0]
  37. reddit_instance = get_reddit_instance()
  38. post = reddit_instance.subreddit(sub).random()
  39. update.message.reply_text(post.url)