Ejemplo n.º 1
0
Archivo: url.py Proyecto: njsmith/sopel
def setup(bot):
    bot.config.define_section('url', UrlSection)

    if bot.config.url.exclude:
        regexes = [re.compile(s) for s in bot.config.url.exclude]
    else:
        regexes = []

    # We're keeping these in their own list, rather than putting then in the
    # callbacks list because 1, it's easier to deal with plugins that are still
    # using this list, and not the newer callbacks list and 2, having a lambda
    # just to pass is kinda ugly.
    if 'url_exclude' not in bot.memory:
        bot.memory['url_exclude'] = regexes
    else:
        exclude = bot.memory['url_exclude']
        if regexes:
            exclude.extend(regexes)
        bot.memory['url_exclude'] = exclude

    # Ensure last_seen_url is in memory
    if 'last_seen_url' not in bot.memory:
        bot.memory['last_seen_url'] = tools.SopelIdentifierMemory()

    # Initialize shortened_urls as a dict if it doesn't exist.
    if 'shortened_urls' not in bot.memory:
        bot.memory['shortened_urls'] = tools.SopelMemory()
Ejemplo n.º 2
0
    def __init__(self, nick, admin=False, owner=False):
        self.nick = nick
        self.user = "******"

        channel = tools.Identifier("#Sopel")
        self.channels = tools.SopelIdentifierMemory()
        self.channels[channel] = tools.target.Channel(channel)

        self.users = tools.SopelIdentifierMemory()
        self.privileges = tools.SopelMemory()

        self.memory = tools.SopelMemory()
        self.memory['url_callbacks'] = tools.SopelMemory()

        self.config = MockConfig()
        self._init_config()

        self.output = []

        if admin:
            self.config.core.admins = [self.nick]
        if owner:
            self.config.core.owner = self.nick
Ejemplo n.º 3
0
def test_sopel_identifier_memory_id():
    user = tools.Identifier('Exirel')
    memory = tools.SopelIdentifierMemory()
    test_value = 'king'

    memory[user] = test_value
    assert user in memory
    assert 'Exirel' in memory
    assert 'exirel' in memory
    assert 'exi' not in memory
    assert '#channel' not in memory

    assert memory[user] == test_value
    assert memory['Exirel'] == test_value
    assert memory['exirel'] == test_value
Ejemplo n.º 4
0
def test_sopel_identifier_memory_channel_str():
    channel = tools.Identifier('#adminchannel')
    memory = tools.SopelIdentifierMemory()
    test_value = 'perfect'

    memory['#adminchannel'] = test_value
    assert channel in memory
    assert '#adminchannel' in memory
    assert '#AdminChannel' in memory
    assert 'adminchannel' not in memory
    assert 'Exirel' not in memory

    assert memory[channel] == test_value
    assert memory['#adminchannel'] == test_value
    assert memory['#AdminChannel'] == test_value
Ejemplo n.º 5
0
def setup(bot):
    if 'mangle_lines' not in bot.memory:
        bot.memory['mangle_lines'] = tools.SopelIdentifierMemory(
            identifier_factory=bot.make_identifier,
        )
