From 226fa8ee768fc821daaed71303c7e21108331fde Mon Sep 17 00:00:00 2001 From: agessaman Date: Sun, 7 Sep 2025 15:16:46 -0700 Subject: [PATCH] Fix 'prefix free' command accuracy --- modules/commands/prefix_command.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/commands/prefix_command.py b/modules/commands/prefix_command.py index 58827b8..f03b49d 100644 --- a/modules/commands/prefix_command.py +++ b/modules/commands/prefix_command.py @@ -194,10 +194,18 @@ class PrefixCommand(BaseCommand): # Get all used prefixes from both API cache and database used_prefixes = set() + # Always try to refresh cache if it's empty or stale + current_time = time.time() + if not self.cache_data or current_time - self.cache_timestamp > self.cache_duration: + self.logger.info("Refreshing cache for free prefixes lookup") + await self.refresh_cache() + # Add prefixes from API cache for prefix in self.cache_data.keys(): used_prefixes.add(prefix.upper()) + self.logger.info(f"Found {len(used_prefixes)} used prefixes from API cache") + # Add prefixes from database try: query = ''' @@ -226,6 +234,8 @@ class PrefixCommand(BaseCommand): if prefix not in used_prefixes: free_prefixes.append(prefix) + self.logger.info(f"Found {len(free_prefixes)} free prefixes out of {len(all_prefixes)} total valid prefixes") + # Return up to 10 free prefixes return free_prefixes[:10]