コード例 #1
0
 async def send_action(self,
                       message: str,
                       room: str = None,
                       color=None,
                       style=None):
     """/me messages, styling doesn't work"""
     if color is None and self.bot_settings.rainbow:
         color = Colors.random()
         await self.change_color(color)
     elif color is not None:
         await self.change_color(color)
     if style is not None:
         # TODO check if valid style
         message = encodetxt(message, style)
     if not room:
         room = self.bot_settings.roomname
     data = [
         "room::command", {
             "message": {
                 "command": "me",
                 "value": message
             },
             "room": room
         }
     ]
     await self.ws_send(data=data)
コード例 #2
0
    async def send_message(self, message: str, room: str = None, color=None, style=None):
        if not room:
            room = self.bot_settings.roomname

        if color is None and self.bot_settings.rainbow:
            color = Colors.random()
            await self.change_color(color)
        elif color is not None:
            await self.change_color(color)

        if len(message) > 254:
            # re.DOTALL makes . match everything, including newline
            messages = re.findall("(.{1,254}[.,;:]|.{1,254})", message, re.DOTALL)
            chunk_limit = self.bot_settings.chunk_limit
            if chunk_limit == 0 or chunk_limit == None:
                chunk_limit = len(messages)
            for i in range(0, chunk_limit):
                message = messages[i][:254]
                if style is not None:
                    message = encodetxt(message, style)
                await self.send_message(message, room=room, color=color, style=style)
            return
        else:
            if style is not None:
                # TODO check if valid style
                message = encodetxt(message, style)
            data = [
                "room::message",
                {
                    "message": message,
                    "room": room
                }
            ]
            await self.ws_send(data=data)
コード例 #3
0
 async def send_message(self,
                        message: str,
                        room: str = None,
                        color=None,
                        style=None):
     if color is None and self.bot_settings.rainbow:
         color = Colors.random()
         await self.change_color(color)
     elif color is not None:
         await self.change_color(color)
     if style is not None:
         # TODO check if valid style
         message = encodetxt(message, style)
     if not room:
         room = self.bot_settings.roomname
     data = ["room::message", {"message": message, "room": room}]
     await self.ws_send(data=data)