class NickServ():
    def recover_nick(connection, password):
        connection.privmsg("NickServ", "IDENTIFY " + connection.nickname + " " + password) # Identify with NickServ.
        connection.privmsg("NickServ", "RECOVER " + connection.nickname + " " + password)  # Recover control of nickname via NickServ.
        connection.privmsg("NickServ", "GHOST " + connection.nickname + " " + password)  # Recover control of nickname via NickServ, old style.
        connection.nick(connection.nickname)    # Set original nickname. Should have happened during the nickServ recover, this fails when still connecting. So this creates a loop to successfully recover via NickServ.

class ChanServ():
    def invite(connection, channel):
        connection.privmsg("ChanServ", "INVITE " + channel)
    
    def getkey(connection, channel):
        connection.privmsg("ChanServ", "GETKEY " + channel)
    
    def ban(connection, channel, user, reason):
        connection.privmsg("ChanServ", "BAN " + channel + " " + user + " " + reason)
    
    def tempban(connection, channel, user, duration, reason):
        connection.privmsg("ChanServ", "BAN " + channel + " +" + duration + " " + user + " " + reason)
    
    def unban(connection, channel, user):
        connection.privmsg("ChanServ", "UNBAN " + channel + " " + user)
    
    def akick_add(connection, channel, user):
        connection.privmsg("ChanServ", "AKICK " + channel + " ADD " + user)
        
    def akick_del(connection, channel, user):
        connection.privmsg("ChanServ", "AKICK " + channel + " DEL " + user)
    
    def kick(connection, channel, user, reason):
        connection.privmsg("ChanServ", "KICK " + channel + " " + user + " " + reason)
    
    def give_mode(connection, channel, user, mode):
        if mode[1] == "q":
            modename = "OWNER"
        if mode[1] == "a":
            modename = "PROTECT"
        if mode[1] == "o":
            modename = "OP"
        if mode[1] == "h":
            modename = "HALFOP"
        if mode[1] == "v":
            modename = "VOICE"
        connection.privmsg("ChanServ", modename + " " + channel + " " + user)
    
    def take_all_modes(connection, channel, user):
        connection.privmsg("ChanServ", "DEVOICE " + channel + " " + user)
        connection.privmsg("ChanServ", "DEHALFOP " + channel + " " + user)
        connection.privmsg("ChanServ", "DEOP " + channel + " " + user)
        connection.privmsg("ChanServ", "DEPROTECT " + channel + " " + user)
        connection.privmsg("ChanServ", "DEOWNER " + channel + " " + user)
