From d4926d1b65634ef6ff79c33ac1d3abeedbbfcbaf Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Tue, 12 Nov 2024 23:02:38 +0000 Subject: [PATCH] Update scp.py --- scp/scp.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scp/scp.py b/scp/scp.py index 95eb80c..8f36a87 100644 --- a/scp/scp.py +++ b/scp/scp.py @@ -20,8 +20,8 @@ async def scp_group(self, ctx, scp_number: str = None): await ctx.send("Please specify a subcommand or SCP number. Available subcommands: lookup, list, random, info.") @scp_group.command(name='lookup') - async def scp_lookup(self, ctx, scp_number: str): - """Lookup SCP articles by their number and provide a summary.""" + async def scp_lookup(self, ctx, scp_number: str, search_term: str = None): + """Search SCP articles and provide a summary and number.""" url = f"http://www.scpwiki.com/scp-{scp_number}" async with aiohttp.ClientSession() as session: async with session.get(url) as response: @@ -34,7 +34,15 @@ async def scp_lookup(self, ctx, scp_number: str): description_tag = soup.find('div', {'id': 'page-content'}) description = description_tag.text.strip()[:500] if description_tag else "Description not available." - await ctx.send(f"**{title}**\n{description}\n[Read more]({url})") + # If a search term is provided, check if it's in the content + if search_term: + content_text = description_tag.text if description_tag else "" + if search_term.lower() in content_text.lower(): + await ctx.send(f"**{title}**\nThe term '{search_term}' was found in SCP-{scp_number}.\n{description}\n[Read more]({url})") + else: + await ctx.send(f"**{title}**\nThe term '{search_term}' was not found in SCP-{scp_number}.\n{description}\n[Read more]({url})") + else: + await ctx.send(f"**{title}**\n{description}\n[Read more]({url})") else: await ctx.send(f"SCP-{scp_number} not found.")