summaryrefslogtreecommitdiff
path: root/subbot.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-03-17 12:42:09 +0100
committerChristian Franke <nobody@nowhere.ws>2013-03-17 12:47:40 +0100
commit625fc3e4fd50451b950c3d1e2bf2356fb74dcefa (patch)
treed10c9a187b505b881c3bc29c18dabbcf6bf5e8f7 /subbot.py
parent76c0532b5638eda76e71a748832290adb985f21a (diff)
Add the other scripts (funny code is funny)
Diffstat (limited to 'subbot.py')
-rw-r--r--subbot.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/subbot.py b/subbot.py
new file mode 100644
index 0000000..7462bce
--- /dev/null
+++ b/subbot.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import irc.bot
+import json, time
+import traceback
+
+import settings
+
+svcpw = settings.bot_svcpw
+
+class TestBot(irc.bot.SingleServerIRCBot):
+ def __init__(self, channel, nickname, server, port=6667):
+ irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
+ self.channel = channel
+
+ def on_nicknameinuse(self, c, e):
+ c.nick(c.get_nickname() + "_")
+
+ def on_welcome(self, c, e):
+ c.privmsg('NickServ', 'identify sublab|open %s' % (svcpw, ))
+ self.refresh()
+ c.join(self.channel)
+
+ def refresh(self):
+ c = self.connection
+ havenick = c.get_nickname()
+ curtime = time.time()
+
+ try:
+ sdata = json.load(file('/home/services/http/subcan.json', 'r'))
+ door = sdata[u'door.lock']
+
+ if door[u'ts'] < curtime - 120:
+ wantnick = 'sublab|error'
+ elif door[u'text'] == u'closed':
+ wantnick = 'sublab|closed'
+ elif door[u'text'] == u'open':
+ wantnick = 'sublab|open'
+ else:
+ wantnick = 'sublab|error'
+ except Exception, e:
+ traceback.print_exc()
+ wantnick = 'sublab|error'
+
+ if wantnick != havenick:
+ print int(curtime), 'nick:', havenick, '->', wantnick
+ c.privmsg('NickServ', 'ghost %s %s' % (wantnick, svcpw))
+ c.privmsg('NickServ', 'release %s %s' % (wantnick, svcpw))
+ c.nick(wantnick)
+ self.ircobj.execute_delayed(5, self.refresh)
+
+def main():
+ bot = TestBot('#sublab', 'sublab|closed', '172.22.24.1', 6667)
+ bot.start()
+
+if __name__ == "__main__":
+ main()