From 23164d3925515148450f6888244375996161c552 Mon Sep 17 00:00:00 2001 From: lulzette Date: Thu, 15 Dec 2022 18:50:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=96=D0=B8=D1=80=D0=BD=D1=8B=D0=B9=20=D1=88?= =?UTF-8?q?=D1=80=D0=B8=D1=84=D1=82,=20=D0=BE=D1=82=D1=81=D1=82=D1=83?= =?UTF-8?q?=D0=BF=D1=8B,=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 73fde21..e200e8c 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ import os import sys import telebot from telebot.types import InputFile +from telebot import types from datetime import datetime import requests import shutil @@ -45,10 +46,16 @@ def stream_message_worker(data: dict): time_now = datetime.utcnow().replace(microsecond=0) stream_duration = time_now - time_started # Готовим сообщение - message = stream_title + '\n' + \ + message = "*"+stream_title+"*" + '\n' + '\n' + \ "Игра: " + game_name + '\n' + \ "Зрителей: " + stream_viewers + '\n' + \ "Длительность: " + str(stream_duration) + + # Готовим кнопку + stream_button = types.InlineKeyboardButton('Открыть стрим', url='https://twitch.tv/'+streamer) + keyboard = types.InlineKeyboardMarkup() + keyboard.add(stream_button) + log.info(message) # Если файл с айди существует, читаем его и редактируем сообщение из него if os.path.exists('msgid'): @@ -60,15 +67,22 @@ def stream_message_worker(data: dict): msgid = 0 if msgid == 0: - send_message = bot.send_photo(config_python.tgchat, InputFile('tmppic.jpg'), message) + # Отправляем новое сообщение + send_message = bot.send_photo(config_python.tgchat, InputFile('tmppic.jpg'), message, reply_markup=keyboard, + parse_mode='MarkdownV2') print(send_message) msgid = send_message.message_id with open('msgid', 'w') as f: f.write(str(msgid)) else: try: - media = telebot.types.InputMediaPhoto(InputFile('tmppic.jpg'), message) - edit_msg_media = bot.edit_message_media(media, config_python.tgchat, msgid) + # Готовим медиа для отправки + media = telebot.types.InputMediaPhoto(InputFile('tmppic.jpg')) + # Редактируем фотку + edit_msg_media = bot.edit_message_media(media, config_python.tgchat, msgid, reply_markup=keyboard) + # Редактируем текст + edit_msg_caption = bot.edit_message_caption(message,config_python.tgchat,msgid,reply_markup=keyboard, + parse_mode='MarkdownV2') except telebot.apihelper.ApiTelegramException as e: log.error(e)