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

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 sys
import telebot import telebot
from telebot.types import InputFile from telebot.types import InputFile
from telebot import types
from datetime import datetime from datetime import datetime
import requests import requests
import shutil import shutil
@ -45,10 +46,16 @@ def stream_message_worker(data: dict):
time_now = datetime.utcnow().replace(microsecond=0) time_now = datetime.utcnow().replace(microsecond=0)
stream_duration = time_now - time_started stream_duration = time_now - time_started
# Готовим сообщение # Готовим сообщение
message = stream_title + '\n' + \ message = "*"+stream_title+"*" + '\n' + '\n' + \
"Игра: " + game_name + '\n' + \ "Игра: " + game_name + '\n' + \
"Зрителей: " + stream_viewers + '\n' + \ "Зрителей: " + stream_viewers + '\n' + \
"Длительность: " + str(stream_duration) "Длительность: " + str(stream_duration)
# Готовим кнопку
stream_button = types.InlineKeyboardButton('Открыть стрим', url='https://twitch.tv/'+streamer)
keyboard = types.InlineKeyboardMarkup()
keyboard.add(stream_button)
log.info(message) log.info(message)
# Если файл с айди существует, читаем его и редактируем сообщение из него # Если файл с айди существует, читаем его и редактируем сообщение из него
if os.path.exists('msgid'): if os.path.exists('msgid'):
@ -60,15 +67,22 @@ def stream_message_worker(data: dict):
msgid = 0 msgid = 0
if 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) print(send_message)
msgid = send_message.message_id msgid = send_message.message_id
with open('msgid', 'w') as f: with open('msgid', 'w') as f:
f.write(str(msgid)) f.write(str(msgid))
else: else:
try: 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: except telebot.apihelper.ApiTelegramException as e:
log.error(e) log.error(e)