yandex code
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from random import choice
|
||||
|
||||
from telebot.types import Message, ReplyKeyboardRemove
|
||||
|
||||
@@ -8,6 +9,7 @@ from helpers import get_next_daily_notify_time
|
||||
from helpers.keyboards import main_keyboard, notify_keyboard, yes_no_keyboard, again_keyboard, no_daily_notify, \
|
||||
campus_keyboard, daily_notify_type, notify_type, first_lesson_notify
|
||||
from helpers.mongo import mongo
|
||||
from helpers.platform import platform
|
||||
from helpers.ruz import ruz
|
||||
|
||||
|
||||
@@ -34,7 +36,8 @@ class Answer:
|
||||
'daily_notify_today': True,
|
||||
'first_lesson_notify': None,
|
||||
'last_schedule_fetch': datetime.datetime.now(),
|
||||
'yandex_id': None
|
||||
'yandex_id': None,
|
||||
'yandex_code': None,
|
||||
}
|
||||
mongo.users_collection.insert_one(user)
|
||||
self.user = user
|
||||
@@ -143,7 +146,15 @@ class Answer:
|
||||
return
|
||||
elif self.message_text == "Подключение Алисы":
|
||||
if self.user['yandex_id'] is None:
|
||||
text = "Для того, чтобы подключить Яндекс.Алису, вызови навык \"Расписание вышки\" и назови этот код: " + str(self.user['hse_id'])
|
||||
words = platform.get_config('words')
|
||||
while True:
|
||||
random_words = [choice(words) for _ in range(4)]
|
||||
code = ' '.join(random_words)
|
||||
u = mongo.users_collection.find_one({"yandex_code": code})
|
||||
if u is None:
|
||||
break
|
||||
mongo.users_collection.update_one({'chat_id': self.user['chat_id']}, {"$set": {"yandex_code": code}})
|
||||
text = "Для того, чтобы подключить Яндекс.Алису, вызови навык \"Расписание вышки\" и назови этот код: " + code
|
||||
else:
|
||||
text = "Янедкс.Алиса уже подключена. Чтобы узнать ближайшую пару, вызови навык \"Расписание вышки\""
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user