Beispiel #1
0
 def process(self, event):
     event.i18n.enable(I18N_DOMAIN)
     action, action_param, help_args, timezone = self.parse_args(
         event.command_args.split())
     original_command = event.command
     if timezone != "main":
         event.command = UnderscoredCommandBuilder.build_command(
             original_command, "tz", timezone)
     if action in ("recent", "ranking", "last"):
         state = TimezoneStorageHandler(
             event.state.get_for("pole")).get_timezone_state(timezone)
         poles = PoleStorageHandler(state).get_stored_poles(self.kind)
         if poles.is_empty():
             response = self.get_response_empty()
         elif action == "recent":
             response = self.get_response_recent(event, poles, action_param)
         elif action == "ranking":
             response = self.get_response_ranking(event, poles,
                                                  action_param)
         else:
             response = self.get_response_last(event, poles, action_param)
     else:
         response = self.get_response_help(event, help_args)
     if response.reply_to_message_id is None:
         response = response.to_chat_replying(event.message)
     self.api.send_message(response)
     event.command = original_command
Beispiel #2
0
 def printable_version(self, event, user_storage_handler, index):
     formatted_user = UserFormatter.retrieve_and_format(
         self.user_id, user_storage_handler)
     formatted_date = DateFormatter.format(self.date)
     view_pole_command = UnderscoredCommandBuilder.build_command(
         event.command, str(index + 1))
     return _("{date} → {user} → {view_pole_command}")\
         .format(date=formatted_date, user=formatted_user, view_pole_command=view_pole_command)
Beispiel #3
0
 def get_response_ranking(self, event, poles, number_of_users_to_display):
     user_storage_handler = UserStorageHandler.get_instance(self.state)
     printable_poles = poles.grouped_by_user(
         number_of_users_to_display).printable_version(user_storage_handler)
     recent_poles_command = UnderscoredCommandBuilder.build_command(
         event.command, "recent")
     recent_poles_text = FormattedText().normal(_("Write {0} to see recent {poles}."))\
         .start_format().normal(recent_poles_command).normal(**self.pole_format_dict).end_format()
     return self.__build_success_response_message(
         event, self.__formatted(_("Ranking of {poles}:")), printable_poles,
         recent_poles_text)
Beispiel #4
0
 def get_response_number(self, event, voices, number_of_users_to_display):
     user_storage_handler = UserStorageHandler.get_instance(self.state)
     printable_voices = voices.grouped_by_user(number_of_users_to_display)\
         .printable_version(user_storage_handler)
     suggested_command = UnderscoredCommandBuilder.build_command(
         event.command, "mean")
     footer_text = FormattedText().normal("Write ").normal(
         suggested_command).normal(" to see mean audio length per user.")
     return self.__build_success_response_message(
         event, "Number of audios sent per user:", printable_voices,
         footer_text)
Beispiel #5
0
 def get_response_biggest(self, event, voices, number_of_voices_to_display):
     user_storage_handler = UserStorageHandler.get_instance(self.state)
     format_string = "{formatted_size} → {formatted_user} → {formatted_command}"
     printable_voices = voices.biggest().limit(number_of_voices_to_display)\
         .printable_version(event, user_storage_handler, format_string)
     suggested_command = UnderscoredCommandBuilder.build_command(
         event.command, "smallest")
     footer_text = FormattedText().normal("Write ").normal(
         suggested_command).normal(" to see smallest audios.")
     return self.__build_success_response_message(event, "Biggest audios:",
                                                  printable_voices,
                                                  footer_text)
Beispiel #6
0
 def get_response_size(self, event, voices, number_of_users_to_display):
     user_storage_handler = UserStorageHandler.get_instance(self.state)
     formatter = SizeFormatter.format
     printable_voices = voices.grouped_by_size(number_of_users_to_display)\
         .printable_version(user_storage_handler, formatter)
     suggested_command = UnderscoredCommandBuilder.build_command(
         event.command, "biggest")
     footer_text = FormattedText().normal("Write ").normal(
         suggested_command).normal(" to see biggest audios.")
     return self.__build_success_response_message(
         event, "Sum of audios size per user:", printable_voices,
         footer_text)
