Added support for 25+

This commit is contained in:
jmueller
2023-12-14 22:19:12 +01:00
parent 3f867325ef
commit b3db08c03c

62
main.py
View File

@@ -723,14 +723,7 @@ class report_select_menu50(discord.ui.View):
async def on_timeout(self): async def on_timeout(self):
self.clear_items() self.clear_items()
class generate_report25(discord.ui.View): async def process_generate_report(select, interaction):
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
min_values=1, # the minimum number of values that must be selected by the users
max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
options=[]
)
async def select_callback(self, select, interaction):
await interaction.response.defer(ephemeral=True) await interaction.response.defer(ephemeral=True)
embed = discord.Embed( embed = discord.Embed(
title="Rekrutenbesichtigung: Erstellter Report", title="Rekrutenbesichtigung: Erstellter Report",
@@ -739,11 +732,13 @@ class generate_report25(discord.ui.View):
description = "```\n" description = "```\n"
guild = interaction.guild guild = interaction.guild
for recruit in select.values: for recruit in select.values:
cur.execute("SELECT recruits.nickname, count(yes_votes.id), count(no_votes.id) FROM recruits LEFT JOIN no_votes ON recruits.discord_id = no_votes.discord_id_recruit LEFT JOIN yes_votes ON recruits.discord_id = yes_votes.discord_id_recruit WHERE recruits.discord_id = ?", (recruit, )) cur.execute(
"SELECT recruits.nickname, count(yes_votes.id), count(no_votes.id) FROM recruits LEFT JOIN no_votes ON recruits.discord_id = no_votes.discord_id_recruit LEFT JOIN yes_votes ON recruits.discord_id = yes_votes.discord_id_recruit WHERE recruits.discord_id = ?",
(recruit,))
data = cur.fetchone() data = cur.fetchone()
description = description + "**" + str(data[0]) + ":** " + str(data[1]) + " Ja | " + str(data[2]) + "Nein -> \n" description = description + "**" + str(data[0]) + ":** " + str(data[1]) + " Ja | " + str(data[2]) + "Nein -> \n"
if data[1] != 0: if data[1] != 0:
cur.execute("SELECT discord_id_voter, reason FROM no_votes WHERE discord_id_recruit = ?", (recruit, )) cur.execute("SELECT discord_id_voter, reason FROM no_votes WHERE discord_id_recruit = ?", (recruit,))
no_votes = cur.fetchall() no_votes = cur.fetchall()
for vote in no_votes: for vote in no_votes:
nick = guild.get_member(vote[0]).display_name nick = guild.get_member(vote[0]).display_name
@@ -752,6 +747,37 @@ class generate_report25(discord.ui.View):
description = description + "```" description = description + "```"
embed.description = description embed.description = description
await interaction.followup.send(embed=embed, ephemeral=True) await interaction.followup.send(embed=embed, ephemeral=True)
class generate_report25(discord.ui.View):
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
min_values=1, # the minimum number of values that must be selected by the users
max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
options=[]
)
async def select_callback(self, select, interaction):
await process_generate_report(select, interaction)
await self.message.delete()
class generate_report50(discord.ui.View):
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
min_values=1, # the minimum number of values that must be selected by the users
max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
options=[]
)
async def select1(self, select, interaction):
await process_generate_report(select, interaction)
await self.message.delete()
@discord.ui.select( # the decorator that lets you specify the properties of the select menu
placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
min_values=1, # the minimum number of values that must be selected by the users
max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
options=[]
)
async def select2(self, select, interaction):
await process_generate_report(select, interaction)
await self.message.delete() await self.message.delete()
@@ -776,14 +802,30 @@ class report_buttons(discord.ui.View):
@discord.ui.button(label="Rekrutenbesichtigung generieren", style=discord.ButtonStyle.primary, row=1, custom_id="report_buttons_checkout") @discord.ui.button(label="Rekrutenbesichtigung generieren", 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):
if get_count_recruits(1) > 25:
generate_report25_inst = generate_report25() generate_report25_inst = generate_report25()
generate_report25_inst.children[0].options = build_option_list()[0] generate_report25_inst.children[0].options = build_option_list()[0]
generate_report25_inst.children[0].max_values = get_count_recruits()
embed = discord.Embed( embed = discord.Embed(
title="Rekrut wählen", title="Rekrut wählen",
description="Bitte wähle einen oder mehrere Rekruten aus", description="Bitte wähle einen oder mehrere Rekruten aus",
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=generate_report25_inst, ephemeral=True) await interaction.response.send_message(embed=embed, view=generate_report25_inst, ephemeral=True)
else:
generate_report50_inst = generate_report50()
generate_report50_inst.children[0].options = build_option_list()[0]
generate_report50_inst.children[0].max_values = get_count_recruits()
generate_report50_inst.children[1].options = build_option_list()[0]
generate_report50_inst.children[1].max_values = get_count_recruits()
embed = discord.Embed(
title="Rekrut wählen",
description="Bitte wähle einen oder mehrere Rekruten aus",
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from
)
await interaction.response.send_message(embed=embed, view=generate_report50_inst, 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):