summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2013-06-13 23:50:53 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2013-06-13 23:50:53 +0200
commit70d9d9ec4dc48362ea00756f957aae231118a59e (patch)
tree616f39589bb5ffaa2f45e6df15100db7024f4ade
parenta8ae2721a7b9c3346aa08c3af8e49c3d49a3076b (diff)
Added mode option to set server-specific usermodes.
-rwxr-xr-xfot.py38
1 files changed, 38 insertions, 0 deletions
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)