예제 #1
0
def finish(update: Update, context: CallbackContext):
    query = update.callback_query
    query.answer()

    user = User.by(query.from_user.id)
    city = City.by(context.user_data['city_name'])
    start_date = datetime.strptime(context.user_data['start_date_str'],
                                   conf.date_format)
    end_date = start_date
    if context.user_data['duration_str']:
        hours, minutes = [
            int(x) for x in context.user_data['duration_str'].split(':')
        ]
        end_date += timedelta(hours=hours, minutes=minutes)

    event = Event.create(creator=user,
                         city=city,
                         name=context.user_data['event_name'],
                         description=context.user_data['event_description'],
                         start_date=start_date,
                         end_date=end_date)

    query.from_user.send_message(s.thanks_for_event_creation_message,
                                 parse_mode=ParseMode.HTML,
                                 reply_markup=default_markup)
    return ConversationHandler.END
예제 #2
0
def finish_registration(update: Update, context: CallbackContext):
    query = update.callback_query
    query.answer()

    city_name = query.data.split(':')[1]
    city = City.by(name=city_name)
    if city:
        User.create(tg_id=query.from_user.id, city=city)

        query.edit_message_text(s.registration_complete)
        query.from_user.send_message(
            s.registration_complete_message.format(city.name),
            parse_mode=ParseMode.HTML,
            reply_markup=default_markup)
    else:
        conf.logger.error("Unrecognized city: %s", city_name)
    return ConversationHandler.END
예제 #3
0
def finish_update_city(update: Update, context: CallbackContext):
    query = update.callback_query
    query.answer()

    city_name = query.data.split(':')[1]
    city = City.by(name=city_name)
    if city:
        user = User.by(tg_id=query.from_user.id)
        user.update(city)

        query.edit_message_text(s.got_it)
        query.from_user.send_message(s.settings_update_city_done.format(
            user.city.name),
                                     parse_mode=ParseMode.HTML,
                                     reply_markup=default_markup)
    else:
        conf.logger.error("Unrecognized city in update city: %s", city_name)
    return ConversationHandler.END