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.3.tar.gz (6.5 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.3-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyredditchatbot-0.1.3.tar.gz
  • Upload date:
  • Size: 6.5 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.9.9

File hashes

Hashes for pyredditchatbot-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6a38e3bc374f3777da560060e604bb4de7c5d94e312bd76e1d2cc170bdbe8916
MD5 216895f32fb5064d24a1ec477c3a12ad
BLAKE2b-256 33952b9634988a8bc4855189aa5d2d8560797da369271fb448d1b310d964d406

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyredditchatbot-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.2 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.9.9

File hashes

Hashes for pyredditchatbot-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9335bbc2fd53044c6cda39fe5cf7afdda5a58a0adb10da4818de789c8ff921a2
MD5 4b8d5c2b15297270013d6cfda5cc75ba
BLAKE2b-256 a03e00b09516d09ba7a4d53a84766e4bf206d352a2adaa0a067c7bb13fb37ceb

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