Advertisement
Guest User

Untitled

a guest
May 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. import socket
  2. import time
  3. import random
  4. import linecache
  5. import re
  6.  
  7. ###
  8. # I want this:
  9. #  If you type: kill <VICTIM> then it read random lines randomly (time .. um 3-6 seconds) until you say: "BOTNAME: stop!"
  10. ###
  11.  
  12. ###
  13. HOST = "irc.gyaloglo.hu"
  14. PORT = 6667
  15. NICK = "VINCSENZO"
  16. PASS = "sziszi"
  17. USERNAME = "VINCSENZO"
  18. REALNAME = "VINCSENZO"
  19. CHAN = "#Afro_C"
  20. ###
  21.  
  22. def randomLine(filename):
  23.     fh = open(filename, "r")
  24.     lineNum = 0
  25.     it = ''
  26.    
  27.     while 1:
  28.         aLine = fh.readline()
  29.         lineNum = lineNum + 1
  30.         if aLine != "":
  31.             if random.uniform(0,lineNum)<1:
  32.                 it = aLine
  33.             else:
  34.                 break
  35.         fh.close()
  36.         return it
  37.  
  38. def countLine(filename):
  39.     with open(filename) as f:
  40.         for i, l in enumerate(f):
  41.             pass
  42.     return i + 1
  43.  
  44.  
  45. irc = socket.socket ( )
  46. irc.connect ( ( HOST, PORT ) )
  47. irc.send ( "NICK %s\r\n" % NICK )
  48. irc.send ( "USER %s %s %s :%s\r\n" % ( USERNAME, HOST, NICK, REALNAME ) )
  49. irc.send ( "PASS %s\r\n" % PASS )
  50. time.sleep( 5 )
  51. irc.send ( "JOIN %s\r\n" % CHAN )
  52. while True:
  53.    data = irc.recv ( 4096 )
  54.    IRC_NICK = str(data).split ( '!' ) [ 0 ] . split ( ":")[1]
  55.    IRC_NICK = re.sub("_", " ", IRC_NICK)
  56.    if data.find ( 'PING' ) != -1:
  57.        irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
  58.    if data.find ( 'kcsg' ) != -1:
  59.        irc.send ( "PRIVMSG %s :%s: %s\r\n" % ( CHAN, IRC_NICK, linecache.getline( 'test.txt', random.randint( 1, countLine( 'test.txt' ) ) ) ) )
  60.    if data.find ( 'proba' ) != -1:
  61.        irc.send ( "PRIVMSG #Afro_C :%s\r\n" % IRC_NICK )
  62.    print data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement