Permalink
Browse files

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.
  • Loading branch information...
jlu5 committed Jun 30, 2017
1 parent f800c9f commit f0fab0c0add34e6b74583f524c86a3b42a7c7c54
Showing with 1 addition and 50 deletions.
  1. +1 −50 plugins/games.py
View
@@ -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 @@ def eightball(irc, source, args):
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')

0 comments on commit f0fab0c

Please sign in to comment.