diff options
-rw-r--r-- | bot/exts/info/information.py | 28 | ||||
-rw-r--r-- | tests/bot/exts/info/test_information.py | 6 |
2 files changed, 14 insertions, 20 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 80e7a5b6c..73afa3309 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -524,22 +524,15 @@ class Information(Cog): await self.send_raw_content(ctx, message, json=True) @command(aliases=("rule",)) - async def rules(self, ctx: Context, args: Optional[str]) -> Optional[Set[int]]: + async def rules(self, ctx: Context, *, args: Optional[str]) -> Optional[Set[int]]: """ Provides a link to all rules or, if specified, displays specific rule(s). It accepts either rule numbers or particular keywords that map to a particular rule. Rule numbers and keywords can be sent in any order. """ - # Temporary fix for discord.py greedy string quote conversion bug - if not args: - args = () - elif isinstance(args, str): - msg = ctx.message.content - # Remove the command - if len(msg := msg.split()) > 1: - msg.pop(0) - args = tuple(msg) + # Note: *args cannot be used due to a discord.py bug + # causing infinite loops during greedy string parsing. rules_embed = Embed(title="Rules", color=Colour.og_blurple(), url="https://www.pythondiscord.com/pages/rules") keywords, rule_numbers = [], [] @@ -551,13 +544,14 @@ class Information(Cog): for rule_keyword in rule_keywords: keyword_to_rule_number[rule_keyword] = rule_number - for word in args: - try: - rule_numbers.append(int(word)) - except ValueError: - if (kw := word.lower()) not in keyword_to_rule_number: - break - keywords.append(kw) + if args: + for word in args.split(): + try: + rule_numbers.append(int(word)) + except ValueError: + if (kw := word.lower()) not in keyword_to_rule_number: + break + keywords.append(kw) if not rule_numbers and not keywords: # Neither rules nor keywords were submitted. Return the default description. diff --git a/tests/bot/exts/info/test_information.py b/tests/bot/exts/info/test_information.py index 267346c58..9f5143c01 100644 --- a/tests/bot/exts/info/test_information.py +++ b/tests/bot/exts/info/test_information.py @@ -614,7 +614,7 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase): str(rule_number) for rule_number in extracted_rule_numbers if rule_number < 1 or rule_number > len(self.full_rules)) - final_rule_numbers = await self.cog.rules(self.cog, self.ctx, raw_user_input) + final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input) self.assertEqual( self.ctx.send.call_args, @@ -631,7 +631,7 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase): for raw_user_input, expected_matched_rule_numbers in test_cases: with self.subTest(identifier=raw_user_input): - final_rule_numbers = await self.cog.rules(self.cog, self.ctx, raw_user_input) + final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input) self.assertEqual(expected_matched_rule_numbers, final_rule_numbers) async def test_return_default_rules_when_no_input_or_no_match_are_found(self): @@ -643,7 +643,7 @@ class RuleCommandTests(unittest.IsolatedAsyncioTestCase): for raw_user_input, expected_matched_rule_numbers in test_cases: with self.subTest(identifier=raw_user_input): - final_rule_numbers = await self.cog.rules(self.cog, self.ctx, raw_user_input) + final_rule_numbers = await self.cog.rules(self.cog, self.ctx, *raw_user_input) embed = self.ctx.send.call_args.kwargs['embed'] self.assertEqual(information.DEFAULT_RULES_DESCRIPTION, embed.description) self.assertEqual(expected_matched_rule_numbers, final_rule_numbers) |