-
Notifications
You must be signed in to change notification settings - Fork 1
/
ircreporter.py
42 lines (33 loc) · 1.31 KB
/
ircreporter.py
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
import socket
import random
class IRCReporter:
PRE_NICK = "bluebox"
USER_HOST = "bluebox"
USER_SERVER = "bluebox"
USER_REALNAME = "bluebox parser"
RECEIVER_NICK = "#aausat4packets"
IRC_SERVER = "irc.freenode.org"
IRC_PORT = 6667
IRC_CHANNEL = "#aausat4packets"
def __init__(self):
# Generate nick
self.nick = "{}{}".format(IRCReporter.PRE_NICK, random.randint(0,10000))
self.connect()
def connect(self):
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.irc.connect( (IRCReporter.IRC_SERVER, IRCReporter.IRC_PORT) )
self.irc.recv(8192)
# Register
self.irc.send('NICK {}\r\n'.format(self.nick))
self.irc.send('USER {}, {}, {} :{}\r\n'.format(
self.nick, IRCReporter.USER_HOST,
IRCReporter.USER_SERVER, IRCReporter.USER_REALNAME))
self.irc.recv(8192)
# Connect to channel
self.irc.send('JOIN {}\r\n'.format(IRCReporter.IRC_CHANNEL))
self.irc.recv(8192)
self.irc.send('PRIVMSG {} : I have joined!\r\n'.format(IRCReporter.RECEIVER_NICK))
def send(self, msg):
lines = msg.replace("\r","").split("\n")
for line in lines:
self.irc.send('PRIVMSG {} :{}\r\n'.format(IRCReporter.RECEIVER_NICK, line))