def _summarized(self, field="text", max_characters=15):
     text = FormattedText()
     content = getattr(self.last_message, field)
     if content:
         summarized_content = TextSummarizer.summarize(
             content, max_number_of_characters=max_characters)
         text.normal(" [ ").italic(summarized_content).normal(" ]")
     return text
 def _item(label: str, value, additional_text: str = ""):
     text = FormattedText()\
         .normal("{label}: {value}")\
         .start_format()\
         .normal(label=label)\
         .bold(value=value)\
         .end_format()
     if additional_text:
         text.normal(" ").normal(additional_text)
     return text
Beispiel #3
0
 def get_response_list(event, action_params, handler):
     text = FormattedText().normal("List of pole timezones:").newline()
     for alias in handler.get_timezones():
         state = handler.get_timezone_state(alias)
         name = state.get_value("timezone", DEFAULT_TIMEZONE)
         text.bold(alias).normal(" → ").bold(name)
         offset_seconds = state.offset_seconds
         if offset_seconds is not None:
             text.normal(" (with ").bold(offset_seconds).normal(
                 " seconds offset)")
         text.newline()
     return text.build_message()
Beispiel #4
0
 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
Beispiel #6
0
 def process(self, event):
     code = event.command_args
     response = FormattedText()
     try:
         result = eval(code)
     except Exception as e:
         response.normal("Error: {error}").start_format().bold(
             error=ExceptionFormatter.format(e)).end_format()
     else:
         response.normal("Result: {result}").start_format().bold(
             result=result).end_format()
     self.api.no_async.send_message(
         response.build_message().to_chat_replying(event.message))
Beispiel #7
0
 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)
Beispiel #8
0
 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()
Beispiel #9
0
 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 _full_edits_content(self, edited_field="text"):
     text = FormattedText()
     total_number_of_edits = len(self.edited_messages)
     for index, edited_message in enumerate(self.edited_messages):
         formatted_date = DateFormatter.format_full(
             edited_message.edit_date)
         edited_content = getattr(edited_message, edited_field)
         text.newline().newline()
         text.normal(self.bullet).normal("Edit ").bold(index + 1).bold("/").bold(total_number_of_edits)\
             .normal(", done at ").bold(formatted_date).normal(".").newline()
         if edited_content is None:
             text.normal(self.bullet).bold(
                 edited_field.capitalize()).bold(" deleted")
         else:
             text.normal(self.start_content).bold("New ").bold(
                 edited_field).bold(":").newline()
             text.normal(edited_content)
     return text
Beispiel #11
0
 def list_settings(settings):
     keys = settings.list()
     response = FormattedText().normal(
         "Settings status for this chat:").newline()
     for setting_name, value, default_value, is_set, is_supported in keys:
         response.newline()
         if not is_supported:
             response.code_inline(setting_name)
         elif is_set:
             response.bold(setting_name)
         else:
             response.normal(setting_name)
         response.normal(" → ").code_inline(value)
         if is_set and is_supported:
             response.normal(" (default: ").code_inline(
                 default_value).normal(")")
     return response.build_message()
Beispiel #12
0
 def _offset(offset: str):
     formatted_offset = FormattedText()
     if offset:
         formatted_offset.normal(" (offset {offset})").start_format().bold(
             offset=offset).end_format()
     return formatted_offset