From 70d9d9ec4dc48362ea00756f957aae231118a59e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 13 Jun 2013 23:50:53 +0200 Subject: Added mode option to set server-specific usermodes. --- fot.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fot.py b/fot.py index 28ffdff..387b426 100755 --- a/fot.py +++ b/fot.py @@ -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) -- cgit v1.2.3