From cae11de4fcae8d2aa3f10f814f65edf4df60f787 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 22:47:48 +0200 Subject: [PATCH 01/22] Some more Ruff fixes Signed-off-by: robertsokola --- cogs/poll_command.py | 12 +++++++----- readme.md | 1 - src/db_folder/databases.py | 7 +++++-- src/ui/button.py | 16 ++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index 302de02..92925da 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -15,7 +15,8 @@ def error_handling(answer: list[str]) -> str: if len(answer) > Poll.MAX_OPTIONS: return f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" - return f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" + if len(answer) < Poll.MIN_OPTIONS: + return f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" class PollCreate(commands.Cog): @@ -45,16 +46,17 @@ def __init__(self, bot: Jachym): answer='Odpovědi, rozděluješ odpovědi uvozovkou ("), maximálně pouze 10 možností', ) async def pool( - self, - interaction: discord.Interaction, - question: str, - answer: str, + self, + interaction: discord.Interaction, + question: str, + answer: str, ) -> discord.Message: await interaction.response.send_message( embed=PollEmbedBase("Dělám na tom, vydrž!"), ) message = await interaction.original_response() + # bugfix for answers that were empty answers = [ answer for answer in re.split("|".join(self.REGEX_PATTERN), answer) diff --git a/readme.md b/readme.md index 404abb0..8e17c8c 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,3 @@ -r

