Пример #1
0
    def __init__(self):
        self.logger = logmaker.make_logger("CLI")
        self.logger.debug("Starting CLI")
        # Connect to db.
        dh.create()

        # Start praw object using credentials in data base.
        self.r = self.start_bot()
        self.run()
Пример #2
0
 def run(self):
     try:
         main.subreddit_choice = self.fetch_config("subreddit")
     except Exception:
         main.subreddit_choice = botinfo.subreddit
     main.reddit = self.r
     main.subreddit = main.reddit.subreddit(main.subreddit_choice)
     main.logger = logmaker.make_logger("CLI")
     print()
     print("Commands:")
     print("message check")
     print("post reply")
     print("comment reply")
     print("find mentions")
     print("downvote remover")
     print("add -x flag to add a repetition loop with x minutes pause")
     print("all")
     print("exit")
     print()
     print("Extra:")
     print("response add")
     print("table search")
     print()
     while True:
         command = input("> ")
         main.comments_replied_to, main.posts_replied_to, main.blacklisted, main.mentions, main.additional_responses = main.getprevious()
         loop = True
         delay = 0
         if "-" in command:
             print("Hit control + C to stop looping")
             delay = int(command.split("-")[1])
         while loop:
             try:
                 if "message check" in command or "all" in command:
                     main.message_check(main.additional_responses)
                 if "post reply" in command or "all" in command:
                     main.post_reply(main.subreddit)
                 if "comment reply" in command or "all" in command:
                     main.comment_reply(main.subreddit)
                 if "find mentions" in command or "all" in command:
                     main.find_mentions()
                 if "downvote remover" in command or "all" in command:
                     downvote.downvoted_remover(main.reddit)
                 if "response add" in command:
                     self.response_add()
                 if "table search" in command:
                     self.search()
                 if command == "exit":
                     main.stopbot(True)
                 if "-" not in command:
                     loop = False
                 time.sleep(delay * 60)
             except KeyboardInterrupt:
                 print()
                 loop = False
Пример #3
0
 def __init__(self):
     self.logger = logmaker.make_logger("CLI")
     self.logger.debug("Starting CLI")
     # Connect to db.
     dh.create()
     # Imports the credentials
     try:
         if sys.argv[1].lower() == "import":
             self.cred_import()
             return
     except IndexError:
         self.logger.debug("Did not set import")
     # Start praw object using credentials in data base.
     self.reddit = self.setup_praw()
     self.run()
Пример #4
0
def downvoted_remover(r):
    logger = logmaker.make_logger("Comment Remover")
    logger.info("Starting Downvoted Removal")

    comments = r.redditor(botinfo.username).comments.controversial(limit=1000)

    deleted = 0

    for comment in comments:
        if comment.score <= -1:
            logger.info("Removing comment {}".format(comment.id))
            comment.delete()
            deleted += 1
    if deleted == 0:
        logger.debug("No comments were deleted")
    else:
        logger.info("{0} comments were deleted".format(deleted))

    logger.info("Finished Downvote removal")
