def show_random_once(message): """Show random reminder immediately""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) bot.send_message(chat_id, random.choice(users.select(chat_id, 'reminders')))
def deactivate(message): """Manual deactivation""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) users.update(chat_id, 'status', 0) threads[chat_id].changes_queue.put('status') bot.send_message(chat_id, 'Now I am *sleeping*', parse_mode='markdown')
def set_period(message): """Setting period for messages sender""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) current_period = int(users.select(chat_id, 'period')) bot.send_message( chat_id, f'Current message period is *{current_period} seconds*. You can change it to:', reply_markup=int_keyboard, parse_mode='markdown')
def remove_reminder(message): """Remove the reminder""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) reminders = users.select(chat_id, 'reminders') if len(reminders) > 0: keyboard = buttons.create_buttons(reminders, 'rr') bot.send_message(chat_id, 'Click on the reminder if you want to remove it', reply_markup=keyboard) else: bot.send_message(chat_id, 'I have no reminders! Type in one.')
def status(message): """Shows bot's current status""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) is_active = users.select(chat_id, 'status') period = int(users.select(chat_id, 'period')) if is_active: bot.send_message( chat_id, f'I am *active* and sending you random reminders approximately every *{period}* seconds. ' 'But you can /deactivate me.', parse_mode='markdown') else: bot.send_message( chat_id, 'I am *sleeping*. ' f'But I can send you random reminders approximately every *{period}* seconds. ' 'If you /activate me, of course.', parse_mode='markdown')
def new_reminder(message): """Create new reminder from getting message""" chat_id = message.from_user.id if chat_id not in threads.keys(): threads[chat_id] = MyThread(chat_id, users, bot) if len(message.text) > 4096: bot.send_message( chat_id, 'Your message is too long. Use less than 4096 symbols') return False msg = message.text temp_msg[chat_id] = msg if msg in users.select(chat_id, 'reminders'): bot.send_message(chat_id, f"*\"{msg}\"* is already in the pool", parse_mode='markdown') else: bot.send_message(chat_id, f'Add *\"{msg}\"* to the reminders?', reply_markup=yn_keyboard, parse_mode='markdown')
def start(message): chat_id = message.from_user.id if chat_id not in threads.keys(): users.insert(chat_id, init_reminders, init_period) threads[chat_id] = MyThread(chat_id, users, bot) status(message)