Advertising
- BHB's Code
- Thursday, April 3rd, 2008 at 7:13:37pm MDT
- import sys
- import string
- import socket
- import os
- import time
- #import irclib
- from constants import *
- # twisted imports
- #from twisted.protocols import irc
- #from twisted.internet import reactor, protocol
- #from twisted.python import log
- # Generic echo handler ( space added )
- # This is used to output some initial information from the server
- #def handleEcho ( connection, event ):
- # print
- # print ' '.join ( event.arguments() )
- #irc = irclib.IRC()
- #irc.add_global_handler ( 'welcome', handleEcho )
- def send(self, to, msg):
- """Sends a message "msg" to "to" """
- s.send('PRIVMSG %s :%s\r\n' % (to, msg))
- def sendresponse(self, to, msg, nick):
- """Personalized version of send."""
- msg = msg.replace('[nick]', nick)
- s.send('PRIVMSG %s :%s\r\n' % (to, msg))
- def me(s): return ctcp('ACTION %s' % s)
- def rightnow():
- "Return a string representing the current time and date."
- return time.strftime('%X on %x',time.localtime(time.time()))
- def factoidsdict():
- f = open('factoids.txt', 'r')
- toggle = True
- for line in factoids.txt:
- if toggle:
- key = line.rstrip()
- toggle = False
- else:
- value = line.rstrip()
- toggle = True
- table[key] = value
- f.close()
- def parsemsg(msg):
- complete=msg[1:].split(':',1)
- #complete=msg[1:].split(' ',1)
- info=complete[0].split(' ')
- msgpart=complete[1]
- sender=info[0].split('!')
- #line=line.rstrip()
- #line=line.split()
- ask=msgpart.split(' ')
- #if sender[0].find('bot')==-1:
- if msgpart[0]=='`' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- #else s.send('PRIVMSG %s :%s, I can not op you, this is most likely because you suck' % (info[2], sender[0]))
- cmd=msgpart[1:].split(' ')
- # cmd=msgpart[2:].split(' ')
- if cmd[0]=='say':
- response = cmd[2].split(' ', 2)
- s.send('PRIVMSG %s :%s\n' % (cmd[1], response[0]))
- if cmd[0]=='notify':
- s.send('notify %s %s\n' % (cmd[1], cmd[2]))
- if cmd[0]=='op':
- s.send('MODE %s +o %s \n' % (info[2], cmd[1]))
- if cmd[0]=='kill':
- s.send('kick %s %s %s\r\n' % (cmd[1], cmd[2], cmd[3]))
- s.send('PRIVMSG %s :%s, I hope you know what you are doing.\n' % (info[2], sender[0]))
- if cmd[0]=='deop':
- s.send('MODE %s -o %s \n' % (info[2], cmd[1]))
- reply = 'muhahahaha'
- if cmd[0]=='voice':
- s.send('MODE %s +v %s \n' % (info[2], cmd[1]))
- reply = 'Oh, but it was so quiet'
- if cmd[0]=='devoice':
- s.send('MODE %s -v %s \n' % (info[2], cmd[1]))
- reply = 'Much better'
- if cmd[0]=='invite':
- # target = cmd.split(' ')
- s.send('invite %s %s\n' % (cmd[1], info[2]))
- if cmd[0]=='kick':
- #cmd[0] = cmd[2].split(' ', 2)
- s.send('kick %s %s\r\n' % (info[2], cmd[1]))
- if cmd[0]=='quit':
- s.send('quit %s %s\r\n' % (info[2], cmd[1]))
- if cmd[0]=='part':
- s.send('part %s %s\r\n' % (info[2], cmd[1]))
- # if cmd[0]=='time':
- # s.send('ctcp %s %s\r\n' % (sender[0], info[4]))
- #if cmd[0]=='ignore':
- if cmd[0]=='sys':
- syscmd(msgpart[1:],info[2])
- if msgpart[0]=='-' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- cmd=msgpart[1:]
- s.send('%s \n' % (cmd))
- print 'cmd= %s' % (cmd)
- # if msgpart[0]==(NICK):
- # cmd=msgpart[1:].strip()
- # #receiver = None
- # if ask[0]=='%s' % (NICK):
- # cmd=msgpart[1:].strip()
- # receiver = None
- if msgpart[0]=='@':
- cmd=msgpart[1:].strip()
- receiver = None
- if cmd.find('|')!=-1:
- cmd = cmd.split('|')
- receiver = cmd[1].strip()
- cmd = cmd[0].strip()
- #if ask[0]=='bhb ':
- # cmd=msgpart[1:].strip()
- # receiver = None
- # if (msgpart.find('bhb ')!=-1):
- # cmd=msgpart[1:].strip()
- # receiver = None
- # if msgpart[0]==(NICK):
- # cmd=msgpart[1:].strip()
- # receiver = None
- # if cmd.find('|')!=-1:
- # cmd = cmd.split('|')
- # receiver = cmd[1].strip()
- # cmd = cmd[0].strip()
- cmd = cmd.lower()
- channel=info[2]
- #if sender[0].find('bot')==-1:
- # if cmd == 'rtfm on' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2):
- # global RTFM
- # RTFM = 0
- # reply = 'RTFM responses enabled'
- factoids(cmd,channel,sender,receiver)
- msgpart = msgpart.lower()
- # if (msgpart.find('bhb ')!=-1):
- # s.send('PRIVMSG %s :%s, I am only a bot.' % (info [2], sender[0]))
- if (msgpart.find('fuck')!=-1): #or msgpart.find('fucking')!=-1: #and fuck == 0:
- s.send('PRIVMSG %s :%s, Please do not swear in here. This is a family friendly channel.\n' % (info[2], sender[0]))
- if (msgpart.find('RTFM')!=-1): #and RTFM == 0:
- s.send('PRIVMSG %s :%s, We do not tolerate telling people to RTFM in this channel.\n' % (info[2], sender[0]))
- s.send('kick %s %s\r\n' % (info[2], sender[0]))
- if (msgpart.find('rtfm')!=-1):
- s.send('PRIVMSG %s :%s, We do not tolerate telling people to RTFM in this channel.\n' % (info[2], sender[0]))
- s.send('kick %s %s\r\n' % (info[2], sender[0]))
- if (msgpart.find('slaps')!=-1):
- s.send('PRIVMSG %s :%s, This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.\r\n' % (info[2], sender[0]))
- if (msgpart.find('hello bhb')!=-1):
- s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
- if (msgpart.find('hey bhb')!=-1):
- s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
- if (msgpart.find('hi bhb')!=-1):
- s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
- if (msgpart.find('JOIN')!=-1):
- s.send('PRIVMSG %s :%s, Welcome to #beginners-help!\r\n' % (info[2], sender[0]))
- if (msgpart.find('bhb gtfo')!=-1 and sender[0]==OWNER):
- s.send("PRIVMSG %s :That was mean :'(\r\n" % (info[2]))
- s.send('quit %s\r\n' % (sender[0]))
- #if (msgpart.find('PING')!=-1):
- # s.send('PONG')
- #channel=info[2]
- #factoids(cmd,channel,sender,receiver)
- # if sline[0] == "PING":
- # s.send("PONG %s\r\n" % line[1])
- # logging.debug('Pinged.')
- def factoids(cmd,channel,sender,receiver):
- print cmd
- reply = "%s I have no idea what you're talking about" % (sender[0])
- if table.get(cmd)!= None: reply = table.get(cmd)
- # if cmd == 'ping':
- # reply = 'No pong for you'
- # if cmd == 'info':
- # reply = "I am ajmorris' python bot"
- # if cmd == 'cbf':
- # reply = 'TOO BAD! DO IT!!'
- # if cmd == 'bhb':
- # reply = "I am ajmorris' python bot. Beware me for i am god in this channel"
- ## if cmd == 'pacman':
- # reply = 'OM NOM NOM NOM! I EAT YOU!'
- # if cmd == 'help':
- # reply = 'ajmorris, Joeb454, bodhi_zazen, attention please!'
- # if cmd == 'help!':
- # reply = 'ajmorris, Joeb454, bodhi_zazen, attention please!'
- # if cmd == 'run':
- # reply = '%s, im coming to eat you!' % (sender[0])
- # if cmd == 'you suck':
- # reply = 'no you do %s\r\n' % (sender[0])
- # if cmd == 'ohmy':
- # reply = 'Please watch your language and topic to help keep this channel family friendly.'
- # if cmd == 'microsoft':
- # reply = 'Microsoft is bad, VERY BAD. END OF DISCUSSION!'
- # if cmd == 'pastebin':
- # reply = 'pastebin is a service to post multiple-lined texts so you do not flood the channel. One of the many is located at http://www.pastebin.ca'
- # if cmd == 'insult':
- # reply = 'You are nothing but a weedy ooze of penguin-molesting bladders.'
- # if cmd == 'bodhi_zazen':
- # reply = 'bodhi is an op in this channel, do what he says or incur his wrath ;)'
- # if cmd == 'ajmorris':
- # reply = 'ajmorris is an op in this channel, and my creator, do what he says or incur his wrath ;)'
- ##if cmd == 'botsnack':
- # reply = 'This is old :/'
- #if cmd == 'opera':
- # reply = "Opera is an internet browser. IMHO you're better off with Firefox, it renders faster"
- # if cmd == 'joeb454':
- # reply = 'Joe is an op in this channel, do what he says or incur his wrath ;)'
- # if cmd == 'flood':
- # reply = 'If you flood this channel, i will shoot you :) Please have a nice day'
- # if cmd == 'firefox':
- # reply = 'an open source browser, used by ~33% of the world, making great strides again IE. It has many plugins. I prefer FF3 over FF2'
- # if cmd == 'ubuntu':
- # reply = "Ubuntu is a Linux Distribution...chances are you're using it, given this is the help channel for the UBUNTU forums beginners team ;)"
- #if cmd == 'recbot':
- # reply = "recbot, an annoying bot spawned from paultag's computer"
- ''' if cmd.find('kill')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- reason = cmd.split(' ')
- s.send('kick %s %s %s\r\n' % (channel, receiver, reason))
- # if cmd.find('time')!=-1:
- # s.send('return time.strftime('%X on %x',time.localtime(time.time()))
- if cmd.find('join')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- chan = cmd.split(' ')
- print cmd
- s.send('JOIN %s\r\n' % (chan[1]))
- reply = 'done'
- #if cmd.find('kick')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- # target = cmd.split(' ')
- # print cmd
- #s.send('KICK %s %s\r\n' % (channel, target[1]))
- # reply = 'with pleasure'
- if cmd.find('cs')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- #chan = cmd.split(' ')
- print cmd
- s.send('PRIVMSG ChanServ :OP %s\r\n' % (channel))
- reply = 'I feel the power!'
- #if cmd.find('op')!=-1 and cmd.find('op')!=2 and (sender[0] == OWNER or sender[0] == ADMIN and MODE[0] == '+e'):
- # target = cmd.split(' ')
- # s.send('ChanServ :OP %s %s\r\n' % (channel, target[1]))
- # reply = "I hope you know what you're doing"
- #if cmd.find('deop')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN and MODE[0] == '+e'):
- # target = cmd.split(' ')
- # s.send('deop %s\r\n' % (target[1]))
- if cmd == 'quit' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- s.send("PRIVMSG %s : Fine, if you don't want me :'(\r\n" % (channel))
- s.send('QUIT \r\n')
- if cmd == 'part' and (sender[0] == OWNER):
- reply = 'bye'
- s.send('PART %s\r\n' % (channel))
- if cmd.find('identify')!=-1 and (sender [0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- cmd = cmd.split(' ')
- s.send('PRIVMSG NickServ: IDENTIFY %s\r\n' % (PASS))
- #if cmd.find('invite')!=-1 and (sender [0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
- # target = cmd.split(' ')
- # print cmd
- # s.send('invite %s %s\r\n' % (target[0], channel))'''
- if receiver != None:
- s.send('PRIVMSG %s :%s, %s\n' % (channel, receiver, reply))
- elif receiver == None:
- s.send('PRIVMSG %s :%s\n' % (channel, reply))
- def syscmd(commandline,channel):
- cmd=commandline.replace('sys ',' ')
- cmd=cmd.rstrip()
- os.system(cmd+' >temp.txt')
- a=open('temp.txt')
- ot=a.read()
- ot.replace('n','|')
- a.close()
- s.send('PRIVMSG %s :%s\n' % (channel, ot))
- return 0
- #Connection
- s=socket.socket( )
- s.connect((HOST, PORT))
- s.send('NICK %s \n' % (NICK)) #Tells nick server nickname
- s.send('USER %s %s bla : %s \n' % (IDENT, HOST, REALNAME)) #Tells user Identity, current host, and actual name
- s.send('PRIVMSG NickServ :IDENTIFY %s\r\n' % (PASS))
- s.send('PRIVMSG ChanServ :OP %s\r\n' % (CHAN))
- while 1: #While True
- line=s.recv(4096)
- print line # I believe this is for the bot owners information. It doesn't send anything to chatroom
- log = file('log.txt', 'a')
- log.write(line)
- log.close()
- if line.find('Welcome to the freenode IRC Network')!=-1: #If any line says this it will join the channel(s) put in CHAN
- s.send('JOIN %s\n' % (CHAN))
- s.send('PRIVMSG %s : Hello World.\r\n' % (CHAN))
- s.send('PRIVMSG ChanServ :OP %s\r\n' % (CHAN))
- if line.find('PRIVMSG')!=-1: # For private messaging, I do not know how this works
- parsemsg(line)
- line=line.rstrip()
- line=line.split()
- if(line[0]=='PING'):
- s.send('PONG %s \n' %line[1])
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.