diff options
-rwxr-xr-x | fot.py | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -115,7 +115,45 @@ class Bot(irc.IRCClient): self.nickname = config.get(self.factory.server, 'nickname') irc.IRCClient.connectionMade(self) + def set_usermodes(self): + mode = config.get(self.factory.server, 'mode', None) + if not mode: + return + + from StringIO import StringIO + + s = StringIO(mode) + mode = 0 + add = set() + remove = set() + c = s.read(1) + while c: + if c == '+': + mode = 1 + c = s.read(1) + elif c == '-': + mode = -1 + c = s.read(1) + if mode > 0: + add.add(c) + elif mode < 0: + remove.add(c) + else: + raise RuntimeError('No mode set!') + c = s.read(1) + + intersect = add.intersection(remove) + if intersect: + print 'Modes conflict:', intersect + add.difference_update(intersect) + remove.difference_update(intersect) + if add: + self.mode(self.nickname, True, ''.join(add)) + if remove: + self.mode(self.nickname, False, ''.join(remove)) + def signedOn(self): + self.set_usermodes() for chan in config.get(self.factory.server, 'channels').split(' '): self.join(chan) |