All pastes #507530 Raw Edit

Something

public text v1 · immutable
·published 2007-05-24 16:51 UTC
rendered paste body
I ADD YOUR NAME TO THE SUPERUSERLIST. Make a new nick, register, and give a name.



import socket
from time import strftime, gmtime
 
mySock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
mySock.connect(('irc.freenode.net', 6667));
 
read = str(mySock.recv( 500 ))
 
time = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
 
channel = '#mopars'
superuser = ['newbiehacker']

mySock.send( 'PASS passhere\n' )
mySock.send( 'USER namehere * Slave\n' )
mySock.send( 'NICK namehere\n' )
mySock.send( 'JOIN ' + channel + '\n' )
mySock.send( 'PRIVMSG ' + channel + ' :EhPrettyEasy is my god, !cmds for commands. ''\n' )
 
def parseString(string):
    ex = int(string.find( '!' ))
    sender = string[1:ex]
    ex = int(string.find( '@' )) + 1
    ex2 = int(string.find( ' ' ))
    host = string[ex:ex2]
    ex1 = string.find( ' ', ex2 + 1) + 1
    ex3 = string.find( ' ', ex1)
    channel = string[ex1:ex3]
    returned = { "sender":sender, "host":host, "channel":channel }
    return returned
 
def parseTime(daTime):
    tarray = daTime.split(' ')
    tarray = tarray[4].split(':')
 
    hours = int(tarray[0]) % 12
    minutes = int(tarray[1])
    seconds = int(tarray[2])
 
    toReturn = { 'hours':hours, 'minutes':minutes, 'seconds':seconds }
    return toReturn
 
