Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. import praw
  2. import requests
  3. import json
  4.  
  5. bot = praw.Reddit(client_id='-----------',
  6. client_secret='----------------------',
  7. user_agent='User-Agent: Python/PRAW:firstdoge:v0.0.1 (by /u/FirstDogecoin)',
  8. password='-------------',
  9. username='FirstDogecoin')
  10.  
  11. subreddit = bot.subreddit('firstdogecss')
  12. moderators = []
  13.  
  14. workingstate = True
  15.  
  16. approve = '!a'
  17. toggle = '!t'
  18. ban = '!b'
  19. report = '!r'
  20.  
  21. response = 'This is a test message that actually tips'
  22.  
  23. for moderator in subreddit.moderator():
  24. moderators.append(moderator.name)
  25.  
  26. print(moderators)
  27.  
  28. try:
  29. for comment in subreddit.stream.comments():
  30. if (not comment.is_root and
  31. approve in comment.body.lower() and
  32. comment.author.name in moderators):
  33. try:
  34. if (workingstate == True):
  35. replied = 0
  36. parent = comment.parent()
  37. parent.refresh()
  38. for counter in range(0, len(parent.replies.list()) - 1):
  39. if (parent.replies.list()[counter].author.name == 'FirstDogecoin'):
  40. replied = 1
  41. if replied == 0:
  42. parent.reply(response)
  43. comment.mod.remove()
  44. try:
  45. connection = requests.get("https://api.blockcypher.com/v1/doge/main/addrs/DN8oRmALs2VDn21uqCGMC1tTZTaEDbyWdC")
  46. if connection.status_code == 200:
  47. j = json.loads(connection.text)
  48. balance = j['final_balance']/100000000
  49. subreddit.flair.set('FirstDogecoin', "Fund balance: " + str(balance) + "Ð")
  50. except Exception as e:
  51. print(e)
  52. print('Error getting balance')
  53. except Exception as e:
  54. print(e)
  55. elif (toggle in comment.body.lower() and
  56. comment.author.name in moderators):
  57. try:
  58. replied = 0
  59. parent = comment.parent()
  60. parent.refresh()
  61. for counter in range(0, len(parent.replies.list()) - 1):
  62. if (parent.replies.list()[counter].author.name == 'FirstDogecoin'):
  63. replied = 1
  64. if replied == 0:
  65. workingstate = not workingstate
  66. if (workingstate == False):
  67. parent.reply('Approval commands disabled on moderator request.')
  68. elif (workingstate == True):
  69. parent.reply('Approval commands re-enabled on moderator request.')
  70. comment.mod.remove()
  71. except Exception as e:
  72. print(e)
  73. elif (ban in comment.body.lower() and
  74. comment.author.name in moderators):
  75. try:
  76. replied = 0
  77. parent = comment.parent()
  78. parent.refresh()
  79. for counter in range(0, len(parent.replies.list()) - 1):
  80. if (parent.replies.list()[counter].author.name == 'FirstDogecoin'):
  81. replied = 1
  82. if replied == 0:
  83. reason = comment.body.replace('!b', '')
  84. subreddit.banned.add(parent.redditor, ban_reason = reason)
  85. parent.reply('User banned on moderator request. Reason: .' + reason)
  86. comment.mod.remove()
  87. except Exception as e:
  88. print(e)
  89.  
  90. except Exception as e:
  91. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement