コード例 #1
0
    def _check_event_ping(self, user_id, events, today=True):
        """Check which events are not already passed and pings the user.
        Args:
            user_id (int): ID of the user.
            events (list of 'Event'): Contains all events of the user for a single day.
            today (bool, optional): Indicates whether the events of today or tomorrow are checked.
                Checking today by default.
        """
        bot = BotControl.get_bot()

        ping_list = []
        logger.info("Checking %s | %s", user_id, events)
        for event in events:
            ping_needed, event_delete = self.check_ping_needed(user_id, event, today)
            if ping_needed:
                event.deleted = event_delete
                ping_list.append(event)

        # Only ping if there are events to notify about
        if ping_list:
            for event in ping_list:
                message = self.build_ping_message(user_id, event)
                if event.deleted:
                    bot.send_message(user_id, text=message, parse_mode=ParseMode.MARKDOWN_V2)
                else:
                    language = DatabaseController.load_selected_language(user_id)
                    postfix = "_{}".format(event.uuid)
                    bot.send_message(user_id, text=message, parse_mode=ParseMode.MARKDOWN_V2,
                                     reply_markup=Event.event_keyboard_alteration(language, "event", postfix))
コード例 #2
0
    def list_all_events_of_user(update, context):
        """Lists all events of the user."""
        user = User.resolve_user(update)

        message = "*{}:*\n\n".format(
            receive_translation("event_list_header", user.language))
        event_data = DatabaseController.load_user_events(user.user_id)
        has_content = False

        for day in DayEnum:
            events = [event for event in event_data if event.day == day]

            if not events:
                continue

            has_content = True
            message += "*{}:*\n".format(
                day.receive_day_translation(user.language))

            for event in events:
                message += event.pretty_print_formatting(user.language)
                message += "\n"

        if not has_content:
            message += "{}".format(
                receive_translation("no_events", user.language))
        bot = BotControl.get_bot()
        bot.send_message(user.user_id,
                         text=message,
                         parse_mode=ParseMode.MARKDOWN_V2,
                         reply_markup=Event.event_keyboard_alteration(
                             user.language))
コード例 #3
0
    def _daily_ping_users(self, user_ids, day):
        """Pings all users inside the user id list with all of their events of the given day.
        Args:
            user_ids (list of 'str'): Contains all users.
            day (int): Represents the day which should be pinged for.
        """
        bot = BotControl.get_bot()

        for user_id in user_ids:
            user_events = DatabaseController.load_user_events(user_id)
            language = DatabaseController.load_selected_language(user_id)
            events_of_today = [event for event in user_events if event.day.value == day and event.in_daily_ping]
            message = ""
            if events_of_today:
                message += "*{}*\n\n".format(receive_translation("event_daily_ping_header", language))
            for event in events_of_today:
                message_event = self.build_ping_message(user_id, event)
                postfix = "_{}".format(event.uuid)
                bot.send_message(user_id, text=message + message_event, parse_mode=ParseMode.MARKDOWN_V2,
                                 reply_markup=Event.event_keyboard_alteration(language, "event", postfix))
                # Clear so that the header is only printed once
                message = ""