Пример #1
0
def print_post(chat_id, event_id, image, date, title, description):
    user = User.get_user('chat_id', chat_id)
    events_all = Event.all_event()
    events_user = []
    cuser_events = user.get_events()
    for cuser_event in cuser_events:
        events_user.append(cuser_event._id)
    text = 'Записаться'
    if event_id in events_user:
        text = 'Отписаться'
    keyboard = telebot.types.InlineKeyboardMarkup(row_width=2)
    keyboard.add(
        telebot.types.InlineKeyboardButton(
            text, callback_data=f"change_event_status\t{event_id}"))
    # if image:
    #try:
    #    photo = open(image, 'rb')
    #except IOError as e:
    #    print(f"I/O error({e.errno}): {e.strerror}")
    #bot.send_photo(chat_id, photo, caption=f'{date} - {title}: {description}')
    bot.send_message(chat_id,
                     f"{date}\n<b>{title}</b>\n{description}",
                     parse_mode="HTML",
                     disable_web_page_preview=True,
                     reply_markup=keyboard)
Пример #2
0
def callback_inline(call):
    cuser = User.get_user('chat_id', call.message.chat.id)
    # Если сообщение из чата с ботом
    if call.message:
        print(call.data)
        action = (call.data).split()[0]
        event_id = (call.data).split()[1]
        if action == "show":
            event = Event.get_event('id', f'{event_id}')
            print_post(call.message.chat.id, event._id, event.photo,
                       event.date, event.title, event.description)
            #            events_all = Event.all_event()
            #            events_user = []
            #            cuser_events = cuser.get_events()
            #            for cuser_event in cuser_events:
            #                events_user.append(cuser_event._id)
            #            text = 'Записаться'
            #            if event_id in events_user:
            #                text = 'Отписаться'
            #            keyboard = telebot.types.InlineKeyboardMarkup(row_width=2)
            #            keyboard.add(telebot.types.InlineKeyboardButton(text, callback_data=f"change_event_status\t{event_id}"))
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text=call.message.text)
            return
        if action == "change_event_status":
            event = Event.get_event('id', f'{event_id}')
            events = Event.all_event()
            list_of_users_event = []
            cuser_events = cuser.get_events()
            for cuser_event in cuser_events:
                list_of_users_event.append(cuser_event._id)
            for event in events:
                is_delete_event = False
                if event_id == str(event._id):
                    for cuser_event in cuser_events:
                        if str(cuser_event._id) == str(event._id):
                            is_delete_event = True
                    if is_delete_event:
                        cuser.decline_event(event._id)
                        bot.edit_message_text(
                            chat_id=call.message.chat.id,
                            message_id=call.message.message_id,
                            text=call.message.text + "\nВы отписаны")
                    else:
                        cuser.accept_event(event._id)
                        bot.edit_message_text(
                            chat_id=call.message.chat.id,
                            message_id=call.message.message_id,
                            text=call.message.text + "\nВы записаны")
            #print_post(call.message.chat.id, event._id, event.photo, event.date, event.title, event.description)
            return

    # Если сообщение из инлайн-режима
    elif call.inline_message_id:
        if call.data == "test":
            bot.edit_message_text(inline_message_id=call.inline_message_id,
                                  text="Вы записаны")
Пример #3
0
def start_command(message):
    cuser = User.get_user('chat_id', message.from_user.id)
    if cuser == None:
        bot.send_message(message.from_user.id,
                         'Ой да бросьте, вы уже не первый раз у нас.')
        print_main_menu(message.chat.id)
    else:
        user_markup = telebot.types.ReplyKeyboardMarkup(True, False)
        button_phone = telebot.types.KeyboardButton(text="Зарегистрироваться",
                                                    request_contact=True)
        user_markup.add(button_phone)
        bot.send_message(message.from_user.id,
                         'Вас привествуют и просят представиться.',
                         reply_markup=user_markup)
Пример #4
0
def handle_text2(message):
    print(f"{message.text}")
    cuser = User.get_user('chat_id', message.from_user.id)
    if not cuser:
        start_command(message)
        return
    if str(message.text) == "Ближайшие мероприятия":
        print_event_week_list(message.chat.id)
    if str(message.text) == "Как там Белка?":
        bot.send_message(message.chat.id, f"Нормально, живая)")
    if str(message.text) == "Мои мероприятия":
        chatId = message.chat.id
        print_event_week_list_for_me(chatId)
    if str(message.text) == "FAQ":
        print("faq")
Пример #5
0
def handle_text(message):
    cuser = User.get_user('chat_id', message.from_user.id)
    # свои ли контакты переслал пользователь?
    if message.from_user.id == message.contact.user_id:
        # может мы его уже знаем?
        if cuser == None:
            return
        # ну лан так и быть зарегистрируем его
        first_name = message.from_user.first_name
        last_name = message.from_user.last_name
        phone = message.contact.phone_number
        chat_id = message.chat.id
        username = message.from_user.username
        cuser = User.registration(first_name, last_name, phone, chat_id,
                                  username)
        print_main_menu(cuser.chat_id)
Пример #6
0
def print_event_week_list(chat_id):
    user = User.get_user('chat_id', chat_id)
    events = Event.all_event()
    curent_date = datetime.now()
    delta_data = timedelta(days=7)
    for event in events:
        event_date = datetime.strptime(f"{event.date} {event.time}",
                                       "%Y-%m-%d %H:%M:%S")
        if event_date > curent_date and event_date < (curent_date +
                                                      delta_data):
            keyboard = telebot.types.InlineKeyboardMarkup(row_width=2)
            keyboard.add(
                telebot.types.InlineKeyboardButton(
                    "Подробнее...", callback_data=f"show\t{event._id}"))
            bot.send_message(
                chat_id,
                f"{event.date} {event.time} - <b>{event.title}</b>\n{event.shortdescription}",
                parse_mode="HTML",
                disable_web_page_preview=True,
                reply_markup=keyboard)
Пример #7
0
def work_schedule(message):
    cuser = User.get_user('chat_id', message.from_user.id)
    if cuser:
        start_command(message)
        return