Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1.  
  2. import socket
  3. import sys
  4.  
  5.  
  6. class IRC:
  7.  
  8. irc = socket.socket()
  9.  
  10. def __init__(self):
  11. self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12.  
  13. def send(self, chan, msg):
  14. self.irc.send("PRIVMSG " + chan + " " + msg + "\n")
  15.  
  16. def connect(self, server, channel, botnick):
  17. #defines the socket
  18. print "connecting to:"+server
  19. self.irc.connect((server, 6667)) #connects to the server
  20. self.irc.send("USER " + botnick + " " + botnick +" " + botnick + " :This is a fun bot!\n") #user authentication
  21. self.irc.send("NICK " + botnick + "\n")
  22. self.irc.send("JOIN " + channel + "\n") #join the chan
  23.  
  24. def get_text(self):
  25. text=self.irc.recv(2040) #receive the text
  26.  
  27. if text.find('PING') != -1:
  28. self.irc.send('PONG ' + text.split() [1] + 'rn')
  29.  
  30. return text
  31. from irc import *
  32. import os
  33. import random
  34.  
  35. channel = "##hackenkunjeleren"
  36. server = "chat.freenode.net"
  37. nickname = "bliksembott"
  38.  
  39. irc = IRC()
  40. irc.connect(server, channel, nickname)
  41.  
  42.  
  43. while 1:
  44. text = irc.get_text()
  45. print text
  46.  
  47.  
  48. if "bliksembott" in text and channel in text and "hello" in text:
  49. irc.send(channel, "Hello!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement