make excuse use beautiful soup
All checks were successful
Build and push / changes (push) Successful in 3s
Build and push / Lint-Python (push) Successful in 3s
Build and push / Build-and-Push-Docker (push) Successful in 20s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-status-to-discord (push) Successful in 2s
All checks were successful
Build and push / changes (push) Successful in 3s
Build and push / Lint-Python (push) Successful in 3s
Build and push / Build-and-Push-Docker (push) Successful in 20s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-status-to-discord (push) Successful in 2s
This commit is contained in:
parent
b2aa137f44
commit
928b1cad07
@ -161,11 +161,11 @@ class Cheeky(commands.Cog):
|
||||
|
||||
await ctx.respond(embed=dice.roll(number_of_die, sides, number_to_add))
|
||||
|
||||
@commands.command(name="excuse")
|
||||
@commands.slash_command(name="excuse")
|
||||
async def excuse(self, ctx: commands.Context):
|
||||
import excuse
|
||||
|
||||
await ctx.reply(excuse.get_excuse())
|
||||
await ctx.respond(excuse.get_excuse())
|
||||
|
||||
async def get_all_meme_templates(ctx: discord.AutocompleteContext):
|
||||
"""
|
||||
|
@ -3,11 +3,26 @@ import requests
|
||||
|
||||
|
||||
def get_excuse():
|
||||
url = requests.get("http://www.devexcuses.com")
|
||||
soup = BeautifulSoup(url.content, features="html.parser")
|
||||
"""
|
||||
Fetches a random developer excuse from devexcuses.com
|
||||
|
||||
return "```{}```".format(
|
||||
str(soup.find("p", {"class": "excuse"}).contents[0])
|
||||
.split(">")[1]
|
||||
.split("</a")[0]
|
||||
Returns:
|
||||
str: A formatted excuse string wrapped in code block
|
||||
"""
|
||||
url = "http://www.devexcuses.com"
|
||||
response = requests.get(url, headers={"Cache-Control": "no-cache"})
|
||||
response.raise_for_status() # Raise exception for bad responses
|
||||
|
||||
soup = BeautifulSoup(response.content, features="html.parser")
|
||||
excuse_element = soup.find("p", {"class": "excuse"})
|
||||
|
||||
if not excuse_element or not excuse_element.contents:
|
||||
return "```Failed to get an excuse. Maybe that's your excuse?```"
|
||||
|
||||
# Extract the excuse text more reliably using the <a> tag inside the <p>
|
||||
excuse_link = excuse_element.find("a")
|
||||
excuse_text = (
|
||||
excuse_link.text.strip() if excuse_link else excuse_element.text.strip()
|
||||
)
|
||||
|
||||
return f"```{excuse_text}```"
|
||||
|
Loading…
x
Reference in New Issue
Block a user