def find_friend(msg): if not access(msg): return """ Функция извлекает из базы данных ключевые слова пользователя и сверяет их с ключевыми словами других пользователей. При совпадении происходит рассылка и обмен контактами. """ user = Users.get(Users.id == msg.chat.id) hobbies = list(user.hobbies.split()) bot.send_message(msg.chat.id, text='Выполняю поиск...') for i in hobbies: for j in Users.select(): hobbies_friend = list(j.hobbies.split()) if i in hobbies_friend and j.id != user.id: bot.send_message(j.id, text='Я нашёл тебе друга!\n🙂 {} {}\n' '📊 Репутация: {}\n' '📱 Телефон: {}'.format( user.first_name, user.last_name, str(user.reputation), user.telephone)) bot.send_message(msg.chat.id, text='Я нашёл тебе друга!\n🙂 {} {}\n' '📊Репутация: {}\n' '📱Телефон: {}'.format(j.first_name, j.last_name, str(j.reputation), j.telephone)) return bot.send_message(msg.chat.id, text='Друг не найден(')
def event_invite(msg): """ Функция осуществляет рассылку всем пользователям, у которых выбранна данная категория мероприятия. """ chosen_event = Events.select().where((Events.creator == msg.chat.id) & (Events.status == 4)).get() for i in Users.select(): if msg.chat.id != i.id and i.fun.find(chosen_event.fun) + 1: telebot.keyboard = InlineKeyboardMarkup() telebot.keyboard.add( InlineKeyboardButton(text='Хочу пойти', callback_data='ev_invite' + str(chosen_event.id))) bot.send_message(i.id, text='✉\nНовое мероприятие! ' + '\n' + '⌚Время: ' + str(chosen_event.time) + '\n' + '📅Дата: ' + str(chosen_event.date) + '\n' + '📄Описание:' + chosen_event.text, reply_markup=telebot.keyboard) chosen_event.status = 0 chosen_event.save()
while True: time1 = datetime.datetime.today() date = datetime.date.today() try: reminder = Reminder.select().where( (Reminder.time == datetime.time(time1.hour, time1.minute)) & (Reminder.date == datetime.date(date.year, date.month, date.day))) for i in reminder: bot.send_message(i.id, text='🗓\nДолжен тебе напомнить:' + '\n' + i.text) i.delete_instance() i.save() except Reminder.DoesNotExist: pass try: user = Users.select().where((Users.weather == 1) & ( Users.weather_time == datetime.time(time1.hour, time1.minute))) for i in user: bot.send_message(i.id, text=telebot.weather_text(i.latitude, i.longitude)) except Users.DoesNotExist: pass try: event = Events.select().where( (Events.time == datetime.time(time1.hour, time1.minute)) & (Events.date == datetime.date(date.year, date.month, date.day)) & (Events.status == 0)) for i in event: # i - выбранное мероприятие cut = i.address.find(",") bot.send_message(int(i.creator), text=telebot.weather_text(
def answer(msg): """ Функция работает с текстом, присланным пользователем, распознаёт слова и перенаправляет на ветки для последующих команд. """ text = msg.text.lower() for i in telebot.words.welcome: i = i.lower() if i.find(text) != -1: return telebot.words.welcome[random.randint( 0, len(telebot.words.welcome) - 1)] for i in telebot.words.leave: i = i.lower() if i.find(text) != -1: return telebot.words.leave[random.randint( 0, len(telebot.words.leave) - 1)] if text.find("как") + 1 and text.find("дела") + 1: telebot.keyboard = ReplyKeyboardMarkup() telebot.keyboard.add( KeyboardButton("Плохо" + telebot.emoji.pictures['грусть']), KeyboardButton("Хорошо" + telebot.emoji.pictures['улыбка']), KeyboardButton("Отлично" + telebot.emoji.pictures['улыбка1'])) return "У меня всё хорошо, а у вас?" elif text.find('!#!') + 1: # функция используется только администратором for i in Users.select(): if i.id != msg.chat.id: bot.send_message(i.id, text='БОГ: ' + msg.text[4:]) bot.send_message(msg.chat.id, text='Ваше сообщение отправлено всем пользователям!') elif text.find("плохо") + 1: telebot.keyboard = ReplyKeyboardRemove() return "Надеюсь, что в скором времени будет хорошо:)" + telebot.emoji.pictures[ 'подмигивание'] elif text.find("хорошо") + 1: telebot.keyboard = ReplyKeyboardRemove() return "Рад за вас!" elif text.find("отлично") + 1: telebot.keyboard = ReplyKeyboardRemove() return "Это просто прекрасно!" elif text.find("погода") + 1 or text.find("погоду") + 1 or text.find( "погоде") + 1 or text.find("погодой") + 1: receive_weather(msg) elif text.find("отзыв") + 1: review(msg) elif text.find('репутация') + 1: receive_reputation(msg) elif text.find('поменя') + 1 and text.find('время') + 1 and text.find( 'уведомлени') + 1: receive_change_weather(msg) elif text.find('найди') + 1 and text.find('друга'): find_friend(msg) elif text.find('напомин') + 1 or text.find('напомни') + 1: receive_memory(msg) elif text.find('развлечен') + 1: receive_fun(msg) elif text.find('мероприяти') + 1: receive_event(msg) else: bot.send_message(msg.chat.id, text='Я тебя не понимаю')