Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions nao.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,46 @@ async def search_mabinogi_wiki(query):
"""

try:
# Format the query from URL
formatted_query = query.replace(" ", "_")
url = f"https://wiki.mabinogiworld.com/view/{formatted_query}"
variations = [
query,
query.title(),
query.split()[0]
]

for variation in variations:
# Format the query for URL
formatted_query = variation.replace(" ", "_")
url = f"https://wiki.mabinogiworld.com/view/{formatted_query}"

# Send a request to Mabi Wiki
response = requests.get(url)

# Check http status codes
if response.status_code == 200:
# Parse the HTML content
soup = BeautifulSoup(response.text, "html.parser")

# Extract title of page
title = soup.find("h1", id="firstHeading").text.strip()

contents = soup.find("div", class_="mw-parser-output")

if contents:
return f"**{title}**\n{url}"

elif response.status_code != 404:
# raise for more descriptive error
raise Exception(f"MabiWiki seems to be having problems: {response.status_code} / {url}")
elif response.status_code == 404
# couldn't find variation
continue
else:
# this block should never execute
return "How did you get here, Milletian? Peeking where you shouldn't be? Some secrets are for the gods."

#last resort
return f"Sorry, I couldn't find what you were looking for. Nothing was found on MabiWiki for {query}"

# Send a request to Mabi Wiki
response = requests.get(url)
response.raise_for_status()

# Parse the HTML content
soup = BeautifulSoup(response.text, "html.parser")

# Extract title of page
title = soup.find("h1", id="firstHeading").text.strip()

contents = soup.find("div", class_="mw-parser-output")
if contents:
return f"**{title}**\n{url}"
else:
return f"No content found."
except Exception as e:
return f"An error occurred: {str(e)}"

Expand Down