Add command to init.

Correctly set autocomplete.
Put newlines where I forgot to.
This commit is contained in:
2023-11-07 14:12:42 -05:00
parent 7530c59a94
commit 678fcd37e1
2 changed files with 17 additions and 7 deletions
+2
View File
@@ -7,6 +7,7 @@ from nextcord.ext import commands
from cogs.commands.request import RequestCog from cogs.commands.request import RequestCog
from cogs.commands.set import setCog from cogs.commands.set import setCog
from cogs.commands.test import TestCog from cogs.commands.test import TestCog
from cogs.commands.view import ViewCog
# This function will be called when this extension is loaded. # This function will be called when this extension is loaded.
@@ -19,3 +20,4 @@ def setup(bot: commands.Bot):
bot.add_cog(RequestCog(bot)) bot.add_cog(RequestCog(bot))
bot.add_cog(TestCog(bot)) bot.add_cog(TestCog(bot))
bot.add_cog(setCog()) bot.add_cog(setCog())
bot.add_cog(ViewCog())
+15 -7
View File
@@ -26,7 +26,9 @@ class ViewCog(commands.Cog, name="View Commands"):
Parent slash command for set. Never called. Parent slash command for set. Never called.
""" """
@view.subcommand(description="Shows all voters and who they voted for in a given election.") @view.subcommand(
description="Shows all voters and who they voted for in a given election."
)
async def votes( async def votes(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
@@ -53,17 +55,21 @@ class ViewCog(commands.Cog, name="View Commands"):
for vote in votes: for vote in votes:
content += ( content += (
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>." f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
if vote.VotedForId is not None if vote.VotedForId is not None
else f"<@{vote.VoterId}> abstained from voted." else f"<@{vote.VoterId}> abstained from voted.\n"
) )
await interaction.response.send_message(content=content, ephemeral=True) await interaction.response.send_message(content=content, ephemeral=True)
except: except:
await interaction.response.send_message(f"Invalid election: {election_name}.", ephemeral=True) await interaction.response.send_message(
f"Invalid election: {election_name}.", ephemeral=True
)
@view.on_autocomplete("election_name") @votes.on_autocomplete("election_name")
async def election_autocomplete(self, interaction: nextcord.Interaction, election_name: str): async def election_autocomplete(
self, interaction: nextcord.Interaction, election_name: str
):
""" """
Collects all elections that start with the election string. Collects all elections that start with the election string.
@@ -82,6 +88,8 @@ class ViewCog(commands.Cog, name="View Commands"):
return return
autofilled_elections: "list[str]" = [ autofilled_elections: "list[str]" = [
election for election in elections if election.lower().startswith(election_name.lower()) election
for election in elections
if election.lower().startswith(election_name.lower())
] ]
await interaction.response.send_autocomplete(autofilled_elections[:25]) await interaction.response.send_autocomplete(autofilled_elections[:25])