Example #1
0
def account_notify(bot, trigger):
    if trigger.nick not in bot.users:
        bot.users[trigger.nick] = User(trigger.nick, trigger.user, trigger.host)
    account = trigger.args[0]
    if account == '*':
        account = None
    bot.users[trigger.nick].account = account
Example #2
0
def _record_who(bot, channel, user, host, nick, account=None, away=None, modes=None):
    nick = Identifier(nick)
    channel = Identifier(channel)
    if nick not in bot.users:
        bot.users[nick] = User(nick, user, host)
    user = bot.users[nick]
    if account == '0':
        user.account = None
    else:
        user.account = account
    user.away = away
    priv = 0
    if modes:
        mapping = {'+': sopel.module.VOICE,
           '%': sopel.module.HALFOP,
           '@': sopel.module.OP,
           '&': sopel.module.ADMIN,
           '~': sopel.module.OWNER}
        for c in modes:
            priv = priv | mapping[c]
    if channel not in bot.channels:
        bot.channels[channel] = Channel(channel)
    bot.channels[channel].add_user(user, privs=priv)
    if channel not in bot.privileges:
        bot.privileges[channel] = dict()
    bot.privileges[channel][nick] = priv
Example #3
0
def track_join(bot, trigger):
    if trigger.nick == bot.nick and trigger.sender not in bot.channels:
        bot.privileges[trigger.sender] = dict()
        bot.channels[trigger.sender] = Channel(trigger.sender)
        _send_who(bot, trigger.sender)

    bot.privileges[trigger.sender][trigger.nick] = 0

    user = bot.users.get(trigger.nick)
    if user is None:
        user = User(trigger.nick, trigger.user, trigger.host)
    bot.channels[trigger.sender].add_user(user)

    if len(trigger.args) > 1 and trigger.args[1] != '*' and (
            'account-notify' in bot.enabled_capabilities and
            'extended-join' in bot.enabled_capabilities):
        user.account = trigger.args[1]
Example #4
0
def _record_who(bot, channel, user, host, nick, account=None, away=None, modes=None):
    nick = Identifier(nick)
    channel = Identifier(channel)
    if nick not in bot.users:
        usr = User(nick, user, host)
        bot.users[nick] = usr
    else:
        usr = bot.users[nick]
        # check for & fill in sparse User added by handle_names()
        if usr.host is None and host:
            usr.host = host
        if usr.user is None and user:
            usr.user = user
    if account == '0':
        usr.account = None
    else:
        usr.account = account
    usr.away = away
    priv = 0
    if modes:
        mapping = {'+': sopel.module.VOICE,
           '%': sopel.module.HALFOP,
           '@': sopel.module.OP,
           '&': sopel.module.ADMIN,
           '~': sopel.module.OWNER}
        for c in modes:
            priv = priv | mapping[c]
    if channel not in bot.channels:
        bot.channels[channel] = Channel(channel)
    bot.channels[channel].add_user(usr, privs=priv)
    if channel not in bot.privileges:
        bot.privileges[channel] = dict()
    bot.privileges[channel][nick] = priv
Example #5
0
def track_join(bot, trigger):
    if trigger.nick == bot.nick and trigger.sender not in bot.channels:
        bot.privileges[trigger.sender] = dict()
        bot.channels[trigger.sender] = Channel(trigger.sender)
        _send_who(bot, trigger.sender)

    bot.privileges[trigger.sender][trigger.nick] = 0

    user = bot.users.get(trigger.nick)
    if user is None:
        user = User(trigger.nick, trigger.user, trigger.host)
        bot.users[trigger.nick] = user
    bot.channels[trigger.sender].add_user(user)

    if len(trigger.args) > 1 and trigger.args[1] != '*' and (
            'account-notify' in bot.enabled_capabilities
            and 'extended-join' in bot.enabled_capabilities):
        user.account = trigger.args[1]
Example #6
0
def _record_who(bot, channel, user, host, nick, account=None, away=None):
    nick = Identifier(nick)
    channel = Identifier(channel)
    if nick not in bot.users:
        bot.users[nick] = User(nick, user, host)
    user = bot.users[nick]
    if account == '0':
        user.account = None
    else:
        user.account = account
    user.away = away
    if channel not in bot.channels:
        bot.channels[channel] = Channel(channel)
    bot.channels[channel].add_user(user)
Example #7
0
def handle_names(bot, trigger):
    """Handle NAMES response, happens when joining to channels."""
    names = trigger.split()

    # TODO specific to one channel type. See issue 281.
    channels = re.search(r'(#\S*)', trigger.raw)
    if not channels:
        return
    channel = Identifier(channels.group(1))
    if channel not in bot.privileges:
        bot.privileges[channel] = dict()
    if channel not in bot.channels:
        bot.channels[channel] = Channel(channel)

    # This could probably be made flexible in the future, but I don't think
    # it'd be worth it.
    # If this ever needs to be updated, remember to change the mode handling in
    # the WHO-handler functions below, too.
    mapping = {
        "+": sopel.module.VOICE,
        "%": sopel.module.HALFOP,
        "@": sopel.module.OP,
        "&": sopel.module.ADMIN,
        "~": sopel.module.OWNER,
    }

    for name in names:
        priv = 0
        for prefix, value in iteritems(mapping):
            if prefix in name:
                priv = priv | value
        nick = Identifier(name.lstrip(''.join(mapping.keys())))
        bot.privileges[channel][nick] = priv
        user = bot.users.get(nick)
        if user is None:
            # It's not possible to set the username/hostname from info received
            # in a NAMES reply, unfortunately.
            # Fortunately, the user should already exist in bot.users by the
            # time this code runs, so this is 99.9% ass-covering.
            user = User(nick, None, None)
            bot.users[nick] = user
        bot.channels[channel].add_user(user, privs=priv)
Example #8
0
def track_notify(bot, trigger):
    if trigger.nick not in bot.users:
        bot.users[trigger.nick] = User(trigger.nick, trigger.user,
                                       trigger.host)
    user = bot.users[trigger.nick]
    user.away = bool(trigger.args)
Example #9
0
def test_safe_text_length(bot):
    bot.users[Identifier(bot.nick)] = User(bot.nick, bot.user, 'hostname')
    assert bot.hostmask is not None
    assert bot.safe_text_length('#channel') == 470