Skip to content

Commit

Permalink
Poll buttons now terminate after the given time has passed
Browse files Browse the repository at this point in the history
  • Loading branch information
LuminatiHD committed Feb 17, 2022
1 parent a182d04 commit db85eb9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,25 +713,30 @@ async def goback(self, button: nextcord.Button, interaction: nextcord.Interactio


class Poll_Button(nextcord.ui.Button):
def __init__(self, label, view_obj):
def __init__(self, label, view_obj, duration):
super().__init__()
self.label = label
self.over = datetime.now()+timedelta(seconds=duration)
self.style = nextcord.ButtonStyle.blurple
self.view_obj = view_obj

async def callback(self, interaction: nextcord.Interaction):
if interaction.user.id in self.view_obj.voters.keys():
if interaction.user.id in self.view_obj.voters.keys() \
and self.view_obj.voters[interaction.user.id] != self.label:
await interaction.response.send_message("Dein Vote wurde geändert", ephemeral=True)

self.view_obj.voters[interaction.user.id] = self.label

if datetime.now()> self.over:
self.view_obj.stop()


class Poll_ViewObj(nextcord.ui.View):
def __init__(self, options, duration):
super().__init__(timeout=duration)
self.voters = {}
for opt in options:
self.add_item(Poll_Button(label=opt, view_obj=self))
self.add_item(Poll_Button(label=opt, view_obj=self, duration=duration))


class Vote_btns(nextcord.ui.View):
Expand Down

0 comments on commit db85eb9

Please sign in to comment.