diff options
| author | Samuel Johnson <[email protected]> | 2026-01-09 00:29:45 -0500 |
|---|---|---|
| committer | Samuel Johnson <[email protected]> | 2026-01-09 00:29:45 -0500 |
| commit | f041cdfb2e86f742ab0f1b470d43de8659995cfe (patch) | |
| tree | 90ce33c38cf510d602bd996db375143e04cd1e5c /src/main.py | |
| parent | 3d2380cb6102cd9ddc153527d5dda05ed294d3fa (diff) | |
Add basic scraping and markdown
Diffstat (limited to 'src/main.py')
| -rw-r--r-- | src/main.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.py b/src/main.py index 33affa2..08cdd05 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,8 @@ from discord.ext import commands import discord import os +import scrape_lexicanum + config = { **dotenv_values(".env"), **os.environ, @@ -17,4 +19,28 @@ bot = commands.Bot(command_prefix="Sigmar! ", intents=intents) async def ping(ctx): await ctx.send("pong") [email protected](name="Explain", aliases=["explain", "What's", "what's"]) +async def explain(ctx, query): + try: + search_content = scrape_lexicanum.get_search_response(config, query) + page_header, page_content = scrape_lexicanum.get_page_content(config, search_content[0]) + + embed = discord.Embed( + title=page_header, + description=search_content.pop(0), + color=discord.Colour.blurple(), + ) + + string_results = " ".join(str(x) for x in search_content) + + embed.add_field(name="Overview", value=page_content) + embed.add_field(name="You May Have Meant", value=string_results) + + await ctx.send(embed=embed) + except scrape_lexicanum.WikiError as e: + await ctx.send(f"{e}") + except Exception as e: + print(f"Could not complete explanation: {e}") + await ctx.send("Something has gone most terribly wrong...") + bot.run(config['token']) |
