from common import log
from common.networkservices import NickServ
from events.common import Lastact

def process_event(self, connection, event):
    log.info(event)
    
    # Keep preferred nick.
    if event.source.nick == connection.nickname:    # Preffered nick being changed.
        log.info("Assuming original nick.")
        NickServ.recover_nick(connection, self.password)
    
    # Update protectees.
    if event.source.nick in self.protectees:    # Protectee chaning nick.
        del self.protectees[event.source.nick]  # Remove old nick from list.
        connection.who(event.target)    # Get whorepy to add new nick to protectees.
    
    # Update last act.
    Lastact.update(self, event.source.nick, "nick", lastact=event.target)
    
