mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Changed supplyDefault to _supplyDefault and added %s handling for supybot.nick.alternates.
This commit is contained in:
parent
1290d2e3eb
commit
b22e3c44e2
29
src/conf.py
29
src/conf.py
@ -93,7 +93,7 @@ def registerGlobalValue(group, name, value):
|
||||
return group.register(name, value)
|
||||
|
||||
def registerChannelValue(group, name, value):
|
||||
value.supplyDefault = True
|
||||
value._supplyDefault = True
|
||||
value.channelValue = True
|
||||
return group.register(name, value)
|
||||
|
||||
@ -123,7 +123,7 @@ registerGroup(users, 'plugins')
|
||||
|
||||
def registerUserValue(group, name, value):
|
||||
assert group._name.startswith('users')
|
||||
value.supplyDefault = True
|
||||
value._supplyDefault = True
|
||||
group.register(name, value)
|
||||
|
||||
class ValidNick(registry.String):
|
||||
@ -137,6 +137,21 @@ class ValidNick(registry.String):
|
||||
class ValidNicks(registry.SpaceSeparatedListOf):
|
||||
Value = ValidNick
|
||||
|
||||
class ValidNickAllowingPercentS(ValidNick):
|
||||
"""Value must be a valid IRC nick, with the possible exception of a %s
|
||||
in it."""
|
||||
def setValue(self, v):
|
||||
# If this works, it's a valid nick, aside from the %s.
|
||||
try:
|
||||
ValidNick.setValue(self, v.replace('%s', ''))
|
||||
# It's valid aside from the %s, we'll let it through.
|
||||
registry.String.setValue(self, v)
|
||||
except registry.InvalidRegistryValue:
|
||||
self.error()
|
||||
|
||||
class ValidNicksAllowingPercentS(ValidNicks):
|
||||
Value = ValidNickAllowingPercentS
|
||||
|
||||
class ValidChannel(registry.String):
|
||||
"""Value must be a valid IRC channel name."""
|
||||
def setValue(self, v):
|
||||
@ -152,10 +167,12 @@ class ValidChannel(registry.String):
|
||||
registerGlobalValue(supybot, 'nick',
|
||||
ValidNick('supybot', """Determines the bot's default nick."""))
|
||||
|
||||
registerGlobalValue(supybot.nick, 'alternates', ValidNicks([], """Determines
|
||||
what alternative nicks will be used if the primary nick (supybot.nick)
|
||||
isn't available. If none are given, or if all are taken, the primary nick
|
||||
will be perturbed appropriately until an unused nick is found."""))
|
||||
registerGlobalValue(supybot.nick, 'alternates',
|
||||
ValidNicksAllowingPercentS(['%s`', '%s_'], """Determines what alternative
|
||||
nicks will be used if the primary nick (supybot.nick) isn't available. A
|
||||
%s in this nick is replaced by the value of supybot.nick when used. If no
|
||||
alternates are given, or if all are used, the supybot.nick will be perturbed
|
||||
appropriately until an unused nick is found."""))
|
||||
|
||||
registerGlobalValue(supybot, 'ident',
|
||||
ValidNick('supybot', """Determines the bot's ident string, if the server
|
||||
|
@ -499,7 +499,10 @@ class Irc(IrcCommandDispatcher):
|
||||
|
||||
def _getNextNick(self):
|
||||
if self.alternateNicks:
|
||||
return self.alternateNicks.pop(0)
|
||||
nick = self.alternateNicks.pop(0)
|
||||
if '%s' in nick:
|
||||
nick %= conf.supybot.nick()
|
||||
return nick
|
||||
else:
|
||||
nick = conf.supybot.nick()
|
||||
ret = nick
|
||||
|
@ -128,19 +128,19 @@ def unescape(name):
|
||||
|
||||
_splitRe = re.compile(r'(?<!\\)\.')
|
||||
def split(name):
|
||||
# XXX: This should eventually handle escapes.
|
||||
return map(unescape, _splitRe.split(name))
|
||||
|
||||
def join(names):
|
||||
return '.'.join(map(escape, names))
|
||||
|
||||
class Group(object):
|
||||
"""A group; it doesn't hold a value unless handled by a subclass."""
|
||||
def __init__(self, supplyDefault=False):
|
||||
self._name = 'unset'
|
||||
self.added = []
|
||||
self._children = utils.InsensitivePreservingDict()
|
||||
self._lastModified = 0
|
||||
self.supplyDefault = supplyDefault
|
||||
self._supplyDefault = supplyDefault
|
||||
OriginalClass = self.__class__
|
||||
class X(OriginalClass):
|
||||
"""This class exists to differentiate those values that have
|
||||
@ -164,7 +164,7 @@ class Group(object):
|
||||
v = self.__class__(self._default, self.help)
|
||||
v.set(s)
|
||||
v.__class__ = self.X
|
||||
v.supplyDefault = False
|
||||
v._supplyDefault = False
|
||||
v.help = '' # Clear this so it doesn't print a bazillion times.
|
||||
self.register(attr, v)
|
||||
return v
|
||||
@ -172,7 +172,7 @@ class Group(object):
|
||||
def __getattr__(self, attr):
|
||||
if attr in self._children:
|
||||
return self._children[attr]
|
||||
elif self.supplyDefault:
|
||||
elif self._supplyDefault:
|
||||
return self.__makeChild(attr, str(self))
|
||||
else:
|
||||
self.__nonExistentEntry(attr)
|
||||
@ -188,7 +188,7 @@ class Group(object):
|
||||
if name in _cache and self._lastModified < _lastModified:
|
||||
#print '***>', _cache[name]
|
||||
self.set(_cache[name])
|
||||
if self.supplyDefault:
|
||||
if self._supplyDefault:
|
||||
for (k, v) in _cache.iteritems():
|
||||
if k.startswith(self._name):
|
||||
group = split(k)[-1]
|
||||
@ -280,7 +280,7 @@ class Value(Group):
|
||||
own setValue."""
|
||||
self._lastModified = time.time()
|
||||
self.value = v
|
||||
if self.supplyDefault:
|
||||
if self._supplyDefault:
|
||||
for (name, v) in self._children.items():
|
||||
if v.__class__ is self.X:
|
||||
self.unregister(name)
|
||||
@ -446,8 +446,9 @@ class StringWithSpaceOnRight(String):
|
||||
String.setValue(self, v)
|
||||
|
||||
class Regexp(Value):
|
||||
"""Value must be a valid regular expression."""
|
||||
def error(self, e):
|
||||
raise InvalidRegistryValue, 'Invalid regexp: %s' % e
|
||||
raise InvalidRegistryValue, 'Value must be a regexp of the form %s' % e
|
||||
|
||||
def set(self, s):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user