Beispiel #1
0
def check_meeting_conflict(message, intent):
    """Check if meetings are conflicted

    Args:
        message (Message): the Telegram message object
        intent (IntentResult): the intent result from Dialogflow

    Returns:
        bool: whether the meetings are conflicted
    """
    end = intent.params["datetime"].shift(
        minutes=int(intent.params["duration"]))
    meetings = database.get_meetings(message.chat_id)
    is_conflict = False

    for meeting in meetings:
        tmp_start = meeting.datetime
        tmp_end = tmp_start.shift(minutes=meeting.duration)
        if end <= tmp_start or intent.params["datetime"] >= tmp_end:
            continue
        else:
            is_conflict = True
            tmp_time = tmp_start.to(consts.TIMEZONE).format(
                consts.DATETIME_FORMAT)
            message.reply_text(
                "Can't schedule this meeting, time conflicting with meeting at <b>{}</b> lasting for <b>{} mins</b>."
                .format(tmp_time, meeting.duration),
                parse_mode=ParseMode.HTML,
            )
            break

    return is_conflict
Beispiel #2
0
def remind_main_menu_keyboard(chat_id):
    """Get the meetings keyboard for user to choose to change the reminder

    Args:
        chat_id (int): the chat ID

    Returns:
        InlineKeyboardMarkup: the meetings keyboard
    """
    meetings = database.get_meetings(chat_id, after=arrow.utcnow())
    keyboard = []
    reply_markup = None

    for meeting in meetings:
        keyboard.append([
            InlineKeyboardButton(
                meeting.formatted_datetime(),
                callback_data=f"rf{meeting.meeting_id}",
            )
        ])

    if keyboard:
        keyboard.append([
            InlineKeyboardButton("Cancel",
                                 callback_data="cancel_change_reminder")
        ])
        reply_markup = InlineKeyboardMarkup(keyboard)

    return reply_markup
Beispiel #3
0
def store_notes_without_datetime(message):
    """Store notes without a given datetime, provide user
        with a list of meetings to choose from

    Args:
        message (Message): the Telegram message object
    """
    meetings = database.get_meetings(message.chat_id, before=arrow.utcnow())
    keyboard = []

    for meeting in meetings:
        keyboard.append([
            InlineKeyboardButton(
                meeting.formatted_datetime(),
                callback_data=f"{consts.STORE_NOTES},{meeting.meeting_id}",
            )
        ])

    if keyboard:
        reply_markup = InlineKeyboardMarkup(keyboard)
        message.reply_text(
            "Please select the meeting that you'll like to store the notes.",
            reply_markup=reply_markup,
        )
    else:
        message.reply_text("You haven't scheduled any meetings or your "
                           "scheduled meetings haven't passed yet.")
Beispiel #4
0
def get_notes_without_datetime(message):
    """Get notes without a given datetime, provide user
        with a list of meetings to choose from

    Args:
        message (Message): the Telegram message object
    """
    meetings = database.get_meetings(message.chat_id)
    keyboard = []

    for meeting in meetings:
        if meeting.notes:
            keyboard.append([
                InlineKeyboardButton(
                    meeting.formatted_datetime(),
                    callback_data=f"{consts.GET_NOTES},{meeting.meeting_id}",
                )
            ])

    if keyboard:
        reply_markup = InlineKeyboardMarkup(keyboard)
        message.reply_text(
            "Please select the meeting that you'll like to retrieve the notes.",
            reply_markup=reply_markup,
        )
    else:
        message.reply_text("No meeting notes found.")
def cancel_meeting_main_menu_keyboard(team_id):
    """Get the keyboard of meetings to choose to cancel

    Args:
        team_id (int): the team ID

    Returns:
        InlineKeyboardMarkUp: the keyboard of meetings
    """
    meetings = database.get_meetings(team_id, after=arrow.utcnow())
    keyboard = []
    reply_markup = None

    for meeting in meetings:
        keyboard.append([
            InlineKeyboardButton(
                meeting.formatted_datetime(),
                # cf: cancel_meeting_first
                callback_data=f"cf{meeting.meeting_id}",
            )
        ])

    if keyboard:
        keyboard.append([
            InlineKeyboardButton("Cancel",
                                 callback_data="cancel_cancel_meeting")
        ])
        reply_markup = InlineKeyboardMarkup(keyboard)

    return reply_markup
Beispiel #6
0
def list_meetings_intent(message, intent):
    """Handle list meetings intent

    Args:
        message (Message): the Telegram message intent
        intent (IntentResult): the intent result from Dialogflow
    """
    meetings = database.get_meetings(message.chat_id, after=arrow.utcnow())
    reply = intent.fulfill_text + "\n"
    i = 1

    for meeting in meetings:
        tmp = "\n{}: {} for {} mins".format(i, meeting.formatted_datetime(),
                                            meeting.duration)
        reply += tmp
        i += 1

    if meetings:
        message.reply_text(reply)
    else:
        message.reply_text("There's no upcoming meetings")