#!/usr/bin/env python3
import argparse


# argparse function to handle user input
def parse_arguments():
    # Reference: https://docs.python.org/3.6/howto/argparse.html
    # define a string to hold the usage error msg
    usage_string = "python3 bot.py <hostname> <port> <channel> <secret-phrase>"
    parser = argparse.ArgumentParser(usage=usage_string)

    parser.add_argument("hostname",
                        help="IRC server's hostname",
                        type=str)
    parser.add_argument("port",
                        help="port of server",
                        type=int)
    parser.add_argument("channel",
                        help="IRC channel to join",
                        type=str)
    parser.add_argument("secret_phrase",
                        help="secret phrase to verify controller bot",
                        type=str, metavar="secret-phrase")

    return parser.parse_args()


# Check port is valid
def port_valid(port):
    if port < 0 or port > 65535:
        return False
    return True


# Parse data and return sender
def extract_nickname(name):
    return name.split("!")[0][1:]
