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