- #! usr/bin/env python
- """
- Program: Cowsay
- Version: 1.0.3.36
- Author: banhammer
- Editors: Cam, Thugaim
- Description: Cowsay is a bot designed to send different ascii cows and text to an IRC channel, similar to the cowsay program.
- """
- import socket
- import sys
- from time import sleep
- import urllib
- irc = socket.socket()
- network = 'irc.n0v4.com'
- port = 6667
- ircchannels = ['#sexy', '#bots', '#lobby']
- ircname = 'Cowsay' # max 30 characters
- realname = 'COWSAYBOT'
- ident = 'cows'
- password = 'lol'
- crlf = '\r\n'
- onoff = 'on'
- cow = True
- noucounter = 0
- admins = []
- allowedhosts = []
- def SendIRCRaw(rawtext):
- irc.send(rawtext+crlf)
- def SendText(text):
- irc.send("PRIVMSG %s :%s" % (location, text) + crlf)
- def SendPM(text):
- irc.send("PRIVMSG %s :%s" % (nick, text) + crlf)
- def CowIsOff():
- SendText("Cowsay is off.")
- irc.connect((network, port))
- SendIRCRaw("NICK %s" % (ircname))
- SendIRCRaw("USER %s **** **** :%s" % (ident, realname))
- sleep(1)
- SendIRCRaw("NickServ IDENTIFY %s" % (password))
- SendIRCRaw("MODE %s +B" % (ircname))
- sleep(1)
- # [0]host, [1]channel, [2]nick, [3+]message
- while True:
- # Parse Message --------------------------------------------
- msg = irc.recv(512)
- msgsplit = msg.split()
- print(msg)
- if len(msg.split())>0:
- if msg.split()[0] == "PING":
- SendIRCRaw("PONG %s" % (msg.split()[1]))
- if len(msg.split())>1:
- if msg.split()[1] == "372":
- print("372")
- for channel in ircchannels:
- SendIRCRaw("JOIN %s" % (channel))
- if len(msg.split())>1:
- if msg.split()[1] == "433":
- print("433")
- SendIRCRaw("MSG NICKSERV GHOST %s %s" % (ircname, password))
- sleep(1)
- for channel in ircchannels:
- SendIRCRaw("JOIN %s" % (channel))
- if len(msg.split())>=4:
- try:
- host = msgsplit[0].split("@")[1].lower()
- except:
- host = ""
- text = " ".join(msg.split()[3:][1:])
- cmd = msg.split()[3][1:].lower()
- location = msg.split()[2]
- nick = (msg.split()[0].split("!")[0])[1:].lower()
- elif len(msg.split())>=4:
- cmd = msg.split()[4].lower()
- else:
- cmd = ""
- location = ""
- nick = ""
- text = ""
- # Logging --------------------------------------------------
- # cowsaylog = open("cowsaylog.txt",'a')
- # cowsaylog.write(msg)
- # Ignore PMs -----------------------------------------------
- # Admin Commands -------------------------------------------
- if nick in admins:
- if host in allowedhosts:
- if cmd == "cow":
- onoff = " ".join(msg.split()[3:][1:])
- if onoff == "off":
- cow = False
- SendIRCRaw("NOTICE %s COW OFF" % (nick))
- if onoff == "on":
- cow = True
- SendIRCRaw("NOTICE %s COW ON" % (nick))
- if cmd == "part":
- SendIRCRaw("PART :#" + msg.split()[4])
- if cmd == "join":
- SendIRCRaw("JOIN :#" + msg.split()[4])
- if cmd == "cowshit":
- SendIRCRaw("QUIT MOO")
- quit()
- if cmd == "status":
- SendPM(onoff)
- if cmd == "sendraw":
- SendIRCRaw(" ".join(msg.split()[3:][1:]))
- # Cows -----------------------------------------------------
- c = " ".join(msg.split()[3:][1:])
- cnum = int(len(c))
- cdash = cnum*"_"
- cdash2 = cnum*"-"
- def say_beginning(cdash,c,cdash2):
- SendText(" _%s_" % (cdash))
- SendText("< %s >" % (c))
- SendText(" -%s-" % (cdash2))
- def thought_beginning(cdash,c,cdash2):
- SendText(" _%s_" % (cdash))
- SendText("( %s )" % (c))
- SendText(" -%s-" % (cdash2))
- if cow is True:
- if cmd == "cowsay":
- say_beginning(cdash,c,cdash2)
- SendText(" \ ^__^")
- SendText(" \ (oo)\_______")
- SendText(" (__)\ )\/\ ")
- SendText(" ||----w |")
- SendText(" || ||")
- if cmd == "cowdrunk":
- say_beginning(cdash,c,cdash2)
- SendText(" \ ^__^")
- SendText(" \ (**)\_______")
- SendText(" (__)\ )\/\ ")
- SendText(" U ||----w |")
- SendText(" || ||")
- if cmd == "cowsex":
- say_beginning(cdash,c,cdash2)
- SendText(" \ _")
- SendText(" \ (_)")
- SendText(" \ ^__^ / \ ")
- SendText(" \ (oo)\_____/_\ \ ")
- SendText(" (__)\ ) /")
- SendText(" ||----w ((")
- SendText(" || ||>> ")
- if cmd == "cowsaytux":
- SendIRCRaw("NICK Penguin")
- sleep(1)
- thought_beginning(cdash,c,cdash2)
- SendText(" o .--.")
- SendText(" o |o_o |")
- SendText(" |:_/ |")
- SendText(" // \\ \\")
- SendText(" (| | )")
- SendText(" /'\\_ _/`\\")
- SendText(" \\___)=(___/")
- SendIRCRaw("NICK Cowsay")
- # Cow Off Notification -------------------------------------
- # elif cmd == "cowsay":
- # CowIsOff()
- # elif cmd == "cowdrunk":
- # CowIsOff()
- # elif cmd == "cowsex":
- # CowIsOff()
- # elif cmd == "tux":
- # CowIsOff()
- # Public Commands ------------------------------------------
- if cmd == "cowhelp":
- SendPM("Available commands are:")
- SendPM("cowhelp status")
- SendPM("cow on/off cowshit")
- SendPM("cowjoin cowpart")
- SendPM("-----------------------")
- SendPM("cowsay cowdrunk")
- SendPM("cowsex")
- if cmd == "no":
- nou = " ".join(msg.split()[3:][1:])
- if nou == "u":
- if noucounter < 10:
- SendText("NO U")
- noucounter += 1
- else:
- SendText("Fine, me.")
- if cmd == "beef":
- beef_for = " ".join(msg.split()[3:][1:])
- SendIRCRaw("PRIVMSG %s :\x01ACTION cooks up some fancy steak for %s.\x01" % (location, beef_for))
- # Other ----------------------------------------------------
- if cmd == "meme":
- memeurl = "http://api.automeme.net/text?lines=1"
- memes = urllib.urlopen(memeurl).read().replace('\n','').replace("_","\x02")
- print(memes)
- SendIRCRaw("PRIVMSG %s %s" % (location, memes))