Skip to content

Commit

Permalink
Fix the rules command now that the source file is an rst file
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Jul 25, 2024
1 parent 51906b8 commit be23270
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions arthur/exts/fun/devops_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from arthur.bot import KingArthur

RULES_URL = "https://raw.githubusercontent.com/python-discord/infra/main/docs/content/docs/onboarding/rules.md"
RULES_URL = "https://raw.githubusercontent.com/python-discord/infra/main/docs/onboarding/rules.rst"


class Rules(Cog):
Expand All @@ -21,12 +21,18 @@ async def cog_load(self) -> None:
resp.raise_for_status()
raw_content = await resp.text()
# Ignore markdown frontmatter
parsed_content = raw_content.split("---")[-1].strip()
# Ignore first 4 lines, as they are not the rules
parsed_content = parsed_content.split("\n")[4:]
parsed_content = raw_content.split("=====")[-1].strip()
# Ignore first 3 lines, as they are not the rules
parsed_content = parsed_content.split("\n", maxsplit=2)[2]
# Split on periods to get each rule, and hope we never use periods in our rules.
parsed_content = parsed_content.split(".")[1:]
self.rules = {}
for line in parsed_content:
number, rule = line.split(".", maxsplit=1)
for number, raw_rule in enumerate(parsed_content, 1):
# Drop extra newlines, backslashes that were added for sphinx
rule = raw_rule.replace("\n", "").replace(r"\ ", "")
if rule[-1].isdecimal():
# Drop the last character, if it is the index of the next rule.
rule = rule[:-1]
self.rules[int(number)] = rule.strip()

@group(name="rules", aliases=("rule",), invoke_without_command=True)
Expand Down

0 comments on commit be23270

Please sign in to comment.