Added wiki command
This commit is contained in:
14
Gwendolyn.py
14
Gwendolyn.py
@ -210,6 +210,20 @@ async def on_message(message):
|
||||
else:
|
||||
await message.channel.send(desc)
|
||||
|
||||
elif message.content.lower().startswith("!wiki "):
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
command = string.capwords(message.content.lower().replace("!wiki ",""))
|
||||
title, content, thumbnail = funcs.findWikiPage(command)
|
||||
if title != "":
|
||||
funcs.logThis("Sending the embedded message")
|
||||
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
|
||||
if thumbnail != "":
|
||||
print(thumbnail)
|
||||
embed.set_thumbnail(url=thumbnail)
|
||||
|
||||
await message.channel.send(embed = embed)
|
||||
else:
|
||||
await message.channel.send(content)
|
||||
|
||||
|
||||
# Runs the whole shabang
|
||||
|
@ -1,4 +1,4 @@
|
||||
from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, logThis
|
||||
from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc, logThis, findWikiPage
|
||||
|
||||
from .swfuncs import parseChar, parseRoll, parseDestiny
|
||||
|
||||
|
@ -7,6 +7,7 @@ import urllib # Used by imageFunc
|
||||
import imdb # Used by movieFunc
|
||||
import time # Used for logging
|
||||
import logging # Used for... you know... logging
|
||||
import wikia # Used by findWikiPage
|
||||
|
||||
from .roll import dice
|
||||
|
||||
@ -118,3 +119,22 @@ def logThis(message : str):
|
||||
localtime = time.asctime(time.localtime(time.time()))
|
||||
print(localtime+" - "+message)
|
||||
logging.info(localtime+" - "+message)
|
||||
|
||||
# Finds a page from the Senkulpa Wikia
|
||||
def findWikiPage(search : str):
|
||||
logThis("Trying to find wiki page for "+search)
|
||||
wikia.set_lang("da")
|
||||
searchResults = wikia.search("senkulpa",search)
|
||||
if len(searchResults) > 0:
|
||||
logThis("Found it")
|
||||
page = wikia.page("senkulpa",searchResults[0])
|
||||
content = page.content.replace(u'\xa0', u' ').split("\n")[0]
|
||||
|
||||
images = page.images
|
||||
if len(images) > 0:
|
||||
return page.title, content, images[0]+"/revision/latest?path-prefix=da"
|
||||
else:
|
||||
return page.title, content, ""
|
||||
else:
|
||||
logThis("Couldn't find the page")
|
||||
return "", "Couldn't find page", ""
|
@ -3,7 +3,7 @@ import unittest
|
||||
import funcs
|
||||
|
||||
class testSwChar(unittest.TestCase):
|
||||
def testNewChar(self):
|
||||
def test1NewChar(self):
|
||||
text1, result = funcs.parseChar("TestUser","")
|
||||
self.assertEqual(result,"Character for TestUser created")
|
||||
|
||||
@ -15,8 +15,8 @@ class testSwChar(unittest.TestCase):
|
||||
text1, result = funcs.parseChar("TestUser","characteristics brawn 1")
|
||||
self.assertEqual(result,"Changed New Character's Characteristics")
|
||||
|
||||
def testDelChar(self):
|
||||
text1, result = funcs.parseChar("TestUser","purge")
|
||||
def testXChar(self):
|
||||
text1, result = funcs.parseChar("TestUser","Purge")
|
||||
self.assertEqual(result,"Character for TestUser deleted")
|
||||
|
||||
|
||||
@ -26,5 +26,21 @@ class testGwendolynFuncs(unittest.TestCase):
|
||||
self.assertEqual(funcs.cap("the greatest showman"),"The Greatest Showman")
|
||||
self.assertEqual(funcs.cap("i'm the best person!"),"I'm the Best Person!")
|
||||
|
||||
def testWikiExists(self):
|
||||
title, content, thumbnail = funcs.findWikiPage("Vivo")
|
||||
self.assertEqual(title,"Vivo (Gud)")
|
||||
self.assertEqual(content,"Vivo er den Phenolske gud for liv. Hun er en af de tre store guder der kom af at Unua splittede sig i 3.")
|
||||
|
||||
def testWikiDoesntExist(self):
|
||||
title, content, thumbnail = funcs.findWikiPage("Big Butts")
|
||||
self.assertEqual(title,"")
|
||||
self.assertEqual(content,"Couldn't find page")
|
||||
|
||||
def testWikiImage(self):
|
||||
title, content, thumbnail = funcs.findWikiPage("Moldaw")
|
||||
self.assertEqual(title,"Moldaw Dragniel")
|
||||
self.assertEqual(content,"Moldaw Dragniel (Født: Moldaw Geisler Dragniel) er en Rock Gnome fra den sydvestlige del af Zules Kongeriget i kejserriget Crozea. Han kommer fra den store landsby Ginti, hvor hans forældre arbejdede som håndværkere.")
|
||||
self.assertEqual(thumbnail,"https://vignette.wikia.nocookie.net/senkulpa/images/9/9e/Moldaw.png")
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user