Python 当第二个人开始输入凭证时,电报机器人(telebot)停止响应
当第二个人开始输入凭证时,电报机器人(telebot)停止响应。我相信问题出在chat.input()中,但我不确定,也不知道如何解决它。我试过的都不管用。当为第二个人运行ask_credentials()时,它会冻结。顺便问一下,我是OOP新手,代码OOP够了吗 代码的主要部分:Python 当第二个人开始输入凭证时,电报机器人(telebot)停止响应,python,python-3.x,telegram-bot,py-telegram-bot-api,Python,Python 3.x,Telegram Bot,Py Telegram Bot Api,当第二个人开始输入凭证时,电报机器人(telebot)停止响应。我相信问题出在chat.input()中,但我不确定,也不知道如何解决它。我试过的都不管用。当为第二个人运行ask_credentials()时,它会冻结。顺便问一下,我是OOP新手,代码OOP够了吗 代码的主要部分: class Chat: global existing_chats global local_order_count def __init__(self, chat, request):
class Chat:
global existing_chats
global local_order_count
def __init__(self, chat, request):
self.request = request
self.previous_answer = None
self.chat_params = chat
self.chat_id = chat.chat.id
self.answer = None
self.answernotrecieved = None
self.status = True
self.keep_waiting = True
for existing_chat in existing_chats:
if existing_chat.chat_id == self.chat_id:
existing_chat.keep_waiting = False
del existing_chat
def input(self, question):
if self.chat_params:
self.answer = bot_.send_message(self.chat_params.chat.id, question)
self.answernotrecieved = True
bot_.register_next_step_handler(self.answer, self.return_answer)
while self.answernotrecieved and self.keep_waiting:
time.sleep(1)
pass
if not self.answernotrecieved:
return self.answer.text
else:
return None
def return_answer(self, answer):
self.answer = answer
self.answernotrecieved = False
def say(self, message):
if self.chat_params:
bot_.send_message(self.chat_params.chat.id, message)
def __del__(self):
print('deleting chat')
class Order:
global existing_chats
global local_order_count
def __init__(self, chat):
self.chat = chat
self.context = {'city': ['Kiev', False,'^\b[a-zA-Z0-9_]+\b$'],
'name': [None, 'What is your full name?', '\w\s+\w+'],
'bdate': [None, 'What is your date of birth (dd-mm-yyyy) split with "-"?','[0-9]{2}-[0-9]{2}-[0-9]{4}'],
'nation': [None, 'What is your nationality (e.g. Ukraine)?', '\w'],
'gender': [None, 'What is your gender Male/Female?', '\w'],
'passport': [None, 'What is your passport number?','\w'],
'flight_date': [None, 'What is your flight date (dd-mm-yyyy) split with "-"?','[0-9]{2}-[0-9]{2}-[0-9]{4}'],
'email': [None, 'What is your email, we will send you the results?','^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'],
'tdate': [None, False, False],
"rdate": [None, False, False]}
self.notsent = True
self.ask_credentials()
def ask_credentials(self):
try:
for key, [credential, question, form] in self.context.items():
if not credential and question and self.chat.keep_waiting:
self.reply = self.chat.input(question)
if self.reply is not None:
if re.search(form,self.reply) or not form:
self.context[key] = [self.reply, question, form]
elif not re.search(form,self.reply):
self.ask_credentials()
elif not form:
pass
else:
break
else:
try:
for key, [credential, question, form] in self.context.items():
if (type(credential)==str) and question and form:
pass
except ValueError:
self.ask_credentials()
else:
self.check_credentials()
except:
pass
class Login(threading.Thread):
def __init__(self, chat_params):
threading.Thread.__init__(self)
self.chat = Chat(chat_params, self)
self.chat_params = chat_params
existing_chats.append(self.chat)
if self.chat.status:
self.chat.say(
f'Dear {chat_params.from_user.first_name}, \n****')
self.chat.say('To get the AI Lab Password, contact us on instagram')
self.password = self.chat.input('Enter your AI Lab password:')
self.login(self.password)
def login(self, password):
global existing_chats
global local_order_count
if password in pass_list:
self.chat.say('Access Granted. Lets enter your credentials.')
print(f'New Order #{local_order_count} '
f'at {datetime.now().strftime("%Y-%m-%d %H:%M")} '
f'by {self.chat_params.from_user.first_name} '
f'@{self.chat_params.from_user.username}')
local_order_count += 1
order = Order(self.chat)
else:
if password:
if '/' not in password:
self.chat.say('Access Declined. Press /start')
@bot_.message_handler(commands=["start"])
def start(chat_params):
Login(chat_params)