From 5248368561f084b2fe2ea3ce0a978dc02fd3bb07 Mon Sep 17 00:00:00 2001 From: jmueller Date: Tue, 12 Dec 2023 22:01:59 +0100 Subject: [PATCH] Implemented +25 Recruits support on Select vote and delete --- main.py | 98 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index a24a7cd..325f346 100644 --- a/main.py +++ b/main.py @@ -138,6 +138,9 @@ class yes_question_cause_overlap(discord.ui.View): await self.message.delete() await interaction.response.send_message(embed=embed, ephemeral=True) + async def on_timeout(self): + self.clear_items() + async def process_yes_vote(select, interaction): found = False overlap_embed = discord.Embed( @@ -295,6 +298,9 @@ class no_question(discord.ui.View): await self.message.delete() await interaction.response.send_message(embed=embed, ephemeral=True) + async def on_timeout(self): + self.clear_items() + class no_clicked_but_yes_vote_question(discord.ui.View): discord_id = "" vote_id = "" @@ -452,6 +458,9 @@ class delete_and_view_votes_message(discord.ui.View): embed.set_footer(text="Wenn du denkst, dass dies nicht korrekt ist, wende dich bitte an LordofAgents.") await interaction.response.send_message(embed=embed, ephemeral=True) + async def on_timeout(self): + self.clear_items() + @discord.ui.button(label="Stimme auswählen und löschen", custom_id="delete-votes", style=discord.ButtonStyle.secondary) async def delete_votes(self, button, interaction): cur.execute("SELECT count(yes_votes.id) FROM recruits, yes_votes WHERE recruits.discord_id = yes_votes.discord_id_recruit AND recruits.recruit = 1 AND yes_votes.discord_id_voter = ?", (interaction.user.id,)) @@ -467,17 +476,26 @@ class delete_and_view_votes_message(discord.ui.View): ) embed.set_footer(text="Wenn du denkst, dass dies nicht korrekt ist, wende dich bitte an LordofAgents.") await interaction.response.send_message(embed=embed, ephemeral=True) + elif count <= 25: + embed = discord.Embed( + title="Stimme löschen", + description="Wähle einen Rekruten aus, um deine Stimme für ihn zu löschen", + color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from + ) + delete_recruit_vote_inst = delete_recruit_vote25() + delete_recruit_vote_inst.children[0].options = getvotes(interaction.user.id) + await interaction.response.send_message(embed=embed, view=delete_recruit_vote_inst, ephemeral=True) else: embed = discord.Embed( title="Stimme löschen", description="Wähle einen Rekruten aus, um deine Stimme für ihn zu löschen", color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from ) - delete_recruit_vote_inst = delete_recruit_vote() + delete_recruit_vote_inst = delete_recruit_vote50() delete_recruit_vote_inst.children[0].options = getvotes(interaction.user.id) + delete_recruit_vote_inst.children[1].options = getvotes(interaction.user.id, 2) await interaction.response.send_message(embed=embed, view=delete_recruit_vote_inst, ephemeral=True) - def getvotes(voterid, part = 1): cur.execute("SELECT count(*) FROM yes_votes WHERE discord_id_voter = ?", (voterid, )) yes_vote_count = cur.fetchone()[0] @@ -512,23 +530,40 @@ def getvotes(voterid, part = 1): if part == 1: count = 0 for option_single in option: - if count > 25: + if count >= 25: break else: new_option.append(option_single) + count = count + 1 return new_option else: count = 0 for option_single in option: - if count <= 25: + if count < 25: + count = count + 1 continue else: new_option.append(option_single) + count = count + 1 return new_option +async def process_deletion_request(select, interaction): + confirm_deletion_of_vote_inst = confirm_deletion_of_vote() + confirm_deletion_of_vote.votes = select.values + description = "Du möchtest deine Stimme für folgenden Rekruten löschen:\n" + for choice in select.values: + cur.execute("SELECT nickname FROM recruits WHERE discord_id = ?", (choice,)) + nickname = cur.fetchone()[0] + description = description + nickname + "\n" + embed = discord.Embed( + title="Stimme löschen", + description=description, + color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from + ) + await interaction.response.send_message(embed=embed, view=confirm_deletion_of_vote_inst, ephemeral=True) -class delete_recruit_vote(discord.ui.View): - voterid = 0 + +class delete_recruit_vote25(discord.ui.View): @discord.ui.select( placeholder = "Rekruten auswählen...", min_values = 1, @@ -536,21 +571,36 @@ class delete_recruit_vote(discord.ui.View): options = [] ) async def select_callback(self, select, interaction): # the function called when the user is done selecting options - confirm_deletion_of_vote_inst = confirm_deletion_of_vote() - confirm_deletion_of_vote.votes = select.values - description = "Du möchtest deine Stimme für folgenden Rekruten löschen:\n" - for choice in select.values: - cur.execute("SELECT nickname FROM recruits WHERE discord_id = ?", (choice, )) - nickname = cur.fetchone()[0] - description = description + nickname + "\n" - embed = discord.Embed( - title="Stimme löschen", - description=description, - color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from - ) - await interaction.response.send_message(embed=embed, view=confirm_deletion_of_vote_inst, ephemeral=True) + await process_deletion_request(select, interaction) await self.message.delete() + async def on_timeout(self): + self.clear_items() + +class delete_recruit_vote50(discord.ui.View): + @discord.ui.select( + placeholder = "Rekruten auswählen...", + min_values = 1, + max_values = 1, # the maximum number of values that can be selected by the users + options = [] + ) + async def select1(self, select, interaction): # the function called when the user is done selecting options + await process_deletion_request(select, interaction) + await self.message.delete() + + @discord.ui.select( + placeholder = "Rekruten auswählen...", + min_values = 1, + max_values = 1, # the maximum number of values that can be selected by the users + options = [] + ) + async def select2(self, select, interaction): # the function called when the user is done selecting options + await process_deletion_request(select, interaction) + await self.message.delete() + + async def on_timeout(self): + self.clear_items() + class confirm_deletion_of_vote(discord.ui.View): # Create a class called MyView that subclasses discord.ui.View votes = [] @discord.ui.button(label="Stimme löschen", style=discord.ButtonStyle.danger) @@ -578,6 +628,9 @@ class confirm_deletion_of_vote(discord.ui.View): # Create a class called MyView await interaction.response.send_message(embed=embed, ephemeral=True) await self.message.delete() + async def on_timeout(self): + self.clear_items() + async def send_delete_message(channel): embed = discord.Embed( @@ -636,6 +689,8 @@ class report_select_menu25(discord.ui.View): async def select_callback(self, select, interaction): await self.message.delete() await process_detailed_report(select, interaction) + async def on_timeout(self): + self.clear_items() class report_select_menu50(discord.ui.View): @discord.ui.select( # the decorator that lets you specify the properties of the select menu @@ -660,6 +715,9 @@ class report_select_menu50(discord.ui.View): await self.message.delete() await process_detailed_report(select, interaction) + async def on_timeout(self): + self.clear_items() + class report_buttons(discord.ui.View): def __init__(self): super().__init__(timeout=None) @@ -681,7 +739,7 @@ class report_buttons(discord.ui.View): @discord.ui.button(label="Rekruten auschecken", style=discord.ButtonStyle.primary, row=1, custom_id="report_buttons_checkout") async def checkout_recruits(self, button, interaction): - await interaction.response.send_message("You clicked the button!") + await interaction.response.send_message("Äääh ich funktioniere noch nicht. Sorrryyyyyy :D", ephemeral=True) @discord.ui.button(label="Daten aktualisieren", style=discord.ButtonStyle.secondary, row=2, custom_id="report_buttons_refresh") async def refresh_button(self, button, interaction):