From 4dff86fbe1c7210aadef74bf1e7799e0e7432a74 Mon Sep 17 00:00:00 2001 From: Kozejin <2613841+dkoz@users.noreply.github.com> Date: Thu, 14 Nov 2024 00:55:58 -0500 Subject: [PATCH] Fix Server Autocomplete --- cogs/connect.py | 6 +++--- cogs/economy/shop.py | 19 +++++++++---------- cogs/kits.py | 5 ++++- cogs/palcon.py | 6 +++--- cogs/palguard.py | 12 ++++-------- cogs/playerlist.py | 11 +++++------ cogs/query.py | 4 ++-- requirements.txt | 2 +- 8 files changed, 31 insertions(+), 34 deletions(-) diff --git a/cogs/connect.py b/cogs/connect.py index ce2f30e..1f69e9d 100644 --- a/cogs/connect.py +++ b/cogs/connect.py @@ -132,9 +132,9 @@ async def announce_player_leave(self, server_name, player_name, steamid): async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): if interaction.guild is None: - return - - choices = [server for server in self.servers if current.lower() in server.lower()] + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) @nextcord.slash_command(name="eventlogs", description=t("ConnectCog", "eventlogs.description"), default_member_permissions=nextcord.Permissions(administrator=True), dm_permission=False) diff --git a/cogs/economy/shop.py b/cogs/economy/shop.py index f1cdee3..68b471f 100644 --- a/cogs/economy/shop.py +++ b/cogs/economy/shop.py @@ -127,6 +127,13 @@ async def get_server_info(self, server_name: str): } return None + async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): + if interaction.guild is None: + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] + await interaction.response.send_autocomplete(choices) + @nextcord.slash_command(description=t("ShopCog", "shop.description"), dm_permission=False) async def shop(self, _interaction: nextcord.Interaction): pass @@ -140,11 +147,7 @@ async def menu(self, interaction: nextcord.Interaction, server: str = nextcord.S @menu.on_autocomplete("server") async def on_autocomplete_server(self, interaction: nextcord.Interaction, current: str): - if interaction.guild is None: - return[] - - choices = [server for server in self.servers if current.lower() in server.lower()][:10] - await interaction.response.send_autocomplete(choices) + await self.autocomplete_server(interaction, current) async def purchase_item(self, interaction: nextcord.Interaction, item_name: str, server: str): user_id = str(interaction.user.id) @@ -300,11 +303,7 @@ async def redeem( @redeem.on_autocomplete("server") async def on_autocomplete_server(self, interaction: nextcord.Interaction, current: str): - if interaction.guild is None: - return[] - - choices = [server for server in self.servers if current.lower() in server.lower()][:10] - await interaction.response.send_autocomplete(choices) + await self.autocomplete_server(interaction, current) @redeem.on_autocomplete("item_name") async def on_autocomplete_shop_items(self, interaction: nextcord.Interaction, current: str): diff --git a/cogs/kits.py b/cogs/kits.py index 60cd8ed..fd87bea 100644 --- a/cogs/kits.py +++ b/cogs/kits.py @@ -29,7 +29,10 @@ async def load_servers(self): self.servers = await server_autocomplete() async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): - choices = [server for server in self.servers if current.lower() in server.lower()][:10] + if interaction.guild is None: + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) async def get_server_info(self, server_name: str): diff --git a/cogs/palcon.py b/cogs/palcon.py index 0b722a5..9babeab 100644 --- a/cogs/palcon.py +++ b/cogs/palcon.py @@ -19,9 +19,9 @@ async def load_servers(self): async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): if interaction.guild is None: - return[] - - choices = [server for server in self.servers if current.lower() in server.lower()] + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) async def get_server_info(self, server_name: str): diff --git a/cogs/palguard.py b/cogs/palguard.py index 2feec12..4b4a6bd 100644 --- a/cogs/palguard.py +++ b/cogs/palguard.py @@ -36,15 +36,11 @@ def load_eggs(self): with open(eggs_path, "r", encoding="utf-8") as eggs_file: self.eggs = json.load(eggs_file)["eggs"] - async def autocomplete_server( - self, interaction: nextcord.Interaction, current: str - ): + async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): if interaction.guild is None: - return[] - - choices = [ - server for server in self.servers if current.lower() in server.lower() - ] + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) async def autocomplete_palid(self, interaction: nextcord.Interaction, current: str): diff --git a/cogs/playerlist.py b/cogs/playerlist.py index 9437af3..6921640 100644 --- a/cogs/playerlist.py +++ b/cogs/playerlist.py @@ -71,12 +71,11 @@ def __init__(self, bot): async def load_servers(self): self.servers = await server_autocomplete() - async def autocomplete_server( - self, interaction: nextcord.Interaction, current: str - ): - choices = [ - server for server in self.servers if current.lower() in server.lower() - ] + async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): + if interaction.guild is None: + return [] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) async def get_server_info(self, server_name: str): diff --git a/cogs/query.py b/cogs/query.py index a8920ee..e1799ae 100644 --- a/cogs/query.py +++ b/cogs/query.py @@ -183,8 +183,8 @@ async def extract_server_info(self, response): async def autocomplete_server(self, interaction: nextcord.Interaction, current: str): if interaction.guild is None: return [] - - choices = [server for server in self.servers if current.lower() in server.lower()] + server_names = await server_autocomplete() + choices = [server for server in server_names if current.lower() in server.lower()][:25] await interaction.response.send_autocomplete(choices) @nextcord.slash_command(description=t("QueryCog", "query.description"), default_member_permissions=nextcord.Permissions(administrator=True), dm_permission=False) diff --git a/requirements.txt b/requirements.txt index e9f1c6f..eed7a46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ nextcord==2.6.0 python-dotenv==1.0.1 -gamercon-async==1.0.6 +gamercon-async==1.0.7 aiohttp==3.10.10 aiosqlite==0.20.0 pytz==2024.2