def process(self, event):
     response = FormattedText().newline().join(ConfigStatus(self.config, self.state).get_config_status())
     response.newline().newline()\
         .italic("These are the current values read from storage.").newline()\
         .italic("But please, note that most of them are being cached at startup and "
                 "changing them will not modify bot behavior until it is restarted.")
     self.api.send_message(response.build_message().to_chat_replying(event.message))
 def get_response_opt_out(self, event, action):
     manager = OptOutManager(self.state)
     user_id = event.message.from_.id
     had_user_opted_out = manager.has_user_opted_out(user_id)
     if action == "add-me":
         if had_user_opted_out:
             response = FormattedText().bold("❌ You had already opted-out.")
         else:
             manager.add_user(user_id)
             response = FormattedText().bold(
                 "✅ You have been added to the opt-out list of this feature."
             )
     elif action == "remove-me":
         if not had_user_opted_out:
             response = FormattedText().bold(
                 "❌ You are not currently on the list.")
         else:
             manager.remove_user(user_id)
             response = FormattedText().bold(
                 "✅ You have been removed from the opt-out list of this feature."
             )
     else:
         if had_user_opted_out:
             response = FormattedText().bold(
                 "🙃 You are in the opt-out list.")
         else:
             response = FormattedText().bold(
                 "🙂 You are NOT in the opt-out list.")
     if manager.is_override_enabled_on_chat(event):
         response.newline().newline()\
             .bold("⚠️ Opt-out override is currently enabled on this chat ⚠️").newline()\
             .normal("Opt-out list is not in effect here while override is enabled.")
     return response.build_message()
Exemple #3
0
 def get_current_value(self, settings, key):
     value = self.__get_current_value(settings, key)
     response = FormattedText().bold("Setting").normal(":").newline().code_block(key).newline().newline()\
         .bold("Value").normal(":").newline().concat(value)
     is_supported = settings.is_supported(key)
     response.newline().newline()\
         .bold("Supported?").newline().code_block("yes" if is_supported else "no")
     if is_supported and settings.is_set(key):
         response.newline().newline()\
             .bold("Default value").normal(":").newline().code_block(settings.get_default_value(key))
     return response.build_message()
Exemple #4
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()
Exemple #5
0
 def poll_completed(self, message: MessageViewModel, poll_id: PollIdViewModel, full_poll: FullPollViewModel):
     text = FormattedText()\
         .normal("Poll #{id}:\n\n{poll}")\
         .start_format()\
         .normal(
             id=poll_id.id
         ).concat(
             poll=self.poll_formatter.format_poll(full_poll)
     ).end_format()
     inline_keyboard = self.inline_keyboard_formatter.poll_creation_inline_keyboard(poll_id)
     api_message = text.build_message().with_reply_markup(inline_keyboard)
     self._send_message(api_message, message)
Exemple #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))
Exemple #7
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()
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()
Exemple #9
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()
class VersionAction(Action):
    def __init__(self, project_package_name: str, releases_url: str = None):
        super().__init__()
        version = self.get_version(project_package_name)
        self.text = FormattedText().normal("Version {version}")
        if releases_url:
            self.text.newline().newline().normal("Releases: {releases_url}")
        self.text.start_format().bold(version=version).normal(
            releases_url=releases_url).end_format()

    @staticmethod
    def get_version(project_package_name: str):
        try:
            return pkg_resources.get_distribution(project_package_name).version
        except:
            return "<unknown>"

    def process(self, event):
        self.api.send_message(self.text.build_message().to_chat_replying(
            event.message))
Exemple #11
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)
Exemple #12
0
 def _send_formatted_text(self, text: FormattedText, replying_to: Message):
     self.api. async .send_message(
         text.build_message().to_chat_replying(replying_to))
 def process(self, event):
     response = FormattedText().newline().newline().join(
         (self.get_active_threads(), self.get_running_workers(),
          self.get_worker_pools()))
     self.api.send_message(response.build_message().to_chat_replying(
         event.message))
 def process(self, event):
     response = FormattedText().normal("Bot instance: {instance_name}")\
         .start_format().bold(instance_name=self.config.instance_name).end_format()
     self.api.send_message(response.build_message().to_chat_replying(
         event.message))
Exemple #15
0
 def _send_formatted_text(self, text: FormattedText,
                          message: MessageViewModel):
     return self._send_message(text.build_message(), message)