-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirc.py
39 lines (31 loc) · 1.12 KB
/
irc.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
import socket
class IRC:
irc = socket.socket()
def __init__(self):
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def send(self, chan, msg):
#print msg
if msg != "":
try:
self.irc.send("PRIVMSG " + chan + " :" + msg + "\n")
except:
pass
def command(self, command):
if command != "":
#print command
try:
self.irc.send(command+"\n")
except:
pass
def connect(self, server, channel, botnick):
#defines the socket
print "connecting to: "+server
self.irc.connect((server, 6667)) #connects to the server
self.command("USER " + botnick + " " + botnick +" " + botnick + " :"+botnick+" in the house!") #user authentication
self.command("NICK " + botnick)
self.command("JOIN " + channel) #join the chan
def get_text(self):
text = self.irc.recv(2040) #receive the text
if text.find('PING') != -1:
self.irc.send('PONG ' + text.split() [1] + '\r\n')
return text