Beispiel #1
0
def all_messages(message):
    # функция календаря, принимает мессендж
    def start(m, v_string):
        calendar, step = DetailedTelegramCalendar().build()
        bot.send_message(m.chat.id,
                         f"{v_string} {LSTEP[step]}",
                         reply_markup=calendar)
        return message.message_id

    # Настройки календаря
    @bot.callback_query_handler(func=DetailedTelegramCalendar.func())
    def cal(c):
        result, key, step = DetailedTelegramCalendar(locale='ru', min_date=d1, max_date=d2).process(c.data)
        if not result and key:
            bot.edit_message_text(f"Select {LSTEP[step]}",
                                  c.message.chat.id,
                                  c.message.message_id,
                                  reply_markup=key)
        elif result:
            bot.edit_message_text(f"Min: {result.strftime('%d.%m.%Y')}",
                                  c.message.chat.id,
                                  c.message.message_id)

            # функция построения диапазона дат от d1 до d2
            def date_range(d1, d2):
                return (d1 + datetime.timedelta(days=i) for i in range((d2 - d1).days + 1))

            first_date = result
            # вывод всех
            for d in date_range(first_date, d2):
                print(d.strftime('%Y.%m.%d'))

    start(message, v_string='Выберите начальную дату')
Beispiel #2
0
def in_date(message):
    # функция календаря, принимает мессендж
    def start(m, v_string):
        calendar, step = DetailedTelegramCalendar().build()
        bot.send_message(m.chat.id,
                         f"{v_string} {LSTEP[step]}",
                         reply_markup=calendar)


        return message.message_id

    # Настройки календаря
    @bot.callback_query_handler(func=DetailedTelegramCalendar.func())
    def cal(c):
        result, key, step = DetailedTelegramCalendar(locale='ru', min_date=d1, max_date=d2).process(c.data)
        if not result and key:
            bot.edit_message_text(f"Select {LSTEP[step]}",
                                  c.message.chat.id,
                                  c.message.message_id,
                                  reply_markup=key)
        elif result:
            bot.edit_message_text(f"Min: {result.strftime('%d.%m.%Y')}",
                                  c.message.chat.id,
                                  c.message.message_id)

            # функция построения диапазона дат от d1 до d2
            def date_range(d1, d2):
                return (d1 + datetime.timedelta(days=i) for i in range((d2 - d1).days + 1))

            first_date = result
            # вывод всех
            for d in date_range(first_date, d2):
                print(d.strftime('%Y.%m.%d'))

    markup = telebot.types.InlineKeyboardMarkup()
    button = telebot.types.InlineKeyboardButton(text='Выбрать начало', callback_data='first_date')
    markup.add(button)
    button = telebot.types.InlineKeyboardButton(text='Выбрать конец', callback_data='second_date')
    markup.add(button)
    bot.send_message(chat_id=message.chat.id, text='Выберите начальную и конечную даты', reply_markup=markup)

    @bot.callback_query_handler(func=lambda call: True)
    def query_handler(call):
        if call.data == 'first_date':
            bot.answer_callback_query(callback_query_id=call.id, text='Hello world')
            start(message, v_string='Выберите начальную дату')
        if call.data == 'second_date':
            bot.answer_callback_query(callback_query_id=call.id, text='Sad world')
        'C:/Users/sergey/PycharmProjects/pythonProject2/telegram/static/sticker.webp',
        'rb')
    bot.send_sticker(message.chat.id, img)
    bot.reply_to(
        message,
        f"Привет, сейчас я предложу выбрать дату поездки. Для этого НАПИШИ /date, "
        f"{message.from_user.first_name}")


@bot.message_handler(commands=['date'])
def start(m):
    calendar, step = DetailedTelegramCalendar().build()
    bot.send_message(m.chat.id, f"Select {LSTEP[step]}", reply_markup=calendar)


@bot.callback_query_handler(func=DetailedTelegramCalendar.func())
def cal(c):
    result, key, step = DetailedTelegramCalendar().process(c.data)
    if not result and key:
        bot.edit_message_text(f"Select {LSTEP[step]}",
                              c.message.chat.id,
                              c.message.message_id,
                              reply_markup=key)
    elif result:
        bot.edit_message_text(
            f"Ты выбрал {result}, теперь пора выбрать наш маршрут НАПИШИ /city ",
            c.message.chat.id, c.message.message_id)


start_city = ''
end_city = ''
from telegram_bot_calendar import DetailedTelegramCalendar, LSTEP

bot = Bot(token="token")
dp = Dispatcher(bot)


@dp.message_handler(commands='start')
async def start(message):
    calendar, step = DetailedTelegramCalendar().build()
    await bot.send_message(message.chat.id,
                           f"Select {LSTEP[step]}",
                           reply_markup=calendar)


@dp.callback_query_handler(DetailedTelegramCalendar.func())
async def inline_kb_answer_callback_handler(query):
    result, key, step = DetailedTelegramCalendar().process(query.data)

    if not result and key:
        await bot.edit_message_text(f"Select {LSTEP[step]}",
                                    query.message.chat.id,
                                    query.message.message_id,
                                    reply_markup=key)
    elif result:
        await bot.edit_message_text(f"You selected {result}",
                                    query.message.chat.id,
                                    query.message.message_id)


executor.start_polling(dp, skip_updates=True)
Beispiel #5
0
api_id = 123456
api_hash = "1233456789"
bot_token = '1219481769:AAFrlaSczx4xa0OtsBGp51dESfNmoJrH6zg'

bot = TelegramClient("bot", api_id, api_hash)

class MyStyleCalendar(DetailedTelegramCalendar):
    empty_month_button = ""
    empty_year_button = ""


@bot.on(events.NewMessage(pattern="/start"))
async def reply_handler(event):
    calendar, step = DetailedTelegramCalendar(telethon=True, min_date=date.today()).build()
    await event.respond(f"Select {LSTEP[step]}", buttons=calendar)


@bot.on(events.CallbackQuery(pattern=DetailedTelegramCalendar.func(telethon=True)))
async def calendar_handler(event):
    result, key, step = DetailedTelegramCalendar(telethon=True, min_date=date.today()).process(event.data.decode("utf-8"))

    if not result and key:
        await event.edit(f"Select {LSTEP[step]}", buttons=key)
    elif result:
        await event.edit(f"You selected {result}")


bot.start(bot_token=bot_token)
with bot:
    bot.run_until_disconnected()
    bot.send_message(m.chat.id,
                     f"Calendar 1: Select {LSTEP[step]}",
                     reply_markup=calendar)


@bot.message_handler(commands=['start2'])
def start2(m):
    # do not forget to put calendar_id
    calendar, step = DetailedTelegramCalendar(calendar_id=2,
                                              locale='ru').build()
    bot.send_message(m.chat.id,
                     f"Calendar 2: Select {LSTEP[step]}",
                     reply_markup=calendar)


@bot.callback_query_handler(func=DetailedTelegramCalendar.func(calendar_id=1))
def cal1(c):
    # calendar_id is used here too, since the new keyboard is made
    result, key, step = DetailedTelegramCalendar(calendar_id=1).process(c.data)
    if not result and key:
        bot.edit_message_text(f"Calendar 1: Select {LSTEP[step]}",
                              c.message.chat.id,
                              c.message.message_id,
                              reply_markup=key)
    elif result:
        bot.edit_message_text(f"You selected {result} in calendar 1",
                              c.message.chat.id, c.message.message_id)


@bot.callback_query_handler(func=DetailedTelegramCalendar.func(calendar_id=2))
def cal1(c):