-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
url: documented as calling other plugins when redirects match, but doesn't #2230
Comments
I believe the "did any redirects happen?" part of the fix for this issue involves looking at A patch may want to add a note to |
That would constitute an inability to re-implement the documented behavior, then, wouldn't it?
|
The URL plugin should probably say to request not to follow redirect, and to implement the follow-redirect logic ourselves. This way, we should be able to look at a request, if it's a redirect, ask the bot if a plugin can deal with it, etc. and so on up until there is no redirect and no plugin can handle it. |
Or the bot's URL dispatcher can test for redirects itself if no plugin's handler matches? I wouldn't mind decoupling this redirect-handling behavior from Problem is the |
If we're considering that, my dream is something like:
This would let plugins like bugzilla or a hypothetical mastodon/activitypub plugin to handle the relevant application regardless of the domain/path it lives at (mastodon.social, nondeterministic.computer, etc etc etc etc etc), and for others that use page data instead of turning a URL into an API call, they could dump it directly through an xml parser or BS4. Worth it? No idea. |
We've talked about that idea before, and I like it. Not this late in 8.0, and it's big enough I think it has to wait for 9.0, but I like it. If you're up for taking your bullets there and fleshing them out a bit into a standalone feature issue, go for it. 😃 FWIW, a mastodon plugin is no longer hypothetical (soon to be adopted under our org, I think). The question now is, how can we resolve this issue in a relatively low-effort way for 8.0, while planning ahead to replace it in 9? |
(semantic warning: longposting)
I think I'm keying mostly off of your suggestion that the patch that implements this should live in Sopel doing requests on the plugins behalf
I'm a -1 on Sopel doing eager requests, I don't think the core should be performing a request on every matched URL before dispatching to plugins. What should the rules for this one-size-fits all request look like? What if someone links to an However, reflecting on this suggestion, I began wondering if it makes sense for Sopel to provide a helper for requests that will dispatch to plugins that have a registered pattern matching an eventual redirect. Let's assume @plugin.url("https://example.com")
def pluginA_example(bot, trigger):
urls = web.search_urls(trigger, exclusion_char=bot.config.url.exclusion_char, clean=True)
for url in urls:
# in the servicing of get(), we could dispatch to decorators that match the redirect URL, where appropriate
response = web.get(url) # type: requests.Response
# ...
# …somewhere else, a cousin decoration occurs…
@plugin.url("https://example.com/with/a/specific/path")
def pluginB_example_specific(bot, trigger):
# ... Other spellings of this "let the bot do the request" ideas might include a helper for explicitly delegating back to the bot (e.g. I think all of that is definitely well past the bar for 8.0, but it's interesting to think about how to get redirects working cooperatively. |
I've filed #2432 as longer-term planning for restoration of this feature, so that for 8.0 we can focus on 'just' fixing the incorrect claim in the docstrings. It's a good idea to dispatch to callbacks who want to know about redirects, but I think we need to think about that some more. |
Once upon a time, the
url
plugin'stitle_auto
feature would check if a link redirected to a URL that should be handled by another plugin, but that appears to no longer be the case since the conversion to userequests
. Its documentation and that for theprocess_urls
helper (below) still say this is the case, but the behavior is gone.sopel/sopel/modules/url.py
Lines 290 to 295 in d36a19d
sopel/sopel/modules/url.py
Lines 322 to 329 in d36a19d
I would argue that this is a useful feature, and we should bring it back. For example, our first-party GitHub plugin could get free handling of repo/issue/PR/commit links shortened through git.io if this was still the case. Any shortened URL at present, actually, is only ever going to get the generic title-fetching behavior.
While it's certainly possible to create Yet Another Sopel Plugin that resolves short URLs, it would be fairly annoying to implement—and it wouldn't block the built-in title handling, either.
Note, I don't care if this is part of
url
, but it makes more sense to put it there than into the bot's core URL handling. We don't necessarily want the core bot making HTTP requests every time it sees a link. Some of the thoughts in this issue were previously expressed in #sopel@libera on 2021-11-30.The text was updated successfully, but these errors were encountered: