Ejemplo n.º 1
0
def send_video(video_id, chat_id, first=False):
    counts[chat_id].count = video_id
    all_video = Video.objects.all()
    video = all_video[video_id]
    markup = types.InlineKeyboardMarkup()
    btn1 = types.InlineKeyboardButton('Ссылка на фул',
                                      url=f'{video.url_video}')
    btn2 = types.InlineKeyboardButton('⬅', callback_data='<')
    btn3 = types.InlineKeyboardButton('➡', callback_data='>')
    markup.row(btn1).row(btn2, btn3)
    if first:
        msg = bot.send_document(
            chat_id,
            open(
                fr'C:\Users\levni\Desktop\real_porno_bot\mysite\media\{str(video.video)}',
                'rb'),
            caption=f'{video.name}\n\n{video.discription}',
            reply_markup=markup)
        return msg.message_id
    else:
        bot.edit_message_media(media=types.InputMediaVideo(media=open(
            fr'C:\Users\levni\Desktop\real_porno_bot\mysite\media\{str(video.video)}',
            'rb')),
                               chat_id=chat_id,
                               message_id=counts[chat_id].id,
                               reply_markup=markup)
        bot.edit_message_caption(
            caption=f'{video.name}\n\n{video.discription}',
            chat_id=chat_id,
            message_id=counts[chat_id].id,
            reply_markup=markup)
Ejemplo n.º 2
0
 def test_send_media_group_local_files(self):
     photo = open('../examples/detailed_example/kitten.jpg', 'rb')
     video = open('./test_data/test_video.mp4', 'rb')
     tb = telebot.TeleBot(TOKEN)
     medias = [types.InputMediaPhoto(photo, "View"),
               types.InputMediaVideo(video)]
     result = tb.send_media_group(CHAT_ID, medias)
     assert len(result) == 2
     assert result[0].media_group_id is not None
     assert result[1].media_group_id is not None
Ejemplo n.º 3
0
def callback_query(call):
    bot.answer_callback_query(call.id, "Доставляю")
    logger.info('uid is {}, name is {} '.format(call.message.chat.id,
                                                call.data))
    try:
        try:
            all_data = sql.get_values(call.data, str(call.message.chat.id))
            logger.info(all_data)
            if len(all_data['photos']) > 2:
                try:
                    bot.send_media_group(call.message.chat.id,
                                         (types.InputMediaPhoto(i)
                                          for i in all_data['photos']))
                except Exception as e:
                    '''maybe make some regular for Bad Request or find another way'''
                    chunks_ = chunks(all_data['photos'], 10)
                    for chunk in chunks_:
                        bot.send_media_group(call.message.chat.id,
                                             (types.InputMediaPhoto(i)
                                              for i in chunk))
            else:
                for i in all_data['photos']:
                    bot.send_photo(call.message.chat.id, i)
            if len(all_data['videos']) > 0:
                bot.send_media_group(call.message.chat.id,
                                     (types.InputMediaVideo(i)
                                      for i in all_data['videos']))
            if len(all_data['gifs']) > 0:
                bot.send_media_group(call.message.chat.id,
                                     (types.InputMediaDocument(i)
                                      for i in all_data['gifs']))
            if len(all_data['doc_images']) > 0:
                for doc in all_data['doc_images']:
                    bot.send_document(call.message.chat.id, doc)
            sql.session_add((call.message.chat.id, call.message.date))

        except FileNotFoundError:
            bot.send_message(call.message.chat.id, 'No data')

    except Exception as e:
        logger.error(e)
        bot.send_message(call.message.chat.id, 'Что-то пошло не так')