summaryrefslogtreecommitdiff
path: root/proxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'proxy.py')
-rw-r--r--proxy.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/proxy.py b/proxy.py
new file mode 100644
index 0000000..ba5ac36
--- /dev/null
+++ b/proxy.py
@@ -0,0 +1,60 @@
+import select
+import socket
+import string
+
+LOCAL_PORT = 54321
+
+HOST = 'irc.oftc.net'
+PORT = 6667
+NICK = 'CommitBot'
+IDENT = 'chrysalidecommitbot'
+REALNAME = 'CommitBot'
+
+CHANNEL = '#chrysalide'
+
+local_fd = socket.socket()
+local_fd.bind(('127.0.0.1', LOCAL_PORT))
+local_fd.listen(1)
+
+print('Listeing...')
+
+irc_fd = socket.socket()
+irc_fd.connect((HOST, PORT))
+
+irc_fd.send('NICK %s\r\n' % NICK)
+irc_fd.send('USER %s %s bla :%s\r\n' % (IDENT, HOST, REALNAME))
+
+print('Connected to IRC...')
+
+irc_fd.send('JOIN ' + CHANNEL + '\r\n')
+
+print('Online!')
+
+while True:
+
+ ready_socks, _, _ = select.select([local_fd, irc_fd], [], [])
+
+ if local_fd in ready_socks:
+
+ conn, addr = local_fd.accept()
+ print 'Got data from ' + addr[0] + ':' + str(addr[1])
+
+ data = conn.recv(1024)
+ irc_fd.send('PRIVMSG ' + CHANNEL + ' :' + data + '\r\n')
+
+ conn.close()
+
+ else:
+
+ data = irc_fd.recv(1024)
+
+ for line in data.split('\n'):
+
+ line = string.rstrip(line)
+ line = string.split(line)
+
+ if len(line) == 0:
+ continue
+
+ if line[0] == "PING":
+ irc_fd.send("PONG %s\r\n" % line[1])