<commit_before>reddit-replier
==============

[![Build Status](https://travis-ci.org/naiyt/reddit-replier.svg?branch=master)](https://travis-ci.org/naiyt/reddit-replier)

A simple Python module that simplifies creating Reddit bots that reply to comments based on specific criteria. 

The `Replier` class takes a `parser` function and a `replier` function. The `parser` function is passed a `praw` formatted Reddit message and should return `True` or `False`.

If your `parser` function returns `True` for that message, then your `Replier` object will reply to the specified message using your `replier` function, which should just return a string. (Your `replier` gets a copy of the message, so you can use it to format your response.)

This is very much in beta and there are likely bugs.

Replier Parameters
==================
    class Replier(parser, replier, user_name, user_pass, subreddits='all', user_agent='redditreplier v0.01 by /u/naiyt', limit=1000, debug=False)

Arguments
---------

    parser

The `parser` should be a function that takes one argument (message) and returns `True` or `False`.

    replier

The `replier` should be a function that takes one argument (message) and returns a string that will be posted in reply to the message.

    user_name

Your bot's Reddit username.

    user_pass

Your bot's Reddit password

    subreddits

The subreddits you want your bot to watch. (For multiple subreddits, use the format `sub1+sub2+sub3`) Defaults to /r/all.

    user_agent

The default user_agent should be okay, but I would prefer if you defined your own for your own bot.

    limit

The limit of posts to request at once. The Reddit API restricts you to at most 1000 per request. Less should be just fine if you are watching smaller subreddits.

    debug

Mainly used for tests.

Examples
========

Say I want to respond and thank anybody who says 'redditreplier is awesome!' on /r/redditreplier. First, I would write a `parser` method:

    def parser(message):
        if 'redditreplier is awesome' in message.body.lower():
            return True
        else:
            return False

Then, create a replier with the message you want to send:

    def replier(message):
        return 'Hey, thanks {}! You are pretty swell yourself.'.format(message.author.name)

Then create and run your Replier Bot:

    from redditreplier import Replier
    bot = Replier(
		parser,
		replier,
		your_reddit_username,
		your_reddit_pass,
		'redditreplier' # The subreddit, leave blank for /r/all
		user_agent='My cool bot by /u/username'
    )
    bot.start()

And there you go! It will start watching your subreddits and replying when needed.


Running tests
-------------

You need to define the environment variables `user` and `password` for the Reddit logins. (Done this way to make it work with travis-ci). Try this:

    python -c 'import os; os.environ["password"]=<PASSWORD>; os.environ["user"]=youruser; os.sytem("python tests/test.py")'

Just run `python tests/tests.py`. You need to create a file called `secrets.py` in `/tests` with your bot's `user` and `password` defined as variables.

Installation<commit_msg>Testing push<commit_after>reddit-replier
==============

[![Build Status](https://travis-ci.org/naiyt/reddit-replier.svg?branch=master)](https://travis-ci.org/naiyt/reddit-replier)

A simple Python module that simplifies creating Reddit bots that reply to comments based on specific criteria. 

The `Replier` class takes a `parser` function and a `replier` function. The `parser` function is passed a `praw` formatted Reddit message and should return `True` or `False`.

If your `parser` function returns `True` for that message, then your `Replier` object will reply to the specified message using your `replier` function, which should just return a string. (Your `replier` gets a copy of the message, so you can use it to format your response.)

This is very much in beta and there are likely bugs.

Replier Parameters
==================
    class Replier(parser, replier, user_name, user_pass, subreddits='all', user_agent='redditreplier v0.01 by /u/naiyt', limit=1000, debug=False)

Arguments
---------

    parser

The `parser` should be a function that takes one argument (message) and returns `True` or `False`.

    replier

The `replier` should be a function that takes one argument (message) and returns a string that will be posted in reply to the message.

    user_name

Your bot's Reddit username.

    user_pass

Your bot's Reddit password

    subreddits

The subreddits you want your bot to watch. (For multiple subreddits, use the format `sub1+sub2+sub3`) Defaults to /r/all.

    user_agent

The default user_agent should be okay, but I would prefer if you defined your own for your own bot.

    limit

The limit of posts to request at once. The Reddit API restricts you to at most 1000 per request. Less should be just fine if you are watching smaller subreddits.

    debug

Mainly used for tests.

Examples
========

Say I want to respond and thank anybody who says 'redditreplier is awesome!' on /r/redditreplier. First, I would write a `parser` method:

    def parser(message):
        if 'redditreplier is awesome' in message.body.lower():
            return True
        else:
            return False

Then, create a replier with the message you want to send:

    def replier(message):
        return 'Hey, thanks {}! You are pretty swell yourself.'.format(message.author.name)

Then create and run your Replier Bot:

    from redditreplier import Replier
    bot = Replier(
		parser,
		replier,
		your_reddit_username,
		your_reddit_pass,
		'redditreplier' # The subreddit, leave blank for /r/all
		user_agent='My cool bot by /u/username'
    )
    bot.start()

And there you go! It will start watching your subreddits and replying when needed. Run it with nohup or a screen session if you want it to be running continuously.


Running tests
-------------

You need to define the environment variables `user` and `password` for the Reddit logins. (Done this way to make it work with travis-ci). Try this:

    python -c 'import os; os.environ["password"]=<PASSWORD>; os.environ["user"]=youruser; os.sytem("python tests/test.py")'

Installation
{'fraction_non_alphanumeric': 0.09355409098215721, 'fraction_numerical': 0.004500884102234368, 'mean_word_length': 3.7172100075815013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4833712', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1807, 'n_words': 805}