def rotors_kb(estat_id): kb = InlineKeyboard() for r in ROTORS.keys(): kb.callback(r, f'enigma-rotors {estat_id} rotor {r}') for r in sorted(REFLECTORS.keys()): kb.callback(r, f'enigma-rotors {estat_id} reflector {r}') kb.callback('3-rotors', f'enigma-rotors {estat_id} 3rotors none') kb.callback('4-rotors', f'enigma-rotors {estat_id} 4rotors none') kb.callback('NEXT ▶️', f'enigma-rotors {estat_id} done none') return kb.arrange_simple(5).render()
async def enigma_setup_rotors(): estat_id, command, letter = context2.update.callback_query.data.split()[1:] estat = enigmas.get(estat_id) if estat is None: await EditMessageReplyMarkup(chat_id=context2.update.callback_query.message.chat.chat_id, message_id=context2.update.callback_query.message.message_id).send() AnswerCallbackQuery(context2.update.callback_query.query_id, MSG.expired).webhook() return AnswerCallbackQuery(context2.update.callback_query.query_id).webhook() if command == 'rotor': if letter not in ROTORS.keys(): return t = list(estat.rotors_list) estat.rotors_list.pop(0) estat.rotors_list.append(letter) if t == estat.rotors_list: return if command == 'reflector': if letter not in REFLECTORS.keys(): return if letter == estat.reflector: return estat.reflector = letter if command == '3rotors': if estat.rotors == 3: return estat.rotors = 3 if len(estat.rotors_list) != 3: estat.rotors_list.pop(0) estat.rings_list = ['A', 'A', 'A'] estat.display = ['A', 'A', 'A'] if command == '4rotors': if estat.rotors == 4: return estat.rotors = 4 if len(estat.rotors_list) != 4: estat.rotors_list.insert(0, 'I') estat.rings_list = ['A', 'A', 'A', 'A'] estat.display = ['A', 'A', 'A', 'A'] if command == 'done': m = MSG.setup.format(setting=MSG.setup_rings, display=' '.join(estat.display), reflector=estat.reflector, rotors=' '.join(estat.rotors_list), rings=' '.join(estat.rings_list), plugboard=' '.join(estat.plugboard) if len( estat.plugboard) else MSG.plugboard_empty, idisplay=' '.join(estat.display)) kb = enigma_kb(estat_id, 'enigma-rings') await EditMessageText(chat_id=context2.update.callback_query.message.chat.chat_id, message_id=context2.update.callback_query.message.message_id, text=m, reply_markup=kb).send() return m = MSG.setup.format(setting=MSG.setup_rotors, display=' '.join(estat.display), reflector=estat.reflector, rotors=' '.join(estat.rotors_list), rings=' '.join(estat.rings_list), plugboard=' '.join(estat.plugboard) if len( estat.plugboard) else MSG.plugboard_empty, idisplay=' '.join(estat.display)) await EditMessageText(chat_id=context2.update.callback_query.message.chat.chat_id, message_id=context2.update.callback_query.message.message_id, text=m, reply_markup=rotors_kb(estat_id)).send()