add pirate, piglatin, devexcuse

This commit is contained in:
Gordon Shumway 2019-02-25 17:42:48 -05:00 committed by GitHub
parent ca93cdfdb8
commit 7604f01645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 61 additions and 1 deletions

View File

@ -13,6 +13,8 @@ import supybot.callbacks as callbacks
import supybot.ircmsgs as ircmsgs
import requests
import html
import arrr
from bs4 import BeautifulSoup
try:
from supybot.i18n import PluginInternationalization
@ -153,5 +155,63 @@ class Fun(callbacks.Plugin):
if line.strip():
irc.reply(line, prefixNick=False)
ascii = wrap(ascii, [getopts({'font':'something', 'fontlist':''}), additional('text')])
def pirate(self, irc, msg, args, text):
"""<text>
English to pirate translator.
"""
channel = msg.args[0]
pirate = arrr.translate(text)
irc.reply(pirate)
pirate = wrap(pirate, ['text'])
def devexcuse(self, irc, msg, args):
"""
Returns an excuse from http://developerexcuses.com
"""
data = requests.get('http://developerexcuses.com')
if not data: # http fetch breaks.
irc.reply("ERROR")
return
soup = BeautifulSoup(data.text)
text = soup.find('center').getText()
irc.reply("{0}".format(text))
devexcuse = wrap(devexcuse)
def _pigword(self, word):
shouldCAP = (word[:1] == word[:1].upper())
word = word.lower()
letters = "qwertyuiopasdfghjklzxcvbnm"
i = len(word) - 1
while i >= 0 and letters.find(word[i]) == -1:
i = i - 1
if i == -1:
return word
punctuation = word[i+1:]
word = word[:i+1]
vowels = "aeiou"
if vowels.find(word[0]) >= 0:
word = word + "yay" + punctuation
else:
word = word[1:] + word[0] + "ay" + punctuation
if shouldCAP:
return word[:1].upper() + word[1:]
else:
return word
def piglatin(self, irc, msg, args, optinput):
"""<text>
Convert text from English to Pig Latin.
"""
l = optinput.split(" ")
for i in range(len(l)):
l[i] = self._pigword(l[i])
irc.reply(" ".join(l))
piglatin = wrap(piglatin, [('text')])
Class = Fun