Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.61 KB | None | 0 0
  1. config={
  2.    'network':'irc.synirc.net',#Irc Net
  3.    'port':'6667',#Irc Port
  4.    'name':'derpyhooves',#Bot name
  5.    'rl':'unknown',#Real name (Leave unknown)
  6.    'room':'ponygoons',#Room to join
  7.    'botid':'0',#BotID
  8.    'silent':False#Silent mode
  9.    }
  10.  
  11. try:
  12.    while True:
  13.       irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  14.       try:
  15.          irc.connect ( ( config["network"], int(config["port"]) ) )
  16.       except:
  17.          print "unable to connect to %s" % config["network"]
  18.          continue
  19.       IrcStep = 0
  20.       while True:
  21.          while True:
  22.             if IrcStep>1:
  23.                data = irc.recv ( 4096 ).split()
  24.                if not data:
  25.                   break
  26.             else:
  27.                data = "  "
  28.             if data:
  29.                if 'NOTICE' in data:
  30.                   IrcStep -= 1
  31.                  
  32.                   continue
  33.                
  34.                irc_message = None
  35.                #
  36.                #IRC COMMANDS
  37.                #
  38.                if data[0]=="PING":
  39.                   irc_message = "PONG " + data[1] + "\r\n"
  40.                elif data[1]=="KICK":
  41.                   irc_message = 'JOIN #%s\r\n' % config["room"]
  42.                elif data[1]=="JOIN":
  43.                   if config['greet']:
  44.                      irc_message = "PRIVMSG #%s :%s(%s) > %s : %s\r\n" % (config["room"], str(0), config["name"],'',config['greet'])
  45.                #
  46.                #TEXT COMMANDS
  47.                #
  48.                elif data[1]=="PRIVMSG":
  49.                   message = ""
  50.                   try:
  51.                      realuser,channel,command,user = data[0],data[2]," ".join(data[3:])[1:],data[0].split("!~")[0][1:]
  52.                   except:
  53.                      continue
  54.  
  55.                     #real user: their full user+netmask
  56.                     #channel: the channel the command was recieved from
  57.                     #command: the text they sent
  58.                     #user: just their username
  59.                    
  60.                   if command=="!hello":
  61.                      message = "hi %s" % user
  62.                   elif command=="!sleep":
  63.                      irc_message = "PRIVMSG #%s :%s(%s) > %s : %s\r\n" % (config["room"], str(config['botid']), config["name"],'','derpybot is sleepybot')
  64.                      
  65.                      config['silent']=True
  66.                   elif command=="!awake":
  67.                      config['silent']=False
  68.                   else:
  69.                       #Have all results in the variable `message`
  70.                      
  71.                       #Here is where your commands would be
  72.  
  73.                       try:
  74.                           command,arguements = command.split(" ",1)
  75.                       except:
  76.                           pass
  77.                   if message:
  78.                      if config['silent']==False:
  79.                         irc_message = "PRIVMSG #%s :%s(%s) > %s : %s\r\n" % (config["room"], str(config['botid']), config["name"],'',message)
  80.                elif IrcStep < 3:
  81.                   if IrcStep == 0:
  82.                      irc_message = 'NICK %s\r\n' % config["name"]
  83.                   elif IrcStep == 1:
  84.                      irc_message = 'USER %s %s bla :%s\r\n' % (config["name"].lower(),config["network"],config["rl"])
  85.                   elif IrcStep == 2:
  86.                      print "JOINING #%s" % config["room"]
  87.                      
  88.                      irc_message = 'JOIN #%s\r\n' % config["room"]
  89.                   IrcStep += 1
  90.                if irc_message:
  91.                   irc.send(irc_message)
  92.          print "lost host"
  93.          break
  94. except Exception,e:
  95.    print Exception,e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement