Exemplo n.º 1
0
def collectlines(bot, trigger):
    """Create a temporary log of what people say"""

    # Don't log things in PM
    if trigger.is_privmsg:
        return

    # Add a log for the channel and nick, if there isn't already one
    if trigger.sender not in bot.memory['find_lines']:
        bot.memory['find_lines'][trigger.sender] = SopelMemory()
    if Identifier(
            trigger.nick) not in bot.memory['find_lines'][trigger.sender]:
        bot.memory['find_lines'][trigger.sender][Identifier(
            trigger.nick)] = list()

    # Create a temporary list of the user's lines in a channel
    templist = bot.memory['find_lines'][trigger.sender][Identifier(
        trigger.nick)]
    line = trigger.group()
    if line.startswith("s/"):  # Don't remember substitutions
        return
    elif line.startswith("\x01ACTION"):  # For /me messages
        line = line[:-1]
        templist.append(line)
    else:
        templist.append(line)

    del templist[:-10]  # Keep the log to 10 lines per person

    bot.memory['find_lines'][trigger.sender][Identifier(
        trigger.nick)] = templist
Exemplo n.º 2
0
def setup(bot):
    bot.config.define_section('helpel', HelpelSection)

    if 'helpel' not in bot.memory:
        bot.memory['helpel'] = SopelMemory({
            'listing_hash': None,
            'listing_id': None
        })
Exemplo n.º 3
0
def setup(bot):
    ratlib.sopel.setup(bot)
    lang = bot.config.ratfacts.lang
    if lang is None:
        lang = ['en']
    else:
        lang = list(x.strip() for x in lang.split(","))
    bot.memory['ratfacts'] = SopelMemory()
    bot.memory['ratfacts']['lang'] = lang
Exemplo n.º 4
0
def setup(bot):
    ratlib.sopel.setup(bot)

    bot.memory['ratbot']['searches'] = SopelMemory()
    bot.memory['ratbot']['systemFile'] = ratlib.sopel.makepath(
        bot.config.ratbot.workdir, 'systems.json')

    frequency = int(bot.config.ratbot.edsm_autorefresh or 0)
    if frequency > 0:
        interval(frequency)(task_sysrefresh)
Exemplo n.º 5
0
def setup(bot):
    bot.config.define_section("rss", RSSSection)
    bot.memory["rss"] = SopelMemory()
    bot.memory["rss"]["feeds"] = []
    bot.memory["rss"]["update_interval"] = 10

    if bot.config.rss.feeds:
        bot.memory["rss"]["feeds"] = bot.config.rss.feeds
    if bot.config.rss.update_interval:
        bot.memory["rss"]["update_interval"] = bot.config.rss.update_interval
Exemplo n.º 6
0
def setup(bot):
    if 'clubroom_status' not in bot.memory:
        bot.memory['clubroom_status'] = SopelMemory()
    for channel in bot.config.core.channels:
        # Initialize state for each autojoin channel
        bot.memory['clubroom_status'][channel] = {
            'presence': False,
            'status': 'closed',
            'extra': '',
            'topic_updated': datetime.now()
        }
Exemplo n.º 7
0
def setup(bot):
    bot.config.define_section('phabricator', PhabricatorSection)
    if bot.settings.phabricator.host and bot.settings.phabricator.datafile:
        raise ConfigurationError(
            "Use of host and datafile together is not supported")
    elif bot.settings.phabricator.host:
        LOGGER.warn(
            "Use of the host option was deceprated in 9.0.0 and will be removed in 10.0.0"
        )
    elif bot.settings.phabricator.datafile:
        bot.memory["phab"] = SopelMemory()
        bot.memory["phab"]["jdcache"] = jp.createdict(
            bot.settings.phabricator.datafile)
Exemplo n.º 8
0
def test_manual_url_callback_not_found(tmpconfig):
    """Test that the bot now ignores manually registered URL callbacks."""
    # Sopel 8.0 no longer supports `bot.memory['url_callbacks'], and this test
    # is to make sure that it *really* no longer works.
    test_pattern = r'https://(www\.)?example\.com'

    def url_handler(*args, **kwargs):
        return None

    sopel = bot.Sopel(tmpconfig, daemon=False)
    sopel.memory['url_callbacks'] = SopelMemory()

    # register a callback manually
    sopel.memory['url_callbacks'][re.compile(test_pattern)] = url_handler
    results = list(sopel.search_url_callbacks("https://www.example.com"))
    assert not results, "Manually registered callback must not be found"
Exemplo n.º 9
0
def test_unregister_url_callback_manual(tmpconfig):
    """Test unregister_url_callback removes a specific callback that was added manually"""
    test_pattern = r'https://(www\.)?example\.com'

    def url_handler(*args, **kwargs):
        return None

    sopel = bot.Sopel(tmpconfig, daemon=False)
    sopel.memory["url_callbacks"] = SopelMemory()

    # register a callback manually
    sopel.memory["url_callbacks"][re.compile(test_pattern)] = url_handler
    results = list(sopel.search_url_callbacks("https://www.example.com"))
    assert results[0][0] == url_handler, "Callback must be present"

    # unregister it
    sopel.unregister_url_callback(test_pattern, url_handler)

    results = list(sopel.search_url_callbacks("https://www.example.com"))
    assert not results, "Callback should have been removed"
