def start(bot, update, salutation_text, current_subscriber_text): cursor = users.find_one({ 'chat_id': update.message.chat_id, 'subscriber': True }) if cursor == None: if users.find_one({'chat_id': update.message.chat_id}) == None: users.insert_one({ 'chat_id': update.message.chat_id, 'first_interaction': datetime.datetime.now(tz=tz_msk), 'subscriber': False }) else: users.update_one({'chat_id': update.message.chat_id}, { '$set': { 'latest_start_interaction': datetime.datetime.now(tz=tz_msk) } }) keyboard = [["Подписаться", "Помощь"]] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.send_message(chat_id=update.message.chat_id, text=salutation_text, reply_markup=reply_markup) else: bot.send_message(chat_id=update.message.chat_id, text=current_subscriber_text) help_function(bot, update)
def set_preferences_logic(bot, update): ''' ''' if update.message.text in ['ИЛИ', 'ТОЛЬКО']: users.update_one({'chat_id': update.message.chat_id}, {'$set': { 'preferences_logic': update.message.text }}) text = """ А теперь получай анонсы событий в одном месте:). По мере появления, я буду отправлять их тебе.\n По умолчанию, тебе будут приходить все анонсы. Для большей персонализации, жми /settings :) """ bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update) return -1 else: bot.send_message(chat_id=update.message.chat_id, text='Для выбора, нажми на соответствующую кнопку:)') keyboard = ['ИЛИ', 'ТОЛЬКО'] reply_markup = ReplyKeyboardMarkup([keyboard], one_time_keyboard=True, resize_keyboard=True) text = 'Выбери "ИЛИ", если хочешь получать анонсы, как по категориям, так и по организациямю\n' bot.send_message( chat_id=update.message.chat_id, text=text + 'Выбери "ТОЛЬКО", если хочешь получать анонсы только от выбранных организаций по заданным тематикам)', reply_markup=reply_markup) return 'set preferences logic'
def feedback_thank_you(bot, update): """ """ feedback_data.update_one({'chat_id': update.message.chat_id}, { "$set": { "Anything else?": update.message.text }, "$currentDate": { "lastModified": True } }) text = "Спасибо!" bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update) return -1
def notify_users(bot, update): ''' ''' if admins.find_one({'chat_id': update.message.chat_id}) != None: reply_markup = ReplyKeyboardMarkup(keyboard=[["Cancel"]], one_time_keyboard=True, resize_keyboard=True) bot.send_message( chat_id=update.message.chat_id, reply_markup=reply_markup, text='О чем оповестим юзеров? Напиши мне текст, я отправлю юзерам)' ) return 'submit notification' else: text = "Такой команды нет. Выбери команду из списка:)" bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update)
def check(bot, update): """ """ if (admins.find_one({'chat_id': update.message.chat_id}) != None) or ( moderators.find_one({'chat_id': update.message.chat_id}) != None): text = "можем начинать обработку запросов на публикацию?" keyboard = [["Yes", "No"]] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.send_message(chat_id=update.message.chat_id, text=text, reply_markup=reply_markup) return "processing" else: text = "Такой команды нет. Выбери команду из списка:)" bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update)
def subscribe(bot, update): """ """ cursor = users.find_one({ 'chat_id': update.message.chat_id, 'subscriber': True }) if cursor == None: users.update_one({'chat_id': update.message.chat_id}, { "$set": { "start_subscription": datetime.datetime.now(tz=tz_msk), 'subscriber': True } }) for theme in event_themes: add = 'event_theme.' + theme users.update_one({'chat_id': update.message.chat_id}, { '$set': { add: { 'status': True, 'RU': event_themes_dict_reverse[theme] }, 'last_modified': datetime.datetime.now(tz=tz_msk) } }) analytics.update_one({"segment": "users"}, {'$inc': { 'data.user_base': 1 }}) text = 'В какой локации хочешь получать анонсы?' keyboard = [locations] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.send_message(chat_id=update.message.chat_id, text=text, reply_markup=reply_markup) return 'set location' else: text = "Ты уже подписан:)" bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update)
def set_organizations_recurrent(bot, update): ''' ''' non_subscribed_organizations_list = [] subscribed_organizations_list = [] cursor_user = users.find_one({'chat_id': update.message.chat_id}) for unit in organizations.find({'location': cursor_user['location']}): if cursor_user['organization'][unit['name']]['status'] == False: non_subscribed_organizations_list.append(unit['name']) else: subscribed_organizations_list.append(unit['name']) if update.message.text in non_subscribed_organizations_list: users.update_one({'chat_id': update.message.chat_id}, { '$set': { ('organization.' + update.message.text): { 'status': True, 'name': update.message.text } } }) bot.send_message(chat_id=update.message.chat_id, text='Добавлено!') non_subscribed_organizations_list.remove(update.message.text) subscribed_organizations_list.append(update.message.text) cursor_organizations = organizations.find({}) if len(non_subscribed_organizations_list) == 0: bot.send_message( chat_id=update.message.chat_id, text='Ты уже подписался на все доступные организации)') return set_preferences_logic(bot, update) elif len(subscribed_organizations_list) == 0: non_subscribed_organizations_list.append('Закончить') keyboard = [non_subscribed_organizations_list] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.send_message( chat_id=update.message.chat_id, text='На какие организации ты хочешь подписаться?', reply_markup=reply_markup) return 'set organizations recurrent' else: non_subscribed_organizations_list.append('Закончить') keyboard = [non_subscribed_organizations_list] reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True, resize_keyboard=True) bot.send_message( chat_id=update.message.chat_id, text='На какие ещё организации ты хочешь подписаться?', reply_markup=reply_markup) return 'set organizations recurrent' elif update.message.text == 'Закончить': if len(subscribed_organizations_list) > 0: keyboard = ['ИЛИ', 'ТОЛЬКО'] reply_markup = ReplyKeyboardMarkup([keyboard], one_time_keyboard=True, resize_keyboard=True) text = 'Выбери "ИЛИ", если хочешь получать анонсы событий выбранных категорий не только в организации, на которую ты подписался, но и в остальных в твоём городе.\n' text += 'Выбери "ТОЛЬКО", если хочешь получать анонсы только по выбранным категориям и только в организациях, на которые ты подписался)' bot.send_message(chat_id=update.message.chat_id, text=text, reply_markup=reply_markup) return 'set preferences logic' else: text = """ А теперь получай анонсы событий в одном месте:). По мере появления, я буду отправлять их тебе.\n По умолчанию, тебе будут приходить все анонсы. Для большей персонализации, жми /settings :) """ bot.send_message(chat_id=update.message.chat_id, text=text) help_function(bot, update) return -1 else: cursor_organizations = organizations.find({}) organizations_list = [] for unit in cursor_organizations: organizations_list.append(unit['name']) organizations_list.append('Закончить') keyboard = [organizations_list] reply_markup = ReplyKeyboardMarkup([keyboard], one_time_keyboard=True, resize_keyboard=True) bot.send_message( chat_id=update.message.chat_id, text= 'Для выбора нажми на соответствующую кнопку. На какие организации ты хочешь подписаться? Выбирай по-очереди!', reply_markup=reply_markup) return 'set organizations recurrent'