def parseCommand(dict, string):
    if string.startswith('!say'):
        toSay = string[5:]
        mySock.send('PRIVMSG ' + dict['channel'] + ' :[' + dict['sender'] + ']: ' + toSay + '\n')
 
    if string.startswith('!op') and dict['sender'] in superuser:
        toOp = string.split(' ')
 
        if len(toOp) > 1:
            mySock.send("MODE " + dict['channel'] + ' +o ' +toOp[1]+ '\n')
        else:
            mySock.send("MODE " + dict['channel'] + ' +o ' +dict['sender']+ '\n')
 
 
    if string.startswith('!deop') and dict['sender'] in superuser:
        toDeop = string.split(' ')
 
        if len(toDeop) > 1:
            mySock.send("MODE " + dict['channel'] + ' -o ' +toDeop[1]+ '\n')
        else:
            mySock.send("MODE " + dict['channel'] + ' -o ' +dict['sender']+ '\n')

    if string.startswith('!ban') and dict['sender'] in superuser:
        toBan = string[5:]
        mySock.send('MODE ' + dict['channel'] + ' +b ' +toBan+ '\n')
 
    if string.startswith('!unban') and dict['sender'] in superuser:
        toBan = string[7:]
        mySock.send('MODE ' + dict['channel'] + ' -b ' +toBan+ '\n')
 
    if string.startswith('!voice') and dict['sender'] in superuser:
        toVoice = string[7:]
        mySock.send("MODE " + dict['channel'] + ' +v ' +toVoice+ '\n')
 
    if string.startswith('!devoice') and dict['sender'] in superuser:
        toDeVoice = string[9:]
        mySock.send("MODE " + dict['channel'] + ' -v ' +toDeVoice+ '\n')
 
    if string.startswith('!kick') and dict['sender'] in superuser:
        toKick = string[6:]
        mySock.send("KICK " + dict['channel'] + ' ' +toKick+ '\n')
 
    if string.startswith('!kickban') and dict['sender'] in superuser:
        toKickBan = string[9:]
        mySock.send("MODE " + dict['channel'] + ' +b '+toKickBan+' \n')
        mySock.send('KICK ' + dict['channel'] + ' '+toKickBan+'' ' \n')

    if string.startswith('!op self') and dict['sender'] in superuser:
        toOpSelf = string[8:]
        mySock.send('CS op ' + dict['channel'] +' Py[Bot]' '\n')

    if string.startswith('!deop self') and dict['sender'] in superuser:
        toOpSelf = string[10:]
        mySock.send("MODE " + dict['channel'] + ' -o ' ' Py[Bot]' '\n')
 
    if string.startswith('!cmds') and dict['sender'] in superuser:
        toCmds = string[5:]
        mySock.send('PRIVMSG ' + dict["channel"] + ' :!op !deop !ban !unban !voice !devoice !kick !default' '\n')
        mySock.send('PRIVMSG ' + dict['channel'] + ' :!kickban !about !join !part !moderate !unmoderate' '\n')
        mySock.send('PRIVMSG ' + dict['channel'] + ' :!op self !deop self !invite on !invite off' '\n')
 
    if string.startswith('!moderate') and dict['sender'] in superuser:
        toModerate = string[10:]
        mySock.send('MODE ' + dict["channel"] + ' +m ''\n')
 
    if string.startswith('!unmoderate') and dict['sender'] in superuser:
        toUnModerate = string[12:]
        mySock.send('MODE ' + dict["channel"] + ' -m ''\n')
 
    if string.startswith('!invite on') and dict['sender'] in superuser:
        toUnModerate = string[11:]
        mySock.send('MODE ' + dict["channel"] + ' +i ''\n')
 
    if string.startswith('!invite off') and dict['sender'] in superuser:
        toUnModerate = string[12:]
        mySock.send('MODE ' + dict["channel"] + ' -i ''\n')
 
    if string.startswith('!default') and dict['sender'] in superuser:
        toUnModerate = string[9:]
        mySock.send('MODE ' + dict["channel"] + ' +tnc ''\n')
 
    if string.startswith('!join') and dict['sender'] in superuser:
        toJoin = string[6:]
        mySock.send('JOIN '+toJoin+' \n')
 
    if string.startswith('!part') and dict['sender'] in superuser:
        toPart = string[6:]
        mySock.send('PART '+toPart+' \n')

    if string.startswith('!noob'):
        toNoob = string[6:]
        mySock.send('PRIVMSG ' + dict['channel'] + ' :According to ' + dict['sender'] + ' The biggest noob in the world is ' + toNoob + '\n')

    if string.startswith('!pimp'):
        toPimp = string[6:]
        mySock.send('PRIVMSG ' + dict['channel'] + ' :According to ' + dict['sender'] + ', There is this real pimping mother fucker called ' +toPimp+ ' ''\n')
 
    if string.startswith('!about'):
        toGoogle = string[7:]
        mySock.send( 'PRIVMSG ' + dict['channel'] + ' :Project[Py] -- Project Python, a IRC Bot designed in Python to manage your channels with set commands. \n' )
 
    if string.startswith('!starting time'):
        daTime = parseTime(time)
        print daTime
        mySock.send('PRIVMSG ' + dict['channel'] + " :I started running at " + time + '\n')
        print 'hours = ' + str(daTime['hours'])
        print 'minutes = ' + str(daTime['minutes'])
        print 'seconds = ' + str(daTime['seconds'])

    if string.startswith('!Dancing teletubies') and dict['sender'] in superuser:
        toTeletubies = string[19:]
        mySock.send('PRIVMSG ' + dict['channel'] + ' :http://www.youtube.com/watch?v=j-nL1rTxrqM' '\n')
 
 
 
def readFromSocket():
    return str(mySock.recv( 500 ))
 

 
while read is not None:        
    ppl = { "Bob":"Haxxer of ur base pls" }
    msg = read
    dict = parseString(read)
    if read.startswith( ':' ):
        colon = read.find(':', 1)
        msg = read[colon + 1:]
    print read
    print '[' + dict["channel"] + '] ' + dict["sender"] + ': ' + msg
 
    found = read.find( 'Hello' )
 
    if msg.startswith( '!' ):
        parseCommand(dict, msg)
 
 
        if msg.find(' is ') > -1:
            if msg.find('who is') == -1:
                split = msg.split(' ')
                if split[1] == 'is':
                    _is = msg.find(' is ')
                    heis = msg[_is + 4:]
                    name = split[0]
                    print name, ":", heis
                    ppl[name] = heis
 
                    mySock.send("PRIVMSG " + dict["channel"] + " :From now on, " + name + " is " + heis + '\n')
 
        if msg.startswith('who is'):
            split = msg.split(' ')
            name = split[2]
            nname = name[0:-2]
            thekeys = ppl.keys()
            r = 0
 
            desc = None
 
            for key in thekeys:
                if key == nname:
                    desc = ppl[nname]
                    break
                else:
                    continue
 
                if desc is not None:
                    print ppl
                    mySock.send('PRIVMSG ' + dict['channel'] + ' :' + nname + ' is ' + desc + '\n')
                else:
                        mySock.send('PRIVMSG ' + dict['channel'] + ' : I don\' know who ' + nname + ' is.\n')
 
    read = readFromSocket()