Move all commands into the 'citizen' commands group.

master
Valentin Lorentz 2013-05-23 13:11:16 +02:00
parent 2f90ce06bf
commit 1d64a3ad20
1 changed files with 64 additions and 62 deletions

View File

@ -33,6 +33,7 @@ import json
from string import Template
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
@ -74,8 +75,9 @@ def flatten_subdicts(dicts):
class ERepublik(callbacks.Plugin):
threaded = True
def _getCitizen(self, irc, name):
key = self.registryValue('apikey')
class citizen(callbacks.Commands):
def _get(self, irc, name):
key = conf.supybot.plugins.ERepublik.apikey()
if not key:
irc.error(_('No API key set. Ask the owner to add one.'),
Raise=True)
@ -89,7 +91,7 @@ class ERepublik(callbacks.Plugin):
else:
base = 'http://api.erpk.org/citizen/search/%s/1.json?key=%s'
data = json.load(utils.web.getUrlFd(base % (name, key)))
return self._getCitizen(irc, str(data[0]['id']))
return self._get(irc, str(data[0]['id']))
except:
raise
irc.error(_('This citizen does not exist.'), Raise=True)
@ -98,7 +100,7 @@ class ERepublik(callbacks.Plugin):
"""<format> <name|id>
Returns informations about a citizen with advanced formating."""
citizen = flatten_subdicts(self._getCitizen(irc, name))
citizen = flatten_subdicts(self._get(irc, name))
try:
repl = lambda x:Template(x).safe_substitute(citizen)
irc.replies(map(repl, format_.split('\\n')))
@ -141,7 +143,7 @@ class ERepublik(callbacks.Plugin):
"""<name|id>
Displays the citizen's medals."""
citizen = self._getCitizen(irc, name)
citizen = self._get(irc, name)
medals = ['%s (%i)' % x for x in citizen['medals'].items() if x[1]]
irc.reply(_('%s has the following medal(s): %s') %
(name, ', '.join(medals)))