def start(message): user_dict = { 'first_name': message.chat.first_name, 'username': message.chat.username, 'last_name': message.chat.last_name, 'user_id': message.chat.id, } keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) try: if Users.objects.get(user_id=message.chat.id): user = Users.objects.get(user_id=message.chat.id) bot.send_message(message.chat.id, text=f'Hi again {user.username}', reply_markup=keyboard) else: Users(**user_dict).save() bot.send_message(message.chat.id, text=f'Hello new buyer {message.chat.username}', reply_markup=keyboard) user = Users.objects.get(user_id=message.chat.id) basket = Basket(user=user) basket.save() except Exception: Users(**user_dict).save() bot.send_message(message.chat.id, text=f'Hello new buyer {message.chat.username}', reply_markup=keyboard) user = Users.objects.get(user_id=message.chat.id) basket = Basket(user=user) basket.save()
def start(message): dict_of_user = message.from_user user_id = models.User.objects(id_user=str(dict_of_user.id)).first() print(user_id) print(dict_of_user.id) if not models.User.objects(id_user=str(dict_of_user.id)): data_of_user = models.User( **{ 'id_user': str(dict_of_user.id), 'first_name': dict_of_user.first_name, 'username': dict_of_user.username, 'last_name': dict_of_user.last_name }).save() greeting_str = f'Hello {dict_of_user.first_name} {dict_of_user.last_name}' keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) bot.send_message(message.chat.id, greeting_str, reply_markup=keyboard) real_user_id = models.User.objects(id_user=str(dict_of_user.id)).first() print(real_user_id) if not models.Cart.objects(user=user_id, active=True): cart_user = models.Cart(**{'user': real_user_id}).save() else: pass
def start(message): """ First handler run on user first connection Adds new user to db Shows main keyboard Make user status active in order to check if user stop bot """ if not db.User.objects(user_id=str(message.chat.id)): db.User.create_user(str(message.chat.id), f'{message.chat.last_name}', f'{message.chat.first_name}', message.chat.username) db.User.objects(user_id=str(message.chat.id)).get().update( **{'active': True}) greeting_str = 'Добро пожаловать в виртуальный мир BEATLEX' keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) keyboard.add('Личный кабинет \U0001F468\U0001F3FC\U0000200D\U0001F4BB') bot.send_message(message.chat.id, greeting_str, reply_markup=keyboard)
def start(message): greeting_str = models.Texts.objects(title='Greetings').get().body keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) bot.send_message(message.chat.id, greeting_str, reply_markup=keyboard)
def main_menu(message): keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) bot.send_message(message.chat.id, u'\U0001F3E0' + " Главное меню", reply_markup=keyboard)
def start(message): greeting_str = 'Добро пожаловать в магазин minimall' keyboard = ReplyKB().generate_kb(*keyboards.beginning_kb.values()) bot.send_message(message.chat.id, greeting_str, reply_markup=keyboard)