Skip to content

Commit

Permalink
Fix Server Autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Nov 14, 2024
1 parent c9f57be commit 4dff86f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 34 deletions.
6 changes: 3 additions & 3 deletions cogs/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 9 additions & 10 deletions cogs/economy/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion cogs/kits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions cogs/palcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions cogs/palguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 5 additions & 6 deletions cogs/playerlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions cogs/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4dff86f

Please sign in to comment.