Skip to content

Commit

Permalink
name search maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCos17 committed Nov 10, 2024
1 parent 3e1ddfb commit b1c4359
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scp/scp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,22 @@ async def scp_info(self, ctx, scp_number: str):
except Exception as e:
await ctx.send(f"An unexpected error occurred: {str(e)}")

@scp_group.command(name='search')
async def scp_search(self, ctx, *, scp_name: str):
"""Search for SCP articles by their name."""
base_url = "https://scp-api.com/scp/search"
params = {'query': scp_name}

async with aiohttp.ClientSession() as session:
async with session.get(base_url, params=params) as response:
if response.status == 200:
articles = await response.json()
if articles:
article_titles = [article['title'] for article in articles]
await ctx.send(f"Search results for '{scp_name}':\n" + "\n".join(article_titles))
else:
await ctx.send(f"No SCPs found matching: {scp_name}.")
else:
await ctx.send("Failed to fetch SCP articles. Please try again later.")


0 comments on commit b1c4359

Please sign in to comment.