Esempio n. 1
0
def validate_comment(comment):
    # Decides whether or not to reply to a given comment.
    #    - Must contain command
    #    - Must not have already replied
    #    - Must not reply to self
    if command in comment.body.lower():
        queue = pickle.load(open(file, "rb"))
        if not queue:
            queue = Queue()
        data = pickle.load(open('RSRData.p', 'rb'))
        # Already in the queue, don't add.
        if queue.contains(comment.id) or comment.id in [x[0] for x in data]:
            return False
        # We wrote the comment, don't loop.
        if comment.author.name is "garlicbot":
            _register_comment(comment, "Cannot respond to self.")
            return False
        # Parent comment was deleted, don't respond.
        if get_receiver(comment) == '[deleted]':
            _register_comment(comment, "Parent comment was deleted!")
            return False
        # We've blacklisted this sub, don't respond.
        if comment.subreddit.display_name.lower() in banned_subs:
            _register_comment(comment, "Subreddit is blacklisted!")
            return False

        comment.refresh()
        for child_comment in comment.replies:
            if child_comment.author.name == "garlicbot":
                _register_comment(
                    comment,
                    "Already replied to this comment. Will not do it again.")
                return False
        return True
    return False
def validate_comment(comment):
    # Decides whether or not to reply to a given comment.
    #    - Must contain command
    #    - Must not have already replied
    #    - Must not reply to self
    if command in comment.body.lower():
        queue = pickle.load(open(file, "rb"))
        if not queue:
            queue = Queue()
        data = pickle.load(open('RSRData.p', 'rb'))
        if queue.contains(comment.id) or comment.id in [x[0] for x in data]:
            return False
        if comment.author.name is "RedditSilverRobot":
            _register_comment(comment, "Cannot respond to self.")
            return False
        if get_receiver(comment) == '[deleted]':
            _register_comment(comment, "Parent comment was deleted!")
            return False
        comment.refresh()
        for child_comment in comment.replies:
            if child_comment.author.name == "RedditSilverRobot":
                _register_comment(comment, "Already replied to this comment. Will not do it again.")
                return False
        return True
    return False
Esempio n. 3
0
    def _gen_markov_model(self, text):
        lines = text.split("\n")  # Get an array of lines of text

        # from the corpus

        # TODO: figure out how to clean this up
        def handle_begin(queue):
            begin_state = tuple(queue.contents[:2])
            next_state = tuple(queue.contents[1:])

            self._graph.insert_word(begin_state)
            self._graph.insert_word(next_state)
            self._graph.upsert_vert(".", begin_state)
            self._graph.upsert_vert(begin_state, next_state)

        def handle_end(queue):
            prev_state = tuple(queue.contents[:-1])
            next_state = tuple(queue.contents[1:])

            self._graph.insert_word(next_state)
            self._graph.insert_word(prev_state)
            self._graph.upsert_vert(prev_state, next_state)
            self._graph.upsert_vert(next_state, "?")

        def handle_rest(queue):
            prev_state = tuple(queue.contents[:-1])
            next_state = tuple(queue.contents[1:])

            self._graph.insert_word(prev_state)
            self._graph.insert_word(next_state)
            self._graph.upsert_vert(prev_state, next_state)

        for line in lines:
            queue = Queue(self.order + 1)
            tokens = self._tokenize_line(line)

            for index, token in enumerate(tokens):
                queue.enqueue(token)

                if len(queue.contents) >= self.order + 1:
                    # handles the start of sentences
                    if index == self.order:
                        handle_begin(queue)

                        # handles edge case where len of sentence == order + 1
                        if token is tokens[-1]:
                            handle_end(queue)

                    # handles the end of sentences
                    elif token is tokens[-1]:
                        handle_end(queue)
                    # handles everything else
                    else:
                        handle_rest(queue)
Esempio n. 4
0
def start_stream():
    comments = sub.stream.comments()
    for comment in comments:
        for bot in bots:
            if bot.validate_comment(comment):
                queue = pickle.load(open(bot.file, 'rb'))
                if queue:
                    queue.enqueue(comment.id)
                else:
                    queue = Queue()
                    queue.enqueue(comment.id)
                pickle.dump(queue, open(bot.file, 'wb'))
                timestr = str(time.localtime()[3]) + ":" + str(time.localtime()[4])
                print("> %s - Added comment to queue! Queue length: %s" % (timestr, len(queue)))
