STATE_CONVERT_CC = 1
STATE_WAIT_CURRENT_CC = 2
STATE_WAIT_NEW_CC = 3
cc_convert = {}
def change_cc(peer_id, text):
state = cc_convert[peer_id]["state"]
if state == STATE_CONVERT_CC:
cc_num(peer_id, text)
elif state == STATE_WAIT_CURRENT_CC:
current_cc(peer_id, text)
elif state == STATE_WAIT_NEW_CC:
new_cc(peer_id, text)
def cc_num(peer_id, text):
if text.isdigit():
cc_convert[peer_id]["number"] = int(text)
cc_convert[peer_id]["state"] = STATE_WAIT_CURRENT_CC
write_msg(event.peer_id, 'Введите изначальную CC')
def current_cc(peer_id, text):
if text.isdigit():
cc_convert[peer_id]["from_cc"] = int(text)
cc_convert[peer_id]["state"] = STATE_WAIT_NEW_CC
write_msg(event.peer_id, 'Введите CC, в которую нужно перевести число')
def new_cc(peer_id, text):
if text.isdigit():
to_cc = int(text)
from_cc = cc_convert[peer_id]["from_cc"]
number = cc_convert[peer_id]["number"]
result = convert_base(number, to_cc, from_cc)
cc_convert.pop(peer_id)
write_msg(peer_id, result)
# ...
# MAIN
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
request = event.text
if request.lower() == "привет":
write_msg(event.user_id, "Здравствуй!")
elif request.lower() == "пока":
write_msg(event.user_id, "Пока((")
elif request.lower() == "спасибо":
write_msg(event.user_id, "Всегда пожалуйста!")
elif request in set(commands_later):
write_msg(event.user_id, 'Скоро все будет)')
elif request in set(commands):
peer_id = event.peer_id
if peer_id not in cc_convert:
cc_convert[peer_id] = {"number": 0, "from_cc": 0, "to_cc": 0, "state": STATE_CONVERT_CC}
write_msg(event.peer_id, 'Введите число для перевода в другую CC')
else:
change_cc(peer_id, event.text)