Added support for 25+

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

100
main.py
View File

@@ -723,6 +723,31 @@ class report_select_menu50(discord.ui.View):
async def on_timeout(self): async def on_timeout(self):
self.clear_items() self.clear_items()
async def process_generate_report(select, interaction):
await interaction.response.defer(ephemeral=True)
embed = discord.Embed(
title="Rekrutenbesichtigung: Erstellter Report",
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from
)
description = "```\n"
guild = interaction.guild
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,))
data = cur.fetchone()
description = description + "**" + str(data[0]) + ":** " + str(data[1]) + " Ja | " + str(data[2]) + "Nein -> \n"
if data[1] != 0:
cur.execute("SELECT discord_id_voter, reason FROM no_votes WHERE discord_id_recruit = ?", (recruit,))
no_votes = cur.fetchall()
for vote in no_votes:
nick = guild.get_member(vote[0]).display_name
description = description + "Begründung von " + nick + ": " + vote[1] + "\n"
description = description + "\n"
description = description + "```"
embed.description = description
await interaction.followup.send(embed=embed, ephemeral=True)
class generate_report25(discord.ui.View): class generate_report25(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
placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
@@ -731,27 +756,28 @@ class generate_report25(discord.ui.View):
options=[] options=[]
) )
async def select_callback(self, select, interaction): async def select_callback(self, select, interaction):
await interaction.response.defer(ephemeral=True) await process_generate_report(select, interaction)
embed = discord.Embed( await self.message.delete()
title="Rekrutenbesichtigung: Erstellter Report",
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from class generate_report50(discord.ui.View):
) @discord.ui.select( # the decorator that lets you specify the properties of the select menu
description = "```\n" placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
guild = interaction.guild min_values=1, # the minimum number of values that must be selected by the users
for recruit in select.values: max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
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, )) options=[]
data = cur.fetchone() )
description = description + "**" + str(data[0]) + ":** " + str(data[1]) + " Ja | " + str(data[2]) + "Nein -> \n" async def select1(self, select, interaction):
if data[1] != 0: await process_generate_report(select, interaction)
cur.execute("SELECT discord_id_voter, reason FROM no_votes WHERE discord_id_recruit = ?", (recruit, )) await self.message.delete()
no_votes = cur.fetchall()
for vote in no_votes: @discord.ui.select( # the decorator that lets you specify the properties of the select menu
nick = guild.get_member(vote[0]).display_name placeholder="Rekruten wählen...", # the placeholder text that will be displayed if nothing is selected
description = description + "Begründung von " + nick + ": " + vote[1] + "\n" min_values=1, # the minimum number of values that must be selected by the users
description = description + "\n" max_values=get_count_recruits(), # the maximum number of values that can be selected by the users
description = description + "```" options=[]
embed.description = description )
await interaction.followup.send(embed=embed, ephemeral=True) 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):
generate_report25_inst = generate_report25()
generate_report25_inst.children[0].options = build_option_list()[0] if get_count_recruits(1) > 25:
embed = discord.Embed( generate_report25_inst = generate_report25()
title="Rekrut wählen", generate_report25_inst.children[0].options = build_option_list()[0]
description="Bitte wähle einen oder mehrere Rekruten aus", generate_report25_inst.children[0].max_values = get_count_recruits()
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from embed = discord.Embed(
) title="Rekrut wählen",
await interaction.response.send_message(embed=embed, view=generate_report25_inst, ephemeral=True) 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_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):