From f7c903852c5123819735a7b18b19d01ee36e7885 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Sun, 11 Apr 2021 01:34:26 +0200 Subject: [PATCH] :bug: Fixed wiki command --- cogs/MiscCog.py | 2 +- funcs/other/other.py | 36 +++++++++++++++----------- requirements.txt | 46 ++++++++++++++++++---------------- resources/slashParameters.json | 2 +- 4 files changed, 48 insertions(+), 38 deletions(-) diff --git a/cogs/MiscCog.py b/cogs/MiscCog.py index 7b4d940..ef50213 100644 --- a/cogs/MiscCog.py +++ b/cogs/MiscCog.py @@ -67,7 +67,7 @@ class MiscCog(commands.Cog): # Finds a page on the Senkulpa wiki @cog_ext.cog_slash(**params["wiki"]) - async def wiki(self, ctx, wikiPage): + async def wiki(self, ctx, wikiPage = ""): await self.bot.other.findWikiPage(ctx, wikiPage) #Searches for movie and adds it to Bedre Netflix diff --git a/funcs/other/other.py b/funcs/other/other.py index e63fbb9..444d8cd 100644 --- a/funcs/other/other.py +++ b/funcs/other/other.py @@ -4,7 +4,7 @@ import discord # Used in movieFunc import datetime # Used in helloFunc import urllib # Used in imageFunc import lxml # Used in imageFunc -import wikia # Used in findWikiPage +import fandom # Used in findWikiPage import d20 # Used in rollDice import ast from .bedreNetflix import BedreNetflix @@ -13,6 +13,9 @@ from .generators import Generators from utils import cap +fandom.set_lang("da") +fandom.set_wiki("senkulpa") + class MyStringifier(d20.MarkdownStringifier): def _str_expression(self, node): if node.comment == None: @@ -136,29 +139,32 @@ class Other(): # Finds a page from the Senkulpa Wikia async def findWikiPage(self, ctx, search : str): await ctx.defer() - search = cap(search) foundPage = False - self.bot.log("Trying to find wiki page for "+search) - wikia.set_lang("da") - searchResults = wikia.search("senkulpa",search) - if len(searchResults) > 0: + if search != "": + self.bot.log("Trying to find wiki page for "+search) + searchResults = fandom.search(search) + if len(searchResults) > 0: + foundPage = True + searchResult = searchResults[0].replace(",","%2C") + else: + self.bot.log("Couldn't find the page") + await ctx.send("Couldn't find page (error code 1002)") + else: foundPage = True - searchResult = searchResults[0].replace(",","%2C") + self.bot.log("Searching for a random page") + searchResult = fandom.random() + + if foundPage: self.bot.log("Found page \""+searchResult+"\"") - page = wikia.page("senkulpa",searchResult) - content = page.content.replace(u'\xa0', u' ').split("\n")[0] + page = fandom.page(searchResult) + content = page.summary images = page.images if len(images) > 0: - image = images[len(images)-1]+"/revision/latest?path-prefix=da" + image = images[0] else: image = "" - else: - self.bot.log("Couldn't find the page") - await ctx.send("Couldn't find page (error code 1002)") - - if foundPage: self.bot.log("Sending the embedded message",str(ctx.channel_id)) content += f"\n[Læs mere]({page.url})" embed = discord.Embed(title = page.title, description = content, colour=0xDEADBF) diff --git a/requirements.txt b/requirements.txt index e49b144..0d28511 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,40 +1,44 @@ -aiohttp==3.6.3 +aiohttp==3.7.4.post0 +astroid==2.5.3 async-timeout==3.0.1 attrs==20.3.0 beautifulsoup4==4.9.3 cachetools==4.2.1 certifi==2020.12.5 -chardet==3.0.4 -d20==1.0.4 -discord-py-slash-command @ git+https://github.com/eunwoo1104/discord-py-slash-command.git@3c63f9fe9d186c8492e85c3153aff268f1dd5cae +chardet==4.0.0 +colorama==0.4.4 +d20==1.1.0 +discord-py-slash-command==1.1.1 discord.py==1.7.1 dnspython==2.1.0 -finnhub-python==2.1.0 +docutils==0.17 +fandom-py==0.1.6 +finnhub-python==2.4.0 gitdb==4.0.7 -GitPython==3.1.0 +GitPython==3.1.14 greenlet==1.0.0 idna==2.10 -IMDbPY==6.8 -inflect==5.3.0 +IMDbPY==2020.9.25 +isort==5.8.0 jaraco.context==4.0.0 -jaraco.itertools==6.0.1 lark-parser==0.9.0 -lxml==4.5.0 +lazy-object-proxy==1.6.0 +lxml==4.6.3 +mccabe==0.6.1 more-itertools==8.7.0 -multidict==4.7.6 -numexpr==2.7.1 -numpy==1.18.2 -Pillow==7.1.1 +multidict==5.1.0 +numpy==1.20.2 +Pillow==8.2.0 +pylint==2.7.4 pymongo==3.11.3 requests==2.25.1 -six==1.15.0 smmap==4.0.0 soupsieve==2.2.1 -SQLAlchemy==1.4.5 +SQLAlchemy==1.4.7 +toml==0.10.2 typing-extensions==3.7.4.3 -urllib3==1.25.8 -websockets==8.1 -wikia==1.4.4 -wolframalpha==4.0.0 +urllib3==1.26.4 +wolframalpha==5.0.0 +wrapt==1.12.1 xmltodict==0.12.0 -yarl==1.5.1 +yarl==1.6.3 diff --git a/resources/slashParameters.json b/resources/slashParameters.json index 0b38945..db44a4e 100644 --- a/resources/slashParameters.json +++ b/resources/slashParameters.json @@ -431,7 +431,7 @@ "name" : "wikiPage", "description" : "The page to find", "type" : 3, - "required" : "true" + "required" : "false" } ] },