diff options
author | tv <tv@xso> | 2011-09-06 14:36:57 +0200 |
---|---|---|
committer | tv <tv@xso> | 2011-09-06 14:36:57 +0200 |
commit | 5bb7fdb08dd0f755ddde627f21e0f9a8ebd524ba (patch) | |
tree | 6a54bcef0f5c253731a2b7a648e14bffed4c5f97 /IRC | |
parent | 67a78596e826aa88375b21d5f194812245cfa04a (diff) |
//Reaktor/IRC: get name from tinc.conf
Diffstat (limited to 'IRC')
-rwxr-xr-x | IRC/bot2.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/IRC/bot2.py b/IRC/bot2.py index 7365686..49e8a57 100755 --- a/IRC/bot2.py +++ b/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) |