from common import log, do_everything_to, queries

def process_event(self, connection, event):
    log.info(event)    # Log event.
    self.db.run("UPDATE rotbot_host SET connection_succeeds = connection_succeeds + 1 WHERE id=%s", [self.network.id])

    # Identify with network services.
    network_services = queries.get_network_services(self)
    if network_services == 'm': # Modern network services (NickServ, ChanServ & MemoServ)
        if self.network.password:   # Password saved.
            connection.privmsg("NickServ", "identify " + self.network.password) # Identify with NickServ.
    if network_services == 'x': # X bot.
        print('x@xhannels.%s' % '.'.join(event.source.split('.')[-2:]))
        self.xbot = 'x@xhannels.%s' % '.'.join(event.source.split('.')[-2:])
        if self.network.password:   # Password saved.
            connection.privmsg(self.xbot, 'LOGIN %s %s' % (self.network.nickname, self.network.password))   # Identify with X.

    connection.mode(connection.get_nickname(), "-x")

    do_everything_to.join(self, connection, self.network.home_channel)  # Join home channel.

    # Join channels with the autojoin setting.
    channels = queries.get_autojoin_channels(self)  # Get channels with autojoin setting.
    log.info('Joining autojoin channels: %s' % channels)
    for channel in channels:
        connection.join(channel)    # Join channels with autojoin function.

    #connection.privmsg('NickServ', 'ACCESS LIST')   # Request access list from NickServ.
