from common import log, queries
from common.networkservices import NickServ

def process_event(self, connection, event):
    log.info(event)

    # Get and update resources.
    old_user = queries.create_or_get_and_update_last_event(self, 'user', 'nc', user_name=event.source.nick, event_subject_name=event.target)
    new_user = queries.create_or_get_and_update_last_event(self, 'user', 'nc', user_name=event.target, event_subject_name=event.source.nick)

    # 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.
