• 23-10-2023, 23:37:15
    #1
    merhaba arkadaşlar telegramda şunu yapmaya çalışıyorum botumu eklediğim gruplarımda alıntıladığım mesajdan sonraki atılan mesajları alacak(alıntılanan mesaj 10.00 da alıntılanmış ve saat 15.00 ise 10.00 dan 15.00 a kadar atılmış tüm mesajlar için ayrı ayrı ) ve buna göre işlemler yaptıracağım ancak mesajları çekemedim tecrübeli bir arkadaş yardım edebilir mi ?

    aldığım hata şu



    import telegram
    from telegram.ext import Updater, MessageHandler, Filters, CommandHandler
    
    bot_token = ' bot tokenim'
    
    message_to_track = {}
    def forward_messages(update, context):
        chat_id = update.effective_chat.id
    
        quoted_message = update.message.reply_to_message
        if quoted_message:
    
            start_time = quoted_message.date
    
            current_time = update.message.date
    
            messages = get_messages_from_chat(update, start_time, current_time)
            for message in messages:
    
                print(f"{message.from_user.first_name}: {message.text}")
    
                message_key = f"{start_time}-{quoted_message.text}"
    
                message_to_track[message_key] = []
    def get_messages_from_chat(update, from_time, to_time):
        messages = update.effective_chat.get_updates()
        relevant_messages = []
        should_collect = False
        for message in messages:
            if should_collect:
                relevant_messages.append(message)
            if message.message.date == from_time:
                should_collect = True
            if message.message.date == to_time:
                should_collect = False
                break
        return relevant_messages
    def add_messages(update, context):
        chat_id = update.effective_chat.id
    
        latest_update = get_latest_update(update)
        if latest_update:
            start_time = latest_update.message.date
            quoted_message_text = latest_update.message.text
            message_key = f"{start_time}-{quoted_message_text}"
            if message_key in message_to_track:
                messages = message_to_track[message_key]
    
                for message in messages:
                    print(f"{message.from_user.first_name}: {message.text}")
    def get_latest_update(update):
        return update.message.reply_to_message
    def main():
        updater = Updater(token=bot_token, use_context=True)
        dp = updater.dispatcher
    
        dp.add_handler(MessageHandler(Filters.reply, forward_messages))
    
        dp.add_handler(CommandHandler('ekle', add_messages))
    
        updater.start_polling()
        updater.idle()
    if __name__ == '__main__':
        main()
  • 24-10-2023, 03:57:42
    #2