Code-Society-Lab / grace

The official Code Society Discord bot
GNU General Public License v3.0
18 stars 12 forks source link

Voting #67

Closed MrNesli closed 1 year ago

MrNesli commented 1 year ago

Voting System #40

Command:

/poll create title=<poll title> options_count=<number of poll options> poll_time=<poll duration>

options_count default value = 2 poll_time default value = 120 secs

Possible improvements:

image

MrNesli commented 1 year ago

Oops I messed up a little with commits

MrNesli commented 1 year ago

Omg, I did fucky wacky again :)

PenguinBoi12 commented 1 year ago

I decided to write you an example on how to do a countdown that changes the message at the end of the countdown. This will be an modified version of the PagedEmbed view and to make this easier to read, I will only include the new code and old code will be represented by ....

class PagedEmbedView(View):
    def __init__(self, embeds: List[Embed], seconds: int = 30):
        ...
        self._seconds = seconds

    ...

    async def send(self, ctx: Context, ephemeral: bool = True):
        self.__message = await ctx.send(embed=self.__embeds.current, view=self, ephemeral=ephemeral)
        asyncio.create_task(self.__countdown_task())

   async def refresh(self):
       await self.__message.edit(embed=self.__embeds.current, view=self)

    async def __countdown_task(self):
        while self._seconds > 0:
            self.__embeds.current.set_footer(text=f"Time left: {self._seconds}")
            await self.refresh()

            self._seconds -= 1
            await asyncio.sleep(1)
        await self.__countdown_callback()

    async def __countdown_callback(self):
        self.__embeds.current.title = "Time's up!"
        self.__embeds.current.set_footer(text="")
        self.clear_items()

        await self.refresh()

This is what it looks like Peek 02-12-2022 21-43