Example #1
0
    def test_data_preservation(self):
        """
        Tests if Message does not corrupt data.
        """
        CLIENT_NAME = "New Horizon"
        MESSAGE = "pluto is fun"
        UNIQUE_ID = 5

        client = Client(1, CLIENT_NAME)
        msg = Message(MESSAGE, client, UNIQUE_ID)
        self.assertEqual(CLIENT_NAME, msg.get_sender())
        self.assertEqual(MESSAGE, msg.get_msg())
        self.assertEqual(UNIQUE_ID, msg.get_msg_id())
Example #2
0
    def on_message(self, data):
        message = Message(sender=self.name, data=json.loads(data))

        #将消息发送给每个在群组里的人
        for key in self.application.groupChats[self.topic].people.keys():
            if key != self.id:
                self.application.groupChats[self.topic].people[key](
                    message.response())

        #将消息存入消息记录
        if len(self.application.groupChats[
                self.topic].records) > GROUP_CHAT_RECORD_SIZE:
            self.application.groupChats[self.topic].records.pop()
        self.application.groupChats[self.topic].records.insert(
            0, message.response())
Example #3
0
 def getCommentData(self) -> None:
     foundVideo : Video = self.currentVideo
     commentCount : int = 0
     for comment in (foundVideo.comments):
         currentData : dict() = comment.data
         emoticonInfo : dict() = dict()
         emotes : bool = False
         Logger.print_info('Extracted ' + str(commentCount) + ' messages...', end='\r')
         for emoteIndex in range(len(currentData.get("message", None).get("emoticons", []))):
             emotes = True
             id = (currentData.get("message", None).get("emoticons", [])[emoteIndex]['_id'])
             emoticonInfo[id] = self.commentData.cached(id)
             if(not emoticonInfo[id]):
                 start = currentData.get("message", None).get("emoticons", [])[emoteIndex]['begin']
                 end = currentData.get("message", None).get("emoticons", [])[emoteIndex]['end']
                 emoticonInfo[id] = currentData.get("message", None).get("body", None)[start:end+1]
         if(emotes):
             self.commentData.add(
                 Message(
                 currentData['commenter']['name'], 
                 currentData['created_at'], 
                 currentData['message']['body'],
                 emoticonInfo
                 )
             )
         commentCount+=1
     Logger.exit_line()
     Logger.print_pass("Completed...")
     return
 def run(self):
   while self.client.alive:
     try:
       content = input()
       message = Message(self.sender, content)
       self.client.pipeline.push(message)
     except KeyboardInterrupt:
       self.client.kill()
       return
Example #5
0
    def content( self ):

        ## real content loading

        if self.type == 'thread':
                ## Message.HEADER = 'chat-message:(.*)'
                Message.HEADER = 'thread-message:(.*)'
                msg = Message.load_per_block( self.file , self._content  )
                return msg

        if self.type == 'chat':
            Message.HEADER = 'chat:(.*)meta'
            msg = Message.load_per_block( self.file , self._content  )

            ## different Presemo versions use differend headers, lets collect them all
            Message.HEADER = 'chat-message:(.*)'
            msg += Message.load_per_block( self.file , self._content  )

            return msg

        if self.type == 'rating':
            Message.HEADER = 'rating:(.*)'
            _msg = Message.load_per_block( self.file , self._content  )

            ## some Presemo versions used this heading
            Message.HEADER = 'rating-message:(.*)'
            _msg += Message.load_per_block( self.file , self._content  )

            ## return only unique ratings
            msg = {}

            for m in _msg:

                if m not in msg:
                    msg[ m.id ] = m

            return msg.values()

        if self.type == 'poll':
            polls = Poll.load_per_block( self.file , [ self.id ] )
            return polls

        return []
Example #6
0
 def searchExternalEmote(self, emoteName : str) -> None:
     foundVideo : Video = self.currentVideo
     commentCount : int = 0
     for comment in (foundVideo.comments):
         currentData : dict() = comment.data
         if(StringUtil.stringSearch(currentData['message']['body'], emoteName, __defaultBase__)):
             self.commentData.addExternal(
                 Message(
                     currentData['commenter']['name'], 
                     currentData['created_at'], 
                     currentData['message']['body'],
                     {"Ext": emoteName}
                 )
             )
         Logger.print_info('Seeked ' + str(commentCount) + ' messages...', end='\r')
         commentCount+=1
     Logger.exit_line()
     Logger.print_pass("Completed...")
     return