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)
async def demofonts(self, c: Command): fontstyles = { "bold": encodetxt("bold", Styles.bold), "italic": encodetxt("italic", Styles.italic), "bolditalic": encodetxt("bolditalic", Styles.bolditalic), "bubble": encodetxt("bubble", Styles.bubble), "bubbleinvert": encodetxt("bubbleinvert", Styles.bubbleinvert), "square": encodetxt("square", Styles.square), "squareinvert": encodetxt("squareinvert", Styles.squareinvert), "script": encodetxt("script", Styles.script) } if len(c.message) < 2: a_ = [] for each in fontstyles.keys(): a_.append(fontstyles[each]) await self.send_message(", ".join(a_)) else: parts = c.message.split(" ") type_ = parts[0] message = " ".join(parts[1:]) if type_ in Styles.__dict__.keys(): formated = encodetxt(message, Styles.__dict__[type_]) else: formated = encodetxt(c.message, Styles.script) await self.send_message(formated)
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)
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)