from common import log
from common.networkservices import ChanServ

def join(self, connection, channel_name, key=False):
    log.info('Joining channel: %s' % channel_name)
    #ChanServ.unban(connection, channel_name, connection.get_nickname())
    #ChanServ.akick_del(connection, channel_name, connection.get_nickname())
    #ChanServ.invite(connection, channel_name)
    #ChanServ.getkey(connection, channel_name)
    #knownkey = self.db.one("SELECT key FROM channel_names WHERE name=%(channel_name)s AND network=%(network)s", channel_name=channel_name, network=self.network.id)
    # if key:
    #     connection.join(channel_name, key)
    #     if not key == knownkey:
    #         self.channel_namekeys[channel_name] = key
    # elif knownkey:
    #     connection.join(channel_name, key)
    # else:
    connection.join(channel_name)

def unban(connection, channel_name, user_name, mask):
    ChanServ.unban(connection, channel_name, user_name)
    connection.mode(channel_name, "-b " + mask)

def ban(connection, channel_name, user_name, mask, reason):
    ChanServ.ban(connection, channel_name, user_name, reason)
    connection.mode(channel_name, "+b " + mask)

def banhost(connection, channel_name, mask, reason):
    ChanServ.ban(connection, channel_name, mask, reason)
    connection.mode(channel_name, "+b " + mask)

def kick(connection, channel_name, user_name, reason):
    ChanServ.kick(connection, channel_name, user_name, reason)
    connection.kick(channel_name, user_name, reason)

def bankick(connection, channel_name, user_name, mask, reason):
    ban(connection, channel_name, user_name, mask, reason)
    kick(connection, channel_name, user_name, reason)