Пример #5
0
def find_mentions():
    toadd = []
    for x in reddit.inbox.mentions():
        if str(x) not in mentions:
            try:
                logger.debug("Found mention {id}. User {user} Body {body}".format(id=x, user=x.author, body=x.body))
                x.reply("Hello, I see you mentioned me. How can I help?")
                logger.debug("Replying to {}".format(x))
                marked = [x.id, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')]
                toadd.append(marked)
            except Exception as e:
                logger.warn(e)
    datahandler.data_insert("replied_mentions", toadd)


if __name__ == "__main__":
    datahandler.create()
    logger = logmaker.make_logger("Main")
    logger.info("Starting up")
    reddit = start()
    subreddit_choice = botinfo.subreddit
    subreddit = reddit.subreddit(botinfo.subreddit)
    comments_replied_to, posts_replied_to, blacklisted, mentions, additional_responses = getprevious()
    additional_choice = None
    message_check(additional_responses)
    post_reply(subreddit)
    comment_reply(subreddit)
    find_mentions()
    downvote.downvoted_remover(reddit)
    stopbot(True)
Пример #6
0
"""Functions that removes negative comments"""
# Internal
import logmaker
import botinfo  # pylint: disable=import-error

logger = logmaker.make_logger("Comment Remover")


def downvoted_remover(reddit_client) -> None:
    """
    Removed all comments that are negative
    Parameters
    ----------
    reddit_client: praw.Reddit
        The reddit client
    """
    logger.info("Starting Downvoted Removal")
    # Gets comments that are most likely to be downvoted
    comments = reddit_client.redditor(botinfo.username).comments.controversial(
        limit=1000
    )

    deleted = 0

    for comment in comments:
        if comment.score <= -1:
            logger.info("Removing comment: %s", comment.id)
            comment.delete()
            deleted += 1
    if deleted == 0:
        logger.debug("No comments were deleted")
Пример #7
0
"""Deals with all database transactions"""
# External
import sqlite3

# Internal
import logmaker

connection = sqlite3.connect("data.db")
cursor = connection.cursor()
logger = logmaker.make_logger("DataHandler")


def create() -> None:
    """
    Creates all the tables in the database.
    Runs every time because tables will not be created if they exist
    """
    tables = [
        """
CREATE TABLE IF NOT EXISTS Posts (
id text NOT NULL DEFAULT '',
time text NOT NULL,
subreddit text,
reply text,
PRIMARY KEY (id)
);""",
        """
CREATE TABLE IF NOT EXISTS Comments (
id text NOT NULL DEFAULT '',
time text NOT NULL,
subreddit text,
Пример #8
0
 def run(self) -> None:
     # pylint: disable=too-many-branches,too-many-statements
     """
     Main Menu that calls all the sub-functions
     """
     try:
         main.SUBREDDIT_CHOICE = self.fetch_config("subreddit")
     except ValueError:
         main.SUBREDDIT_CHOICE = botinfo.subreddit
     main.reddit = self.reddit
     main.subreddit = main.reddit.subreddit(main.SUBREDDIT_CHOICE)
     main.logger = logmaker.make_logger("CLI")
     print()
     print("Commands:")
     print("message check")
     print("post reply")
     print("comment reply")
     print("find mentions")
     print("downvote remover")
     print("add -x flag to add a repetition loop with x minutes pause")
     print("all")
     print("exit")
     print()
     print("Extra:")
     print("response add")
     print("response delete")
     print("table search")
     print("change subreddit")
     print()
     while True:
         command = input("> ").lower()
         (
             main.comments_replied_to,
             main.posts_replied_to,
             main.ignored,
             main.mentions,
             main.additional_responses,
             main.comment_responses,
             main.post_responses,
         ) = main.get_previous()
         loop = True
         delay = 0
         if "-" in command:
             print("Hit control + C to stop looping")
             delay = int(command.split("-")[1])
         while loop:
             try:
                 if "message check" in command or "all" in command:
                     main.message_check(main.additional_responses)
                 if "post reply" in command or "all" in command:
                     main.post_reply(main.subreddit)
                 if "comment reply" in command or "all" in command:
                     main.comment_reply(main.subreddit)
                 if "find mentions" in command or "all" in command:
                     main.find_mentions()
                 if "downvote remover" in command or "all" in command:
                     downvote.downvoted_remover(main.reddit)
                 if "response add" in command:
                     self.response_add()
                 if "response delete" in command:
                     self.response_delete()
                 if "table search" in command:
                     search()
                 if "change subreddit" in command:
                     self.replace_subreddit()
                 if command == "exit":
                     main.stop_bot(True)
                 if "-" not in command:
                     loop = False
                 time.sleep(delay * 60)
             except KeyboardInterrupt:
                 print()
                 loop = False