Ejemplo n.º 6
0
    def __init__(self, config, daemon=False):
        super(Sopel, self).__init__(config)
        self._daemon = daemon  # Used for iPython. TODO something saner here
        self.wantsrestart = False
        self._running_triggers = []
        self._running_triggers_lock = threading.Lock()
        self._plugins = {}
        self._rules_manager = plugin_rules.Manager()
        self._scheduler = plugin_jobs.Scheduler(self)

        self._times = {}
        """
        A dictionary mapping lowercased nicks to dictionaries which map
        function names to the time which they were last used by that nick.
        """

        self.server_capabilities = {}
        """A dict mapping supported IRCv3 capabilities to their options.

        For example, if the server specifies the capability ``sasl=EXTERNAL``,
        it will be here as ``{"sasl": "EXTERNAL"}``. Capabilities specified
        without any options will have ``None`` as the value.

        For servers that do not support IRCv3, this will be an empty set.
        """

        self.privileges = dict()
        """A dictionary of channels to their users and privilege levels.

        The value associated with each channel is a dictionary of
        :class:`sopel.tools.Identifier`\\s to a bitwise integer value,
        determined by combining the appropriate constants from
        :mod:`sopel.plugin`.

        .. deprecated:: 6.2.0
            Use :attr:`channels` instead. Will be removed in Sopel 8.
        """

        self.channels = tools.SopelIdentifierMemory()
        """A map of the channels that Sopel is in.

        The keys are :class:`sopel.tools.Identifier`\\s of the channel names,
        and map to :class:`sopel.tools.target.Channel` objects which contain
        the users in the channel and their permissions.
        """

        self.users = tools.SopelIdentifierMemory()
        """A map of the users that Sopel is aware of.

        The keys are :class:`sopel.tools.Identifier`\\s of the nicknames, and
        map to :class:`sopel.tools.target.User` instances. In order for Sopel
        to be aware of a user, it must share at least one mutual channel.
        """

        self.db = SopelDB(config)
        """The bot's database, as a :class:`sopel.db.SopelDB` instance."""

        self.memory = tools.SopelMemory()
        """
        A thread-safe dict for storage of runtime data to be shared between
        plugins. See :class:`sopel.tools.SopelMemory`.
        """

        self.shutdown_methods = []
        """List of methods to call on shutdown."""
Ejemplo n.º 7
0
    def __init__(self, config, daemon=False):
        super().__init__(config)
        self._daemon = daemon  # Used for iPython. TODO something saner here
        self._running_triggers = []
        self._running_triggers_lock = threading.Lock()
        self._plugins: Dict[str, Any] = {}
        self._rules_manager = plugin_rules.Manager()
        self._scheduler = plugin_jobs.Scheduler(self)

        self._url_callbacks = tools.SopelMemory()
        """Tracking of manually registered URL callbacks.

        Should be manipulated only by use of :meth:`register_url_callback` and
        :meth:`unregister_url_callback` methods, which are deprecated.

        Remove in Sopel 9, along with the above related methods.
        """

        self._times = {}
        """
        A dictionary mapping lowercased nicks to dictionaries which map
        function names to the time which they were last used by that nick.
        """

        self.server_capabilities = {}
        """A dict mapping supported IRCv3 capabilities to their options.

        For example, if the server specifies the capability ``sasl=EXTERNAL``,
        it will be here as ``{"sasl": "EXTERNAL"}``. Capabilities specified
        without any options will have ``None`` as the value.

        For servers that do not support IRCv3, this will be an empty set.
        """

        self.modeparser = modes.ModeParser()
        """A mode parser used to parse ``MODE`` messages and modestrings."""

        self.channels = tools.SopelIdentifierMemory(
            identifier_factory=self.make_identifier, )
        """A map of the channels that Sopel is in.

        The keys are :class:`~sopel.tools.identifiers.Identifier`\\s of the
        channel names, and map to :class:`~sopel.tools.target.Channel` objects
        which contain the users in the channel and their permissions.
        """

        self.users = tools.SopelIdentifierMemory(
            identifier_factory=self.make_identifier, )
        """A map of the users that Sopel is aware of.

        The keys are :class:`~sopel.tools.identifiers.Identifier`\\s of the
        nicknames, and map to :class:`~sopel.tools.target.User` instances. In
        order for Sopel to be aware of a user, it must share at least one
        mutual channel.
        """

        self.db = db.SopelDB(config, identifier_factory=self.make_identifier)
        """The bot's database, as a :class:`sopel.db.SopelDB` instance."""

        self.memory = tools.SopelMemory()
        """
        A thread-safe dict for storage of runtime data to be shared between
        plugins. See :class:`sopel.tools.memories.SopelMemory`.
        """

        self.shutdown_methods = []
        """List of methods to call on shutdown."""
Ejemplo n.º 8
0
def setup(bot):
    if 'mangle_lines' not in bot.memory:
        bot.memory['mangle_lines'] = tools.SopelIdentifierMemory()