Skip to content

Reddit bot for the HoN Patch Notes Guessing Game in /r/heroesofnewerth

License

Notifications You must be signed in to change notification settings

ElementUser/HoN-Patch-Notes-Game-Bot

Repository files navigation

HoN Patch Notes Guessing Game (Bot)

Build

codecov

security: bandit

This application automates the process of HoN's Patch Notes Guessing Game that is hosted in a thread on the Reddit platform.

Specifically, the bot is intended to create a thread in the /r/heroesofnewerth subreddit.

Reddit users post their guess according to the Rules of the game.

To skip to Bot Usage directly, go to the Requirements section.

Rules of the Game

  • Pick a number between 1 and max_line_count, and post that number to the main thread or the comment that /u/hon-bot responds to you with.
  • Guesses for lines that actually have content in the patch notes are considered "valid guesses", and the user will be entered into the pool of potential winners for a prize if they get a valid guess! See the Rewards section for more information.
  • Each user gets max_num_guesses guesses until they run out of guesses.
  • If your guess has a number in it in your first line of your comment, it WILL be parsed by the bot and will count as a guess (whether you want it to or not). For simplicity's sake, please only include a number in your guess.
  • Guesses for line numbers that don't exist in the patch notes count as an invalid guess. You have been warned!
  • There are invalid lines in the patch notes. These are blank lines, and lines with separator elements like _______ and -------.
    • If you guess an invalid line, you will receive a Whiffed! comment response. Your number of guesses remaining will reduce by 1 when this occurs, and you will no longer be able to participate if this number reaches 0.
  • PLEASE USE CTRL+F or the search feature IF YOUR NUMBER HAS BEEN GUESSED. A guess with a number that has already been guessed will count as an invalid guess.

The Bot

The bot enforces these rules and outputs various text lines from a given patch_notes.txt file, depending on if a user guesses a line with the appropriate number of content or not. Some features/behaviours that the bot will encompass:

  • Log into Reddit (credentials are configured in hon_patch_notes_game_bot/praw.ini) and communicate with its API at fixed time intervals
  • Keep track of each unique user that responds to the bot in the thread and/or to a comment that the bot made in the thread
  • Keep track of these user's statistics pertaining to the current game instance
  • Prevent Reddit accounts that are too new or below a certain comment karma from commenting
  • Creates a second Reddit thread where it keeps track of the correctly guessed patch note lines & fills in the content for the public to view

Requirements

  • Python 3.7 or higher must be installed on the host system.
    • If installing Python 3.8 or higher on Linux, follow the directions here

Setup

  • Log onto the bot's Reddit account at: https://www.reddit.com/login/
  • Set up a Reddit app by following the instructions here, and obtain your app's client_id and client_secret (required for next step)
  • Create a praw.ini file in this directory: hon_patch_notes_game_bot/praw.ini.

Configure praw.ini with your bot credentials so it looks like this:

[insertBotNameHere]
client_id=insert_client_id_here
client_secret=insert_client_secret_here
password=insert_bot_password_here
username=insert_bot_username_here

Using a praw.ini file is a secure way to provide the login credentials for PRAW in the bot script. .ini files are not committed to source control (as defined in .gitignore). praw.ini reference

  • Install Poetry by following the installation steps from their official documents. Do not use pip install to install Poetry.
  • Mac/Linux: After installation, on Mac/Linux you must run this command to enable the poetry command in your terminal: source $HOME/.poetry/env
  • Update Poetry to the latest version by running this command: poetry self update --preview
    • Poetry is required to handle dependencies in a virtualenv & run the script in a consistent environment regardless of the host system.

Development - Extra Steps

To ensure that the proper libraries and modules are used, use the Python interpreter python.exe found in the virtualenv generated by Poetry. This can be found by running poetry shell in the terminal, navigating to the path, and then having your IDE select the python.exe file in that directory as the Python interpreter.

When run through the virtual environment, praw.ini will not be detected in the current working directory. To resolve this, you have a few options:

Mac/Linux - Additional Setup

  • Navigate to the project root directory in your terminal and run stat scripts.sh to check its permissions. This file must have execute permissions (the "x" flag set) to run properly.
  • If required, use chmod 744 scripts.sh (assuming the current account is the owner of the file) to set file permissions properly.

Usage

Navigate to the project root directory in your terminal.

  • To run the script, use ./scripts.sh start
  • To run unit tests, use ./scripts.sh test
  • To reset the cache & database, use ./scripts.sh reset before running ./scripts.sh start

More Usage Notes

For unreleased patch notes, do not commit and push the branch to source control before their official release.

For hon_patch_notes_game_bot/config/reward_codes.txt, populate the file manually (this is done via private means).

To change up some commonly changed configuration before starting a new run, go to hon_patch_notes_game_bot/config/config.py and edit them.

Extra Documentation

Feel free to browse the docs folder in the repository and browse the documentation there for more details on some of the tools, resources & references used for this project & the reason why they were included in this project.

About

Reddit bot for the HoN Patch Notes Guessing Game in /r/heroesofnewerth

Resources

License

Stars

Watchers

Forks

Packages

No packages published