mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-03 01:39:23 +01:00
Default dictionary support.
This commit is contained in:
parent
b876d792e0
commit
662a8cccc2
@ -60,14 +60,16 @@ def configure(advanced):
|
|||||||
server = something('What server?')
|
server = something('What server?')
|
||||||
conf.supybot.plugins.Dict.server.set(server)
|
conf.supybot.plugins.Dict.server.set(server)
|
||||||
|
|
||||||
replyTimeout = 'Timeout on the dictd server.'
|
|
||||||
|
|
||||||
conf.registerPlugin('Dict')
|
conf.registerPlugin('Dict')
|
||||||
# TODO: We should make this check to see if there's actually a dictd server
|
# TODO: We should make this check to see if there's actually a dictd server
|
||||||
# running on the host given.
|
# running on the host given.
|
||||||
conf.registerGlobalValue(conf.supybot.plugins.Dict, 'server',
|
conf.registerGlobalValue(conf.supybot.plugins.Dict, 'server',
|
||||||
registry.String('dict.org', """Determines what server the bot will
|
registry.String('dict.org', """Determines what server the bot will
|
||||||
retrieve definitions from."""))
|
retrieve definitions from."""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Dict, 'default',
|
||||||
|
registry.String('', """Determines the default dictionary the bot will
|
||||||
|
ask for definitions in. If this value is '*' (without the quotes) the bot
|
||||||
|
will use all dictionaries to define words."""))
|
||||||
|
|
||||||
class Dict(callbacks.Privmsg):
|
class Dict(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
@ -82,8 +84,8 @@ class Dict(callbacks.Privmsg):
|
|||||||
dbs = conn.getdbdescs().keys()
|
dbs = conn.getdbdescs().keys()
|
||||||
dbs.sort()
|
dbs.sort()
|
||||||
irc.reply(utils.commaAndify(dbs))
|
irc.reply(utils.commaAndify(dbs))
|
||||||
except socket.timeout:
|
except socket.error, e:
|
||||||
irc.error(replyTimeout)
|
irc.error(webutils.strError(e))
|
||||||
|
|
||||||
def random(self, irc, msg, args):
|
def random(self, irc, msg, args):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
@ -95,8 +97,8 @@ class Dict(callbacks.Privmsg):
|
|||||||
conn = dictclient.Connection(server)
|
conn = dictclient.Connection(server)
|
||||||
dbs = conn.getdbdescs().keys()
|
dbs = conn.getdbdescs().keys()
|
||||||
irc.reply(random.choice(dbs))
|
irc.reply(random.choice(dbs))
|
||||||
except socket.timeout:
|
except socket.error, e:
|
||||||
irc.error(replyTimeout)
|
irc.error(webutils.strError(e))
|
||||||
|
|
||||||
def dict(self, irc, msg, args):
|
def dict(self, irc, msg, args):
|
||||||
"""[<dictionary>] <word>
|
"""[<dictionary>] <word>
|
||||||
@ -108,14 +110,21 @@ class Dict(callbacks.Privmsg):
|
|||||||
try:
|
try:
|
||||||
server = conf.supybot.plugins.Dict.server()
|
server = conf.supybot.plugins.Dict.server()
|
||||||
conn = dictclient.Connection(server)
|
conn = dictclient.Connection(server)
|
||||||
except socket.timeout:
|
except socket.error, e:
|
||||||
irc.error('Timeout on the dict server.')
|
irc.error(webutils.strError(e))
|
||||||
return
|
return
|
||||||
dbs = sets.Set(conn.getdbdescs())
|
dbs = sets.Set(conn.getdbdescs())
|
||||||
if args[0] in dbs:
|
if args[0] in dbs:
|
||||||
dictionary = args.pop(0)
|
dictionary = args.pop(0)
|
||||||
else:
|
else:
|
||||||
dictionary = '*'
|
default = self.registryValue('default', msg.args[0])
|
||||||
|
if default in dbs:
|
||||||
|
dictionary = default
|
||||||
|
else:
|
||||||
|
if default:
|
||||||
|
self.log.info('Default dict for %s is not a supported '
|
||||||
|
'dictionary: %s.', msg.args[0], default)
|
||||||
|
dictionary = '*'
|
||||||
word = privmsgs.getArgs(args)
|
word = privmsgs.getArgs(args)
|
||||||
definitions = conn.define(dictionary, word)
|
definitions = conn.define(dictionary, word)
|
||||||
dbs = sets.Set()
|
dbs = sets.Set()
|
||||||
|
Loading…
Reference in New Issue
Block a user