mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import socket
|
|
|
|
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, channels, botnick):
|
|
# 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"))
|
|
# time.sleep(5)
|
|
|
|
# join the channel
|
|
for chan in channels:
|
|
self.irc.send(bytes("JOIN " + chan + "\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().decode("UTF-8") [1] + '\r\n', "UTF-8"))
|
|
|
|
return resp
|