Python Don';我不知道如何处理PyAPI中的几个回调

Python Don';我不知道如何处理PyAPI中的几个回调,python,python-3.x,telegram-bot,py-telegram-bot-api,Python,Python 3.x,Telegram Bot,Py Telegram Bot Api,我期待着制作某种电报。所以它是基于内联键盘的。用户应按下ILNLINE按钮选择棋子,然后按下按钮放置棋子。我不知道在选择了一个棋子之后,如何在inlineKeyboard的“board”上选择一个空闲的单元格,只是现在。我试着做bot.register\u next\u step\u handler,但他没有给出我期望的结果 @bot.callback_query_handler(func=lambda call: True) def callback_inline(call): try

我期待着制作某种电报。所以它是基于内联键盘的。用户应按下ILNLINE按钮选择棋子,然后按下按钮放置棋子。我不知道在选择了一个棋子之后,如何在inlineKeyboard的“board”上选择一个空闲的单元格,只是现在。我试着做bot.register\u next\u step\u handler,但他没有给出我期望的结果

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
    try:
        if call.message:
            if call.data == "suck":
                bot.send_message(call.message.chat.id, "Just wait a bit, OK?")
            elif call.data == "frick":
                bot.send_message(call.message.chat.id, "No, frick you")
            elif call.data == "sad":
                bot.send_message(call.message.chat.id, "Well, shit happens")
            elif call.data == "good":
                bot.send_message(call.message.chat.id, "I am soulless robot. How do      you think I can feel?")
            elif call.data.partition('pawn')[1] == "pawn":
                bot.register_next_step_handler(call.data, process_move_step)

else:
                bot.send_message(call.message.chat.id, call.data)
                bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=
                                                                                                      "some_text",reply_markup=None)

    except Exception as e:
        print(repr(e))


def process_move_step(call):
    try:
        if call.message:
            if call.data.partition('empty')[1] == "empty":
                next_move = new_board.get_chessman(call.data)
                new_board.move(call, next_move.X, next_move.Y)
                bot.send_message(call.message.chat.id, "Moved to "+str(next_move.X+str(next_move.Y)))
                print(new_board)

    except Exception as e:
        print(repr(e))
所以我希望进程跳转到进程移动步骤,等待新的回调并在那个里检查它,但在得到“典当”回调和“空”回调之后,我得到了来自else的结果:part而不是if

if call.data.partition('empty')[1] == "empty":

那个么我怎样才能从回调中得到“pawn”单元格,然后是“empty”单元格,然后完成函数呢。“empty”代表对象EmptyCell,它有属性X和Y,所以我可以将兵移动到Board obj中的确切位置,并编辑内联键盘。我在@TrueMafiaBot中看到过类似的东西。当警察被问到是否要检查或射杀某人时,他会挑选一名球员来做出选择的动作。

这并不像你想象的那样有效。每个请求总是传递给主函数(回调函数)。因此,如果您尝试在选择典当后捕获下一步,您应该保存用户的当前状态。如果用户选择pawn,则其状态设置为\u pawn\u selected=true。在此之后,您可以添加一些逻辑来处理此状态。在您的情况下,应该是这样的:

 if (users.get(user_ID).is_pawn_selected) { 
    user.is_pawn_selected = false
    process_move_step 
}

最直接的方法是在运行bot时保持某种状态,并对回调查询答案执行
if-else
检查。例如,您可以执行以下操作:

从枚举导入枚举
从数据类导入数据类
类别颜色(枚举):
白色=0
黑色=1
@数据类
类游戏状态:
聊天室id:int
颜色
握棋手:棋手
#…游戏流程的另一个有用数据
#数据是从用户处收到的回调数据
#gamestate是服务器(或数据库)上游戏状态的本地实例
#内部回调应答处理:
如果gamestate.turn!=data.user.color:
返回错误('不轮到您,请稍候!')
如果gamestate.holding_chessman为无:
gamestate.holding_chessman=data.pressed_figure
返回信息('现在按下一个按钮,将棋子移动到哪里')
其他:
执行棋子移动()
开关(u turn)
返回信息('您移动了一个棋子,现在另一个用户必须转向')