summaryrefslogtreecommitdiff
path: root/proxy.py
blob: ba5ac36f8269030cfc3facd0cd1ae9183e176727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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])