-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.py
37 lines (28 loc) · 1.25 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
import socket
import time
class IRC:
irc = socket.socket()
def __inti__(self):
self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def private_msg(self, msg,dest):
self.irc.send(bytes("*"+dest+"* ","UTF-8"))
def send(self, channel, msg):
# Transfer data
self.irc.send(bytes("PRIVMSG " + channel + " " + msg + "\n", "UTF-8"))
def connect(self, server, port, channel, botnick, botpass, botnickpass):
# Connect to the server
print("Connecting to: " + server)
self.irc.connect((server, port))
# Perform user authentication
self.irc.send(bytes("USER " + botnick + " " + botnick + " " + botnick + " :python\n", "UTF-8"))
self.irc.send(bytes("NICK " + botnick + "\n", "UTF-8"))
self.irc.send(bytes("NICKSERV IDENTIFY " + botnickpass + " " + botpass + "\n", "UTF-8"))
# join the channel
self.irc.send(bytes("JOIN " + channel + "\n", "UTF-8"))
def get_response(self):
time.sleep(1)
# Get the response
resp = self.irc.recv(2040).decode("UTF-8")
if resp.find('PING') != -1:
self.irc.send(bytes('PONG ' + resp.split()[1] + '\r\n', "UTF-8"))
return resp