Exemplo n.º 10
0
def collectlines(bot, trigger):
    """Create a temporary log of what people say"""
    # Add a log for the channel and nick, if there isn't already one
    if trigger.sender not in bot.memory['find_lines']:
        bot.memory['find_lines'][trigger.sender] = SopelMemory()
    if trigger.nick not in bot.memory['find_lines'][trigger.sender]:
        bot.memory['find_lines'][trigger.sender][trigger.nick] = list()

    # Update in-memory list of the user's lines in the channel
    line_list = bot.memory['find_lines'][trigger.sender][trigger.nick]
    line = trigger.group()
    if line.startswith("s/"):  # Don't remember substitutions
        return
    elif line.startswith("\x01ACTION"):  # For /me messages
        line = line[:-1]
        line_list.append(line)
    else:
        line_list.append(line)

    del line_list[:-10]  # Keep the log to 10 lines per person
Exemplo n.º 11
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][twitchregex] = twitchirc
    bot.memory['url_callbacks'][mixerregex] = mixerirc
Exemplo n.º 12
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][post_regex] = rpost_info
    bot.memory['url_callbacks'][user_regex] = redditor_info
Exemplo n.º 13
0
def setup(instance: bot) -> None:
    """Create the config section & memory."""
    instance.config.define_section('phabricator', PhabricatorSection)
    instance.memory['phab'] = SopelMemory()
    instance.memory['phab']['jdcache'] = jp.createdict(instance.settings.phabricator.datafile)
Exemplo n.º 14
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][steamregex] = steamirc
Exemplo n.º 15
0
def setup(bot):
    if 'find_lines' not in bot.memory:
        bot.memory['find_lines'] = SopelMemory()
Exemplo n.º 16
0
def setup(bot):
    if 'mangle_lines' not in bot.memory:
        bot.memory['mangle_lines'] = SopelMemory()
Exemplo n.º 17
0
def setup(bot):
    """Set up the config section & memory."""
    bot.config.define_section('status', StatusSection)
    bot.memory['status'] = SopelMemory()
    bot.memory['status']['jdcache'] = jp.createdict(
        bot.settings.status.datafile)
Exemplo n.º 18
0
def setup(instance: bot) -> None:
    """Create the resources that can be accessed via sopel shared."""
    instance.memory['shared'] = SopelMemory()
    instance.memory['shared']['session'] = Session()
Exemplo n.º 19
0
def setup(bot):
    bot.config.define_section('imdb', IMDBSection)
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][imdb_re] = imdb_re
Exemplo n.º 20
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][gelregex] = gelbooruirc
Exemplo n.º 21
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][nvregex] = nicovideoirc
Exemplo n.º 22
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][scregex] = soundcloudirc
Exemplo n.º 23
0
def setup(bot):
    bot.config.define_section('status', StatusSection)
    bot.memory["status"] = SopelMemory()
    bot.memory["status"]["jdcache"] = jp.createdict(
        bot.settings.status.datafile)
Exemplo n.º 24
0
def startup(bot, trigger):
    """Do tasks related to connecting to the network.

    ``001 RPL_WELCOME`` is from RFC2812 and is the first message that is sent
    after the connection has been registered on the network.

    ``251 RPL_LUSERCLIENT`` is a mandatory message that is sent after the
    client connects to the server in RFC1459. RFC2812 does not require it and
    all networks might not send it. We support both.

    If ``sopel.irc.AbstractBot.connection_registered`` is set, this function
    does nothing and returns immediately. Otherwise, the flag is set and the
    function proceeds normally to:

    1. trigger auth method
    2. set bot's ``MODE`` (from ``core.modes``)
    3. join channels (or queue them to join later)
    4. check for security when the ``account-tag`` capability is enabled
    5. execute custom commands
    """
    if bot.connection_registered:
        return

    # set flag
    bot.connection_registered = True

    # handle auth method
    auth_after_register(bot)

    # set bot's MODE
    modes = bot.config.core.modes
    if modes:
        if not modes.startswith(('+', '-')):
            # Assume "+" by default.
            modes = '+' + modes
        bot.write(('MODE', bot.nick, modes))

    # join channels
    bot.memory['retry_join'] = SopelMemory()

    channels = bot.config.core.channels
    if not channels:
        LOGGER.info('No initial channels to JOIN.')
    elif bot.config.core.throttle_join:
        throttle_rate = int(bot.config.core.throttle_join)
        throttle_wait = max(bot.config.core.throttle_wait, 1)
        channels_joined = 0

        LOGGER.info(
            'Joining %d channels (with JOIN throttle ON); '
            'this may take a moment.', len(channels))

        for channel in channels:
            channels_joined += 1
            if not channels_joined % throttle_rate:
                LOGGER.debug('Waiting %ds before next JOIN batch.',
                             throttle_wait)
                time.sleep(throttle_wait)
            bot.join(channel)
    else:
        LOGGER.info(
            'Joining %d channels (with JOIN throttle OFF); '
            'this may take a moment.', len(channels))

        for channel in bot.config.core.channels:
            bot.join(channel)

    # warn for insecure auth method if necessary
    if (not bot.config.core.owner_account
            and 'account-tag' in bot.enabled_capabilities
            and '@' not in bot.config.core.owner):
        msg = (
            "This network supports using network services to identify you as "
            "my owner, rather than just matching your nickname. This is much "
            "more secure. If you'd like to do this, make sure you're logged in "
            "and reply with \"{}useserviceauth\"").format(
                bot.config.core.help_prefix)
        bot.say(msg, bot.config.core.owner)

    # execute custom commands
    _execute_perform(bot)
Exemplo n.º 25
0
def setup(bot):
    bot.memory['find_lines'] = SopelMemory()
Exemplo n.º 26
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][instagram_pattern] = instaparse
Exemplo n.º 27
0
def setup(bot):
    if 'clubroom_status' not in bot.memory:
        bot.memory['clubroom_status'] = SopelMemory()
Exemplo n.º 28
0
def setup(bot):
    if not bot.memory.contains('url_callbacks'):
        bot.memory['url_callbacks'] = SopelMemory()
    bot.memory['url_callbacks'][malregex] = malirc