├── .gitattributes ├── .github └── workflows │ └── python-package.yml ├── README.md ├── __pycache__ ├── bot.cpython-39.pyc ├── debug_functions.cpython-39.pyc └── options.cpython-39.pyc ├── bot.py ├── debug_functions.py ├── dist └── pyproject.toml ├── options.py ├── preview.png ├── reddit_bot.py └── requirements.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Upload Python Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | deploy: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up Python 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: '3.x' 21 | - name: Install dependencies 22 | run: | 23 | python -m pip install --upgrade pip 24 | pip install setuptools wheel twine 25 | - name: Build and publish 26 | env: 27 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 28 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 29 | run: | 30 | python setup.py sdist bdist_wheel 31 | twine upload dist/* 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RedditBot 2 | A reddit bot with a lot of functionality. 3 | 4 | ![preview] 5 | 6 | ## Main features 7 | * Auto-reply to submissions on the selected subreddit 8 | * Customizable messages' texts, delays etc. 9 | * Reply to responses to bot's comments or upvote/downvote them **(SOON)** 10 | * Upvote or downvote every submission on a subreddit 11 | * Simple UI 12 | 13 | ## Prerequisites 14 | * Python 3 installed 15 | * Stable internet connection 16 | * `git` installed on your machine (optional) 17 | * *Patience* and *calmness* 18 | 19 | ## Usage 20 | To use RedditBot on your computer, you need to download the source code and run the file called `reddit_bot.py`. 21 | There are multiple ways to download the source code. First is by clicking green button "Code" and the second is using `git clone https://github.com/ExeRhythm/RedditBot/`. To do so, you need to have to have `git` installed on your machine. 22 | ``` 23 | git clone https://github.com/ExeRhythm/RedditBot/ 24 | cd RedditBot 25 | pip3 install -r requirements.txt 26 | python3 reddit_bot.py 27 | ``` 28 | 29 | ## Disclamer 30 | I, the creator, am not responsible for any actions, and or damages, caused by this software. 31 | 32 | You bear the full responsibility of your actions and acknowledge that this software was created for educational purposes only. 33 | 34 | This software's main purpose is NOT to be used maliciously, or on any subreddit that you do not own, or have the right to use. 35 | 36 | By using this software, you automatically agree to the above. 37 | 38 | 39 | [preview]: https://raw.githubusercontent.com/ExeRhythm/RedditBot/main/preview.png 40 | -------------------------------------------------------------------------------- /__pycache__/bot.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcelocation/RedditBot/38082dd2d567424dc41816c0b9a87fcc21ef0a9a/__pycache__/bot.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/debug_functions.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcelocation/RedditBot/38082dd2d567424dc41816c0b9a87fcc21ef0a9a/__pycache__/debug_functions.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/options.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcelocation/RedditBot/38082dd2d567424dc41816c0b9a87fcc21ef0a9a/__pycache__/options.cpython-39.pyc -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import praw 2 | import random 3 | from debug_functions import * 4 | import time 5 | import signal 6 | import sys 7 | 8 | signal.signal(signal.SIGINT, lambda x, y: sys.exit(0)) 9 | 10 | def add_viewed(id): 11 | f = open("Resources/viewed_submissions.txt", "a") 12 | f.write(" " + id) 13 | f.close() 14 | 15 | def views_contains(id): 16 | f = set(open("Resources/viewed_submissions.txt", "r").read().split()) 17 | return id in f 18 | 19 | def start(config): 20 | config = config["data"] 21 | client_id = config["client_id"] 22 | client_secret = config["client_secret"] 23 | password = config["password"] 24 | username = config["username"] 25 | 26 | messages_config = config["auto_messages"] 27 | messages = messages_config["messages"] 28 | subreddit = messages_config["subreddit"] 29 | chance = messages_config["chance"] 30 | 31 | reddit = praw.Reddit( 32 | client_id=client_id, 33 | client_secret=client_secret, 34 | password=password, 35 | user_agent="android", # Yes, android 36 | username=username 37 | ) 38 | 39 | starttime = time.time() 40 | delay = 7.5 41 | while True: 42 | # if len(submissiosn) == 0: 43 | # log(bcolors.INFO, f"No new submissions to reply to.") 44 | for submission in reddit.subreddit(subreddit).new(limit=15): 45 | if not views_contains(submission.id): 46 | if float(random.randint(0, 100)) / 100.0 < chance: 47 | message = random.choice(messages) 48 | submission.reply(message) 49 | 50 | log(bcolors.INFO, f"Replied to submission https://www.reddit.com/r/memes/comments/{submission.id}/ with \"{message}\"") 51 | else: 52 | log(bcolors.INFO, f"Viewed submission https://www.reddit.com/r/memes/comments/{submission.id}/, but did not reply (chance).") 53 | add_viewed(submission.id) 54 | time.sleep(delay) 55 | # Wait 'delay' seconds 56 | time.sleep(delay - ((time.time() - starttime) % delay)) -------------------------------------------------------------------------------- /debug_functions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | class bcolors: 4 | NORMAL = '\033[0m' 5 | HEADER = '\033[95m' 6 | SUCCESS = '\033[92m' 7 | WARNING = '\033[93m' 8 | FAIL = '\033[91m' 9 | DEBUG = '\033[93m' 10 | INFO = '\033[92m' 11 | REDDIT = '\x1b[38;5;124m' 12 | 13 | def log(type, str): 14 | if type == bcolors.WARNING: 15 | print(f"{type}[WARNING] {bcolors.NORMAL}{str}") 16 | elif type == bcolors.FAIL: 17 | print(f"{type}[ERROR] {bcolors.NORMAL}{str}") 18 | elif type == bcolors.INFO: 19 | print(f"{type}[INFO] {bcolors.NORMAL}{str}") 20 | else: 21 | print(f"{type}{str}") 22 | 23 | def new_line(count = 1): 24 | for _ in range(count): 25 | print("\n") 26 | print() -------------------------------------------------------------------------------- /dist/pyproject.toml: -------------------------------------------------------------------------------- 1 | - name: Install pypa/build 2 | run: >- 3 | python -m 4 | pip install 5 | build 6 | --user 7 | - name: Build a binary wheel and a source tarball 8 | run: >- 9 | python -m 10 | build 11 | --sdist 12 | --wheel 13 | --outdir dist/ 14 | . -------------------------------------------------------------------------------- /options.py: -------------------------------------------------------------------------------- 1 | import ast 2 | from debug_functions import * 3 | import json 4 | 5 | def get_options(): 6 | try: 7 | text = open("Resources/configuration.txt", "r").read() 8 | return ast.literal_eval(text) 9 | except IOError: 10 | return None 11 | 12 | def save_options(data): 13 | f = open("Resources/configuration.txt", "w") 14 | f.write(json.dumps( 15 | data, 16 | sort_keys=True, 17 | indent=4, 18 | separators=(',', ': '), 19 | ensure_ascii=False 20 | )) 21 | f.close() 22 | 23 | def setup(): 24 | config = {} 25 | 26 | log(bcolors.INFO, "You are currently in the configuration mode.") 27 | 28 | log(bcolors.NORMAL, f"Do you want your bot to reply to submissions? {bcolors.SUCCESS} Y/N") 29 | choice = input().lower() 30 | new_line() 31 | if choice == "y": 32 | config["auto_messages"] = {} 33 | log(bcolors.NORMAL, f"On what percentage of submissions do you want your bot to reply? Enter {bcolors.SUCCESS}just the number (0.01-100)") 34 | chance = float(input()) / 100 35 | config["auto_messages"]["chance"] = chance 36 | new_line() 37 | log(bcolors.NORMAL, f"Now let's set up actual messages to reply to submissions. Enter your messages on below. {bcolors.SUCCESS}If you want to add another message, press \"Enter\" key. {bcolors.HEADER} When you are done, leave new line empty and press \"Enter\" key") 38 | message = " " 39 | config["auto_messages"]["messages"] = [] 40 | while message != "": 41 | message = input() 42 | if message != "": 43 | config["auto_messages"]["messages"].append(message) 44 | 45 | new_line() 46 | log(bcolors.NORMAL, f"On what subreddit do you want your bot to post comments? (enter without r/)") 47 | config["auto_messages"]["subreddit"] = input() 48 | log(bcolors.INFO, "Great! Now let's go to the next step.") 49 | log(bcolors.NORMAL, f"Do you want your bot to respond to replies of the bot's comments? (Eg. Submission <- Bot (Nice post!) <- User (Thanks!) <- Bot (No problem!) ) {bcolors.SUCCESS} Y/N") 50 | 51 | choice = input().lower() 52 | new_line() 53 | if choice == "y": 54 | log(bcolors.FAIL, "Soon... Sorry for inconvenience.") 55 | 56 | log(bcolors.NORMAL, "Enter client_id and client_secret below (space separated) (if you don't have them, follow the guide at https://github.com/reddit-archive/reddit/wiki/OAuth2-Quick-Start-Example#first-steps. Setup an application as a script)") 57 | 58 | client_id, client_secret = map(str, input().split()) 59 | config["client_id"] = client_id 60 | config["client_secret"] = client_secret 61 | 62 | log(bcolors.NORMAL, f"Now this tool must know your account's username and account's password. (space separated) {bcolors.WARNING}If you don't trust this utility, you can look at it's code. Or you can just press Control+C to exit. {bcolors.NORMAL}") 63 | username, password = map(str, input().split()) 64 | 65 | config["username"] = username 66 | config["password"] = password 67 | 68 | log(bcolors.SUCCESS, "Configuration complete! You may now start the bot.") 69 | save_options({"data":config}) 70 | def setup_configuration_file(): 71 | new_line(2) 72 | if get_options() != None: 73 | log(bcolors.WARNING, f"You had already configured bot. In the current version it is not possible to edit bot's configuration via this tool, but you can manually edit it in {bcolors.WARNING}RedditBot/Resources/configuration.txt. ") 74 | log(bcolors.HEADER, "Do you want to overwrite configuration file? Y/n") 75 | if input().lower() != "y": 76 | print("\n") 77 | log(bcolors.INFO, "Leaving configuration file as it is.") 78 | else: 79 | new_line() 80 | setup() 81 | else: 82 | # TODO 83 | setup() -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sourcelocation/RedditBot/38082dd2d567424dc41816c0b9a87fcc21ef0a9a/preview.png -------------------------------------------------------------------------------- /reddit_bot.py: -------------------------------------------------------------------------------- 1 | from debug_functions import * 2 | from options import * 3 | import bot 4 | import sys 5 | 6 | #log(bcolors.INFO, "Welcome to RedditBot!\n") 7 | #Cool stuff 8 | print(f'''{bcolors.REDDIT} ____ __ ___ __ {bcolors.NORMAL}____ _ 9 | {bcolors.REDDIT} / __ \___ ____/ /___/ (_) /_{bcolors.NORMAL}| __ ) ___ | |_ 10 | {bcolors.REDDIT} / /_/ / _ \/ __ / __ / / __/{bcolors.NORMAL}| _ \ / _ \| __| 11 | {bcolors.REDDIT} / _, _/ __/ /_/ / /_/ / / /_ {bcolors.NORMAL}| |_) | (_) | |_ 12 | {bcolors.REDDIT}/_/ |_|\___/\__,_/\__,_/_/\__/ {bcolors.NORMAL}|____/ \___/ \__| 13 | ''') 14 | log(bcolors.WARNING, f"This tool has been made purely {bcolors.FAIL}for educational purposes. {bcolors.NORMAL}By using this utility you agree, that the developer of this tool {bcolors.WARNING}is not responsible for anything done with this tool.") 15 | 16 | 17 | # Start 18 | def go_to_menu(): 19 | new_line() 20 | log(bcolors.INFO, "You are in the menu. What do you want to do?") 21 | print(f"{bcolors.SUCCESS}1 {bcolors.NORMAL}- Start bot (Options must be configured)") 22 | print(f"{bcolors.SUCCESS}2 {bcolors.NORMAL}- Configure bot") 23 | 24 | choice = input() 25 | 26 | if choice == "1": 27 | log(bcolors.WARNING, f"Are you really sure you want to continue? {bcolors.WARNING}Your account will probably get banned if you use it on some subreddits! {bcolors.HEADER}N/y") 28 | choice = input() 29 | if choice.lower() != "y": 30 | go_to_menu() 31 | return 32 | else: 33 | bot.start(get_options()) 34 | go_to_menu() 35 | elif choice == "2": 36 | setup_configuration_file() 37 | go_to_menu() 38 | else: 39 | go_to_menu() 40 | go_to_menu() 41 | 42 | 43 | # Slant for 'bot' and 44 | ### 45 | 46 | ### -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | praw --------------------------------------------------------------------------------