diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..bdec4c5 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,24 @@ +name: Test with pytest + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@main + + - name: Set up Python 3 + uses: actions/setup-python@main + with: + python-version: "3.x" + + - name: Install Poetry + run: curl https://install.python-poetry.org | python - + + - name: Install dependencies + run: poetry install + + - name: Run pytest + run: poetry run python -m pytest diff --git a/wulkabot/cogs/automod.py b/wulkabot/cogs/automod.py index d4fee49..8e66b59 100644 --- a/wulkabot/cogs/automod.py +++ b/wulkabot/cogs/automod.py @@ -18,7 +18,7 @@ def is_ios_request(text: str, /) -> bool: # the text is longer and doesn't look like just a simple question return False - words = set(remove_diacritics(text.replace("?", "").replace("!", "")).lower().split()) + words = set(remove_diacritics(text.replace("?", "").replace("!", "")).casefold().split()) if "ios" not in words: return False diff --git a/wulkabot/cogs/faq.py b/wulkabot/cogs/faq.py index 69868f9..15f4b11 100644 --- a/wulkabot/cogs/faq.py +++ b/wulkabot/cogs/faq.py @@ -29,7 +29,7 @@ class FAQ(commands.Cog): return [ app_commands.Choice(name=question, value=question) for question in self.questions - if current.lower() in question.lower() + if current.casefold() in question.casefold() ] @app_commands.command() diff --git a/wulkabot/cogs/github.py b/wulkabot/cogs/github.py index 85c26c0..6c7422b 100644 --- a/wulkabot/cogs/github.py +++ b/wulkabot/cogs/github.py @@ -155,7 +155,8 @@ class GitHub(commands.Cog): if message.author.bot: return - words = message.content.split() + # `dict.fromkeys` allows us to deduplicate the list whilst preserving order + words = dict.fromkeys(message.content.casefold().split()).keys() embeds = [] try: @@ -193,6 +194,7 @@ class GitHub(commands.Cog): view = DeleteButton(message.author) reply = await message.reply(embeds=embeds[:3], view=view) view.message = reply + print(reply.embeds) async def setup(bot: bot.Wulkabot): diff --git a/wulkabot/utils/views.py b/wulkabot/utils/views.py index ca76b88..a20fc55 100644 --- a/wulkabot/utils/views.py +++ b/wulkabot/utils/views.py @@ -8,11 +8,17 @@ class DeleteButton(discord.ui.View): self.message: discord.Message | None = None async def interaction_check(self, interaction: discord.Interaction) -> bool: - return ( + if ( interaction.user == self.invoker or isinstance(interaction.user, discord.Member) and interaction.user.resolved_permissions.manage_messages + ): + return True + + await interaction.response.send_message( + "Tylko osoba która wywołała bota może usunąć tę wiadomość", ephemeral=True ) + return False @discord.ui.button(label="Usuń", style=discord.ButtonStyle.danger) async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button) -> None: