Example #1
0
def init():
    global shell, logger
    shell = SlackbotShell()
    slack_api_token = os.environ['SLACK_API_TOKEN']
    shell.subreddit_name = os.environ.get('SUBREDDIT_NAME')
    shell.sc = slackclient.SlackClient(slack_api_token)
    shell.logger = logger
    if shell.subreddit_name:
        base_user_agent = 'python:gr.terrasoft.reddit.slackmodbot'
        user_agent = f'{base_user_agent}-{shell.subreddit_name}:v0.2 (by /u/gschizas)'
        shell.reddit_session = praw_wrapper(user_agent=user_agent, scopes=['*'])
        if 'REDDIT_ALT_USER' in os.environ:
            alt_user = os.environ['REDDIT_ALT_USER']
            alt_user_agent = f'{base_user_agent}-{shell.subreddit_name}-as-{alt_user}:v0.2 (by /u/gschizas)'
            shell.bot_reddit_session = praw_wrapper(user_agent=alt_user_agent,
                                                    prompt=f'Visit the following URL as {alt_user}:',
                                                    scopes=['*'])
Example #2
0
    return submissions_replied_to


# Get the data of which submissions could not be replied to (for any reason)
def get_saved_submissions_unabletos():
    if not os.path.isfile("submissions_unable_to_reply.txt"):
        submissions_unable_to_reply = []
        logging.warning("submissions_unable_to_reply.txt could not be found.\n")

    else:
        with open("submissions_unable_to_reply.txt", "r") as f:
            submissions_unable_to_reply = f.read()
            submissions_unable_to_reply = submissions_unable_to_reply.split(",")
            logging.info("submissions_unable_to_reply.txt was found.")

    return submissions_unable_to_reply



# Uses these functions to run the bot
r = praw_wrapper(user_agent="eu.pythoneverywhere.com:AmputatorBot:v1.4 (by /u/Killed_Mufasa)")
submissions_replied_to = get_saved_submissions_repliedtos()
submissions_unable_to_reply = get_saved_submissions_unabletos()
allowed_subreddits = get_allowed_subreddits()


# Run the program
while True:
    run_bot(r, allowed_subreddits, submissions_replied_to,
            submissions_unable_to_reply)