From 1a9a104fa9a56809739a6db51788b7f094d22999 Mon Sep 17 00:00:00 2001 From: Koei Date: Fri, 2 May 2025 08:43:45 -0400 Subject: [PATCH 1/3] change burn command behavior --- techsupport_bot/commands/burn.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/techsupport_bot/commands/burn.py b/techsupport_bot/commands/burn.py index 8d0c3b46..48541eee 100644 --- a/techsupport_bot/commands/burn.py +++ b/techsupport_bot/commands/burn.py @@ -83,10 +83,13 @@ async def burn_command( ctx (commands.Context): The context in which the command was run user_to_match (discord.Member): The user in which to burn """ - prefix = await self.bot.get_prefix(ctx.message) - message = await auxiliary.search_channel_for_message( - channel=ctx.channel, prefix=prefix, member_to_match=user_to_match - ) + if ctx.message.reference is None: + prefix = await self.bot.get_prefix(ctx.message) + message = await auxiliary.search_channel_for_message( + channel=ctx.channel, prefix=prefix, member_to_match=user_to_match + ) + else: + message = ctx.message.reference.resolved await self.handle_burn(ctx, user_to_match, message) @@ -94,11 +97,11 @@ async def burn_command( @commands.guild_only() @commands.command( brief="Declares a BURN!", - description="Declares the user's last message as a BURN!", + description="Declares mentioned user's message as a BURN!", usage="@user", ) async def burn( - self: Self, ctx: commands.Context, user_to_match: discord.Member + self: Self, ctx: commands.Context, user_to_match: discord.Member = None ) -> None: """The only purpose of this function is to accept input from discord @@ -106,4 +109,13 @@ async def burn( ctx (commands.Context): The context in which the command was run user_to_match (discord.Member): The user in which to burn """ + if user_to_match is None: + if ctx.message.reference is None: + await auxiliary.send_deny_embed( + message="You need to mention someone to declare a burn.", channel=ctx.channel + ) + return + + user_to_match = ctx.message.reference.resolved.author + await self.burn_command(ctx, user_to_match) From 5191bf5da55b7c2d3b86302c413bed9b1199eed1 Mon Sep 17 00:00:00 2001 From: Koei Date: Fri, 2 May 2025 09:51:55 -0400 Subject: [PATCH 2/3] `make format` ran `make format` --- techsupport_bot/commands/burn.py | 5 +++-- techsupport_bot/commands/modmail.py | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/techsupport_bot/commands/burn.py b/techsupport_bot/commands/burn.py index 48541eee..df61b9d7 100644 --- a/techsupport_bot/commands/burn.py +++ b/techsupport_bot/commands/burn.py @@ -112,10 +112,11 @@ async def burn( if user_to_match is None: if ctx.message.reference is None: await auxiliary.send_deny_embed( - message="You need to mention someone to declare a burn.", channel=ctx.channel + message="You need to mention someone to declare a burn.", + channel=ctx.channel, ) return - + user_to_match = ctx.message.reference.resolved.author await self.burn_command(ctx, user_to_match) diff --git a/techsupport_bot/commands/modmail.py b/techsupport_bot/commands/modmail.py index fbb11cf7..17454fb2 100644 --- a/techsupport_bot/commands/modmail.py +++ b/techsupport_bot/commands/modmail.py @@ -153,7 +153,6 @@ async def on_message_edit( isinstance(before.channel, discord.DMChannel) and before.author.id in active_threads ): - if await Ts_client.models.ModmailBan.query.where( Ts_client.models.ModmailBan.user_id == str(before.author.id) ).gino.first(): @@ -452,7 +451,6 @@ async def create_thread( if not thread.name.startswith("[OPEN]") and thread.name.split("|")[ -1 ].strip() == str(user.id): - past_thread_count += 1 if past_thread_count == 0: @@ -1197,7 +1195,6 @@ async def contact(self: Self, ctx: commands.Context, user: discord.User) -> None ) case ui.ConfirmResponse.CONFIRMED: - # Makes sure the user can reply if they were timed out from creating threads if user.id in delayed_people: del delayed_people[user.id] @@ -1207,7 +1204,6 @@ async def contact(self: Self, ctx: commands.Context, user: discord.User) -> None user=user, source_channel=ctx.channel, ): - await auxiliary.send_confirm_embed( message="Thread successfully created!", channel=ctx.channel ) @@ -1259,7 +1255,6 @@ async def selfcontact(self: Self, ctx: commands.Context) -> None: ) case ui.ConfirmResponse.CONFIRMED: - # Makes sure the user can reply if they were timed out from creating threads if ctx.author in delayed_people: del delayed_people[ctx.author.id] @@ -1269,7 +1264,6 @@ async def selfcontact(self: Self, ctx: commands.Context) -> None: user=ctx.author, source_channel=ctx.channel, ): - await auxiliary.send_confirm_embed( message="Thread successfully created!", channel=ctx.channel ) From 92754f67fe27456547c6e5958cd1996d9d335117 Mon Sep 17 00:00:00 2001 From: Koei Date: Fri, 2 May 2025 10:28:51 -0400 Subject: [PATCH 3/3] Delete test_extensions_burn.py --- .../commands_tests/test_extensions_burn.py | 166 ------------------ 1 file changed, 166 deletions(-) delete mode 100644 techsupport_bot/tests/commands_tests/test_extensions_burn.py diff --git a/techsupport_bot/tests/commands_tests/test_extensions_burn.py b/techsupport_bot/tests/commands_tests/test_extensions_burn.py deleted file mode 100644 index 66ec2e47..00000000 --- a/techsupport_bot/tests/commands_tests/test_extensions_burn.py +++ /dev/null @@ -1,166 +0,0 @@ -""" -This is a file to test the extensions/burn.py file -This contains 6 tests -""" - -from __future__ import annotations - -import importlib -from typing import Self -from unittest.mock import AsyncMock - -import pytest -from core import auxiliary -from tests import config_for_tests - - -class Test_Phrases: - """A simple set of tests to ensure the PHRASES variable won't cause any problems""" - - def test_all_phrases_are_short(self: Self) -> None: - """ - This is a test to ensure that the generate burn embed function is working correctly - This specifically looks at the description for every phrase in the PHRASES array - This looks at the length of the description as well to ensure that - the phrases aren't too long - """ - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - - # Step 2 - Call the function - test_phrases = discord_env.burn.PHRASES - - # Step 3 - Assert that everything works - for phrase in test_phrases: - assert len(f"🔥🔥🔥 {phrase} 🔥🔥🔥") <= 4096 - - -class Test_HandleBurn: - """A set of test cases testing the handle_burn function""" - - @pytest.mark.asyncio - async def test_handle_burn_calls_reactions(self: Self) -> None: - """ - This is a test to ensure that handle_burn works correctly when a valid message can be found - It checks to ensure that the reactions are added correctly - """ - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - message_history = [discord_env.message_person1_noprefix_1] - discord_env.channel.message_history = message_history - discord_env.context.send = AsyncMock() - auxiliary.add_list_of_reactions = AsyncMock() - - # Step 2 - Call the function - await discord_env.burn.handle_burn( - discord_env.context, - discord_env.person1, - discord_env.message_person1_noprefix_1, - ) - - # Step 3 - Assert that everything works - auxiliary.add_list_of_reactions.assert_called_once_with( - message=discord_env.message_person1_noprefix_1, - reactions=["🔥", "🚒", "👨‍🚒"], - ) - - # Step 4 - Cleanup - importlib.reload(auxiliary) - - @pytest.mark.asyncio - async def test_handle_burn_calls_send(self: Self) -> None: - """ - This is a test to ensure that handle_burn works correctly when a valid message can be found - It checks to ensure that the reactions are added correctly - """ - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - message_history = [discord_env.message_person1_noprefix_1] - discord_env.channel.message_history = message_history - discord_env.context.send = AsyncMock() - auxiliary.add_list_of_reactions = AsyncMock() - - # Step 2 - Call the function - await discord_env.burn.handle_burn( - discord_env.context, - discord_env.person1, - discord_env.message_person1_noprefix_1, - ) - - # Step 3 - Assert that everything works - discord_env.context.send.assert_called_once() - - # Step 4 - Cleanup - importlib.reload(auxiliary) - - @pytest.mark.asyncio - async def test_handle_burn_no_message(self: Self) -> None: - """ - This is a test to ensure that the send_deny_embed - function is called if no message can be found - """ - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - auxiliary.send_deny_embed = AsyncMock() - - # Step 2 - Call the function - await discord_env.burn.handle_burn(discord_env.context, None, None) - - # Step 3 - Assert that everything works - auxiliary.send_deny_embed.assert_called_once_with( - message="I could not a find a message to reply to", - channel=discord_env.channel, - ) - - # Step 4 - Cleanup - importlib.reload(auxiliary) - - -class Test_BurnCommand: - """A set of test cases for testing the burn_command function""" - - @pytest.mark.asyncio - async def test_calls_search_channel(self: Self) -> None: - """A simple test to ensure that burn_command calls search_channel_for_message - with the correct args""" - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - auxiliary.search_channel_for_message = AsyncMock() - discord_env.burn.handle_burn = AsyncMock() - - # Step 2 - Call the function - await discord_env.burn.burn_command(discord_env.context, discord_env.person1) - - # Step 3 - Assert that everything works - auxiliary.search_channel_for_message.assert_called_once_with( - channel=discord_env.context.channel, - prefix=config_for_tests.PREFIX, - member_to_match=discord_env.person1, - ) - - # Step 4 - Cleanup - importlib.reload(auxiliary) - - @pytest.mark.asyncio - async def test_calls_handle_burn(self: Self) -> None: - """A simple test to ensure that burn_command calls handle_burn - with the correct args""" - # Step 1 - Setup env - discord_env = config_for_tests.FakeDiscordEnv() - auxiliary.search_channel_for_message = AsyncMock( - return_value=discord_env.message_person1_noprefix_1 - ) - discord_env.burn.handle_burn = AsyncMock() - - # Step 2 - Call the function - await discord_env.burn.burn_command(discord_env.context, discord_env.person1) - - # Step 3 - Assert that everything works - discord_env.burn.handle_burn.assert_called_once_with( - discord_env.context, - discord_env.person1, - discord_env.message_person1_noprefix_1, - ) - - # Step 4 - Cleanup - importlib.reload(auxiliary)