summaryrefslogtreecommitdiffstats
path: root/Reaktor
diff options
context:
space:
mode:
authortv <tv@xso>2011-09-06 14:36:57 +0200
committertv <tv@xso>2011-09-06 14:36:57 +0200
commit9250247e57255ab9886fd15107f4f5ec31a0a888 (patch)
tree54a23fd587220d4f48ccc663790834abce86d209 /Reaktor
parent517b059be3acef5fb921d4899c4bc192ffef1b7c (diff)
//Reaktor/IRC: get name from tinc.conf
Diffstat (limited to 'Reaktor')
-rwxr-xr-xReaktor/IRC/bot2.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/Reaktor/IRC/bot2.py b/Reaktor/IRC/bot2.py
index 7365686e..49e8a57f 100755
--- a/Reaktor/IRC/bot2.py
+++ b/Reaktor/IRC/bot2.py
@@ -85,16 +85,32 @@ class IRCBot(SimpleIRCClient):
# TODO reconnect
exit(0)
+# retrieve the value of a [singleton] variable from a tinc.conf(5)-like file
+def getconf1(x, path):
+ from re import findall
+ pattern = '(?:^|\n)\s*' + x + '\s*=\s*(.*\w)\s*(?:\n|$)'
+ y = findall(pattern, open(path, 'r').read())
+ if len(y) < 1:
+ raise AttributeError("len(getconf1('%s', '%s') < 1)" % (x, path))
+ if len(y) > 1:
+ y = ' '.join(y)
+ raise AttributeError("len(getconf1('%s', '%s') > 1)\n ====> %s"
+ % (x, path, y))
+ return y[0]
+
def main():
- host = str(env.get('host', 'irc.freenode.org'))
+ name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf')
+ host = str(env.get('host', 'supernode'))
port = int(env.get('port', 6667))
- nick = str(env.get('nick', 'crabspasm'))
+ nick = str(env.get('nick', name))
target = str(env.get('target', '#tincspasm'))
print('====> irc://%s@%s:%s/%s' % (nick, host, port, target))
client = IRCBot(target)
try:
- client.connect(host, port, nick)
+ from getpass import getuser
+ client.connect(host, port, nick, username=getuser(),
+ ircname='//Reaktor running at %s.retiolum' % (name))
except ServerConnectionError, error:
print(error)
exit(1)