Implemented +25 Recruits support on Select vote and delete

This commit is contained in:
jmueller
2023-12-12 22:01:59 +01:00
parent dff5d6a8ab
commit 5248368561

88
main.py
View File

@@ -138,6 +138,9 @@ class yes_question_cause_overlap(discord.ui.View):
await self.message.delete() await self.message.delete()
await interaction.response.send_message(embed=embed, ephemeral=True) await interaction.response.send_message(embed=embed, ephemeral=True)
async def on_timeout(self):
self.clear_items()
async def process_yes_vote(select, interaction): async def process_yes_vote(select, interaction):
found = False found = False
overlap_embed = discord.Embed( overlap_embed = discord.Embed(
@@ -295,6 +298,9 @@ class no_question(discord.ui.View):
await self.message.delete() await self.message.delete()
await interaction.response.send_message(embed=embed, ephemeral=True) 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): class no_clicked_but_yes_vote_question(discord.ui.View):
discord_id = "" discord_id = ""
vote_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.") 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) 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) @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): 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,)) 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.") 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) 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: else:
embed = discord.Embed( embed = discord.Embed(
title="Stimme löschen", title="Stimme löschen",
description="Wähle einen Rekruten aus, um deine Stimme für ihn zu 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 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[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) await interaction.response.send_message(embed=embed, view=delete_recruit_vote_inst, ephemeral=True)
def getvotes(voterid, part = 1): def getvotes(voterid, part = 1):
cur.execute("SELECT count(*) FROM yes_votes WHERE discord_id_voter = ?", (voterid, )) cur.execute("SELECT count(*) FROM yes_votes WHERE discord_id_voter = ?", (voterid, ))
yes_vote_count = cur.fetchone()[0] yes_vote_count = cur.fetchone()[0]
@@ -512,30 +530,24 @@ def getvotes(voterid, part = 1):
if part == 1: if part == 1:
count = 0 count = 0
for option_single in option: for option_single in option:
if count > 25: if count >= 25:
break break
else: else:
new_option.append(option_single) new_option.append(option_single)
count = count + 1
return new_option return new_option
else: else:
count = 0 count = 0
for option_single in option: for option_single in option:
if count <= 25: if count < 25:
count = count + 1
continue continue
else: else:
new_option.append(option_single) new_option.append(option_single)
count = count + 1
return new_option return new_option
async def process_deletion_request(select, interaction):
class delete_recruit_vote(discord.ui.View):
voterid = 0
@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 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_inst = confirm_deletion_of_vote()
confirm_deletion_of_vote.votes = select.values confirm_deletion_of_vote.votes = select.values
description = "Du möchtest deine Stimme für folgenden Rekruten löschen:\n" description = "Du möchtest deine Stimme für folgenden Rekruten löschen:\n"
@@ -549,8 +561,46 @@ class delete_recruit_vote(discord.ui.View):
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from 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 interaction.response.send_message(embed=embed, view=confirm_deletion_of_vote_inst, ephemeral=True)
class delete_recruit_vote25(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 select_callback(self, select, interaction): # the function called when the user is done selecting options
await process_deletion_request(select, interaction)
await self.message.delete() 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 class confirm_deletion_of_vote(discord.ui.View): # Create a class called MyView that subclasses discord.ui.View
votes = [] votes = []
@discord.ui.button(label="Stimme löschen", style=discord.ButtonStyle.danger) @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 interaction.response.send_message(embed=embed, ephemeral=True)
await self.message.delete() await self.message.delete()
async def on_timeout(self):
self.clear_items()
async def send_delete_message(channel): async def send_delete_message(channel):
embed = discord.Embed( embed = discord.Embed(
@@ -636,6 +689,8 @@ class report_select_menu25(discord.ui.View):
async def select_callback(self, select, interaction): async def select_callback(self, select, interaction):
await self.message.delete() await self.message.delete()
await process_detailed_report(select, interaction) await process_detailed_report(select, interaction)
async def on_timeout(self):
self.clear_items()
class report_select_menu50(discord.ui.View): class report_select_menu50(discord.ui.View):
@discord.ui.select( # the decorator that lets you specify the properties of the select menu @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 self.message.delete()
await process_detailed_report(select, interaction) await process_detailed_report(select, interaction)
async def on_timeout(self):
self.clear_items()
class report_buttons(discord.ui.View): class report_buttons(discord.ui.View):
def __init__(self): def __init__(self):
super().__init__(timeout=None) 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") @discord.ui.button(label="Rekruten auschecken", style=discord.ButtonStyle.primary, row=1, custom_id="report_buttons_checkout")
async def checkout_recruits(self, button, interaction): 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") @discord.ui.button(label="Daten aktualisieren", style=discord.ButtonStyle.secondary, row=2, custom_id="report_buttons_refresh")
async def refresh_button(self, button, interaction): async def refresh_button(self, button, interaction):