Skip to content

Commit

Permalink
use embed
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamSH-LLK committed Nov 21, 2023
1 parent ef911a3 commit e499b5f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions dozer/cogs/firstqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ async def frcqa(self, ctx: DozerContext, question: int):
async def frcrule(self, ctx: DozerContext, rule: str):
letter_part = ''.join([char for char in rule if char.isalpha()])
number_part = ''.join([char for char in rule if char.isdigit()])
embed = discord.Embed(
title=f"Rule {letter_part.upper()}{number_part}",
url=f"https://frc-qa.firstinspires.org/manual/rule/{letter_part.upper()}/{number_part}",
color=discord.Color.blue()
)


if not re.match(r'^[a-zA-Z]\d{3}$', rule):
await ctx.send("Invalid rule number")

embed.add_field(
name="Error",
value="Invalid rule number"
)

else:
async with ctx.cog.ses.get('https://firstfrc.blob.core.windows.net/frc2023/Manual/HTML/2023FRCGameManual.htm') as response:
Expand All @@ -118,10 +128,18 @@ async def frcrule(self, ctx: DozerContext, rule: str):

result = ruleSoup.find("a", attrs={"name": f"{letter_part.upper()}{number_part}"})
if result is not None:
await ctx.send(f"{result.parent.get_text()}\n[Read More](https://frc-qa.firstinspires.org/manual/rule/{letter_part.upper()}/{number_part})")
embed.add_field(
name="Summary",
value=result.parent.get_text()
)

else:
await ctx.send("No such rule")
embed.add_field(
name="Error",
value="No such rule"
)

await ctx.send(embed=embed)
frcrule.example_usage = """
`{prefix}frcrule g301` - sends the summary and link to rule G301
"""
Expand Down

0 comments on commit e499b5f

Please sign in to comment.