Support 50 Recruits

This commit is contained in:
jmueller
2023-12-06 20:03:15 +01:00
parent 2505cddda3
commit ce88baceeb

176
main.py
View File

@@ -39,12 +39,18 @@ bot = discord.Bot(intents = intents)
@bot.event
async def on_ready():
global Yes_select_inst
Yes_select_inst = Yes_select()
bot.add_view(Yes_select_inst)
global no_select_inst
no_select_inst = No_select()
bot.add_view(no_select_inst)
global Yes_select_inst25
Yes_select_inst25 = Yes_select_25()
bot.add_view(Yes_select_inst25)
global Yes_select_inst50
Yes_select_inst50 = Yes_select_50()
bot.add_view(Yes_select_inst50)
global no_select_inst25
no_select_inst25 = No_select25()
bot.add_view(no_select_inst25)
global no_select_inst50
no_select_inst50 = No_select50()
bot.add_view(no_select_inst50)
bot.add_view(delete_and_view_votes_message())
print(f"{bot.user} is ready and online!")
@@ -54,9 +60,12 @@ cur = conn.cursor()
# create Slash Command group with bot.create_group
settings = bot.create_group("set", "Einstellungen")
def get_count_recruits():
def get_count_recruits(real = 0):
cur.execute("SELECT count(*) FROM recruits WHERE recruit=1")
count = cur.fetchone()[0]
if real is 0:
if count > 25:
count = count / 2
return int(count)
@@ -125,19 +134,7 @@ class yes_question_cause_overlap(discord.ui.View):
await self.message.delete()
await interaction.response.send_message(embed=embed, ephemeral=True)
class Yes_select(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="yes1",
placeholder="Rekruten wählen...",
min_values=1,
max_values=get_count_recruits(),
options=build_option_list()
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
async def process_yes_vote(select, interaction):
found = False
overlap_embed = discord.Embed(
title="Stimmen bereits vorhanden",
@@ -146,7 +143,9 @@ class Yes_select(discord.ui.View):
)
yes_question_cause_overlap_inst = yes_question_cause_overlap()
for yes_vote in select.values:
cur.execute("SELECT recruits.nickname, no_votes.reason, no_votes.id FROM recruits, no_votes WHERE no_votes.discord_id_recruit = recruits.discord_id AND no_votes.discord_id_voter = ? AND no_votes.discord_id_recruit = ?", (interaction.user.id, yes_vote))
cur.execute(
"SELECT recruits.nickname, no_votes.reason, no_votes.id FROM recruits, no_votes WHERE no_votes.discord_id_recruit = recruits.discord_id AND no_votes.discord_id_voter = ? AND no_votes.discord_id_recruit = ?",
(interaction.user.id, yes_vote))
result = cur.fetchall()
if result:
found = True
@@ -154,10 +153,46 @@ class Yes_select(discord.ui.View):
yes_question_cause_overlap_inst.vote_ids.append(result[0][2])
if found:
yes_question_cause_overlap_inst.select = select
await interaction.response.send_message(embed=overlap_embed, view=yes_question_cause_overlap_inst, ephemeral=True)
await interaction.response.send_message(embed=overlap_embed, view=yes_question_cause_overlap_inst,
ephemeral=True)
else:
await send_yes_confirm(select, interaction)
class Yes_select_25(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="yes25",
placeholder="Rekruten wählen...",
min_values=1,
max_values=get_count_recruits(),
options=build_option_list()
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
await process_yes_vote(select, interaction)
class Yes_select_50(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="yes50_1",
placeholder="Rekruten wählen...",
min_values=1,
max_values=get_count_recruits(),
options=build_option_list(1)
)
@discord.ui.select(
custom_id="yes50_2",
placeholder="Rekruten wählen...",
min_values=1,
max_values=get_count_recruits(),
options=build_option_list(2)
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
await process_yes_vote(select, interaction)
def create_yes_embed():
embed = discord.Embed(
@@ -169,7 +204,10 @@ def create_yes_embed():
async def send_yes_message(channel):
message = await channel.send(embed=create_yes_embed(), view=Yes_select_inst)
if get_count_recruits(1) <= 25:
message = await channel.send(embed=create_yes_embed(), view=Yes_select_inst25)
else:
message = await channel.send(embed=create_yes_embed(), view=Yes_select_inst50)
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_voting_yes'", (message.id, ))
async def edit_yes_message():
@@ -178,10 +216,18 @@ async def edit_yes_message():
cur.execute("SELECT value FROM settings WHERE name='message_voting_yes'")
message = await channel.fetch_message(int(cur.fetchone()[0]))
conn.commit()
global Yes_select_inst
Yes_select_inst.children[0].options = build_option_list()
Yes_select_inst.children[0].max_values = get_count_recruits()
await message.edit(embed=create_yes_embed(), view=Yes_select_inst)
if get_count_recruits(1) <= 25:
global Yes_select_inst25
Yes_select_inst25.children[0].options = build_option_list()
Yes_select_inst25.children[0].max_values = get_count_recruits()
await message.edit(embed=create_yes_embed(), view=Yes_select_inst25)
else:
global Yes_select_inst50
Yes_select_inst50.children[0].options = build_option_list()
Yes_select_inst50.children[1].options = build_option_list(2)
Yes_select_inst50.children[0].max_values = get_count_recruits()
Yes_select_inst50.children[1].max_values = get_count_recruits()
await message.edit(embed=create_yes_embed(), view=Yes_select_inst50)
def insert_no_vote(recruit_id, voter_id, reason):
@@ -256,21 +302,14 @@ class no_clicked_but_yes_vote_question(discord.ui.View):
)
await interaction.response.send_message(embed=embed, ephemeral=True)
class No_select(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="no1",
placeholder="Rekruten wählen...",
min_values=1,
max_values=1,
options=build_option_list()
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
cur.execute("SELECT no_votes.reason, recruits.nickname, no_votes.id FROM recruits, no_votes WHERE recruits.discord_id = no_votes.discord_id_recruit AND no_votes.discord_id_voter = ? AND no_votes.discord_id_recruit = ?", (interaction.user.id, select.values[0]))
async def process_no_vote(interaction, select):
cur.execute(
"SELECT no_votes.reason, recruits.nickname, no_votes.id FROM recruits, no_votes WHERE recruits.discord_id = no_votes.discord_id_recruit AND no_votes.discord_id_voter = ? AND no_votes.discord_id_recruit = ?",
(interaction.user.id, select.values[0]))
no_vote = cur.fetchall()
cur.execute("SELECT recruits.nickname, yes_votes.id FROM recruits, yes_votes WHERE yes_votes.discord_id_voter = ? AND yes_votes.discord_id_recruit = ? AND recruits.discord_id = yes_votes.discord_id_recruit", (interaction.user.id, select.values[0]))
cur.execute(
"SELECT recruits.nickname, yes_votes.id FROM recruits, yes_votes WHERE yes_votes.discord_id_voter = ? AND yes_votes.discord_id_recruit = ? AND recruits.discord_id = yes_votes.discord_id_recruit",
(interaction.user.id, select.values[0]))
yes_vote = cur.fetchall()
if yes_vote:
yes_question_inst = no_clicked_but_yes_vote_question()
@@ -294,10 +333,45 @@ class No_select(discord.ui.View):
)
embed.add_field(name="Rekrut", value=no_vote[0][1])
embed.add_field(name="Angegebener Grund", value=no_vote[0][0])
await interaction.response.send_message(embed=embed, view=no_question_inst, ephemeral = True)
await interaction.response.send_message(embed=embed, view=no_question_inst, ephemeral=True)
else:
await reason(select.values[0], interaction)
class No_select25(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="no25",
placeholder="Rekruten wählen...",
min_values=1,
max_values=1,
options=build_option_list()
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
await process_no_vote(interaction, select)
class No_select50(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # timeout of the view must be set to None
@discord.ui.select(
custom_id="no50_1",
placeholder="Rekruten wählen...",
min_values=1,
max_values=1,
options=build_option_list()
)
@discord.ui.select(
custom_id="no50_2",
placeholder="Rekruten wählen...",
min_values=1,
max_values=1,
options=build_option_list(2)
)
async def select_callback(self, select, interaction): # the function called when the user is done selecting options
await process_no_vote(interaction, select)
def create_no_embed():
embed = discord.Embed(
@@ -309,7 +383,11 @@ def create_no_embed():
async def send_no_message(channel):
message = await channel.send(embed=create_no_embed(), view=no_select_inst)
if get_count_recruits(1) <= 25:
message = await channel.send(embed=create_no_embed(), view=no_select_inst25)
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_voting_no'", (message.id, ))
else:
message = await channel.send(embed=create_no_embed(), view=no_select_inst50)
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_voting_no'", (message.id, ))
@@ -319,9 +397,15 @@ async def edit_no_message():
cur.execute("SELECT value FROM settings WHERE name='message_voting_no'")
message = await channel.fetch_message(int(cur.fetchone()[0]))
conn.commit()
global no_select_inst
no_select_inst.children[0].options = build_option_list()
await message.edit(embed=create_no_embed(), view=no_select_inst)
if get_count_recruits(1) <= 25:
global no_select_inst25
no_select_inst25.children[0].options = build_option_list()
await message.edit(embed=create_no_embed(), view=no_select_inst25)
else:
global no_select_inst50
no_select_inst50.children[0].options = build_option_list()
no_select_inst50.children[1].options = build_option_list()
await message.edit(embed=create_no_embed(), view=no_select_inst50)
class delete_and_view_votes_message(discord.ui.View):
def __init__(self):