def __build_success_response_message(event, title, printable_voices, footer_text=None): header = FormattedText().normal(title).newline() footer = FormattedText().newline().newline() if footer_text is not None: footer.concat(footer_text) else: footer.normal("Write ").bold(event.command + " help").normal( " to see more options.") return FormattedText().concat(header).normal(printable_voices).concat( footer).build_message()
def _full_content(self, content_field="text", prepend_newlines_if_content=False): text = FormattedText() content = getattr(self.message, content_field) if content is not None: if prepend_newlines_if_content: text.newline().newline() text.normal(self.start_content).bold( content_field.capitalize()).bold(":").newline() text.normal(content) text.concat(self._full_edits_content(content_field)) return text
class FormattedTextBuilder(MessageBuilder): def __init__( self, separator: FormattedText = FormattedText().newline().newline()): super().__init__(separator) self.formatted_text = FormattedText() def _add(self, formatted_text: FormattedText): self.formatted_text.concat(formatted_text) def get_length(self): return self.formatted_text.length() def get_message(self): return self.formatted_text.build_message() def clear(self): self.formatted_text.clear()
def _add_info(self, label: str, value, separator: str = ":", additional_text: str = ""): info = FormattedText()\ .normal("{label}{separator} {value}")\ .start_format()\ .normal(label=label)\ .normal(separator=separator) if isinstance(value, FormattedText): info.concat(value=value) else: info.bold(value=value) info = info.end_format() if additional_text: info.normal(" ").normal(additional_text) self._add(info)
def __build_success_response_message(event, title, printable_poles, footer_text=None): # header text = FormattedText().normal(title).newline() # body if isinstance(printable_poles, FormattedText): text.concat(printable_poles) else: text.normal(printable_poles) # footer text.newline().newline() if footer_text is not None: text.concat(footer_text) else: text.normal(_("Write {0} to see more options."))\ .start_format().bold(event.command + " help").end_format() return text.build_message()
def __deleted_pole_handler(self, tries, pole, event, pole_number): text = FormattedText().normal(_("Oops, the {0} last {pole} seems to be deleted.")).newline().newline()\ .start_format().normal(pole_number, **self.pole_format_dict).end_format() reply_to_message_id = int(pole.message_id) + tries + 1 if tries == 0: text.normal(_("It was above this message.")) elif tries < 5: text.concat(FormattedText().normal( _("It was above this message, along with other {0} message(s) deleted or " "inaccessible to me (maybe from another bot).")). start_format().normal(tries).end_format()) else: text.concat(FormattedText().normal( _("And at least the next {0} messages are also deleted or inaccessible to me (maybe " "because they are from another bot), so I cannot find where the {pole} was." )).start_format().normal( tries, **self.pole_format_dict).end_format()) reply_to_message_id = None message = text.build_message().to_chat(event.message.chat) if reply_to_message_id: message.reply_to_message(message_id=reply_to_message_id) message.with_error_callback(lambda e: self.__deleted_pole_handler( tries + 1, pole, event, pole_number)) return self.api.send_message(message)
def query_as_title(cls, query: str, offset: str): formatted_query = FormattedText().bold(query) formatted_query.concat(cls._offset(offset)) return formatted_query
def query(cls, query: str, offset: str): formatted_query = FormattedText().normal( "Query: {query}").start_format().bold(query=query).end_format() formatted_query.concat(cls._offset(offset)) return formatted_query