🐛 Fixed wiki command

This commit is contained in:
NikolajDanger
2021-04-11 01:34:26 +02:00
parent 79fe8c6a84
commit f7c903852c
4 changed files with 48 additions and 38 deletions

View File

@ -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)