aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo <[email protected]>2020-02-27 11:47:01 +0100
committerGravatar Matteo <[email protected]>2020-02-27 11:47:01 +0100
commitafc74faadd5fb4d3fd3003bed9f2a1f241c0dc58 (patch)
tree6896e81829e023203ca0d00c9ef9d7976a214580
parentSplit the eval command procedure into two functions. (diff)
Use unicode code point instead of literal for the snekbox re-eval emoji
Unicode literals aren't really safe compared to code points
-rw-r--r--bot/cogs/snekbox.py8
-rw-r--r--tests/bot/cogs/test_snekbox.py6
2 files changed, 8 insertions, 6 deletions
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index 25b2455e8..52d830fa8 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -42,6 +42,8 @@ EVAL_ROLES = (Roles.helpers, Roles.moderator, Roles.admin, Roles.owner, Roles.ro
SIGKILL = 9
+REEVAL_EMOJI = '\U0001f501' # :repeat:
+
class Snekbox(Cog):
"""Safe evaluation of Python code using Snekbox."""
@@ -223,7 +225,7 @@ class Snekbox(Cog):
check=_predicate_eval_message_edit,
timeout=10
)
- await ctx.message.add_reaction('🔁')
+ await ctx.message.add_reaction(REEVAL_EMOJI)
await self.bot.wait_for(
'reaction_add',
check=_predicate_emoji_reaction,
@@ -285,8 +287,8 @@ def predicate_eval_message_edit(ctx: Context, old_msg: Message, new_msg: Message
def predicate_eval_emoji_reaction(ctx: Context, reaction: Reaction, user: User) -> bool:
- """Return True if the reaction 🔁 was added by the context message author on this message."""
- return reaction.message.id == ctx.message.id and user.id == ctx.author.id and str(reaction) == '🔁'
+ """Return True if the reaction REEVAL_EMOJI was added by the context message author on this message."""
+ return reaction.message.id == ctx.message.id and user.id == ctx.author.id and str(reaction) == REEVAL_EMOJI
def setup(bot: Bot) -> None:
diff --git a/tests/bot/cogs/test_snekbox.py b/tests/bot/cogs/test_snekbox.py
index c1c0f8d47..e7a1e3362 100644
--- a/tests/bot/cogs/test_snekbox.py
+++ b/tests/bot/cogs/test_snekbox.py
@@ -303,7 +303,7 @@ class SnekboxTests(unittest.TestCase):
call('message_edit', partial(snekbox.predicate_eval_message_edit, ctx), timeout=10),
call('reaction_add', partial(snekbox.predicate_eval_emoji_reaction, ctx), timeout=10)
)
- ctx.message.add_reaction.assert_called_once_with('🔁')
+ ctx.message.add_reaction.assert_called_once_with(snekbox.REEVAL_EMOJI)
ctx.message.clear_reactions.assert_called_once()
response.delete.assert_called_once()
@@ -336,12 +336,12 @@ class SnekboxTests(unittest.TestCase):
def test_predicate_eval_emoji_reaction(self):
"""Test the predicate_eval_emoji_reaction function."""
valid_reaction = MockReaction(message=MockMessage(id=1))
- valid_reaction.__str__.return_value = '🔁'
+ valid_reaction.__str__.return_value = snekbox.REEVAL_EMOJI
valid_ctx = MockContext(message=MockMessage(id=1), author=MockUser(id=2))
valid_user = MockUser(id=2)
invalid_reaction_id = MockReaction(message=MockMessage(id=42))
- invalid_reaction_id.__str__.return_value = '🔁'
+ invalid_reaction_id.__str__.return_value = snekbox.REEVAL_EMOJI
invalid_user_id = MockUser(id=42)
invalid_reaction_str = MockReaction(message=MockMessage(id=1))
invalid_reaction_str.__str__.return_value = ':longbeard:'