Advertisement
KoopaGaming

TOL Bot 1

Jan 22nd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. # Fill your Reddit and Telegram API in example.config.py and rename it to config.py
  2. import config
  3. # Telegram library for telegram bot
  4. import telepot
  5. # Library to get new message
  6. from telepot.loop import MessageLoop
  7. # Library to interact with Reddit's API
  8. import praw
  9. # Get random jokes
  10. import random
  11. import time
  12. # Limit of jokes
  13. LIMIT = 100
  14. counter = 0
  15. sub = 'Jokes'
  16. sub2 = 'showerthoughts'
  17. jokesTitles = []
  18. jokesTexts = []
  19. showerTitle = []
  20. for i in range(0, LIMIT):
  21. jokesTitles.append('Nothing here... Only pure emptiness')
  22. jokesTexts.append('Only virtual particles are popping up')
  23. reddit = praw.Reddit(client_id = config.client_id,
  24. client_secret = config.client_secret,
  25. username = config.username,
  26. password = config.password,
  27. user_agent = config.user_agent)
  28.  
  29. telebot = telepot.Bot(config.token)
  30.  
  31. def handle(msg):
  32. global counter
  33. user_id = msg['chat']['id']
  34. command = msg['text'].encode('utf-8').lower()
  35.  
  36. if command == '/joke' or command == '/joke@rjokes_bot':
  37. joke = random.randint(1, LIMIT-1)
  38. telebot.sendChatAction(user_id, 'typing')
  39. time.sleep(1)
  40. telebot.sendMessage(user_id, jokesTitles[joke])
  41. telebot.sendChatAction(user_id, 'typing')
  42. time.sleep(2)
  43. telebot.sendMessage(user_id, jokesTexts[joke])
  44. print(user_id)
  45. print(jokesTitles[joke])
  46. print(jokesTexts[joke])
  47. print('\n')
  48. counter+=1
  49. print(counter)
  50.  
  51. if command == '/showerthought' or command == '/showerthought@turtlesonlinebot':
  52. thought = random.randint(1, LIMIT-1)
  53. telebot.sendChatAction(user_id, 'typing')
  54. time.sleep(1)
  55. telebot.sendMessage(user_id, showerTitles[joke])
  56. print(user_id)
  57. print(jokesTitles[joke])
  58. print(jokesTexts[joke])
  59. print('\n')
  60. counter+=1
  61. print(counter)
  62.  
  63. if command == '/help' or command == '/help@turtlesonlinebot':
  64. telebot.sendChatAction(user_id, 'typing')
  65. telebot.sendMessage(user_id, 'Thank you for using the bot for whatever whenever. Tell Carter if you have problems w/ the bot.')
  66.  
  67. if command == '/truth' or command == '/help@turtlesonlinebot':
  68. telebot.sendChatAction(user_id, 'typing')
  69. telebot.sendMessage(user_id, 'Ben is gay.')
  70.  
  71. if command == '/more' or command == '/more@turtlesonlinebot':
  72. telebot.sendChatAction(user_id, 'typing')
  73. telebot.sendMessage(user_id, 'More coming! Tell Carter what should be added next!')
  74.  
  75.  
  76.  
  77.  
  78. MessageLoop(telebot, handle).run_as_thread()
  79. while (1):
  80. subreddit = reddit.subreddit(sub)
  81. #hot_python = subreddit.hot(limit=LIMIT)
  82. hot_python = subreddit.top('day', limit=LIMIT)
  83. # Updating jokes by popping at the beginning of the list and adding new one at the end
  84. # Maybe there is a separate function in python to do this?
  85. for submission in hot_python:
  86. if not submission.stickied:
  87. jokesTitles.pop(0)
  88. jokesTexts.pop(0)
  89. jokesTitles.append(submission.title)
  90. jokesTexts.append(submission.selftext)
  91. print('Updated list! {} {}'.format(len(jokesTitles), len(jokesTexts)))
  92. time.sleep(3600)
  93.  
  94. while (1):
  95. subreddit1 = reddit.subreddit(sub2)
  96. #hot_python = subreddit1.hot(limit=LIMIT)
  97. hot_python = subreddit1.top('day', limit=LIMIT)
  98. # Updating jokes by popping at the beginning of the list and adding new one at the end
  99. # Maybe there is a separate function in python to do this?
  100. for submission in hot_python:
  101. if not submission.stickied:
  102. showerTitles.pop(0)
  103. showerTitles.append(submission.title)
  104. print('Updated list! {} '.format(len(showerTitles)))
  105. time.sleep(3600)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement