def handle_subscription_message(database, reddit, message, payload): Logger.log('Sub message') new_sub = Subscription(payload, str(message.author), message.id) existing_subs = database.get_subscriptions_by_user(str(message.author)) duplicate_subs = new_sub.check_against_existing(existing_subs) if duplicate_subs: Logger.log('Subscription already exists', Color.RED) InboxHandler.reply(message, inbox.compose_duplicate_subscription_message( str(message.author), duplicate_subs[0], new_sub)) message.mark_read() return invalid_subreddits = reddit.check_invalid_subreddits(new_sub.data[Subscription.SUBREDDITS]) if invalid_subreddits: Logger.log('Subreddit(s) invalid: ' + str(invalid_subreddits), Color.RED) InboxHandler.reply(message, inbox.compose_invalid_subreddit_message(str(message.author), invalid_subreddits, message)) message.mark_read() return database.insert_subscription(str(message.author), new_sub.message_id, new_sub.to_string(), times.get_current_timestamp()) existing_subs.append(new_sub) # TODO Remove subreddit not specified stuff, taken care of in SubscriptionParser.py subreddit_not_specified = len(new_sub.data[Subscription.SUBREDDITS]) == 0 InboxHandler.reply(message, inbox.compose_subscribe_message(str(message.author), new_sub, existing_subs, subreddit_not_specified)) database.commit() message.mark_read()
def insert_match(self, username, json, permalink): try: match = [username, json, permalink, times.get_current_timestamp()] self.connection.cursor().execute(database.INSERT_ROW_MATCHES, match) self.connection.cursor().execute(database.INSERT_ROW_ALL_MATCHES, match) # NOTE: Commit is called after message is sent except: raise DatabaseHandlerException('Error - insert_match')
def purge_old_matches(self): Logger.log('purging...', Color.GREEN) current_time = times.get_current_timestamp() quarter_of_year = 31557600 / 4 marked_old_time = current_time - quarter_of_year try: self.connection.cursor().execute(database.PURGE_OLD_MATCHES, [marked_old_time]) self.commit() except: raise DatabaseHandlerException('ERROR - purge_old_matches')
def __init__(self): self.start_time = times.get_current_timestamp() self.run = True self.database = DatabaseHandler() self.reddit = RedditHandler()
def handle_subscription_message(database, reddit, message, payload): Logger.log('Sub message') new_sub = Subscription(payload, str(message.author), message.id) existing_subs = database.get_subscriptions_by_user(str(message.author)) if new_sub.status == Subscription.STATUS_INVALID: message.reply(inbox.compose_reject_message(str(message.author), message.subject, message.body)) message.mark_as_read() return elif new_sub.status == Subscription.STATUS_TOO_GENERIC: message.reply(inbox.compose_too_generic_message(str(message.author))) message.mark_as_read() return duplicate_subs = new_sub.check_against_existing(existing_subs) if duplicate_subs: Logger.log('Subscription already exists', Color.RED) message.reply(inbox.compose_duplicate_subscription_message( str(message.author), duplicate_subs[0], new_sub)) message.mark_as_read() return invalid_subreddits = reddit.check_invalid_subreddits(new_sub.data[Subscription.SUBREDDITS]) if invalid_subreddits: Logger.log('Subreddit(s) invalid: ' + str(invalid_subreddits), Color.RED) message.reply(inbox.compose_invalid_subreddit_message(str(message.author), invalid_subreddits, message)) message.mark_as_read() return database.insert_subscription(str(message.author), str(message.id), new_sub.to_string(), times.get_current_timestamp()) existing_subs.append(new_sub) # TODO Remove subreddit not specified stuff, taken care of in SubscriptionParser.py subreddit_not_specified = len(new_sub.data[Subscription.SUBREDDITS]) == 0 message.reply(inbox.compose_subscribe_message(str(message.author), new_sub, existing_subs, subreddit_not_specified)) database.commit() message.mark_as_read()
def __init__(self, username): self.bot = accounts[username] self.start_time = times.get_current_timestamp() self.run = True self.database = DatabaseHandler(database.get_db_location(self.bot)) self.reddit = RedditHandler(self.bot)
def __init__(self): self.bot = accounts['old_bot'] self.reddit = RedditHandler(self.bot) self.start_time = times.get_current_timestamp()