From b22e3c44e2b03060a586a8b5f9e6f6deb59e086d Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 17 Aug 2004 20:43:25 +0000 Subject: [PATCH] Changed supplyDefault to _supplyDefault and added %s handling for supybot.nick.alternates. --- src/conf.py | 29 +++++++++++++++++++++++------ src/irclib.py | 5 ++++- src/registry.py | 15 ++++++++------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/conf.py b/src/conf.py index 875750628..ca452e29d 100644 --- a/src/conf.py +++ b/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 diff --git a/src/irclib.py b/src/irclib.py index 07c665721..e07e42075 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -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 diff --git a/src/registry.py b/src/registry.py index 8f88abda7..ce514a3aa 100644 --- a/src/registry.py +++ b/src/registry.py @@ -128,19 +128,19 @@ def unescape(name): _splitRe = re.compile(r'(?', _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: