1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
from dotenv import dotenv_values
from discord.ext import commands
import discord
import os
import scrape_lexicanum
config = {
**dotenv_values(".env"),
**os.environ,
}
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="Sigmar! ", intents=intents)
@bot.command()
async def ping(ctx):
await ctx.send("pong")
@bot.command(name="Explain", aliases=["explain", "What's", "what's"])
async def explain(ctx, *args):
query = " ".join(args)
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'])
|