Skip to content

Commit

Permalink
improved search button for bookmarks view
Browse files Browse the repository at this point in the history
added rapidfuzz to requirements.txt
  • Loading branch information
MooshiMochi committed Dec 22, 2024
2 parents 9a35b09 + ff30a56 commit 9fa2638
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#### Consider supporting me on [Patreon](https://patreon.com/mooshi69) or [Ko-Fi](https://ko-fi.com/mooshi69)!

## December 22nd 2024

- Improved the search button from the bookmarks view.
- Adde rapidfuzz to requirements.txt

## // December 16th 2024

### Bug Fixes:
Expand All @@ -19,7 +24,6 @@

- Fixed flamecomics website
- Added support for https://www.beyondtheataraxia.com/
- Added support for https://www.gyarelease.it/
- Fixed asura chapter links

## // November 12th 2024
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ tldextract
brotli
fastapi
patreon
git+https://github.com/Rapptz/discord.py.git
git+https://github.com/Rapptz/discord.py.git
rapidfuzz
18 changes: 11 additions & 7 deletions src/ui/modals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from src.core.database import _levenshtein_distance
from src.enums import BookmarkViewType
import logging
from rapidfuzz import process


class BaseModal(discord.ui.Modal):
Expand Down Expand Up @@ -45,14 +46,17 @@ def __init__(self, logger: Logger, view: BookmarkView):
self.bookmarks: list[Bookmark] = self.view.bookmarks

async def on_submit(self, interaction: discord.Interaction):
titles = [x.manga.title for x in self.bookmarks]
possible_bookmark = [x for x in self.bookmarks if x.manga.title.lower().startswith(self.query.value.lower())]
if len(possible_bookmark) >= 1:
bookmark = possible_bookmark[0]

if possible_bookmark:
titles = [x.manga.title for x in possible_bookmark]
best_match, best_score, index = process.extractOne(self.query.value, titles)
bookmark = possible_bookmark[index]
else:
bookmark = min(
self.bookmarks,
key=lambda x: _levenshtein_distance(x.manga.title.lower(), self.query.value.lower())
)
best_match, best_score, index = process.extractOne(self.query.value, titles)
bookmark = self.bookmarks[index]

self.view.folder = bookmark.folder
self.view.change_view_type(BookmarkViewType.VISUAL)
self.view.clear_components()
Expand Down Expand Up @@ -142,4 +146,4 @@ async def on_submit(self, interaction: discord.Interaction, /) -> None:
else:
self.scanlator = val

await interaction.response.defer(ephemeral=True, thinking=False) # acknowledge the interaction
await interaction.response.defer(ephemeral=True, thinking=False) # noqa: acknowledge the interaction

0 comments on commit 9fa2638

Please sign in to comment.