Added Possibility to view votes
This commit is contained in:
96
main.py
96
main.py
@@ -45,6 +45,7 @@ async def on_ready():
|
||||
global no_select_inst
|
||||
no_select_inst = No_select()
|
||||
bot.add_view(no_select_inst)
|
||||
bot.add_view(delete_message())
|
||||
print(f"{bot.user} is ready and online!")
|
||||
|
||||
conn = connect_db()
|
||||
@@ -114,7 +115,6 @@ async def send_yes_message(channel):
|
||||
message = await channel.send(embed=create_yes_embed(), view=Yes_select_inst)
|
||||
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_voting_yes'", (message.id, ))
|
||||
|
||||
|
||||
async def edit_yes_message():
|
||||
cur.execute("SELECT value FROM settings WHERE name='channel_voting'")
|
||||
channel = bot.get_channel(int(cur.fetchone()[0]))
|
||||
@@ -165,8 +165,11 @@ async def reason(discord_id, interaction):
|
||||
|
||||
class no_question(discord.ui.View):
|
||||
discord_id = ""
|
||||
vote_id = ""
|
||||
@discord.ui.button(label="Ja", style=discord.ButtonStyle.green,)
|
||||
async def yes(self, button, interaction):
|
||||
cur.execute("DELETE FROM no_votes WHERE id = ?", (self.vote_id, ))
|
||||
conn.commit()
|
||||
await reason(self.discord_id, interaction)
|
||||
@discord.ui.button(label="Nein", style=discord.ButtonStyle.grey)
|
||||
async def no(self, button, interaction):
|
||||
@@ -177,6 +180,23 @@ class no_question(discord.ui.View):
|
||||
)
|
||||
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||
|
||||
class no_clicked_but_yes_vote_question(discord.ui.View):
|
||||
discord_id = ""
|
||||
vote_id = ""
|
||||
@discord.ui.button(label="Ja", style=discord.ButtonStyle.green,)
|
||||
async def yes(self, button, interaction):
|
||||
cur.execute("DELETE FROM yes_votes WHERE id = ?", (self.vote_id, ))
|
||||
conn.commit()
|
||||
await reason(self.discord_id, interaction)
|
||||
@discord.ui.button(label="Nein", style=discord.ButtonStyle.grey)
|
||||
async def no(self, button, interaction):
|
||||
embed = discord.Embed(
|
||||
title="Aktion abgebrochen",
|
||||
description="Es wurde nichts gespeichert.\nDeine Ja-Stimme bleibt bestehen.\nWenn du diese löschen möchtest, wähle die Option 'Stimme entfernen'",
|
||||
color=discord.Colour.blurple(),
|
||||
)
|
||||
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
|
||||
@@ -189,21 +209,35 @@ class No_select(discord.ui.View):
|
||||
)
|
||||
|
||||
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 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]))
|
||||
vote = cur.fetchall()
|
||||
if not vote:
|
||||
await reason(select.values[0], interaction)
|
||||
else:
|
||||
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]))
|
||||
yes_vote = cur.fetchall()
|
||||
if yes_vote:
|
||||
yes_question_inst = no_clicked_but_yes_vote_question()
|
||||
yes_question_inst.discord_id = select.values[0] # Discord-ID des Rekruten
|
||||
yes_question_inst.vote_id = yes_vote[0][1]
|
||||
embed = discord.Embed(
|
||||
title="Du hast bereits dem Rekruten eine Ja-Stimme gegeben.",
|
||||
description="Möchtest du diese Stimme löschen und eine Nein-Stimme abgeben?",
|
||||
color=discord.Colour.red(),
|
||||
)
|
||||
embed.add_field(name="Rekrut", value=yes_vote[0][0])
|
||||
await interaction.response.send_message(embed=embed, view=yes_question_inst, ephemeral=True)
|
||||
elif no_vote:
|
||||
no_question_inst = no_question()
|
||||
no_question_inst.discord_id = select.values[0]
|
||||
no_question_inst.vote_id = no_vote[0][2]
|
||||
embed = discord.Embed(
|
||||
title="Du hast bereits für den Rekruten abgestimmt.",
|
||||
description="Möchtest du deine jetzige Stimme löschen und einen neuen Grund angeben?",
|
||||
color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from
|
||||
)
|
||||
embed.add_field(name="Rekrut", value=vote[0][1])
|
||||
embed.add_field(name="Angegebener Grund", value=vote[0][0])
|
||||
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)
|
||||
else:
|
||||
await reason(select.values[0], interaction)
|
||||
|
||||
|
||||
def create_no_embed():
|
||||
@@ -232,12 +266,58 @@ async def edit_no_message():
|
||||
print("Edited!")
|
||||
|
||||
|
||||
class delete_message(discord.ui.View):
|
||||
def __init__(self):
|
||||
super().__init__(timeout=None) # timeout of the view must be set to None
|
||||
@discord.ui.button(label="Stimmen einsehen", custom_id="show-votes", style=discord.ButtonStyle.grey,)
|
||||
async def view_votes(self, button, interaction):
|
||||
embed = discord.Embed(
|
||||
title="Deine Votes",
|
||||
description="Hier sind deine Ja- und Nein-Stimmen aufgelistet:",
|
||||
color=discord.Colour.blurple(),
|
||||
)
|
||||
cur.execute("SELECT recruits.nickname 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, ))
|
||||
yes_votes = cur.fetchall()
|
||||
cur.execute("SELECT recruits.nickname, no_votes.reason FROM recruits, no_votes WHERE recruits.discord_id = no_votes.discord_id_recruit AND recruits.recruit = 1 AND no_votes.discord_id_voter = ?", (interaction.user.id, ))
|
||||
no_votes = cur.fetchall()
|
||||
if yes_votes:
|
||||
yes_message = ""
|
||||
for vote in yes_votes:
|
||||
yes_message = yes_message + vote[0] + "\n"
|
||||
embed.add_field(name="Ja-Stimmen:", value=yes_message)
|
||||
if no_votes:
|
||||
no_message = ""
|
||||
for vote in no_votes:
|
||||
no_message = no_message + vote[0] + ': "' + vote[1] + '"' + "\n"
|
||||
embed.add_field(name="Nein-Stimmen:", value=no_message)
|
||||
if not yes_votes:
|
||||
if not no_votes:
|
||||
embed.description="Du hast keine Stimmen abgeben! Zock mit den Rekruten und fang an!"
|
||||
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)
|
||||
|
||||
@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):
|
||||
print("No")
|
||||
|
||||
|
||||
async def send_delete_message(channel):
|
||||
embed = discord.Embed(
|
||||
title="Stimmen einsehen oder löschen",
|
||||
description="Um deine Stimmene einzusehen oder eine Stimme zu löschen, klicke auf den entsprechenden Button.",
|
||||
color=discord.Colour.dark_red(),
|
||||
)
|
||||
message = await channel.send(embed=embed, view=delete_message())
|
||||
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_delete_vote'", (message.id, ))
|
||||
|
||||
|
||||
@settings.command(description="Sendet die Nachricht zum Abstimmen in den aktuellen Channel.")
|
||||
@default_permissions(manage_roles=True)
|
||||
async def message_voting(ctx):
|
||||
cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'channel_voting'", (ctx.channel_id, ))
|
||||
await send_yes_message(ctx.channel)
|
||||
await send_no_message(ctx.channel)
|
||||
await send_delete_message(ctx.channel)
|
||||
conn.commit()
|
||||
await ctx.respond(f"Done.", ephemeral=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user