Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ankety-upgrade' into jachym_2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheXer committed Sep 3, 2023
2 parents 2c5cbea + 24212d5 commit 8cbbfa6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 46 deletions.
19 changes: 13 additions & 6 deletions cogs/poll_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def pool(
question: str,
answer: Transform[list[str, ...], OptionsTransformer],
date_time: Transform[datetime.datetime, DatetimeTransformer] | None,
) -> discord.Message:
):
await interaction.response.send_message(embed=PollEmbedBase("Nahrávám anketu..."))
message = await interaction.original_response()

Expand All @@ -57,11 +57,11 @@ async def pool(
await PollDatabase(self.bot.pool).add(poll)
await VoteButtonDatabase(self.bot.pool).add_options(poll)

self.bot.active_discord_polls.add((poll, message))
await self.bot.set_presence()

logger.info(f"Successfully added Pool - {message.id}")
return await message.edit(embed=embed, view=view)

await message.edit(embed=embed, view=view)
self.bot.active_discord_polls.add((poll, message))


class PollTaskLoops(commands.Cog):
Expand All @@ -76,14 +76,21 @@ async def send_completed_pool(self):
continue

embed = message.embeds[0]
embed.title = f"{embed.title[0]} [UZAVŘENO] {embed.title[1:]}"
embed_copy = embed.copy()
embed_copy.title = f"{embed.title[0]} [UZAVŘENO] {embed.title[1:]}"
embed_copy.remove_field(len(embed_copy.fields) - 1)

channel = self.bot.get_channel(poll.channel_id)
await channel.send(embed=embed)
await channel.send(embed=embed_copy)

asyncio.create_task(PollDatabase(self.bot.pool).remove(poll.message_id))
asyncio.create_task(message.delete())
self.bot.active_discord_polls.remove((poll, message))

@send_completed_pool.before_loop
async def prepare_loop(self):
await self.bot.wait_until_ready()


async def setup(bot):
await bot.add_cog(PollCreate(bot))
Expand Down
4 changes: 0 additions & 4 deletions src/UNKNOWN.egg-info/PKG-INFO

This file was deleted.

19 changes: 0 additions & 19 deletions src/UNKNOWN.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/UNKNOWN.egg-info/dependency_links.txt

This file was deleted.

6 changes: 0 additions & 6 deletions src/UNKNOWN.egg-info/top_level.txt

This file was deleted.

12 changes: 8 additions & 4 deletions src/ui/error_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ async def on_error(self, interaction: Interaction, error: Exception, item: Item)


class TooManyOptionsError(PrettyError):
"Whether the view has too many options."
"""Whether the view has too many options."""

pass


class TooFewOptionsError(PrettyError):
"Whether the view has too few options."
"""Whether the view has too few options."""

pass


class NoPermissionError(PrettyError):
"Whether the user has no permissions to edit."
"""Whether the user has no permissions to edit."""

pass


class DatetimeNotRecognizedError(PrettyError):
"Whether the datetime is not recognized."
"""Whether the datetime is not recognized."""

pass
22 changes: 16 additions & 6 deletions src/ui/modals.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,25 @@ async def add_item_to_embed(self) -> PollEmbed:
# To avoid circular import
from src.ui.button import ButtonBackend

options = {
"name": f"{NUMBER_EMOJIS[len(self.embed.fields)]} {self.new_option.value}",
"value": "**0** | ",
"inline": False,
}

# Lmao, not ideal, but it is what it is.
if self.embed.fields[len(self.embed.fields) - 1].value.startswith("Anketa vyprší"):
index = len(self.embed.fields) - 1
else:
index = len(self.embed.fields)

options["index"] = index

self.view.add_item(
ButtonBackend(
label=self.new_option.value,
emoji=NUMBER_EMOJIS[len(self.embed.fields)],
index=len(self.embed.fields),
index=index,
poll=self.poll,
custom_id=f"{len(self.embed.fields)}:{self.poll.message_id}",
embed=self.embed,
Expand All @@ -48,8 +62,4 @@ async def add_item_to_embed(self) -> PollEmbed:
)
await VoteButtonDatabase(self.db_poll).add_option(self.poll, self.new_option.value)

return self.embed.add_field(
name=f"{NUMBER_EMOJIS[len(self.embed.fields)]} {self.new_option.value}",
value="**0** | ",
inline=False,
)
return self.embed.insert_field_at(**options)

0 comments on commit 8cbbfa6

Please sign in to comment.