Жирный шрифт, отступы, кнопка

This commit is contained in:
lulzette 2022-12-15 18:50:46 +03:00
parent d5d2af3bd3
commit 23164d3925

22
main.py
View File

@ -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)