Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sopel: don't use bot.search_url_callbacks internally #2635

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespaces = false

[project]
name = "sopel"
version = "8.0.0"
version = "8.1.0.dev0"
description = "Simple and extensible IRC bot"
maintainers = [
{ name="dgw" },
Expand Down
12 changes: 9 additions & 3 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,14 @@ def call(
:param func: the function to call
:type func: :term:`function`
Exirel marked this conversation as resolved.
Show resolved Hide resolved
:param sopel: a SopelWrapper instance
:type sopel: :class:`SopelWrapper`
:param Trigger trigger: the Trigger object for the line from the server
that triggered this call
:param trigger: the Trigger object for the line from the server that
triggered this call

.. deprecated:: 8.1

This method is deprecated and will be removed in Sopel 9.0. The
new rules system uses :meth:`call_rule` instead.

"""
nick = trigger.nick
current_time = time.time()
Expand Down Expand Up @@ -1120,6 +1125,7 @@ def _shutdown(self) -> None:
# Avoid calling shutdown methods if we already have.
self.shutdown_methods = []

# TODO: Remove in Sopel 9.0
# URL callbacks management

@deprecated(
Expand Down
3 changes: 2 additions & 1 deletion sopel/builtins/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ def check_callbacks(
)
return (
excluded or
any(bot.search_url_callbacks(url)) or
# TODO: _url_callbacks is deprecated and will be removed in Sopel 9.0
any(pattern.search(url) for pattern in bot._url_callbacks.keys()) or
bot.rules.check_url_callback(bot, url)
)

Expand Down
14 changes: 10 additions & 4 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,15 +1612,21 @@ def track_topic(bot, trigger):
def handle_url_callbacks(bot, trigger):
"""Dispatch callbacks on URLs

For each URL found in the trigger, trigger the URL callback registered by
the ``@url`` decorator.
For each URL found in the trigger, trigger the URL callback registered
through the now deprecated :meth:`sopel.bot.Sopel.register_url_callback`.

.. deprecated:: 8.1

This is deprecated and will be removed in Sopel 9.0.

"""
# find URLs in the trigger
for url in trigger.urls:
# find callbacks for said URL
for function, match in bot.search_url_callbacks(url):
for pattern, function in bot._url_callbacks.items():
match = pattern.search(url)
# trigger callback defined by the `@url` decorator
if hasattr(function, 'url_regex'):
if match and hasattr(function, 'url_regex'):
# bake the `match` argument in before passing the callback on
@functools.wraps(function)
def decorated(bot, trigger):
Expand Down
Loading