mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 22:51:01 +01:00
Converted to Configurable.
This commit is contained in:
parent
dd4c09e1a4
commit
760483e2f0
@ -44,6 +44,7 @@ import dictclient
|
|||||||
import conf
|
import conf
|
||||||
import debug
|
import debug
|
||||||
import utils
|
import utils
|
||||||
|
import plugins
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
@ -61,47 +62,46 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
server = something('What server?')
|
server = something('What server?')
|
||||||
onStart.append('dictserver %s' % server)
|
onStart.append('dictserver %s' % server)
|
||||||
|
|
||||||
class Dict(callbacks.Privmsg):
|
replyTimeout = 'Timeout on the dictd server.'
|
||||||
|
class Dict(callbacks.Privmsg, plugins.Configurable):
|
||||||
threaded = True
|
threaded = True
|
||||||
dictServer = 'dict.org'
|
configurables = plugins.ConfigurableDictionary(
|
||||||
|
[('server', plugins.ConfigurableStrType, 'dict.org',
|
||||||
|
"""Determines what server the bot will connect to to receive
|
||||||
|
definitions from."""),]
|
||||||
|
)
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.setDictServer(self.dictServer)
|
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
|
plugins.Configurable.__init__(self)
|
||||||
|
|
||||||
def setDictServer(self, server):
|
def die(self):
|
||||||
self.dictServer = server
|
callbacks.Privmsg.die(self)
|
||||||
try:
|
plugins.Configurable.die(self)
|
||||||
conn = dictclient.Connection(server, timeout=3)
|
|
||||||
self.dictdbs = sets.Set(conn.getdbdescs())
|
|
||||||
except socket.timeout:
|
|
||||||
debug.msg('Timeout on server %s' % server)
|
|
||||||
self.dictdbs = sets.Set([])
|
|
||||||
|
|
||||||
def dictserver(self, irc, msg, args):
|
|
||||||
"""[<dictd server>]
|
|
||||||
|
|
||||||
Sets the dictd server the plugin should use.
|
|
||||||
"""
|
|
||||||
server = privmsgs.getArgs(args)
|
|
||||||
try:
|
|
||||||
self.setDictServer(server)
|
|
||||||
irc.reply(msg, conf.replySuccess)
|
|
||||||
except Exception, e:
|
|
||||||
irc.error(msg, debug.exnToString(e))
|
|
||||||
|
|
||||||
def dictionaries(self, irc, msg, args):
|
def dictionaries(self, irc, msg, args):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Returns the dictionaries valid for the dict command.
|
Returns the dictionaries valid for the dict command.
|
||||||
"""
|
"""
|
||||||
irc.reply(msg, utils.commaAndify(self.dictdbs))
|
try:
|
||||||
|
conn = dictclient.Connection(self.configurables.get('server'))
|
||||||
|
dbs = conf.getdbdescs()
|
||||||
|
dbs.sort()
|
||||||
|
irc.reply(msg, utils.commaAndify(dbs))
|
||||||
|
except socket.timeout:
|
||||||
|
irc.error(msg, replyTimeout)
|
||||||
|
|
||||||
def random(self, irc, msg, args):
|
def random(self, irc, msg, args):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Returns a random valid dictionary.
|
Returns a random valid dictionary.
|
||||||
"""
|
"""
|
||||||
irc.reply(msg, random.choice(list(self.dictdbs)))
|
try:
|
||||||
|
conn = dictclient.Connection(self.configurables.get('server'))
|
||||||
|
dbs = conf.getdbdescs()
|
||||||
|
irc.reply(msg, random.choice(dbs))
|
||||||
|
except socket.timeout:
|
||||||
|
irc.error(msg, replyTimeout)
|
||||||
|
|
||||||
def dict(self, irc, msg, args):
|
def dict(self, irc, msg, args):
|
||||||
"""[<dictionary>] <word>
|
"""[<dictionary>] <word>
|
||||||
@ -111,13 +111,12 @@ class Dict(callbacks.Privmsg):
|
|||||||
if not args:
|
if not args:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
try:
|
try:
|
||||||
conn = dictclient.Connection(self.dictServer)
|
conn = dictclient.Connection(self.configurables.get('server'))
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
irc.error(msg, 'Timeout on the dict server.')
|
irc.error(msg, 'Timeout on the dict server.')
|
||||||
return
|
return
|
||||||
if not self.dictdbs:
|
dbs = sets.Set(conn.getdbdescs())
|
||||||
self.dictdbs = sets.Set(conn.getdbdescs())
|
if args[0] in dbs:
|
||||||
if args[0] in self.dictdbs:
|
|
||||||
dictionary = args.pop(0)
|
dictionary = args.pop(0)
|
||||||
else:
|
else:
|
||||||
dictionary = '*'
|
dictionary = '*'
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
|
|
||||||
from test import *
|
from test import *
|
||||||
|
|
||||||
class DictionaryTestCase(PluginTestCase, PluginDocumentation):
|
class DictTestCase(PluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Dictionary', 'Misc')
|
plugins = ('Dict', 'Misc')
|
||||||
def testDict(self):
|
def testDict(self):
|
||||||
self.assertNotError('dict slash')
|
self.assertNotError('dict slash')
|
||||||
self.assertNotRegexp('dict web1913 slash', 'foldoc')
|
self.assertNotRegexp('dict web1913 slash', 'foldoc')
|
Loading…
x
Reference in New Issue
Block a user