def default_location_handler(message): active_user = get_active_user(message.from_user.id) bot.send_message(message.chat.id, f'Your current default location is -> {active_user.default_location}') bot.send_message(message.chat.id, 'You can choose another one from list above', reply_markup=user_locations(active_user.locations)) bot.register_next_step_handler(message, handle_default_location_choise)
def handleWordCommand(message): sentence = message.text.split("/s", 1)[1].strip() if not sentence: return print("selected CUSTOM sentence: {" + sentence + "} for chat: " + message.chat.first_name) data = json.dumps({'text' : sentence}) headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Mashape-Key': 'N8ZR0AG9Mvmsh42TQppAY4NJrMvSp156VdGjsnv33xh2wiltP3',} url = 'https://smallstep-englishgrammar-v1.p.mashape.com/grammar' req = urllib2.Request(url, data, headers) f = urllib2.urlopen(req) response = f.read() f.close() if 'grammarPatterns' in json.loads(response): pattern = jsonDict = json.loads(response)['grammarPatterns'][0] name = pattern['fullName'] msg = bot.send_message(chatId, "*"+sentence+"*"+"\n"name+, parse_mode = "Markdown") else: msg = bot.send_message(chatId, "Error!") # TODO: USe lambda here do distinguish buttons later! bot.register_next_step_handler(msg, handleMenu)
def brands(message): chat_id = message.chat.id text = message.text if text == "Хайтопы": msg = bot.send_message(chat_id, 'Выберите бренд хайтопа', reply_markup=rating_markup) bot.register_next_step_handler(msg, hightop) elif text == "Кроссовки": msg1 = bot.send_message(chat_id, 'Выберите бренд кроссовок', reply_markup=rating_markup) bot.register_next_step_handler(msg1, krossovki) elif text == "Кроссовки для тренировок": msg2 = bot.send_message(chat_id, 'Выберите бренд кроссовок для трени', reply_markup=rating_markup) bot.register_next_step_handler(msg2, krosovki_sport) elif text == "🔶Актуальные модели кроссовок": msg3 = bot.send_message(chat_id, 'Hype Beast', reply_markup=rating_markup) bot.register_next_step_handler(msg3, trands) elif text == "Коллабы и эксклюзивы": msg4 = bot.send_message(chat_id, 'Exclusive collaborations', reply_markup=rating_markup) bot.register_next_step_handler(msg4, collabs) else: bot.send_message(chat_id, f"Такого раздела ({message.text}) не существует")
def wrapper(message, step=step, seq_id=seq_id): seq = Sequence(*[None for i in range(9)], key_id=seq_id) seq.__dict__[lines[step]] = message.text seq._update() if step == 4: pass msg = bot.send_message(message.chat.id, texts[step]) bot.register_next_step_handler(msg, sequencer(step+1, seq_id))
def handle_new(message): id_ = Sequence.create() str_ = gen_string() Sequence.set_link(str_, id_) sequences.update({str_: id_}) sequences2.update({id_: str_}) # print(sequences) with open('sequences.txt', 'w', encoding='utf-8') as file: file.write(json.dumps(sequences)) msg = bot.send_message(message.chat.id, creation_text) bot.register_next_step_handler(msg, )
def daily_weather_handler(message): active_user = get_active_user(message.from_user.id) if active_user.subscribed: bot.send_message(message.chat.id, f'You are subscribed to daily weather, your default city is {active_user.default_location}', reply_markup=daily_weather(active_user.subscribed)) bot.register_next_step_handler(message, handle_subscribe_choise) else: bot.send_message(message.chat.id, 'You are not subscribed to daily weather :(', reply_markup=daily_weather(active_user.subscribed)) bot.register_next_step_handler(message, handle_subscribe_choise)
def handleMessage(message): chatId = message.chat.id if not chatId in currentContexts: keyboard = types.ReplyKeyboardMarkup() keyboard.row(randomWordButtonTag) keyboard.row(randomWikiButtonTag) keyboard.row(randomSimpleWikiButtonTag) keyboard.row(gifButtonTag) keyboard.row(xkcdComicsButtonTag) keyboard.row(dismissButtonTag) context = ChatContext(chatId) currentContexts[chatId] = context msg = bot.send_message(chatId, "Please, select an option", reply_markup=keyboard) # TODO: USe lambda here do distinguish buttons later! bot.register_next_step_handler(msg, handleMenu)
def handle_units_choise(message): active_user = get_active_user(message.from_user.id) new_units = message.text.title() if message.text != 'Back': if new_units in ['C', 'F']: if new_units != active_user.units: active_user.units = message.text.title() active_user.save() bot.send_message(message.chat.id, f'Now you will receive weather in °{message.text}') bot.send_message(message.chat.id, 'Returned to main Menu', reply_markup=main_keyboard()) else: bot.send_message(message.chat.id, f'Your already receive weather and forecast in °{message.text}') bot.send_message(message.chat.id, 'Returned to main Menu', reply_markup=main_keyboard()) else: bot.send_message(message.chat.id, 'Something is wrong, send again or verify entered units!') bot.register_next_step_handler(message, handle_units_choise) else: bot.send_message(message.chat.id, 'Returned to main Menu', reply_markup=main_keyboard())
def handleMenu(message): buttonTag = message.text chatContext = currentContexts[message.chat.id] if buttonTag == randomWordButtonTag: word = getRandomWord() chatContext.word = word chatContext.clean() print("selected word: {" + word + "} for chat: " + message.chat.first_name) msg = bot.send_message(message.chat.id, "*"+word+"*", parse_mode = "Markdown", reply_markup = getOptionsKeyboard()) # TODO: USe lambda here do distinguish buttons later! bot.register_next_step_handler(msg, handleMenu) elif buttonTag in optionButtonActions: print("chatId: {" + message.chat.first_name + "} selected option: {" + buttonTag + "} for word: " + chatContext.word) action = optionButtonActions[buttonTag] msg = action(chatContext) # TODO: USe lambda here do distinguish buttons later! bot.register_next_step_handler(msg, handleMenu)
def handleWordCommand(message): word = message.text.split("/word", 1)[1].strip() if not word: return print (word) chatId = message.chat.id context = None if not chatId in currentContexts: context = ChatContext(chatId) currentContexts[chatId] = context else: context = currentContexts[chatId] context.word = word context.clean() print("selected CUSTOM word: {" + word + "} for chat: " + message.chat.first_name) msg = bot.send_message(chatId, "*"+word+"*", parse_mode = "Markdown", reply_markup = getOptionsKeyboard()) # TODO: USe lambda here do distinguish buttons later! bot.register_next_step_handler(msg, handleMenu)
def handle_weather(message): if message.text == 'Add location': bot.reply_to( message, 'Send your location or city name to add it to favourites!', reply_markup=remove_keyboard) bot.register_next_step_handler(message, add_location_with_weather) elif message.text == 'Back': bot.send_message(message.chat.id, 'Main Menu', reply_markup=main_keyboard()) else: try: active_user = get_active_user(message.from_user.id) weather = Weather(message, active_user.units) bot.send_message(message.chat.id, str(weather), parse_mode='HTML') bot.send_message(message.chat.id, 'Return to main Menu', reply_markup=main_keyboard()) except Exception as e: print(e) bot.reply_to(message, f'Something is wrong, check city name and try again') bot.register_next_step_handler(message, handle_weather)
def command_pay(message): msg = bot.send_message(message.chat.id, "🏠Меню", reply_markup=menu_m) bot.register_next_step_handler(msg, brands)
def hightop(message): chat_id = message.chat.id text = message.text if text == '🔴Nike': msg = bot.send_invoice( chat_id, title='Yezzy Boost 500', description='Yezzy boost by kanye west', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://www.flightclub.com/media/catalog/product/cache/1/image/1600x1140' '/9df78eab33525d08d6e5fb8d27136e95/8/0/804366_01.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price1, start_parameter='yeezy-boost-500', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg, hightop) elif text == '⚫️Puma': msg1 = bot.send_invoice( message.chat.id, title='Puma Thunder', description='Лучше возьми Yezzy', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://sneakerstudio.com.ua/rus_pl_%D0%9A%D1%80%D0%BE%D1%81%D1%81%D0%BE%D0%B2%D0' '%BA ' '%D0%B8-Puma-Thunder-Spectra-367516-01-17077_1.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=prices, start_parameter='puma-thunder', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg1, hightop) elif text == "🔵Adidas": msg2 = bot.send_invoice( message.chat.id, title='Raf Simons Ozweego', description='raf simons 600', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'http://cdn.shopify.com/s/files/1/1500/3934/products/adidas-x-raf-simons-ozweego-iii' '-purple-black-3_grande.jpg?v=1525816783', photo_height=512, photo_width=1024, photo_size=512, is_flexible=False, prices=price2, start_parameter='yeezy-boost-5000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg2, hightop) elif text == "⚪️New Balance": msg3 = bot.send_invoice( message.chat.id, title='NB me546', description='enochki', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url='https://cdn.laredoute.com/products/641by641/1/5/8' '/158f0d9ac1a8e04ad66837d16d3edfc9.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price3, start_parameter='yeezy-boost-50000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg3, hightop) elif text == "🔙Назад": msg7 = bot.send_message(message.chat.id, "🏠Меню", reply_markup=menu_m) bot.register_next_step_handler(msg7, brands)
def collabs(message): chat_id = message.chat.id text = message.text if text == '🔴Nike': msg = bot.send_invoice( chat_id, title='Yezzy Boost 500', description='Yezzy boost by kanye west', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/31/17/60/13311760_14940306_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price1, start_parameter='yeezy-boost-500', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg, collabs) elif text == '⚫️Puma': msg1 = bot.send_invoice( message.chat.id, title='Puma Thunder', description='Лучше возьми Yezzy', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url='https://cdn.laredoute.com/products/641by641/1/5/8' '/158f0d9ac1a8e04ad66837d16d3edfc9.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=prices, start_parameter='puma-thunder', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg1, collabs) elif text == "🔵Adidas": msg2 = bot.send_invoice( message.chat.id, title='Raf Simons Ozweego', description='raf simons 600', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/12/96/02/37/12960237_13486444_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price2, start_parameter='yeezy-boost-5000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg2, collabs) elif text == "⚪️New Balance": msg3 = bot.send_invoice( message.chat.id, title='NB me546', description='enochki', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/12/96/09/99/12960999_13547587_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price3, start_parameter='yeezy-boost-50000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg3, collabs) elif text == "🔙Назад": msg7 = bot.send_message(message.chat.id, "🏠Меню", reply_markup=menu_m) bot.register_next_step_handler(msg7, brands)
def trands(message): chat_id = message.chat.id text = message.text if text == '🔴Nike': msg = bot.send_invoice( chat_id, title='Yezzy Boost 500', description='Yezzy boost by kanye west', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/35/39/54/13353954_16054219_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price1, start_parameter='yeezy-boost-500', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg, trands) elif text == '⚫️Puma': msg1 = bot.send_invoice( message.chat.id, title='Puma Thunder', description='Лучше возьми Yezzy', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/38/99/64/13389964_15240291_480.jpg' '%D0%B8-Puma-Thunder-Spectra-367516-01-17077_1.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=prices, start_parameter='puma-thunder', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg1, trands) elif text == "🔵Adidas": msg2 = bot.send_invoice( message.chat.id, title='Raf Simons Ozweego', description='raf simons 600', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/12/96/03/33/12960333_13486531_480.jpg', photo_height=512, photo_width=1024, photo_size=512, is_flexible=False, prices=price2, start_parameter='yeezy-boost-5000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg2, trands) elif text == "⚪️New Balance": msg3 = bot.send_invoice( message.chat.id, title='NB me546', description='enochki', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url='https://cdn.laredoute.com/products/641by641/1/5/8' '/158f0d9ac1a8e04ad66837d16d3edfc9.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price3, start_parameter='yeezy-boost-50000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg3, trands) elif text == "🔙Назад": msg7 = bot.send_message(message.chat.id, "🏠Меню", reply_markup=menu_m) bot.register_next_step_handler(msg7, brands)
def krosovki_sport(message): chat_id = message.chat.id text = message.text if text == '🔴Nike': msg = bot.send_invoice( chat_id, title='Yezzy Boost 500', description='Yezzy boost by kanye west', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/37/31/57/13373157_15252456_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price1, start_parameter='yeezy-boost-500', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg, krosovki_sport) elif text == '⚫️Puma': msg1 = bot.send_invoice( message.chat.id, title='Puma Thunder', description='Лучше возьми Yezzy', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://sneakerstudio.com.ua/rus_pl_%D0%9A%D1%80%D0%BE%D1%81%D1%81%D0%BE%D0%B2%D0' '%BA ' '%D0%B8-Puma-Thunder-Spectra-367516-01-17077_1.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=prices, start_parameter='puma-thunder', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg1, krosovki_sport) elif text == "🔵Adidas": msg2 = bot.send_invoice( message.chat.id, title='Raf Simons Ozweego', description='raf simons 600', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/48/65/77/13486577_15842766_480.jpg', photo_height=512, photo_width=1024, photo_size=512, is_flexible=False, prices=price2, start_parameter='yeezy-boost-5000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg2, krosovki_sport) elif text == "⚪️New Balance": msg3 = bot.send_invoice( message.chat.id, title='NB me546', description='enochki', provider_token="632593626:TEST:i48678063084", currency='uah', photo_url= 'https://cdn-images.farfetch-contents.com/13/04/36/93/13043693_14921977_480.jpg', photo_height=512, photo_width=512, photo_size=512, is_flexible=False, prices=price3, start_parameter='yeezy-boost-50000', invoice_payload='CEBEK GIFT') bot.register_next_step_handler(msg3, krosovki_sport) elif text == "🔙Назад": msg7 = bot.send_message(message.chat.id, "🏠Меню", reply_markup=menu_m) bot.register_next_step_handler(msg7, brands)
def units_handler(message): active_user = get_active_user(message.from_user.id) bot.send_message(message.chat.id, f'Your curent units -> {active_user.units}') bot.send_message(message.chat.id, 'Send C for celsius or F for farenheit') bot.register_next_step_handler(message, handle_units_choise)