Esempio n. 5
0
def start_stream():
    comments = sub.stream.comments(pause_after=-1)
    for comment in comments:
        if comment == None:
            continue
        if garlicbot.validate_comment(comment):
            queue = pickle.load(open(garlicbot.file, 'rb'))
            if queue:
                queue.enqueue(comment.id)
            else:
                queue = Queue()
                queue.enqueue(comment.id)
            pickle.dump(queue, open(garlicbot.file, 'wb'))
            timestr = str(time.localtime()[3]) + ":" + str(time.localtime()[4])
            print("> %s - Added comment to queue! Queue length: %s" %
                  (timestr, len(queue)))
Esempio n. 6
0
def start_stream():
    messages = rocket.channels_history('GENERAL', count=100).json(
    )  # Alternativt henter 100 siste meldinger på #bot-warz - tznw8qNDK94F3nf3u
    for comment in messages['messages']:
        for bot in bots:
            if bot.validate_comment(comment):
                queue = pickle.load(open(bot.file, 'rb'))
                if queue:
                    queue.enqueue(comment['_id'])
                else:
                    queue = Queue()
                    queue.enqueue(comment['_id'])
                pickle.dump(queue, open(bot.file, 'wb'))
                timestr = str(time.localtime()[3]) + ":" + str(
                    time.localtime()[4])
                print("> %s - Added comment to queue! Queue length: %s" %
                      (timestr, len(queue)))
Esempio n. 7
0
def validate_comment(message):
#    print(message)
    if 'reactions' in message:
        if msg_reaction in message['reactions']:
 #           poster = message['reactions'][msg_reaction]['usernames']
 #           msg_text = message['msg']
 #           print("Message ID %s had the emoji %s on the following message: %s" % (message['_id'], message['reactions'], message['msg']))
            queue = pickle.load(open(file, "rb"))
            if not queue:
               queue = Queue()
            data = pickle.load(open('RSRData.p', 'rb'))
            # Already in the queue, don't add.
            if queue.contains(message['_id']) or message['_id'] in [x[0] for x in data]:
                return False
            if message['reactions'][msg_reaction]['usernames'][0] == get_receiver(message):
                _register_comment(message, "Cannot respond to self.")
                return False
            return True
        return False
    return False
Esempio n. 8
0
def valid_comment(comment):
    if(command in comment.body.lower()):
        #unpack data
        queue = pickle.load(open(queueFile, 'rb'))
        #create if empty
        if not queueFile:
            queue = Queue()

        data = pickle.load(open('FridgeData.p', 'rb'))

        #comment already in queue, or already processed
        if(queue.contains(comment.id) or comment.id in [entry[0] for entry in data]):
            return False

        comment.refresh()
        for child in comment.replies:
            if child.author.name == 'summon-bot':
                #this comment has already been replied to, but it passed our
                #queue for some reason. need to store
        return True
    return False
Esempio n. 9
0
        s = "s"
    message = "Hei, @" + get_receiver(comment)
    message += "! \n"
    message += str(giver_name) + " har gitt deg HBcoin. Du har til sammen " + str(silver_count)
    message += " HBcoin%s." % s
    #message += comment['reactions'][msg_reaction]['usernames'][0] + ") "
    #message += "__[info](http://reddit.com/r/RedditSilverRobot)__" + comment.subreddit.display_name
    return message

if __name__ == '__main__':

    try:
        queue = pickle.load(open(file, "rb"))
    except EOFError and FileNotFoundError as e:
        print("queue startup: %s" % e)
        queue = Queue()
        pickle.dump(queue, open(file, 'wb'))

    try:
        __data = pickle.load(open("RSRData.p", "rb"))
    except EOFError and FileNotFoundError:
        __data = []
        pickle.dump(__data, open("RSRData.p", 'wb'))
    if __data:
        print("There are %s entries in data." % len(__data))
    else:
        print("Data is empty.")
    if queue:
        print("There are %s entries in the queue." % len(queue))
    else:
        print("Queue is empty.")
Esempio n. 10
0
from Classes.Player import Player
from Classes.Position import Position

#PLAYER WHO PLAY THE GAME
player_selected = None
#PLAYERS_CIRCULAR LIST STRUCTURE
players_list = DoubleCircularList()
#SNAKE DOUBLE LIST STRUCTURE
snake_list = None
#LEVELS STACK STRUCTURE
actual_level = 1
level1 = Stack()
level2 = Stack()
level3 = Stack()
#SCOREBOARD QUEUE
scoreboard_queue = Queue()

#VELOCITY OF THE GAME
velocity = 300
direction = "right"


def init_structures(window):
    global snake_list, players_list, player_selected
    height, width = window.getmaxyx()

    if player_selected is not None:
        player_selected.score = 0

    level1 = Stack()
    level2 = Stack()