Skip to main content

A Package to build custom reddit chatbots easily

Project description

Pyredditchatbot

Pyredditchatbot is a Python package for easily building reddit chatbots that surf your favourite subreddit and replies when called. Simply modify the parameters mentioned in the Quickstart to create your own custom reddit chatbot to add some life to your subreddit!

Installation

Pyredditchatbot is supported on Python 3.7 and above. The recommended way to install it is via pip <https://pypi.python.org/pypi/pip>.

pip install pyredditchatbot

For instructions on installing Python and pip see "The Hitchhiker's Guide to Python" Installation Guides <https://docs.python-guide.org/en/latest/starting/installation/>.

Quickstart

Go to https://www.reddit.com/prefs/apps/ and login with your reddit account. This is the account that will be replying, so consider making a new account if you're looking to roleplay as a character. Please also make sure to read reddit etiquette and guidelines before creating a bot.

Create a script type application by filling out the form. You should now have a client id and secret for the application just created.

You can create a bot like so:

import pyredditchatbot as prc

bot = prc.Bot(
    client_id,
    client_secret,
    reddit_username,
    reddit_password,
    "u/my-bot",
    "my-favourite-subreddit"
)

The bot surfs all the comments on the subreddit my-favourite-subreddit and replies whenever it sees the phrase u/my-bot in a comment.

You need to add quotes to your bot to help it choose what to reply with. By default it looks for quotes.txt locally. You can also add your quotes as an iterable like this:

quotes = ["Hi", "How are you!!", "Hello!"]
bot.add_quotes(quotes)

You can also fetch quotes directly from a file:

bot.add_quotes_file("path/to/file/quotes.txt")

Each new line in the file is considered as a new quote.

If you want to pre_process the quotes, you can pass your custom callable like so:

bot = prc.Bot(
    client_id,
    client_secret,
    username,
    password,
    "u/my-bot",
    "my-favourite-subreddit"
    quote_cleaner=my_pre_processor_func
)

This will call my_pre_processor_func(quotes) and add the output to the bot instance.

If no quote_cleaner is passed, a default cleaner which simple removes empty quotes is used.

To run the bot, simply do:

bot.run()

This will run the bot continuously until the script is terminated.

If the bot is run without any quotes and a local quotes.txt doesn't exist, the run fails with a QuotesNotFoundError.

License

Pyredditchatbot is provided under the Simplified BSD License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyredditchatbot-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyredditchatbot-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pyredditchatbot-0.1.2.tar.gz.

File metadata

  • Download URL: pyredditchatbot-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for pyredditchatbot-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5bd38ca2cce4b85c929287c5e7d16123be0e935270831516bedd754142d0b363
MD5 b54e5fe2e6979d269f19fa6c2c59bc03
BLAKE2b-256 27c79a37807772ceeffd42d002b957d61d464ed69cddab72ed3df4f6cb303ad0

See more details on using hashes here.

File details

Details for the file pyredditchatbot-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyredditchatbot-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for pyredditchatbot-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 12b3cd2c0f56ba85fc77d415afa82fab78af532519bc9c30c45ac4c5f73190ec
MD5 c378dfa803bc94aa69595a687e511af8
BLAKE2b-256 7c5ff0462e53bfc7e30b74e9019fde41640ea1a502ed7102beaa876cc41c3b0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page