Logo Jáchyma
diff --git a/src/db_folder/databases.py b/src/db_folder/databases.py index 32ebce9..240fef7 100644 --- a/src/db_folder/databases.py +++ b/src/db_folder/databases.py @@ -1,11 +1,14 @@ from collections.abc import AsyncIterator +from typing import TYPE_CHECKING import aiomysql import discord.errors from discord import Message from loguru import logger -from src.jachym import Jachym +if TYPE_CHECKING: + from src.jachym import Jachym + from src.ui.poll import Poll @@ -68,7 +71,7 @@ async def fetch_all_answers(self, message_id) -> list[str]: tuple_of_tuples_db = await self.fetch_all_values(sql, value) return [answer for tupl in tuple_of_tuples_db for answer in tupl] - async def fetch_all_polls(self, bot: Jachym) -> AsyncIterator[Poll and Message]: + async def fetch_all_polls(self, bot: "Jachym") -> AsyncIterator[Poll and Message]: sql = "SELECT * FROM `Poll`" polls = await self.fetch_all_values(sql) diff --git a/src/ui/button.py b/src/ui/button.py index f09c9a3..51ce2f3 100644 --- a/src/ui/button.py +++ b/src/ui/button.py @@ -14,14 +14,14 @@ class ButtonBackend(discord.ui.Button): LENTGH_STRING = 30 def __init__( - self, - custom_id: str, - poll: Poll, - emoji: str, - embed: PollEmbed, - index: int, - label: str, - db_poll: aiomysql.pool.Pool, + self, + custom_id: str, + poll: Poll, + emoji: str, + embed: PollEmbed, + index: int, + label: str, + db_poll: aiomysql.pool.Pool, ) -> None: super().__init__( label=label if len(label) <= self.LENTGH_STRING else "", From 80808c29df3856412df6d3ebe738cd4c00701dd3 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 23:16:47 +0200 Subject: [PATCH 02/22] bugfix where database couldn't work Signed-off-by: robertsokola --- pyproject.toml | 4 +++- src/db_folder/databases.py | 8 ++++---- src/ui/embeds.py | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cfd22d2..a03c7d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,8 @@ ignore = [ "D", # Ignore docstrings "E501", # Line too long, let Black handle this "ANN", # typing, let mypy handle tis - "INP001" # Namespace package eeeeh + "INP001", # Namespace package eeeeh + "PLR0913", #Too many args to func call + "DTZ005", # datetime object without "tz" is not allowed ] diff --git a/src/db_folder/databases.py b/src/db_folder/databases.py index 240fef7..c30decf 100644 --- a/src/db_folder/databases.py +++ b/src/db_folder/databases.py @@ -111,14 +111,14 @@ async def add_options(self, discord_poll: Poll): ] await self.commit_many_values(sql, values) - async def add_user(self, message_id: Poll, user: int, index: int): + async def add_user(self, discord_poll: Poll, user: int, index: int): sql = "INSERT INTO `Answers`(message_id, vote_user, iter_index) VALUES (%s, %s, %s)" - values = (message_id, user, index) + values = (discord_poll.message_id, user, index) await self.commit_value(sql, values) - async def remove_user(self, message_id: Poll, user: int, index: int): + async def remove_user(self, discord_poll: Poll, user: int, index: int): sql = "DELETE FROM `Answers` WHERE message_id = %s AND vote_user = %s AND iter_index = %s" - value = (message_id, user, index) + value = (discord_poll.message_id, user, index) await self.commit_value(sql, value) async def fetch_all_users(self, poll: Poll, index: int) -> set[int]: diff --git a/src/ui/embeds.py b/src/ui/embeds.py index 1280e04..add4c01 100644 --- a/src/ui/embeds.py +++ b/src/ui/embeds.py @@ -9,6 +9,8 @@ class CooldownErrorEmbed(discord.Embed): + LIMIT = 4 + def __init__(self, seconds: float): self.seconds = round(seconds) formatted_date = discord.utils.format_dt( @@ -22,9 +24,9 @@ def __init__(self, seconds: float): ) def correct_czech_writing(self) -> str: - if self.seconds > 4: + if self.seconds > self.LIMIT: return f"{self.seconds} sekund" - if 4 >= self.seconds > 1: + if self.LIMIT >= self.seconds > 1: return f"{self.seconds} sekundy" return "sekundu" From b95a0a0e07a6b9ae637f0fe064eaa5d81d522b07 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 23:25:35 +0200 Subject: [PATCH 03/22] commit hooks Signed-off-by: robertsokola --- .github/workflows/pre-commit-config.yml | 5 +++++ .github/workflows/pre-commit.yml | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .github/workflows/pre-commit-config.yml create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit-config.yml b/.github/workflows/pre-commit-config.yml new file mode 100644 index 0000000..1898689 --- /dev/null +++ b/.github/workflows/pre-commit-config.yml @@ -0,0 +1,5 @@ +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.0.270 + hooks: + - id: ruff \ No newline at end of file diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..39483b0 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master, dev-branch, main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 \ No newline at end of file From aa240d88cf31bb99618bdf097f40a9d3a2b63ec9 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 23:26:11 +0200 Subject: [PATCH 04/22] test Signed-off-by: robertsokola --- src/ui/embeds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/embeds.py b/src/ui/embeds.py index add4c01..998e66f 100644 --- a/src/ui/embeds.py +++ b/src/ui/embeds.py @@ -9,7 +9,7 @@ class CooldownErrorEmbed(discord.Embed): - LIMIT = 4 + LIMIT = 4x def __init__(self, seconds: float): self.seconds = round(seconds) From b191eb3a3f584b783f46646fc8d3065ae2c8adc4 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 23:30:29 +0200 Subject: [PATCH 05/22] test Signed-off-by: robertsokola --- .../workflows/{pre-commit-config.yml => pre-commit-config.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{pre-commit-config.yml => pre-commit-config.yaml} (100%) diff --git a/.github/workflows/pre-commit-config.yml b/.github/workflows/pre-commit-config.yaml similarity index 100% rename from .github/workflows/pre-commit-config.yml rename to .github/workflows/pre-commit-config.yaml From 9a582f894cbdfea3b745db26c559d04417cbf366 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 5 Jun 2023 23:46:29 +0200 Subject: [PATCH 06/22] Test Signed-off-by: robertsokola --- .github/workflows/.pre-commit-config.yaml | 5 +++++ .github/workflows/pre-commit-config.yaml | 5 ----- src/ui/embeds.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/.pre-commit-config.yaml delete mode 100644 .github/workflows/pre-commit-config.yaml diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml new file mode 100644 index 0000000..f16a370 --- /dev/null +++ b/.github/workflows/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.270 + hooks: + - id: ruff \ No newline at end of file diff --git a/.github/workflows/pre-commit-config.yaml b/.github/workflows/pre-commit-config.yaml deleted file mode 100644 index 1898689..0000000 --- a/.github/workflows/pre-commit-config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -- repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.0.270 - hooks: - - id: ruff \ No newline at end of file diff --git a/src/ui/embeds.py b/src/ui/embeds.py index 998e66f..add4c01 100644 --- a/src/ui/embeds.py +++ b/src/ui/embeds.py @@ -9,7 +9,7 @@ class CooldownErrorEmbed(discord.Embed): - LIMIT = 4x + LIMIT = 4 def __init__(self, seconds: float): self.seconds = round(seconds) From 815d1f829530165814db0a8086de50368659779a Mon Sep 17 00:00:00 2001 From: robertsokola Date: Tue, 6 Jun 2023 00:00:59 +0200 Subject: [PATCH 07/22] Test Signed-off-by: robertsokola --- .github/workflows/pre-commit.yml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 39483b0..0000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: pre-commit - -on: - pull_request: - push: - branches: [master, dev-branch, main] - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.0 \ No newline at end of file From 859fa2633464a175bf2317684d5e5462940f733b Mon Sep 17 00:00:00 2001 From: robertsokola Date: Tue, 6 Jun 2023 00:02:34 +0200 Subject: [PATCH 08/22] Test Signed-off-by: robertsokola --- .github/workflows/.pre-commit-config.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index f16a370..c25dc01 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -2,4 +2,5 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.0.270 hooks: - - id: ruff \ No newline at end of file + - id: ruff + on: push \ No newline at end of file From 5236069f09436a45b82e34ff0d143838f0f8b241 Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Tue, 13 Jun 2023 15:00:13 +0200 Subject: [PATCH 09/22] Formatting, added new file for handling error embeds with using raise --- cogs/error.py | 6 +++--- cogs/morserovka.py | 6 +----- cogs/poll_command.py | 7 ++----- cogs/sync_command.py | 8 ++++---- pyproject.toml | 5 +++++ src/db_folder/databases.py | 9 ++------- src/ui/button.py | 4 +--- src/ui/error_handling.py | 0 src/ui/poll.py | 20 ++++++++------------ tests/manual_testing_generator.py | 4 +--- 10 files changed, 27 insertions(+), 42 deletions(-) create mode 100644 src/ui/error_handling.py diff --git a/cogs/error.py b/cogs/error.py index 5d4031d..2ba44ff 100644 --- a/cogs/error.py +++ b/cogs/error.py @@ -22,9 +22,9 @@ def __init__(self, bot): @commands.Cog.listener() async def on_command_error( - self, - ctx: commands.Context, - error: commands.CommandError, + self, + ctx: commands.Context, + error: commands.CommandError, ): match error: case commands.MissingPermissions(): diff --git a/cogs/morserovka.py b/cogs/morserovka.py index f84e6cc..19225b8 100644 --- a/cogs/morserovka.py +++ b/cogs/morserovka.py @@ -4,7 +4,6 @@ from discord import Message, app_commands from discord.ext import commands - # Klasická morseovka @@ -81,10 +80,7 @@ async def zasifruj(self, interaction: discord.Interaction, message: str) -> Mess @app_commands.command(name="desifruj", description="Dešifruj text z morserovky!") @app_commands.describe(message="Věta nebo slovo pro dešifrování") async def desifruj(self, interaction: discord.Interaction, message: str) -> Message: - decipher = "".join( - self.REVERSED_MORSE_CODE_DICT.get(letter) - for letter in re.split(r"\/|\\|\|", message) - ) + decipher = "".join(self.REVERSED_MORSE_CODE_DICT.get(letter) for letter in re.split(r"\/|\\|\|", message)) return await interaction.response.send_message(decipher) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index 92925da..534f91f 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -17,6 +17,7 @@ def error_handling(answer: list[str]) -> str: return f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" if len(answer) < Poll.MIN_OPTIONS: return f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" + return None class PollCreate(commands.Cog): @@ -57,11 +58,7 @@ async def pool( message = await interaction.original_response() # bugfix for answers that were empty - answers = [ - answer - for answer in re.split("|".join(self.REGEX_PATTERN), answer) - if answer.strip() - ] + answers = [answer for answer in re.split("|".join(self.REGEX_PATTERN), answer) if answer.strip()] if error_handling(answers): return await message.edit(embed=PollEmbedBase(error_handling(answers))) diff --git a/cogs/sync_command.py b/cogs/sync_command.py index 7789b38..45ce82b 100644 --- a/cogs/sync_command.py +++ b/cogs/sync_command.py @@ -16,10 +16,10 @@ def __init__(self, bot: "Jachym"): @commands.guild_only() @commands.is_owner() async def sync( - self, - ctx: Context, - guilds: Greedy[discord.Guild], - spec: Literal["-", "*", "^"] | None = None, + self, + ctx: Context, + guilds: Greedy[discord.Guild], + spec: Literal["-", "*", "^"] | None = None, ) -> None: """ A command to sync all slash commands to servers user requires. Works like this: diff --git a/pyproject.toml b/pyproject.toml index a03c7d5..faae938 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,3 +11,8 @@ ignore = [ "DTZ005", # datetime object without "tz" is not allowed ] +line-length = 120 + +[tool.black] + +line-length = 120 \ No newline at end of file diff --git a/src/db_folder/databases.py b/src/db_folder/databases.py index c30decf..b2f41ee 100644 --- a/src/db_folder/databases.py +++ b/src/db_folder/databases.py @@ -105,10 +105,7 @@ def __init__(self, pool: aiomysql.pool.Pool): async def add_options(self, discord_poll: Poll): sql = "INSERT INTO `VoteButtons`(message_id, answers) VALUES (%s, %s)" - values = [ - (discord_poll.message_id, vote_option) - for vote_option in discord_poll.options - ] + values = [(discord_poll.message_id, vote_option) for vote_option in discord_poll.options] await self.commit_many_values(sql, values) async def add_user(self, discord_poll: Poll, user: int, index: int): @@ -122,9 +119,7 @@ async def remove_user(self, discord_poll: Poll, user: int, index: int): await self.commit_value(sql, value) async def fetch_all_users(self, poll: Poll, index: int) -> set[int]: - sql = ( - "SELECT vote_user FROM `Answers` WHERE message_id = %s AND iter_index = %s" - ) + sql = "SELECT vote_user FROM `Answers` WHERE message_id = %s AND iter_index = %s" values = (poll.message_id, index) users_voted_for = await self.fetch_all_values(sql, values) diff --git a/src/ui/button.py b/src/ui/button.py index 51ce2f3..4b83cc7 100644 --- a/src/ui/button.py +++ b/src/ui/button.py @@ -50,9 +50,7 @@ async def toggle_vote(self, interaction: discord.Interaction) -> set[str]: await vote_button_db.remove_user(self.poll, user, self.index) users_id.remove(user) - return { - interaction.guild.get_member(user_id).display_name for user_id in users_id - } + return {interaction.guild.get_member(user_id).display_name for user_id in users_id} async def edit_embed(self, members: set[str]) -> discord.Embed: return self.embed.set_field_at( diff --git a/src/ui/error_handling.py b/src/ui/error_handling.py new file mode 100644 index 0000000..e69de29 diff --git a/src/ui/poll.py b/src/ui/poll.py index 397cf3b..834c153 100644 --- a/src/ui/poll.py +++ b/src/ui/poll.py @@ -19,23 +19,19 @@ class Poll: ] def __init__( - self, - message_id: int, - channel_id: int, - question: str, - options: list[str], - user_id: int | None = None, - date_created: datetime | None = None, + self, + message_id: int, + channel_id: int, + question: str, + options: list[str], + user_id: int | None = None, + date_created: datetime | None = None, ): self._message_id = message_id self._channel_id = channel_id self._question = question self._options = options - self._date_created_at = ( - datetime.now().strftime("%Y-%m-%d") - if date_created is None - else date_created - ) + self._date_created_at = datetime.now().strftime("%Y-%m-%d") if date_created is None else date_created self._user_id = user_id @property diff --git a/tests/manual_testing_generator.py b/tests/manual_testing_generator.py index aa6b6e8..dbe4b7f 100644 --- a/tests/manual_testing_generator.py +++ b/tests/manual_testing_generator.py @@ -18,9 +18,7 @@ def test_pools(count=2) -> str: def test_events(): date = datetime.now() + timedelta(minutes=1) - test_string = ( - f'!udalost create "Name" "Description" "{date.strftime("%d.%m.%Y %H:%M")}"' - ) + test_string = f'!udalost create "Name" "Description" "{date.strftime("%d.%m.%Y %H:%M")}"' return test_string From afd2b88a52f8897233e06abee880ab31cf9b3d5d Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Thu, 15 Jun 2023 14:30:56 +0200 Subject: [PATCH 10/22] Basic Exception classes, test if they work as intended --- cogs/error.py | 24 ++++++++---------------- cogs/poll_command.py | 8 ++++---- src/ui/error_handling.py | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/cogs/error.py b/cogs/error.py index 2ba44ff..9843050 100644 --- a/cogs/error.py +++ b/cogs/error.py @@ -1,7 +1,7 @@ -import logging - from discord.ext import commands +from src.ui.error_handling import EmbedBaseError + class Error(commands.Cog): """Basic class for catching errors and sending a message""" @@ -9,24 +9,16 @@ class Error(commands.Cog): def __init__(self, bot): self.bot = bot - self.logger = logging.getLogger("discord") - handler = logging.FileHandler( - filename="discord.log", - encoding="utf-8", - mode="w", - ) - handler.setFormatter( - logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"), - ) - self.logger.addHandler(handler) - @commands.Cog.listener() async def on_command_error( - self, - ctx: commands.Context, - error: commands.CommandError, + self, + ctx: commands.Context, + error: commands.CommandError, ): match error: + case EmbedBaseError(): + return await error.send() + case commands.MissingPermissions(): return await ctx.send("Chybí ti požadovaná práva!") diff --git a/cogs/poll_command.py b/cogs/poll_command.py index 534f91f..bf43378 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -1,5 +1,5 @@ import re - +from src.ui.error_handling import TooFewOptionsError, TooManyOptionsError import discord from discord import app_commands from discord.ext import commands @@ -12,11 +12,11 @@ from src.ui.poll_view import PollView -def error_handling(answer: list[str]) -> str: +def error_handling(answer: list[str]) -> TooFewOptionsError | TooManyOptionsError | None: if len(answer) > Poll.MAX_OPTIONS: - return f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" + raise TooManyOptionsError(f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!") if len(answer) < Poll.MIN_OPTIONS: - return f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" + raise TooFewOptionsError(f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!") return None diff --git a/src/ui/error_handling.py b/src/ui/error_handling.py index e69de29..bc66b51 100644 --- a/src/ui/error_handling.py +++ b/src/ui/error_handling.py @@ -0,0 +1,24 @@ + +class EmbedBaseError(Exception): + def __init__(self, message, interaction, inner): + super().__init__(message, inner) + self.message = message + self.interaction = interaction + + async def send(self): + args = { + "content": self.message, + "ephemeral": True + } + if not self.interaction.response.is_done(): + await self.interaction.response.send_message(**args) + else: + self.interaction.followup.send(**args) + +class TooManyOptionsError(EmbedBaseError): + pass + +class TooFewOptionsError(EmbedBaseError): + pass + + From 728be46b51ddad981910ccf0c3030c89499ae659 Mon Sep 17 00:00:00 2001 From: Robert Sokola <76487619+TheXer@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:13:47 +0200 Subject: [PATCH 11/22] Update .pre-commit-config.yaml --- .github/workflows/.pre-commit-config.yaml | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index c25dc01..5adc2cc 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -1,6 +1,21 @@ -repos: - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.270 - hooks: - - id: ruff - on: push \ No newline at end of file +on: push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Set up CPython + uses: actions/setup-python@v4 + + - name: Install dependencies + id: install-deps + run: | + python -m pip install --upgrade pip setuptools wheel ruff + pip install -U -r requirements.txt + + - name: Ruff Check + uses: jpetrucciani/ruff-check@0.0.239 + From b71b713d4c0a33b3e6ecfe46c9d23cc3328be504 Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Fri, 16 Jun 2023 10:26:29 +0200 Subject: [PATCH 12/22] Repaired pyproject.toml, formatting --- cogs/error.py | 18 +++++++----------- cogs/poll_command.py | 9 ++++++--- pyproject.toml | 23 ++++++++++++++--------- src/ui/error_handling.py | 7 +++---- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cogs/error.py b/cogs/error.py index 9843050..bfc76d7 100644 --- a/cogs/error.py +++ b/cogs/error.py @@ -1,4 +1,5 @@ from discord.ext import commands +from loguru import logger from src.ui.error_handling import EmbedBaseError @@ -11,31 +12,26 @@ def __init__(self, bot): @commands.Cog.listener() async def on_command_error( - self, - ctx: commands.Context, - error: commands.CommandError, + self, + ctx: commands.Context, + error: commands.CommandError, ): match error: case EmbedBaseError(): + logger.error(error) return await error.send() case commands.MissingPermissions(): + logger.error(f"Missing Permissions: {error}") return await ctx.send("Chybí ti požadovaná práva!") case commands.CommandNotFound(): return None case _: - self.logger.critical( - f"{ctx.message.id}, {ctx.message.content} | {error}", - ) - print(error) + logger.critical(f"Catched an error: {error}") return None - @commands.Cog.listener() - async def on_command(self, ctx: commands.Context): - self.logger.info(f"{ctx.message.id} {ctx.message.content}") - async def setup(bot): await bot.add_cog(Error(bot)) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index bf43378..f18a9db 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -1,5 +1,5 @@ import re -from src.ui.error_handling import TooFewOptionsError, TooManyOptionsError + import discord from discord import app_commands from discord.ext import commands @@ -8,15 +8,18 @@ from src.db_folder.databases import PollDatabase, VoteButtonDatabase from src.jachym import Jachym from src.ui.embeds import PollEmbed, PollEmbedBase +from src.ui.error_handling import TooFewOptionsError, TooManyOptionsError from src.ui.poll import Poll from src.ui.poll_view import PollView def error_handling(answer: list[str]) -> TooFewOptionsError | TooManyOptionsError | None: if len(answer) > Poll.MAX_OPTIONS: - raise TooManyOptionsError(f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!") + msg = f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" + raise TooManyOptionsError(msg) if len(answer) < Poll.MIN_OPTIONS: - raise TooFewOptionsError(f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!") + msg = f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" + raise TooFewOptionsError(msg) return None diff --git a/pyproject.toml b/pyproject.toml index faae938..d12e56c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,19 @@ [tool.ruff] -select = ["ALL"] - -ignore = [ - "D", # Ignore docstrings - "E501", # Line too long, let Black handle this - "ANN", # typing, let mypy handle tis - "INP001", # Namespace package eeeeh - "PLR0913", #Too many args to func call - "DTZ005", # datetime object without "tz" is not allowed +select = [ + "E", # pycodestyle + "F", # pyflakes + "UP", # pyupgrade, + "I", # isort + "UP", # pyupgrade + "ASYNC", + "BLE", # Blind Exception + "T20", # Found a print! + "RET", # Unnecessary return + "SIM", # Simplify +] +exclude = [ + "tests", ] line-length = 120 diff --git a/src/ui/error_handling.py b/src/ui/error_handling.py index bc66b51..1af1413 100644 --- a/src/ui/error_handling.py +++ b/src/ui/error_handling.py @@ -1,4 +1,3 @@ - class EmbedBaseError(Exception): def __init__(self, message, interaction, inner): super().__init__(message, inner) @@ -8,17 +7,17 @@ def __init__(self, message, interaction, inner): async def send(self): args = { "content": self.message, - "ephemeral": True + "ephemeral": True, } if not self.interaction.response.is_done(): await self.interaction.response.send_message(**args) else: self.interaction.followup.send(**args) + class TooManyOptionsError(EmbedBaseError): pass + class TooFewOptionsError(EmbedBaseError): pass - - From 68bd73ed214c452ec3e084a98bc814713344ad45 Mon Sep 17 00:00:00 2001 From: Robert Sokola <76487619+TheXer@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:31:07 +0200 Subject: [PATCH 13/22] Update .pre-commit-config.yaml --- .github/workflows/.pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index 5adc2cc..9a858b9 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -17,5 +17,5 @@ jobs: pip install -U -r requirements.txt - name: Ruff Check - uses: jpetrucciani/ruff-check@0.0.239 + run: ruff check . From a79b86de1bf6c300457af22928e26a6439da3673 Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Fri, 16 Jun 2023 10:32:11 +0200 Subject: [PATCH 14/22] test --- cogs/poll_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index f18a9db..e64fec7 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -71,7 +71,7 @@ async def pool( question=question, options=answers, user_id=interaction.user.id, - ) + embed = PollEmbed(poll) view = PollView(poll, embed, db_poll=self.bot.pool) From 297eb5d487a38ae614472117fcdbec3c425ea2ee Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Fri, 16 Jun 2023 10:33:31 +0200 Subject: [PATCH 15/22] OK, everything with precommit hooks works now, horray --- cogs/poll_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index e64fec7..f18a9db 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -71,7 +71,7 @@ async def pool( question=question, options=answers, user_id=interaction.user.id, - + ) embed = PollEmbed(poll) view = PollView(poll, embed, db_poll=self.bot.pool) From 97d6d077b829b8f8a25ba49519bee379fa41379d Mon Sep 17 00:00:00 2001 From: Robert Sokola <76487619+TheXer@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:41:37 +0200 Subject: [PATCH 16/22] Update .pre-commit-config.yaml Added Black formatter --- .github/workflows/.pre-commit-config.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index 9a858b9..768b1da 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -13,9 +13,14 @@ jobs: - name: Install dependencies id: install-deps run: | - python -m pip install --upgrade pip setuptools wheel ruff + python -m pip install --upgrade pip setuptools wheel ruff black pip install -U -r requirements.txt + + - name: Black check + run: black . - name: Ruff Check run: ruff check . + + From 6433590a15457864a6030e40126eba298a33b972 Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Fri, 16 Jun 2023 10:42:12 +0200 Subject: [PATCH 17/22] Test Black --- cogs/poll_command.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index f18a9db..4b15524 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -61,7 +61,9 @@ async def pool( message = await interaction.original_response() # bugfix for answers that were empty - answers = [answer for answer in re.split("|".join(self.REGEX_PATTERN), answer) if answer.strip()] + answers = [answer + for answer in re.split("|".join(self.REGEX_PATTERN), answer) + if answer.strip()] if error_handling(answers): return await message.edit(embed=PollEmbedBase(error_handling(answers))) From d487ec8c62ca199535441b5d22ae4fb0dff5af0a Mon Sep 17 00:00:00 2001 From: Robert Sokola <76487619+TheXer@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:52:52 +0200 Subject: [PATCH 18/22] Update .pre-commit-config.yaml --- .github/workflows/.pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index 768b1da..824eb7d 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -15,9 +15,9 @@ jobs: run: | python -m pip install --upgrade pip setuptools wheel ruff black pip install -U -r requirements.txt - - - name: Black check - run: black . + + - name: Black format + uses: psf/black@stable - name: Ruff Check run: ruff check . From fbdbcd1b99e910c0b62de57fd909b92d311ff491 Mon Sep 17 00:00:00 2001 From: z004rmyh Date: Fri, 16 Jun 2023 10:59:03 +0200 Subject: [PATCH 19/22] Testing success --- cogs/poll_command.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cogs/poll_command.py b/cogs/poll_command.py index 4b15524..f18a9db 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -61,9 +61,7 @@ async def pool( message = await interaction.original_response() # bugfix for answers that were empty - answers = [answer - for answer in re.split("|".join(self.REGEX_PATTERN), answer) - if answer.strip()] + answers = [answer for answer in re.split("|".join(self.REGEX_PATTERN), answer) if answer.strip()] if error_handling(answers): return await message.edit(embed=PollEmbedBase(error_handling(answers))) From 550987fb0b1943aa981a18e1c153898f504491db Mon Sep 17 00:00:00 2001 From: Robert Sokola <76487619+TheXer@users.noreply.github.com> Date: Fri, 16 Jun 2023 11:00:12 +0200 Subject: [PATCH 20/22] Update .pre-commit-config.yaml --- .github/workflows/.pre-commit-config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/.pre-commit-config.yaml b/.github/workflows/.pre-commit-config.yaml index 824eb7d..fd5d2ed 100644 --- a/.github/workflows/.pre-commit-config.yaml +++ b/.github/workflows/.pre-commit-config.yaml @@ -13,8 +13,7 @@ jobs: - name: Install dependencies id: install-deps run: | - python -m pip install --upgrade pip setuptools wheel ruff black - pip install -U -r requirements.txt + python -m pip install --upgrade pip setuptools wheel ruff - name: Black format uses: psf/black@stable From 7d4b3e984d9f15dc3148a0afb8e24286ed94b6a1 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Mon, 19 Jun 2023 23:36:40 +0200 Subject: [PATCH 21/22] Functional errors using raise keyword. Signed-off-by: robertsokola --- cogs/error.py | 54 +++++++++++++++++++++------------ cogs/poll_command.py | 64 +++++++++++++++++++++------------------- src/ui/error_handling.py | 23 --------------- 3 files changed, 69 insertions(+), 72 deletions(-) delete mode 100644 src/ui/error_handling.py diff --git a/cogs/error.py b/cogs/error.py index bfc76d7..98804bb 100644 --- a/cogs/error.py +++ b/cogs/error.py @@ -1,7 +1,32 @@ +from discord import Interaction +from discord.app_commands import CommandInvokeError from discord.ext import commands from loguru import logger -from src.ui.error_handling import EmbedBaseError + +class PrettyError(CommandInvokeError): + def __init__(self, message: str, interaction: Interaction, inner_exception: Exception | None = None): + super().__init__(interaction.command, inner_exception) + self.message = message + self.interaction = interaction + + async def send(self): + send_args = { + "content": f"{self.message}", + "ephemeral": False, + } + if not self.interaction.response.is_done(): + await self.interaction.response.send_message(**send_args) + else: + await self.interaction.followup.send(**send_args) + + +class TooManyOptionsError(PrettyError): + pass + + +class TooFewOptionsError(PrettyError): + pass class Error(commands.Cog): @@ -9,28 +34,19 @@ class Error(commands.Cog): def __init__(self, bot): self.bot = bot + tree = self.bot.tree + self._old_tree_error = tree.on_error + tree.on_error = self.on_app_command_error @commands.Cog.listener() - async def on_command_error( - self, - ctx: commands.Context, - error: commands.CommandError, - ): + async def on_app_command_error(self, interaction: Interaction, error: Exception): match error: - case EmbedBaseError(): - logger.error(error) - return await error.send() - - case commands.MissingPermissions(): - logger.error(f"Missing Permissions: {error}") - return await ctx.send("Chybí ti požadovaná práva!") - - case commands.CommandNotFound(): - return None - + case PrettyError(): + # if I use only 'error', gives me NoneType. Solved by this + logger.error(f"{error.__class__.__name__}: {interaction.command.name}") + await error.send() case _: - logger.critical(f"Catched an error: {error}") - return None + logger.critical(error) async def setup(bot): diff --git a/cogs/poll_command.py b/cogs/poll_command.py index f18a9db..4724b6d 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -5,38 +5,47 @@ from discord.ext import commands from loguru import logger +from cogs.error import TooFewOptionsError, TooManyOptionsError from src.db_folder.databases import PollDatabase, VoteButtonDatabase from src.jachym import Jachym from src.ui.embeds import PollEmbed, PollEmbedBase -from src.ui.error_handling import TooFewOptionsError, TooManyOptionsError from src.ui.poll import Poll from src.ui.poll_view import PollView -def error_handling(answer: list[str]) -> TooFewOptionsError | TooManyOptionsError | None: - if len(answer) > Poll.MAX_OPTIONS: - msg = f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" - raise TooManyOptionsError(msg) - if len(answer) < Poll.MIN_OPTIONS: - msg = f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" - raise TooFewOptionsError(msg) - return None +class OptionsTransformer(app_commands.Transformer): + async def transform( + self, interaction: discord.Interaction, option: str + ) -> TooManyOptionsError | TooFewOptionsError | list[str]: + """ + Transformer method to transformate a single string to multiple options. If they are not within parameters, + raises an error, else returns options. + Parameters + ---------- + interaction: discord.Interaction + option: str -class PollCreate(commands.Cog): - POLL_PARAMETERS = { - "name": "anketa", - "description": "Anketa pro hlasování. Jsou vidět všichni hlasovatelé.", - "question": "Otázka, na kterou potřebuješ vědět odpověď", - "answer": 'Odpovědi, rozděluješ odpovědi uvozovkou ("), maximálně pouze 10 možností', - "help": """ - Jednoduchá anketa, která obsahuje otázku a odpovědi. Povoleno je 10 možností. - """, - } - - # Bugfix for iPhone users who have different font for aposthrofe - REGEX_PATTERN = ['"', "”", "“", "„"] + Returns + ------- + List of strings + + Raises: + ------- + TooManyOptionsError, TooFewOptionsError + + """ + answers = [option for option in re.split('"|"|“|„', option) if option.strip()] + if len(answers) > Poll.MAX_OPTIONS: + msg = f"Zadal jsi příliš mnoho odpovědí, můžeš maximálně {Poll.MAX_OPTIONS}!" + raise TooManyOptionsError(msg, interaction) + if len(answers) < Poll.MIN_OPTIONS: + msg = f"Zadal jsi příliš málo odpovědí, můžeš alespoň {Poll.MIN_OPTIONS}!" + raise TooFewOptionsError(msg, interaction) + return answers + +class PollCreate(commands.Cog): def __init__(self, bot: Jachym): self.bot = bot @@ -53,23 +62,18 @@ async def pool( self, interaction: discord.Interaction, question: str, - answer: str, + answer: app_commands.Transform[list[str, ...], OptionsTransformer], ) -> discord.Message: await interaction.response.send_message( - embed=PollEmbedBase("Dělám na tom, vydrž!"), + embed=PollEmbedBase("Nahrávám anketu..."), ) message = await interaction.original_response() - # bugfix for answers that were empty - answers = [answer for answer in re.split("|".join(self.REGEX_PATTERN), answer) if answer.strip()] - if error_handling(answers): - return await message.edit(embed=PollEmbedBase(error_handling(answers))) - poll = Poll( message_id=message.id, channel_id=message.channel.id, question=question, - options=answers, + options=answer, user_id=interaction.user.id, ) diff --git a/src/ui/error_handling.py b/src/ui/error_handling.py deleted file mode 100644 index 1af1413..0000000 --- a/src/ui/error_handling.py +++ /dev/null @@ -1,23 +0,0 @@ -class EmbedBaseError(Exception): - def __init__(self, message, interaction, inner): - super().__init__(message, inner) - self.message = message - self.interaction = interaction - - async def send(self): - args = { - "content": self.message, - "ephemeral": True, - } - if not self.interaction.response.is_done(): - await self.interaction.response.send_message(**args) - else: - self.interaction.followup.send(**args) - - -class TooManyOptionsError(EmbedBaseError): - pass - - -class TooFewOptionsError(EmbedBaseError): - pass From 965bffa50d4131226e9ded93138de1f871060e18 Mon Sep 17 00:00:00 2001 From: robertsokola Date: Thu, 29 Jun 2023 23:08:17 +0200 Subject: [PATCH 22/22] Added Emojis, rewritten error embed, repaired error handling. Signed-off-by: robertsokola --- cogs/error.py | 54 ++++++++++++++++++++++++-------------------- cogs/poll_command.py | 9 ++++---- src/ui/embeds.py | 45 ++++++++++++++++-------------------- src/ui/emojis.py | 9 ++++++++ 4 files changed, 62 insertions(+), 55 deletions(-) create mode 100644 src/ui/emojis.py diff --git a/cogs/error.py b/cogs/error.py index 98804bb..dfa12aa 100644 --- a/cogs/error.py +++ b/cogs/error.py @@ -3,30 +3,7 @@ from discord.ext import commands from loguru import logger - -class PrettyError(CommandInvokeError): - def __init__(self, message: str, interaction: Interaction, inner_exception: Exception | None = None): - super().__init__(interaction.command, inner_exception) - self.message = message - self.interaction = interaction - - async def send(self): - send_args = { - "content": f"{self.message}", - "ephemeral": False, - } - if not self.interaction.response.is_done(): - await self.interaction.response.send_message(**send_args) - else: - await self.interaction.followup.send(**send_args) - - -class TooManyOptionsError(PrettyError): - pass - - -class TooFewOptionsError(PrettyError): - pass +from src.ui.embeds import ErrorMessage class Error(commands.Cog): @@ -47,6 +24,35 @@ async def on_app_command_error(self, interaction: Interaction, error: Exception) await error.send() case _: logger.critical(error) + await interaction.response.send_message( + embed=ErrorMessage( + "Tato zpráva by se nikdy zobrazit správně neměla. " + "Jsi borec, že jsi mi dokázal rozbít Jáchyma, nechceš mi o tom napsat do issues na githubu?" + ) + ) + + +class PrettyError(CommandInvokeError): + """Pretty errors useful for raise keyword""" + + def __init__(self, message: str, interaction: Interaction, inner_exception: Exception | None = None): + super().__init__(interaction.command, inner_exception) + self.message = message + self.interaction = interaction + + async def send(self): + if not self.interaction.response.is_done(): + await self.interaction.response.send_message(embed=ErrorMessage(self.message)) + else: + await self.interaction.followup.send(embed=ErrorMessage(self.message)) + + +class TooManyOptionsError(PrettyError): + pass + + +class TooFewOptionsError(PrettyError): + pass async def setup(bot): diff --git a/cogs/poll_command.py b/cogs/poll_command.py index 4724b6d..c332920 100644 --- a/cogs/poll_command.py +++ b/cogs/poll_command.py @@ -2,6 +2,7 @@ import discord from discord import app_commands +from discord.app_commands import Transform, Transformer from discord.ext import commands from loguru import logger @@ -13,7 +14,7 @@ from src.ui.poll_view import PollView -class OptionsTransformer(app_commands.Transformer): +class OptionsTransformer(Transformer): async def transform( self, interaction: discord.Interaction, option: str ) -> TooManyOptionsError | TooFewOptionsError | list[str]: @@ -62,11 +63,9 @@ async def pool( self, interaction: discord.Interaction, question: str, - answer: app_commands.Transform[list[str, ...], OptionsTransformer], + answer: Transform[list[str, ...], OptionsTransformer], ) -> discord.Message: - await interaction.response.send_message( - embed=PollEmbedBase("Nahrávám anketu..."), - ) + await interaction.response.send_message(embed=PollEmbedBase("Nahrávám anketu...")) message = await interaction.original_response() poll = Poll( diff --git a/src/ui/embeds.py b/src/ui/embeds.py index add4c01..7d05db5 100644 --- a/src/ui/embeds.py +++ b/src/ui/embeds.py @@ -1,35 +1,33 @@ import json import pathlib -from datetime import datetime, timedelta +from datetime import datetime import discord -from discord.colour import Color +from discord.colour import Color, Colour +from src.ui.emojis import ScoutEmojis from src.ui.poll import Poll -class CooldownErrorEmbed(discord.Embed): - LIMIT = 4 +class ErrorMessage(discord.Embed): + def __init__(self, message: str): + title = "⚠️ Jejda, někde se stala chyba..." - def __init__(self, seconds: float): - self.seconds = round(seconds) - formatted_date = discord.utils.format_dt( - datetime.now() + timedelta(seconds=10), - "R", + description = ( + f"{message}\n\n" + f"{ScoutEmojis.FLEUR_DE_LIS} *Pokud máš pocit, že tohle by chyba být neměla, " + f"napiš [sem](https://github.com/TheXer/Jachym/issues/new/choose)*" ) + self.set_footer(text="Uděláno s ♥!") + super().__init__( - title=f"⚠️ Vydrž! Další anketu můžeš založit {formatted_date}! ⚠️", - colour=Color.red(), + title=title, + description=description, + colour=Colour.red(), + timestamp=datetime.now(), ) - def correct_czech_writing(self) -> str: - if self.seconds > self.LIMIT: - return f"{self.seconds} sekund" - if self.LIMIT >= self.seconds > 1: - return f"{self.seconds} sekundy" - return "sekundu" - class PollEmbedBase(discord.Embed): def __init__(self, question) -> None: @@ -43,7 +41,9 @@ def __init__(self, poll: Poll): super().__init__(poll.question) self.answers = poll.options self._add_options() - self._add_timestamp() + + self.set_footer(text="Uděláno s ♥!") + self.timestamp = datetime.now() def _add_options(self): for index, option in enumerate(self.answers): @@ -53,13 +53,6 @@ def _add_options(self): inline=False, ) - def _add_timestamp(self): - self.add_field( - name="", - value=f"Anketa byla vytvořena {discord.utils.format_dt(datetime.now(), 'R')}", - inline=False, - ) - class EmbedFromJSON(discord.Embed): PATH = pathlib.Path("src/text_json/cz_text.json") diff --git a/src/ui/emojis.py b/src/ui/emojis.py new file mode 100644 index 0000000..32b84a6 --- /dev/null +++ b/src/ui/emojis.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass + + +@dataclass() +class ScoutEmojis: + FLEUR_DE_LIS = "<:lilie:814103053208649778>" + SCOUT_SCARF = "<:satek:814103053614972938>" + POTKANI = "<:Potkani:803954899250839582>" + SCOUTS = "<:skauti:814103051878531112>"