Ejemplo n.º 1
0
 def on_recieve_message(self, data):
     messages = utils.messageData_to_strings(data)
     for msg in messages:
         self.log(msg)
         if self.mode == Mode.MCD:
             msg = utils.stringAdd('§7', utils.stringAdd(msg, '§r'))
             self.minecraftServer.say(msg)
Ejemplo n.º 2
0
 def boardcastMessage(self, senderInfo, messageData):
     self.log('Received message "{0}", boardcasting'.format(
         utils.messageData_to_string(messageData)))
     for msg in utils.messageData_to_strings(messageData):
         self.log(msg, ChatLogFile)
     for client in self.clients:
         if client.info != senderInfo:
             client.sendMessage(messageData)
Ejemplo n.º 3
0
 def on_recieve_message(self, data):
     messages = utils.messageData_to_strings(data)
     for msg in messages:
         self.log(msg)
         if self.mode == Mode.MCD:
             self.minecraftServer.execute('tellraw @a {}'.format(
                 json.dumps({
                     'text': msg,
                     'color': 'gray'
                 })))
Ejemplo n.º 4
0
 async def listeningMessage(self):
     self.log('Message listening looping...')
     try:
         channel_chat = self.get_channel(self.config.channel_chat)
         while True:
             try:
                 messageData = self.messages.get(
                     block=False)  # type: MessageData
             except queue.Empty:
                 await asyncio.sleep(0.05)
                 continue
             self.log('Message data with type {} and channel {} get'.format(
                 messageData.type, messageData.channel))
             data = messageData.data
             if messageData.type == MessageDataType.CHAT:  # chat message
                 assert isinstance(data, dict)
                 self.log('Processing chat message from chatbridge: ' +
                          utils.messageData_to_string(data))
                 for message in utils.messageData_to_strings(data):
                     try:
                         translation = translator.translate(data['message'],
                                                            dest='en')
                         dest = 'en'
                         if translation.src != dest:
                             message += '   | [{} -> {}] {}'.format(
                                 translation.src, dest, translation.text)
                     except:
                         self.log('Translate fail')
                     await channel_chat.send(
                         self.formatMessageToDiscord(message))
             elif messageData.type == MessageDataType.EMBED:  # embed
                 assert isinstance(data, discord.Embed)
                 self.log('Sending embed')
                 await self.get_channel(messageData.channel).send(embed=data
                                                                  )
             elif messageData.type == MessageDataType.TEXT:
                 await self.get_channel(messageData.channel).send(
                     self.formatMessageToDiscord(str(data)))
             else:
                 self.log('Unkown messageData type {}'.format(
                     messageData.data))
     except:
         self.log(traceback.format_exc())
         await self.close()
Ejemplo n.º 5
0
 def on_recieve_message(self, data):
     global cq_bot
     if cq_bot is None:
         return
     try:
         messages = utils.messageData_to_strings(data)
         for msg in messages:
             self.log(msg)
         try:
             prefix, message = data['message'].split(' ', 1)
         except:
             pass
         else:
             log('Triggered command, sending message to qq')
             if prefix == '!!qq':
                 cq_bot.send_message(data['client'], data['player'],
                                     message)
     except:
         self.log('Error in on_message()')
         self.log(traceback.format_exc())
Ejemplo n.º 6
0
 async def listeningMessage(self):
     channel = self.get_channel(self.config.channel)
     try:
         while True:
             if len(self.messages) == 0:
                 await asyncio.sleep(0.05)
                 continue
             messageData = self.messages.pop(0)
             if type(messageData) == dict:  # chat message
                 self.log('Processing chat message ' +
                          utils.messageData_to_string(messageData))
                 for message in utils.messageData_to_strings(messageData):
                     try:
                         translation = translator.translate(
                             messageData['message'], dest='en')
                         dest = 'en'
                         if translation.src != dest:
                             message += '   | [{} -> {}] {}'.format(
                                 translation.src, dest, translation.text)
                     except:
                         self.log('Translate fail')
                     await channel.send(self.formatMessageToDiscord(message)
                                        )
             elif type(messageData) == discord.Embed:  # embed
                 self.log('Sending embed')
                 await channel.send(embed=messageData)
             elif type(messageData) == str:
                 await channel.send(self.formatMessageToDiscord(messageData)
                                    )
             else:
                 self.log('Unkown messageData type {}'.format(
                     type(messageData)))
     except:
         s = traceback.format_exc()
         print(s)
         self.log(s)
         await self.close()