Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions efb_telegram_master/slave_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import telegram.error
import telegram.ext
from PIL import Image
from telegram import InputFile, ChatAction, InputMediaPhoto, InputMediaDocument, InputMediaVideo, InputMediaAnimation, \
from telegram import InputFile, ChatAction, InputMediaAudio, InputMediaPhoto, InputMediaDocument, InputMediaVideo, InputMediaAnimation, \
InlineKeyboardMarkup, InlineKeyboardButton, ReplyMarkup, TelegramError, InputMedia

from ehforwarderbot import Message, Status, coordinator
Expand Down Expand Up @@ -739,10 +739,20 @@ def slave_message_voice(self, msg: Message, tg_dest: TelegramChatID, msg_templat

if old_msg_id:
if edit_media:
# Cannot edit voice message content, send a new one instead
msg_template += " " + self._("[Edited]")
if str(tg_dest) == old_msg_id[0]:
target_msg_id = target_msg_id or old_msg_id[1]
original_message = self.channel.get_message_by_id(msg.chat, old_msg_id[1])
if original_message and original_message.type == MsgType.Voice:
# Cannot edit voice message content, send a new one instead
msg_template += " " + self._("[Edited]")
if str(tg_dest) == old_msg_id[0]:
target_msg_id = target_msg_id or old_msg_id[1]
else:
assert msg.file is not None
with tempfile.NamedTemporaryFile() as f:
pydub.AudioSegment.from_file(msg.file).export(f, format="ogg", codec="libopus",
parameters=['-vbr', 'on'])
file = self.process_file_obj(f, f.name)
return self.bot.edit_message_media(chat_id=old_msg_id[0], message_id=old_msg_id[1], media=InputMediaAudio(file), reply_markup=reply_markup,
prefix=msg_template, suffix=reactions, caption=text, parse_mode="HTML")
else:
return self.bot.edit_message_caption(chat_id=old_msg_id[0], message_id=old_msg_id[1],
reply_markup=reply_markup, prefix=msg_template,
Expand Down
Loading