Searches and downloads share one IRC connection and run side by side,
which broke in three ways:
- wait_for_dcc took the first search-results file to arrive, so a late
file for an earlier query was cached under the current one. It now skips
a results file whose name is for a different query.
- A download failing on the shared socket closed it under a search in
flight. The search then cached an empty answer, hiding the book for a
day. Searches and downloads now hold one lock for the whole exchange.
- A search that lost its connection returned [] and counted as a
no-match pass, pushing the request into backoff. It now raises
SourceUnavailableError, which auto-download already treats as an error,
and caches nothing.
This was written with AI assistance. I reviewed the changes and ran the
tests above and verified that this fixed my issues with searching and
downloading using IRC.
*Generated with Claude Sonnet 5.5*
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Search results are matched against the requested title, ignoring
punctuation and accents while rejecting partial-title matches. Filenames
without the usual suffix are also recognized.
* Results and “no results” notices from earlier searches are skipped,
and denied searches report an error.
* Connection drops and DCC read errors are reported as failures rather
than empty results or timeouts.
* Repeated identical searches are rate-limited before sending, and
search time limits apply while waiting for results or downloads.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: CaliBrain <calibrain@l4n.xyz>
The IRC channel setting asks for the name without the `#`, and the
client adds it when it joins. Mine was stored as `#ebooks`, so Shelfmark
joined `##ebooks`, a different and nearly empty channel. The log said
`Joined ##ebooks - 1 servers online`, every search came back empty, and
nothing in the UI said why. With `ebooks` the same search joined
`#ebooks` with 26 servers and returned 9 results.
This strips whitespace and leading `#` where the two channel settings
are read: the release source (availability, search channel, audiobook
channel) and the download handler, which reads `IRC_CHANNEL` on its own.
The join, the message target and the cache key all get the bare name.
Tests are in `tests/irc/test_source.py` (main and audiobook channel) and
a new `tests/irc/test_handler.py`. With the source change reverted all
three fail (`assert '#ebooks' == 'ebooks'`). `make python-checks` is
clean.
One thing I left alone: the download handler always uses `IRC_CHANNEL`,
never `IRC_AUDIOBOOK_CHANNEL`, so an audiobook found in a separate
audiobook channel is requested in the main one.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* IRC channel settings now work consistently whether entered with or
without a leading `#`. Surrounding whitespace is also handled, helping
searches, audiobook routing, and downloads use the intended channel.
* Downloads connect using the normalized channel name while keeping the
channel request correctly formatted.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->