This commit is contained in:
deathbybandaid 2022-05-06 13:42:44 -04:00
parent 022472f414
commit 3ff6f08c17
3 changed files with 33 additions and 9 deletions

View File

@ -36,3 +36,4 @@ sopel.plugins =
spicebot_command_spongemock = spicebot_command_spongemock
spicebot_command_leetspeak = spicebot_command_leetspeak
spicebot_command_dadjoke = spicebot_command_dadjoke
spicebot_command_devexcuse = spicebot_command_devexcuse

View File

@ -9,14 +9,14 @@ from sopel_SpiceBot_Core_Prerun import prerun
@prerun()
@plugin.command('dad', 'dadjoke')
def upper(bot, trigger, comrun):
joke = getDadJoke()
if not joke:
joke = 'My humor module is broken.'
comrun.say(joke)
fetched_str = fetch_string()
if not fetched_str:
fetched_str = 'My humor module is broken.'
comrun.say(fetched_str)
def getDadJoke():
url = 'https://icanhazdadjoke.com'
page = requests.get(url, headers={'Accept': 'text/plain'})
joke = page.text
return joke
def fetch_string():
content_url = 'https://icanhazdadjoke.com'
content_page = requests.get(content_url, headers={'Accept': 'text/plain'})
fetched_str = content_page.text
return fetched_str

View File

@ -0,0 +1,23 @@
import urllib
from xml.dom.minidom import parseString
from sopel import plugin
from sopel_SpiceBot_Core_Prerun import prerun
@prerun()
@plugin.command('devexcuse')
def upper(bot, trigger, comrun):
fetched_str = fetch_string()
if not fetched_str:
fetched_str = 'My humor module is broken.'
comrun.say(fetched_str)
def fetch_string():
content_url = 'http://developerexcuses.com'
content_page = urllib.request.urlopen(content_url).read()
fetched_str = parseString(content_page.replace('&', '')).getElementsByTagName('body')[0].getElementsByTagName('div')[0].getElementsByTagName('center')[0].getElementsByTagName('a')[0].childNodes[0].nodeValue
return fetched_str