LINUX.ORG.RU

История изменений

Исправление annerleen, (текущая версия) :

Ах да, в телеграмной либе мы не можем унаследовать, например, класс бота/апдейтера, там всё на update events и handlers
Поэтому сделал как-то так, тоже не знаю, насколько это правильно

bot_instances = {}

def callBot(bot, update):
    
    # if we don't have instance for this chat AND this chat is not private -- create our bot instance.
    if not update.message.chat_id in bot_instances and update.message.chat.type != 'private': 
        bot_instances[update.message.chat_id] = OraculBot(bot, update)
    
    # if instance created successfully, we can call it passing an event:
    if update.message.chat_id in bot_instances and bot_instances[update.message.chat_id]: 
        bot_instances[update.message.chat_id](update)

dispatcher.add_handler(MessageHandler(Filters.text | Filters.status_update, callBot)) # handling any messages with function callBot()

Исправление annerleen, :

Ах да, в телеграмной либе мы не можем унаследовать, например, класс бота/апдейтера, там всё на update events и handlers
Поэтому сделал как-то так, тоже не знаю, насколько это правильно

bot_instances = {}

dispatcher.add_handler(MessageHandler(Filters.text | Filters.status_update, callBot)) # handling any messages with function callBot()

def callBot(bot, update):
    
    # if we don't have instance for this chat AND this chat is not private -- create our bot instance.
    if not update.message.chat_id in bot_instances and update.message.chat.type != 'private': 
        bot_instances[update.message.chat_id] = OraculBot(bot, update)
    
    # if instance created successfully, we can call it passing an event:
    if update.message.chat_id in bot_instances and bot_instances[update.message.chat_id]: 
        bot_instances[update.message.chat_id](update)

Исходная версия annerleen, :

Ах да, в телеграмной либе мы не можем унаследовать, например, класс бота/апдейтера, там всё на update events и handlers
Поэтому сделал как-то так, тоже не знаю, насколько это правильно

bot_instances = {}


dispatcher.add_handler(MessageHandler(Filters.text | Filters.status_update, callBot)) # handling any messages with function callBot()


def callBot(bot, update):
    
    # if we don't have instance for this chat AND this chat is not private -- create our bot instance.
    if not update.message.chat_id in bot_instances and update.message.chat.type != 'private': 
        bot_instances[update.message.chat_id] = OraculBot(bot, update)
    
    # if instance created successfully, we can call it passing an event:
    if update.message.chat_id in bot_instances and bot_instances[update.message.chat_id]: 
        bot_instances[update.message.chat_id](update)