Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 6.86 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! usr/bin/env python
  2. """
  3. Program: Cowsay
  4. Version: 1.0.3.36
  5. Author: banhammer
  6. Editors: Cam, Thugaim
  7. Description: Cowsay is a bot designed to send different ascii cows and text to an IRC channel, similar to the cowsay program.
  8. """
  9. import socket
  10. import sys
  11. from time import sleep
  12. import urllib
  13. irc = socket.socket()
  14. network = 'irc.n0v4.com'
  15. port = 6667
  16. ircchannels = ['#sexy', '#bots', '#lobby']
  17. ircname = 'Cowsay' # max 30 characters
  18. realname = 'COWSAYBOT'
  19. ident = 'cows'
  20. password = 'lol'
  21. crlf = '\r\n'
  22. onoff = 'on'
  23. cow = True
  24. noucounter = 0
  25. admins = []
  26. allowedhosts = []
  27. def SendIRCRaw(rawtext):
  28.     irc.send(rawtext+crlf)
  29. def SendText(text):
  30.     irc.send("PRIVMSG %s :%s" % (location, text) + crlf)
  31. def SendPM(text):
  32.     irc.send("PRIVMSG %s :%s" % (nick, text) + crlf)
  33. def CowIsOff():
  34.     SendText("Cowsay is off.")
  35. irc.connect((network, port))
  36. SendIRCRaw("NICK %s" % (ircname))
  37. SendIRCRaw("USER %s **** **** :%s" % (ident, realname))
  38. sleep(1)
  39. SendIRCRaw("NickServ IDENTIFY %s" % (password))
  40. SendIRCRaw("MODE %s +B" % (ircname))
  41. sleep(1)
  42. # [0]host, [1]channel, [2]nick, [3+]message
  43. while True:
  44. # Parse Message --------------------------------------------    
  45.     msg = irc.recv(512)
  46.     msgsplit = msg.split()
  47.     print(msg)
  48.     if len(msg.split())>0:
  49.         if msg.split()[0] == "PING":
  50.             SendIRCRaw("PONG %s" % (msg.split()[1]))
  51.     if len(msg.split())>1:
  52.         if msg.split()[1] == "372":
  53.             print("372")
  54.             for channel in ircchannels:
  55.                 SendIRCRaw("JOIN %s" % (channel))
  56.     if len(msg.split())>1:
  57.         if msg.split()[1] == "433":
  58.             print("433")
  59.             SendIRCRaw("MSG NICKSERV GHOST %s %s" % (ircname, password))
  60.             sleep(1)
  61.             for channel in ircchannels:
  62.                 SendIRCRaw("JOIN %s" % (channel))
  63.     if len(msg.split())>=4:
  64.         try:
  65.             host = msgsplit[0].split("@")[1].lower()
  66.         except:
  67.             host = ""
  68.         text = " ".join(msg.split()[3:][1:])
  69.         cmd = msg.split()[3][1:].lower()
  70.         location = msg.split()[2]
  71.         nick = (msg.split()[0].split("!")[0])[1:].lower()
  72.     elif len(msg.split())>=4:
  73.         cmd = msg.split()[4].lower()
  74.     else:
  75.         cmd = ""
  76.         location = ""
  77.         nick = ""
  78.         text = ""
  79. # Logging --------------------------------------------------
  80. #    cowsaylog = open("cowsaylog.txt",'a')
  81. #    cowsaylog.write(msg)
  82. # Ignore PMs -----------------------------------------------
  83. # Admin Commands -------------------------------------------
  84.     if nick in admins:
  85.         if host in allowedhosts:
  86.                 if cmd == "cow":
  87.                     onoff = " ".join(msg.split()[3:][1:])
  88.                     if onoff == "off":
  89.                         cow = False
  90.                         SendIRCRaw("NOTICE %s COW OFF" % (nick))
  91.                     if onoff == "on":
  92.                         cow = True
  93.                         SendIRCRaw("NOTICE %s COW ON" % (nick))
  94.                 if cmd == "part":
  95.                     SendIRCRaw("PART :#" + msg.split()[4])
  96.                 if cmd == "join":
  97.                     SendIRCRaw("JOIN :#" + msg.split()[4])
  98.                 if cmd == "cowshit":
  99.                     SendIRCRaw("QUIT MOO")
  100.                     quit()
  101.                 if cmd == "status":
  102.                     SendPM(onoff)
  103.                 if cmd == "sendraw":
  104.                     SendIRCRaw(" ".join(msg.split()[3:][1:]))
  105. # Cows -----------------------------------------------------
  106.     c = " ".join(msg.split()[3:][1:])
  107.     cnum = int(len(c))
  108.     cdash = cnum*"_"
  109.     cdash2 = cnum*"-"
  110.     def say_beginning(cdash,c,cdash2):
  111.         SendText(" _%s_" % (cdash))
  112.         SendText("< %s >" % (c))
  113.         SendText(" -%s-" % (cdash2))
  114.     def thought_beginning(cdash,c,cdash2):
  115.         SendText(" _%s_" % (cdash))
  116.         SendText("( %s )" % (c))
  117.         SendText(" -%s-" % (cdash2))
  118.     if cow is True:
  119.         if cmd == "cowsay":
  120.             say_beginning(cdash,c,cdash2)
  121.             SendText("        \   ^__^")
  122.             SendText("         \  (oo)\_______")
  123.             SendText("            (__)\       )\/\ ")
  124.             SendText("                ||----w |")
  125.             SendText("                ||     ||")
  126.         if cmd == "cowdrunk":
  127.             say_beginning(cdash,c,cdash2)
  128.             SendText("        \   ^__^")
  129.             SendText("         \  (**)\_______")
  130.             SendText("            (__)\       )\/\ ")
  131.             SendText("             U  ||----w |")
  132.             SendText("                ||     ||")
  133.         if cmd == "cowsex":
  134.             say_beginning(cdash,c,cdash2)
  135.             SendText("      \                _")
  136.             SendText("       \              (_)")
  137.             SendText("        \   ^__^       / \ ")
  138.             SendText("         \  (oo)\_____/_\ \ ")
  139.             SendText("            (__)\       ) /")
  140.             SendText("                ||----w ((")
  141.             SendText("                ||     ||>> ")
  142.         if cmd == "cowsaytux":
  143.             SendIRCRaw("NICK Penguin")
  144.             sleep(1)
  145.             thought_beginning(cdash,c,cdash2)
  146.             SendText("   o    .--.")
  147.             SendText("    o  |o_o |")
  148.             SendText("       |:_/ |")
  149.             SendText("      //   \\ \\")
  150.             SendText("     (|     | )")
  151.             SendText("    /'\\_   _/`\\")
  152.             SendText("    \\___)=(___/")
  153.             SendIRCRaw("NICK Cowsay")
  154. # Cow Off Notification -------------------------------------
  155. #        elif cmd == "cowsay":
  156. #            CowIsOff()
  157. #        elif cmd == "cowdrunk":
  158. #            CowIsOff()
  159. #        elif cmd == "cowsex":
  160. #            CowIsOff()
  161. #        elif cmd == "tux":
  162. #            CowIsOff()
  163. # Public Commands ------------------------------------------
  164.         if cmd == "cowhelp":
  165.             SendPM("Available commands are:")
  166.             SendPM("cowhelp          status")
  167.             SendPM("cow on/off      cowshit")
  168.             SendPM("cowjoin         cowpart")
  169.             SendPM("-----------------------")
  170.             SendPM("cowsay         cowdrunk")
  171.             SendPM("cowsex")
  172.         if cmd == "no":
  173.             nou = " ".join(msg.split()[3:][1:])
  174.             if nou == "u":
  175.                 if noucounter < 10:
  176.                     SendText("NO U")
  177.                     noucounter += 1
  178.                 else:
  179.                     SendText("Fine, me.")
  180.         if cmd == "beef":
  181.             beef_for = " ".join(msg.split()[3:][1:])
  182.             SendIRCRaw("PRIVMSG %s :\x01ACTION cooks up some fancy steak for %s.\x01" % (location, beef_for))
  183. # Other ----------------------------------------------------
  184.         if cmd == "meme":
  185.             memeurl = "http://api.automeme.net/text?lines=1"
  186.             memes = urllib.urlopen(memeurl).read().replace('\n','').replace("_","\x02")
  187.             print(memes)
  188.             SendIRCRaw("PRIVMSG %s %s" % (location, memes))