summaryrefslogtreecommitdiff
path: root/cogs/Wiki.py
diff options
context:
space:
mode:
Diffstat (limited to 'cogs/Wiki.py')
-rw-r--r--cogs/Wiki.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/cogs/Wiki.py b/cogs/Wiki.py
new file mode 100644
index 0000000..7552d07
--- /dev/null
+++ b/cogs/Wiki.py
@@ -0,0 +1,51 @@
+from discord.ext import commands
+import discord
+import wikipedia
+import fuzzywuzzy
+import importlib
+import utils
+importlib.reload(utils)
+
+
+class Wiki(commands.Cog):
+ def __init__(self, bot):
+ self.bot = bot
+
+ @commands.command(aliases=[], application_command_meta=commands.ApplicationCommandMeta(options=[]))
+ @commands.bot_has_permissions(embed_links=True)
+ async def wiki(self, ctx, wiki_search):
+ """Query Wikipedia."""
+ try:
+ wiki_result = wikipedia.WikipediaPage(wiki_search)
+ # print(wiki_result.summary)
+ wiki_summary = wiki_result.summary[:1900]
+ wiki_url = wiki_result.url
+
+ emb = await utils.embed(ctx, f"{wiki_search}", f"{wiki_summary}", url=wiki_url)
+ await ctx.send(embed=emb)
+
+ except wikipedia.DisambiguationError as e:
+ emb = await utils.embed(ctx, f"{wiki_search} may refer to:", "\n".join(e.options))
+ await ctx.send(embed=emb)
+
+ except wikipedia.PageError as e:
+ search_suggestions = wikipedia.search(wiki_search)
+
+ if len(search_suggestions) > 0:
+ emb = await utils.embed(ctx, f"No results found for {wiki_search}.\nDid you mean: ",
+ "\n".join(search_suggestions))
+ await ctx.send(embed=emb)
+ else:
+ emb = await utils.embed(ctx, f"No results found for {wiki_search}.", "")
+ await ctx.send(embed=emb)
+
+
+
+def setup(bot):
+ print("INFO: Loading [Wiki]... ", end="")
+ bot.add_cog(Wiki(bot))
+ print("Done!")
+
+
+def teardown(bot):
+ print("INFO: Unloading [Wiki]")