Advertisement
Guest User

Untitled

a guest
May 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. import socket
  6.  
  7. recv=""
  8. HOST="irc.freenode.net"
  9. PORT=6667
  10. NICK="PedroBot"
  11. USERNAME="PedroBot"
  12. REALNAME="PedroBot"
  13. PASSWORD="21223445"
  14. CHANNEL="##fatchat"
  15. factoids = {} # don't edit this manually
  16.  
  17. def parsemsg(s) :
  18.     trailing = 0
  19.     prefix = 0
  20.     if s[0] == ":" :
  21.         s = s[1:].split(' ', 1)
  22.         prefix = s[0]
  23.         s = s[1]
  24.     if " :" in s :
  25.         s = s.split(" :")
  26.         trailing = s[1]
  27.         s = s[0]
  28.     args = s.split()
  29.     command = args.pop(0)
  30.     if trailing != 0 :
  31.         args.append(trailing)
  32.     return prefix, command, args
  33.  
  34. socket = socket.socket()
  35. socket.connect((HOST, PORT))
  36. if PASSWORD != "(secret)" :
  37.     socket.send("PASS %s\r\n" % (PASSWORD))
  38. socket.send("NICK %s\r\n" % (NICK))
  39. socket.send("USER %s * * :%s\r\n" % (USERNAME, REALNAME))
  40. socket.send("JOIN %s\r\n" % (CHANNEL))
  41.  
  42. while True :
  43.     recv = recv + socket.recv(4096)
  44.     s = recv.split("\r\n")
  45.     recv = s.pop()
  46.     for msg in s :
  47.         print msg
  48.         prefix, command, args = parsemsg(msg)
  49.         if command == "PING" :
  50.             socket.send("PONG\r\n")
  51.         elif args[-1].split()[0].lower() == "!add" :
  52.             print args[-1].split()[3:]
  53.             factoids["!" + args[-1].split()[1]] = args[-1].split()[3:]
  54.             print factoids["!" + args[-1].split()[1]]
  55.             if factoids["!" + args[-1].split()[1]] == args[-1].split()[3:] :
  56.                 socket.send("PRIVMSG %s :Factoid %s added successfully\r\n" % (CHANNEL, args[-1].split()[1]))
  57.         else :
  58.             for item in factoids.keys() :
  59.                 print item
  60.                 print factoids[item]
  61.                 if item == args[-1].split()[0] :
  62.                     socket.send("PRIVMSG %s :%s\r\n" % (CHANNEL, str(factoids[item])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement