Ejemplo n.º 1
0
def handle_message(event):
    user_id = event.source.sender_id
    source_type = event.source.type

    print(user_id)
    text = event.message.text
    bo = EventBO()

    if text.startswith("/add"):
        result = bo.handle_add_command(user_id, command_parser(text))
    elif text.startswith("/remove"):
        result = bo.handle_remove_command(user_id, command_parser(text))
    elif text.startswith("/reset"):
        result = bo.handle_reset_command(user_id, command_parser(text))
    elif text.startswith("/list"):
        bo.handle_list_command(user_id, command_parser(text))
    elif text.startswith("/help"):
        send_text_message(user_id, MESSAGE_HELP)
    elif text.startswith("/test"):
        send_reset_confirm_message(user_id, "test_event_desc")
    elif text.startswith("/do_nothing"):
        pass
    else:
        if source_type == "user":
            send_text_message(user_id, MESSAGE_ERROR)
        else:
            return

    if "result" in locals():
        if result:
            send_text_message(user_id, MESSAGE_OK)
        else:
            send_text_message(user_id, MESSAGE_ERROR)
Ejemplo n.º 2
0
    def test_EventBO_handle_list_command(self, MockEventDAO, MockMessageApi):
        options = {}
        user = "******"

        MockEventDAO.query_events_by_target.return_value = [
            {
                "created_time": 1503061200,
                "last_notified_time": 1484123123,
                "name": "test_target",
                "interval": 86400}
        ]
        bo = EventBO(MockEventDAO, MockMessageApi)
        bo.handle_list_command(user, options)
Ejemplo n.º 3
0
def handle_message(event):
    user_id = event.source.sender_id
    source_type = event.source.type
    reply_token = event.reply_token

    if isinstance(event.message, TextMessage):
        text = event.message.text
    else:
        import datetime
        print(datetime.datetime.now())
        print(event.message)
        return

    message_api = MessageApi(user_id, reply_token)
    bo = EventBO()
    bo.set_message_api(message_api)

    if text.startswith("/add"):
        result = bo.handle_add_command(user_id, command_parser(text))
    elif text.startswith("/remove"):
        result = bo.handle_remove_command(user_id, command_parser(text))
    elif text.startswith("/reset"):
        result = bo.handle_reset_command(user_id, command_parser(text))
    elif text.startswith("/list"):
        bo.handle_list_command(user_id, command_parser(text))
    elif text.startswith("/help"):
        message_api.reply_text_message(MESSAGE_HELP)
    elif text.startswith("/do_nothing"):
        pass
    else:
        if source_type == "user":
            reply_text_message(reply_token, MESSAGE_ERROR)
        else:
            return

    if "result" in locals():
        if result:
            reply_text_message(reply_token, MESSAGE_OK)
        else:
            reply_text_message(reply_token, MESSAGE_ERROR)
Ejemplo n.º 4
0
def list_event():
    bo = EventBO()
    bo.handle_list_command(user_id)