Beispiel #7
0
 def do_enable(self, event):
     disable_command = UnderscoredCommandBuilder.build_command(
         event.command, "off")
     message = FormattedText().normal("Activating #silence mode. I won't send anything here until you ")\
         .normal(disable_command).normal(" me.")\
         .build_message()
     # sending reply before activating silence mode, so that it is actually sent
     message.to_chat_replying(event.message)
     self.api.send_message(message)
     event.state.silenced = "yes"
     # returning a message to avoid caller failing, but message should not be sent, as silence mode is now enabled
     return message
 def get_response_popular(self, event, hashtags,
                          number_of_hashtags_to_display):
     printable_hashtags = hashtags.grouped_by_popularity(
         number_of_hashtags_to_display).printable_version()
     recent_hashtags_command = UnderscoredCommandBuilder.build_command(
         event.command, "recent")
     recent_hashtags_text = FormattedText().normal("Write ").normal(
         recent_hashtags_command).normal(" to see recent hashtags.")
     return self.__build_success_response_message(event,
                                                  "Most popular hashtags:",
                                                  printable_hashtags,
                                                  recent_hashtags_text)
 def __get_framework(event):
     framework_name = project_info.name
     framework_url = project_info.url
     framework_version = VersionAction.get_version(framework_name)
     about_framework_command = UnderscoredCommandBuilder.build_command(
         event.command, ABOUT_FRAMEWORK_ARG)
     return FormattedText()\
         .normal("{url} {version} (see {about_framework_command})")\
         .start_format()\
         .url(framework_name, framework_url, name="url")\
         .normal(version=framework_version, about_framework_command=about_framework_command)\
         .end_format()
Beispiel #10
0
 def printable_version(self, event, user_storage_handler, format_string):
     format_dict = {
         "formatted_user":
         UserFormatter.retrieve_and_format(self.user_id,
                                           user_storage_handler),
         "formatted_date":
         DateFormatter.format(self.date),
         "formatted_duration":
         TimeFormatter.format(self.duration),
         "formatted_size":
         SizeFormatter.format(self.file_size),
         "formatted_command":
         UnderscoredCommandBuilder.build_command(event.command,
                                                 self.message_id),
     }
     return format_string.format(**format_dict)
 def get_response_recent(self, event, hashtags,
                         number_of_hashtags_to_display):
     user_storage_handler = UserStorageHandler.get_instance(self.state)
     sorted_hashtags = hashtags.sorted_by_recent_use(
         number_of_hashtags_to_display)
     printable_hashtags = sorted_hashtags.printable_version(
         user_storage_handler)
     ranking_hashtags_command = UnderscoredCommandBuilder.build_command(
         event.command, "ranking")
     ranking_hashtags_text = FormattedText().normal("Write ").normal(
         ranking_hashtags_command).normal(
             " to see which users write most hashtags.")
     return self.__build_success_response_message(event,
                                                  "Most recent hashtags:",
                                                  printable_hashtags,
                                                  ranking_hashtags_text)
 def get_response_popular(self, event, hashtags, time_interval_in_seconds,
                          number_of_hashtags_to_display, raw_interval):
     if time_interval_in_seconds != HASHTAGS_NO_FILTER_BY_TIME:
         oldest_requested_hashtag = event.message.date - time_interval_in_seconds
         hashtags = hashtags.filter_older_than(oldest_requested_hashtag)
         title = FormattedText().normal(
             "Most popular hashtags during the last {interval}:"
         ).start_format().bold(interval=raw_interval).end_format()
     else:
         title = "Most popular hashtags:"
     printable_hashtags = hashtags.grouped_by_popularity(
         number_of_hashtags_to_display).printable_version()
     recent_hashtags_command = UnderscoredCommandBuilder.build_command(
         event.command, "recent")
     recent_hashtags_text = FormattedText().normal("Write ").normal(
         recent_hashtags_command).normal(" to see recent hashtags.")
     return self.__build_success_response_message(event, title,
                                                  printable_hashtags,
                                                  recent_hashtags_text)
 def printable_info(self, event, user_storage_handler):
     show_command = UnderscoredCommandBuilder.build_command(
         event.command, self.message_id)
     return analyzer.get_short_info(user_storage_handler, self,
                                    show_command)