Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
New updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PokestarFan committed Sep 20, 2017
2 parents 8e0fc63 + bef9f53 commit 8b5d9f0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 42 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bot for duplicates
# How to use

* Unzip
* Create login.py with the following code:
* Go into the modules folder and create login.py with the following code:

```python
import praw
Expand All @@ -17,3 +17,23 @@ reddit = praw.Reddit(username = 'yourusername', password = 'yourpassword', clien


* Use

# Extra scripts

There are extra scripts that come with the bot.

## Delete.py

This script will delete any comment if a person comments delete. It is a mandatory run.

## gb-bb.py

This script controls the good bot/bad bot reply part. It is optional.

## lowpostremover.py

This script removes any comment below 1 karma. It is optional but recommended.

## deleteallcomments.py

If the bot has screwed up and made major mistakes, this script will delete all of the bot's comments.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
theme: jekyll-theme-architect
show_downloads: true
show_downloads: true
2 changes: 1 addition & 1 deletion delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
if 'delete' in item.body.lower():
item.parent().delete()
logging.info('Comment {} removed'.format(str(item.parent())))
item.reply('The top level post has been removed.'+footer)
item.author.message('Removal of comment {}'.format(str(item.parent())),'The top level post has been removed.')
except:
logging.debug('Item {} skipped'.format(str(item)))
except(KeyboardInterrupt):
Expand Down
5 changes: 3 additions & 2 deletions deleteallcomments.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import praw
from modules.logger import setup_logger
from modules.login import reddit
from modules.login import reddit as r
import logging

logger = setup_logger('remallcomments')
logger = setup_logger('remove_all_comments')


def main(count=0):
for comment in r.redditor(str(r.user.me())).comments.new(limit=None):
comment.delete()
logging.info('Finished comment #'+str(count)+', id {}'.format(str(comment)))
count += 1

if __name__ == '__main__':
while True:
Expand Down
71 changes: 36 additions & 35 deletions gb-bb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import praw
import prawcore
from modules.logger import setup_logger
from modules.login import reddit
import logging
Expand All @@ -9,43 +10,43 @@
def main():
try:
for item in reddit.inbox.stream():
written_to = 0
text = ''
with open('comments_written_to.txt', 'r') as file:
for line in file.readlines():
if line == str(item) and written_to == 0:
written_to = 1
logging.info('Comment {} has been already replied to.'.format(str(item)))
if written_to == 0:
if 'good bot' in str(item.body.lower()):
text = 'Good human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'bad bot' in str(item.body.lower()):
text = 'Bad human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'average bot' in str(item.body.lower()):
text = 'Average human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'bot' in str(item.body.lower()):
strings = str(item.body.lower()).split('bot')
text = '{} human'.format(strings[0])
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
try:
written_to = 0
text = ''
with open('comments_written_to.txt', 'r') as file:
for line in file.readlines():
if line == str(item) and written_to == 0:
written_to = 1
logging.info('Comment {} has been already replied to.'.format(str(item)))
if written_to == 0:
if 'good bot' in str(item.body.lower()):
text = 'Good human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'bad bot' in str(item.body.lower()):
text = 'Bad human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
elif 'average bot' in str(item.body.lower()):
text = 'Average human'
item.reply(text+footer)
logging.info('Message with the text {} replied to comment {}'.format(text, str(item)))
with open('comments_written_to.txt', 'a') as file:
file.write(str(item)+'\n')
except(prawcore.exceptions.Forbidden):
logging.info('Blocked on /r/{}'.format(str(item.subreddit)))
except(KeyboardInterrupt):
raise KeyboardInterrupt
except Exception as e:
logging.error('Error on item {}. {}'.format(str(item),str(e)), exc_info=True)
except(KeyboardInterrupt):
raise KeyboardInterrupt
except:
logging.error('Error', exc_info = True)
except Exception as e:
logging.critical('Error on main loop! {}'.format(str(e)), exc_info=True)

if __name__ == '__main__':
while True:
Expand Down
2 changes: 1 addition & 1 deletion modules/footer.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
footer = '\n\n ---- \n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!'
footer = '\n\n----\n\n ^^I ^^am ^^a ^^bot ^^[FAQ](https://www.reddit.com/r/DuplicatesBot/wiki/index)-[Code](https://github.com/PokestarFan/DuplicateBot)-[Bugs](https://www.reddit.com/r/DuplicatesBot/comments/6ypgmx/bugs_and_problems/)-[Suggestions](https://www.reddit.com/r/DuplicatesBot/comments/6ypg85/suggestion_for_duplicatesbot/)-[Block](https://www.reddit.com/r/DuplicatesBot/wiki/index#wiki_block_bot_from_tagging_on_your_posts)\n\n^^Now ^^you ^^can ^^remove ^^the ^^comment ^^by ^^replying ^^delete!'
3 changes: 2 additions & 1 deletion run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
start py duplicate.py
start py delete.py
start py lowpostremover.py
start py lowpostremover.py
start py gb-bb.py

0 comments on commit 8b5d9f0

Please sign in to comment.