Guest User

Command reply bot

a guest
Aug 23rd, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. import praw
  2. import time
  3. import rotmg_discords_bot_config
  4. import re
  5. import os
  6.  
  7. def bot_login():
  8. print ("Loggin in...")
  9. r = praw.Reddit(username = rotmg_discords_bot_config.username,
  10. password = rotmg_discords_bot_config.password,
  11. client_id = rotmg_discords_bot_config.client_id, # Messy stuff at the beginning, r = reddit
  12. client_secret = rotmg_discords_bot_config.client_secret,
  13. user_agent = "tybug's discord bot")
  14. print ("I've logged on!")
  15.  
  16. return r
  17.  
  18.  
  19.  
  20. version = "v1.0"
  21.  
  22.  
  23. # Changelog:
  24. # v0.1 (CURRENT) - Bot can reply to comments based on their content (8/19)
  25. # v1.0 - Bot monitors all new comments and replies to commands (8/20)
  26. #
  27. # PLANNED
  28. #
  29. # v2.0 - Bot responds to comments with multiple commands only once, with multiple discord links in that comment
  30.  
  31.  
  32. def main(r, comments_replied_to):
  33. count = 0
  34. for comment in r.subreddit('rotmg').stream.comments():
  35. print(comment.body + "\n \n (https://www.reddit.com/r/RotMG/comments/%s//%s) \n---- \n " %(comment.submission, comment.id))
  36.  
  37.  
  38. matcher = re.search("(?i)(!train|!fametrain)",comment.body)
  39. if(matcher != None and comment.id not in comments_replied_to):
  40. comment.reply("The Fame Train, previously located on the server EUN2, now moves around to whichever " +
  41. "realm provides the best fpm (fame per minute). Their current location can be found in the #click-here-for-train channel of their discord: " +
  42. "https://discord.gg/pVGQe7g.\n \n" +
  43. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  44. " and this action was performed automatically) ^| ^(Version: " + version + ") ^| ^(Reply to leave feedback)")
  45.  
  46. with open ("comments_replied_to.txt", "a") as f: # a = writing the file
  47. f.write(comment.id + "\n")
  48. count = count + 1
  49. print("--------------- \n \nFame Train discord comment has been left.\n ---------------")
  50.  
  51.  
  52.  
  53.  
  54.  
  55. matcher = re.search("(?i)(!LH|!Lost Halls|!lost halls)",comment.body)
  56. if(matcher != None and comment.id not in comments_replied_to):
  57. comment.reply("The public Lost Halls discord pops LH for as many people as they can get, to ensure its completion." +
  58. " \n \n Their discord can be found here: https://discord.gg/yWASJqd \n \n" +
  59. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  60. " and this action was performed automatically) ^| ^(Version: " + version + ") ^| ^(Reply to leave feedback)")
  61.  
  62. with open ("comments_replied_to.txt", "a") as f:
  63. f.write(comment.id + "\n")
  64. count = count + 1
  65. print("Lost Halls discord comment has been left.")
  66.  
  67.  
  68.  
  69.  
  70.  
  71. matcher = re.search("(?i)(!pitch|PitchOTMG|!POTMG)",comment.body)
  72. if(matcher != None and comment.id not in comments_replied_to):
  73. comment.reply("Pitch is a shatters subscription system where you pay two life a week to gain access to shatters bought with that life." +
  74. "\n \n The Pitch discord can be found here: https://discord.gg/s5c8rKw \n \n" +
  75. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  76. " and this action was performed automatically) ^| ^(Version: " + version + ") ^| ^(Reply to leave feedback)")
  77.  
  78. with open ("comments_replied_to.txt", "a") as f:
  79. f.write(comment.id + "\n")
  80. count = count + 1
  81. print("Pitch discord comment has been left.")
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. matcher = re.search("(?i)(!r/rotmg|!rotmg|!r-rotmg)",comment.body)
  89. if(matcher != None and comment.id not in comments_replied_to):
  90. comment.reply("The official r/rotmg discord can be found here: https://discord.gg/rotmg \n \n" +
  91. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  92. " and this action was performed automatically) ^| ^(Version: " + version + ") ^) ^| ^(Reply to leave feedback)")
  93.  
  94. with open ("comments_replied_to.txt", "a") as f:
  95. f.write(comment.id + "\n")
  96. count = count + 1
  97. print("r/rotmg discord comment has been left.")
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. matcher = re.search("(?i)(!support|!supportlink|!Deca Support)",comment.body)
  105. if(matcher != None and comment.id not in comments_replied_to):
  106. comment.reply("Deca support - used for unban requests, hacker reports, and a host of other things - can be found here: "+
  107. "http://decagames.desk.com/customer/portal/emails/new \n \n" +
  108. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  109. " and this action was performed automatically) ^| ^(Version: " + version + " ^| ^(Reply to leave feedback)")
  110.  
  111. with open ("comments_replied_to.txt", "a") as f:
  112. f.write(comment.id + "\n")
  113. count = count + 1
  114. print("Deca Support comment has been left.")
  115.  
  116.  
  117.  
  118. matcher = re.search("(?i)(!bannedposts)",comment.body)
  119. if(matcher != None and comment.id not in comments_replied_to):
  120. comment.reply("The list of banned posts for the subreddit can be found here: https://www.reddit.com/r/RotMG/wiki/bannedposts \n \n" +
  121. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  122. " and this action was performed automatically) ^| ^(Version: " + version + ") ^| ^(Reply to leave feedback)")
  123.  
  124. with open ("comments_replied_to.txt", "a") as f:
  125. f.write(comment.id + "\n")
  126. count = count + 1
  127. print("Deca Support comment has been left.")
  128.  
  129.  
  130. matcher = re.search("(?i)(!bluenoser)",comment.body)
  131. if(matcher != None and comment.id not in comments_replied_to):
  132. comment.reply("Blunosers guide, an incredibly helpful resource for new players, can be found here: http://bluenosersguide.weebly.com/ \n \n" +
  133. "--- \n \n ^(My creator is Tybug2) ^| ^(I am a bot," +
  134. " and this action was performed automatically) ^| ^(Version: " + version + ") ^| ^(Reply to leave feedback)")
  135.  
  136. with open ("comments_replied_to.txt", "a") as f:
  137. f.write(comment.id + "\n")
  138. count = count + 1
  139. print("Bluenosers guide comment has been left.")
  140.  
  141.  
  142.  
  143. print("I've replied to %s comments!" %count)
  144. print("Finished! Waiting for 5 minutes...")
  145. #time.sleep(500)
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. def get_saved_comments():
  153. if not os.path.isfile("comments_replied_to.txt"):
  154. comments_replied_to = []
  155. else:
  156. with open("comments_replied_to.txt", "r") as f: # r = reading the file
  157. comments_replied_to = f.read()
  158. comments_replied_to = comments_replied_to.split("\n") # Entries in the list are divided by new lines
  159. comments_replied_to = list(filter(None, comments_replied_to)) # Dunno what this does, it works though
  160.  
  161. return comments_replied_to
  162.  
  163. r = bot_login()
  164. comments_replied_to = get_saved_comments()
  165. while True:
  166. main(r, comments_replied_to)
Add Comment
Please, Sign In to add comment