Telegram version of schneiderbot. I'll totally do something w/ this, this is never going to be effectively a mirror.
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.

63 lines
1.6 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_img(bot, update, ['hamsters'])
  27. def reddit(bot, update, args):
  28. if not args:
  29. update.message.reply_text("Geile, sag sub")
  30. return
  31. sub = args[0]
  32. reddit_instance = get_reddit_instance()
  33. post = reddit_instance.subreddit(sub).random()
  34. update.message.reply_text(post.url)
  35. def reddit_img(bot, update, args):
  36. print(args)
  37. if not args:
  38. update.message.reply_text("Geile, sag sub")
  39. return
  40. desired_sub = args[0]
  41. reddit_instance = get_reddit_instance()
  42. sub = reddit_instance.subreddit(desired_sub)
  43. post = sub.random()
  44. while "image" not in get_post_type(post.url):
  45. post = sub.random()
  46. bot.send_photo(chat_id=update.message.chat_id, photo=post.url)