3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

games: remove 'fml'

This is a blocking command which can potentially freeze the server given enough network interruption.
It will likely be reintroduced later on in some sort of "Websites" plugin, possibly in the contrib repository.
This commit is contained in:
James Lu 2017-06-30 00:44:45 -07:00 committed by James Lu
parent f800c9f7c2
commit f0fab0c0ad

View File

@ -1,10 +1,7 @@
"""
games.py: Create a bot that provides game functionality (dice, 8ball, etc).
games.py: Creates a bot providing a few simple games.
"""
import random
import urllib.request
import urllib.error
from xml.etree import ElementTree
from pylinkirc import utils
from pylinkirc.log import log
@ -76,51 +73,5 @@ gameclient.add_cmd(eightball, featured=True)
gameclient.add_cmd(eightball, '8ball')
gameclient.add_cmd(eightball, '8b')
def fml(irc, source, args):
"""[<id>]
Displays an entry from fmylife.com. If <id> is not given, fetch a random entry from the API."""
try:
query = args[0]
except IndexError:
# Get a random FML from the API.
query = 'random'
# TODO: configurable language?
url = ('http://api.betacie.com/view/%s/nocomment'
'?key=4be9c43fc03fe&language=en' % query)
try:
data = urllib.request.urlopen(url).read()
except urllib.error as e:
error(irc, '%s' % e)
return
tree = ElementTree.fromstring(data.decode('utf-8'))
tree = tree.find('items/item')
try:
category = tree.find('category').text
text = tree.find('text').text
fmlid = tree.attrib['id']
url = tree.find('short_url').text
except AttributeError as e:
log.debug("games.FML: Error fetching FML %s from URL %s: %s",
query, url, e)
error(irc, "That FML does not exist or there was an error "
"fetching data from the API.")
return
if not fmlid:
error(irc, "That FML does not exist.")
return
# TODO: customizable formatting
votes = "\x02[Agreed: %s / Deserved: %s]\x02" % \
(tree.find('agree').text, tree.find('deserved').text)
s = '\x02#%s [%s]\x02: %s - %s \x02<\x0311%s\x03>\x02' % \
(fmlid, category, text, votes, url)
reply(irc, s)
gameclient.add_cmd(fml, featured=True)
def die(irc=None):
utils.unregisterService('games')