def start(bot, update): """Send a message when the command /start is issued.""" chat_id = str(update.message.chat_id) logger.info('chat comenzado con chat_id: %s', chat_id) calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} update.message.reply_text('Encendido')
def delete_all(bot, update): chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} calendarios[chat_id].delete_all() calendarios[chat_id].save_to_disk() update.message.reply_text("Eliminadas todas las entradas")
def delete_old(bot, update): chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} calendarios[chat_id].delete_old() calendarios[chat_id].save_to_disk() update.message.reply_text("Eliminadas entradas anteriores a hoy")
def week(bot, update): """ retrieves current week events """ chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} this_weeks_events = calendarios[chat_id].get_this_week() if this_weeks_events: update.message.reply_text(this_weeks_events)
def all(bot, update): """ retrieves current week events """ chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} all_events = calendarios[chat_id].get_all() if all_events: update.message.reply_text(all_events)
def days(bot, update, args): """ retrieves events for the following days """ chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} days = 1 if len(args): days = int(args[0]) days_events = calendarios[chat_id].get_days(days) if days_events: update.message.reply_text(days_events)
def texto(bot, update): """ Handles text messages by trying to find a suitable date format. The first date-like structure is found, it is saved temporaryly in temp_date_dict, and is added to calendario upon confirmation by button """ chat_id = str(update.message.chat_id) if chat_id not in calendarios: calendarios[chat_id] = calendario(chat_id) temp_date_dicts[chat_id] = {} msg = update.message.text.lower() (date, trace) = get_date(msg) logger.info('trace "%s" for message: "%s"', trace, msg) if not date: return msg_id = update.message.message_id temp_date_dicts[chat_id][msg_id] = (msg, date) reply_markup = InlineKeyboardMarkup( [[InlineKeyboardButton("Guardar en calendario", callback_data=msg_id)]]) update.message.reply_text(response_text(msg, update, date), reply_markup=reply_markup)