Exemplo n.º 1
0
    def show_event(self, context, event: Event, user: User, chat_id):
        # Add location keyboard button
        location_button = InlineKeyboardButton(
            "Location", callback_data="event_location_" + event.id)

        # If user is admin, allow to notify or disable an event
        if (user.admin):
            keyboard = [[
                InlineKeyboardButton("Notify!",
                                     callback_data='event_notify_' + event.id)
            ],
                        [
                            InlineKeyboardButton(
                                "Attendees",
                                callback_data='event_attendees_' + event.id)
                        ],
                        [
                            InlineKeyboardButton(
                                "Disable",
                                callback_data='event_disable_' + event.id)
                        ], [location_button]]
            reply_markup = InlineKeyboardMarkup(keyboard)

        # If regular user and not going, allow to mark as going
        if ((not user.admin) and (event.id not in user.events)):
            keyboard = [[
                InlineKeyboardButton("Going!",
                                     callback_data='event_going_' + event.id)
            ], [location_button]]
            reply_markup = InlineKeyboardMarkup(keyboard)

        # If going, allow to unmark
        if ((not user.admin) and (event.id in user.events)):
            keyboard = [[
                InlineKeyboardButton("I changed my mind",
                                     callback_data='event_not_going_' +
                                     event.id)
            ], [location_button]]
            reply_markup = InlineKeyboardMarkup(keyboard)

        context.bot.send_message(chat_id=chat_id,
                                 text=event.format(),
                                 parse_mode=ParseMode.HTML,
                                 reply_markup=reply_markup)
Exemplo n.º 2
0
    def create_event_description(self, update, context, user):
        description = update.message.text
        new_event = user.fields.get('new_event')

        # Handle event builder failure
        if (new_event is None):
            context.bot.send_message(chat_id=update.message.chat_id,
                                     text=responses.CREATE_EVENT_ERROR)
            user.fields['state'] = None
            self.db_driver.update_user(user)
            return

        new_event['description'] = description
        # Save event state
        e = Event(**new_event)
        user.fields['new_event'] = e.to_json()
        user.fields['state'] = None
        self.db_driver.update_user(user)

        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=responses.CREATE_EVENT_DONE)
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=e.format(),
                                 parse_mode=ParseMode.HTML)

        # Add answer options
        keyboard = [[
            InlineKeyboardButton("Yes!", callback_data='event_save'),
            InlineKeyboardButton("Nope...", callback_data='event_cancel')
        ]]

        reply_markup = InlineKeyboardMarkup(keyboard)

        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=responses.CREATE_EVENT_CONFIRM,
                                 reply_markup=reply_markup)