我期待制作某种电报国际象棋机器人。所以它基于内联键盘。用户应该按下 ilnlineButton 来选择一个棋子,然后按下按钮将棋子放在哪里。我不知道如何在 inlineKeyboard 中的“棋盘”上选择一个空闲单元格,仅在现在选择典当。我试图做 bot.register_next_step_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))
所以我希望进程跳转到 process_move_step 并等待新的回调并在那里检查它,但是在得到“pawn”回调而不是得到“空”回调之后,我从 else: part 而不是进入那个 if
if call.data.partition('empty')[1] == "empty":
So how can I get "pawn" cell then "empty" cell from callbacks and then complete functions. For "empty" stands object EmptyCell and it has attributes X and Y, so I can move pawn in exact place in Board obj and edit inline keyboard. I have seen something similar in @TrueMafiaBot. When police officer is asked if he want to check or shoot somebody and then he picks a player to make chosen action.