Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import random
- import socket
- import sys
- class IRC:
- irc = socket.socket()
- def __init__(self):
- self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- def send_raw_text(self, msg):
- self.irc.send(msg.encode())
- def send(self, chan, msg):
- self.irc.send_raw_text("PRIVMSG " + chan + " " + msg + "n")
- def connect(self, server, channel, botnick):
- #defines the socket
- print ("connecting to:"+server)
- self.irc.connect((server, 6667)) #connects to the server
- self.send_raw_text("USER " + botnick + " " + botnick +" " + botnick + " :This is a fun bot!n") #user authentication
- self.send_raw_text("NICK " + botnick + "n")
- def get_text(self):
- text=self.irc.recv(2040) #receive the text
- if text.find('PING'.encode()) != -1:
- self.irc.send_raw_text('PONG ' + text.split() [1] + 'rn')
- return text
- ## IRC Config
- channel = "#python"
- server = "irc.freenode.net"
- nickname = "bender"
- irc = IRC()
- irc.connect(server, channel, nickname)
- while 1:
- text = irc.get_text()
- print (text)
- if "PRIVMSG".encode() in text and channel in text and "hello".encode() in text:
- irc.send(channel, "Hello!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement