Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

BHB's Code
Thursday, April 3rd, 2008 at 7:13:37pm MDT 

  1. import sys
  2. import string
  3. import socket
  4. import os
  5. import time
  6. #import irclib
  7. from constants import *
  8.  
  9. # twisted imports
  10. #from twisted.protocols import irc
  11. #from twisted.internet import reactor, protocol
  12. #from twisted.python import log
  13.  
  14.  
  15. # Generic echo handler ( space added )
  16. # This is used to output some initial information from the server
  17. #def handleEcho ( connection, event ):
  18. #              print
  19. #              print ' '.join ( event.arguments() )
  20.  
  21. #irc = irclib.IRC()
  22. #irc.add_global_handler ( 'welcome', handleEcho )
  23.  
  24. def send(self, to, msg):
  25.         """Sends a message "msg" to "to" """
  26.         s.send('PRIVMSG %s :%s\r\n' % (to, msg))
  27.  
  28.    
  29. def sendresponse(self, to, msg, nick):
  30.         """Personalized version of send."""
  31.         msg = msg.replace('[nick]', nick)
  32.         s.send('PRIVMSG %s :%s\r\n' % (to, msg))
  33.  
  34. def me(s): return ctcp('ACTION %s' % s)
  35.  
  36. def rightnow():
  37.     "Return a string representing the current time and date."
  38.     return time.strftime('%X on %x',time.localtime(time.time()))
  39.  
  40. def factoidsdict():
  41.     f = open('factoids.txt', 'r')
  42.     toggle = True
  43.     for line in factoids.txt:
  44.         if toggle:
  45.                 key = line.rstrip()
  46.             toggle = False
  47.         else:
  48.                 value = line.rstrip()   
  49.                 toggle = True
  50.                 table[key] = value           
  51.     f.close()
  52.    
  53.  
  54. def parsemsg(msg):
  55.     complete=msg[1:].split(':',1)
  56.    #complete=msg[1:].split(' ',1)
  57.     info=complete[0].split(' ')
  58.     msgpart=complete[1]
  59.     sender=info[0].split('!')
  60.     #line=line.rstrip()
  61.     #line=line.split()
  62.     ask=msgpart.split(' ')
  63.    #if sender[0].find('bot')==-1:
  64.     if msgpart[0]=='`' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  65.     #else s.send('PRIVMSG %s :%s, I can not op you, this is most likely because you suck' % (info[2], sender[0]))
  66.         cmd=msgpart[1:].split(' ')
  67. #       cmd=msgpart[2:].split(' ')
  68.         if cmd[0]=='say':
  69.             response = cmd[2].split(' ', 2)
  70.             s.send('PRIVMSG %s :%s\n' % (cmd[1], response[0]))
  71.         if cmd[0]=='notify':
  72.             s.send('notify %s %s\n' % (cmd[1], cmd[2]))
  73.         if cmd[0]=='op':
  74.             s.send('MODE %s +o %s \n' % (info[2], cmd[1]))
  75.         if cmd[0]=='kill':
  76.             s.send('kick %s %s %s\r\n' % (cmd[1], cmd[2], cmd[3]))
  77.             s.send('PRIVMSG %s :%s, I hope you know what you are doing.\n' % (info[2], sender[0]))
  78.         if cmd[0]=='deop':
  79.             s.send('MODE %s -o %s \n' % (info[2], cmd[1]))
  80.             reply = 'muhahahaha'
  81.         if cmd[0]=='voice':
  82.             s.send('MODE %s +v %s \n' % (info[2], cmd[1]))
  83.             reply = 'Oh, but it was so quiet'
  84.         if cmd[0]=='devoice':
  85.             s.send('MODE %s -v %s \n' % (info[2], cmd[1]))
  86.             reply = 'Much better'
  87.         if cmd[0]=='invite':
  88.         #    target = cmd.split(' ')
  89.             s.send('invite %s %s\n' % (cmd[1], info[2]))
  90.         if cmd[0]=='kick':
  91.             #cmd[0] = cmd[2].split(' ', 2)
  92.             s.send('kick %s %s\r\n' % (info[2], cmd[1]))
  93.         if cmd[0]=='quit':
  94.             s.send('quit %s %s\r\n' % (info[2], cmd[1]))
  95.         if cmd[0]=='part':
  96.             s.send('part %s %s\r\n' % (info[2], cmd[1]))
  97. #       if cmd[0]=='time':
  98. #           s.send('ctcp %s %s\r\n' % (sender[0], info[4]))
  99.         #if cmd[0]=='ignore':
  100.         if cmd[0]=='sys':
  101.             syscmd(msgpart[1:],info[2])
  102.  
  103.     if msgpart[0]=='-' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  104.         cmd=msgpart[1:]
  105.         s.send('%s \n' % (cmd))
  106.         print 'cmd= %s' % (cmd)
  107.    
  108. #    if msgpart[0]==(NICK):
  109. #       cmd=msgpart[1:].strip()
  110. #       #receiver = None
  111.  
  112. #    if ask[0]=='%s' % (NICK):
  113. #       cmd=msgpart[1:].strip()
  114. #       receiver = None
  115.  
  116.     if msgpart[0]=='@':
  117.         cmd=msgpart[1:].strip()
  118.         receiver = None
  119.         if cmd.find('|')!=-1:
  120.                 cmd = cmd.split('|')
  121.                 receiver = cmd[1].strip()
  122.                 cmd = cmd[0].strip()
  123.  
  124.     #if ask[0]=='bhb ':
  125. #       cmd=msgpart[1:].strip()
  126. #       receiver = None
  127.  
  128. #    if (msgpart.find('bhb ')!=-1):
  129. #       cmd=msgpart[1:].strip()
  130. #       receiver = None
  131.  
  132. #    if msgpart[0]==(NICK):
  133. #       cmd=msgpart[1:].strip()
  134. #       receiver = None
  135.  #      if cmd.find('|')!=-1:
  136.         #       cmd = cmd.split('|')
  137.         #       receiver = cmd[1].strip()
  138.         #       cmd = cmd[0].strip()
  139.         cmd = cmd.lower()
  140.         channel=info[2]
  141.     #if sender[0].find('bot')==-1:
  142.      #   if cmd == 'rtfm on' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2):
  143.      #          global RTFM
  144.       #         RTFM = 0
  145. #               reply = 'RTFM responses enabled'
  146.  
  147.         factoids(cmd,channel,sender,receiver)
  148.  
  149.         msgpart = msgpart.lower()
  150.  
  151. #    if (msgpart.find('bhb ')!=-1):
  152. #        s.send('PRIVMSG %s :%s, I am only a bot.' % (info [2], sender[0]))
  153.  
  154.     if (msgpart.find('fuck')!=-1): #or msgpart.find('fucking')!=-1: #and fuck == 0:
  155.         s.send('PRIVMSG %s :%s, Please do not swear in here. This is a family friendly channel.\n' % (info[2], sender[0]))
  156.     if (msgpart.find('RTFM')!=-1): #and RTFM == 0:
  157.         s.send('PRIVMSG %s :%s, We do not tolerate telling people to RTFM in this channel.\n' % (info[2], sender[0]))
  158.         s.send('kick %s %s\r\n' % (info[2], sender[0]))
  159.     if (msgpart.find('rtfm')!=-1):
  160.         s.send('PRIVMSG %s :%s, We do not tolerate telling people to RTFM in this channel.\n' % (info[2], sender[0]))
  161.         s.send('kick %s %s\r\n' % (info[2], sender[0]))
  162.     if (msgpart.find('slaps')!=-1):
  163.         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]))
  164.     if (msgpart.find('hello bhb')!=-1):
  165.         s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
  166.     if (msgpart.find('hey bhb')!=-1):
  167.         s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
  168.     if (msgpart.find('hi bhb')!=-1):
  169.         s.send('PRIVMSG %s :Sup %s?\r\n' % (info[2], sender[0]))
  170.     if (msgpart.find('JOIN')!=-1):
  171.         s.send('PRIVMSG %s :%s, Welcome to #beginners-help!\r\n' % (info[2], sender[0]))
  172.     if (msgpart.find('bhb gtfo')!=-1 and sender[0]==OWNER):
  173.         s.send("PRIVMSG %s :That was mean :'(\r\n" % (info[2]))
  174.         s.send('quit %s\r\n' % (sender[0]))
  175.     #if (msgpart.find('PING')!=-1):
  176. #       s.send('PONG')
  177.         #channel=info[2]
  178.         #factoids(cmd,channel,sender,receiver)
  179. #    if sline[0] == "PING":
  180. #       s.send("PONG %s\r\n" % line[1])
  181. #       logging.debug('Pinged.')
  182.  
  183. def factoids(cmd,channel,sender,receiver):
  184.     print cmd
  185.     reply = "%s I have no idea what you're talking about" % (sender[0])
  186.     if table.get(cmd)!= None: reply = table.get(cmd)
  187.    
  188.  #   if cmd == 'ping':
  189.   #     reply = 'No pong for you'
  190. #    if cmd == 'info':
  191. #       reply = "I am ajmorris' python bot"
  192. #    if cmd == 'cbf':
  193. #       reply = 'TOO BAD! DO IT!!'
  194.    # if cmd == 'bhb':
  195.     #   reply = "I am ajmorris' python bot. Beware me for i am god in this channel"
  196. ##    if cmd == 'pacman':
  197.  #      reply = 'OM NOM NOM NOM! I EAT YOU!'
  198. #    if cmd == 'help':
  199. #       reply = 'ajmorris, Joeb454, bodhi_zazen, attention please!'
  200. #    if cmd == 'help!':
  201. #       reply = 'ajmorris, Joeb454, bodhi_zazen, attention please!'
  202. #    if cmd == 'run':
  203. #       reply = '%s, im coming to eat you!' % (sender[0])
  204. #    if cmd == 'you suck':
  205. #       reply = 'no you do %s\r\n' % (sender[0])
  206.  #   if cmd == 'ohmy':
  207.   #     reply = 'Please watch your language and topic to help keep this channel family friendly.'
  208.    # if cmd == 'microsoft':
  209.     #   reply = 'Microsoft is bad, VERY BAD. END OF DISCUSSION!'
  210. #    if cmd == 'pastebin':
  211.  #      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'
  212.   #  if cmd == 'insult':
  213.    #    reply = 'You are nothing but a weedy ooze of penguin-molesting bladders.'
  214. #    if cmd == 'bodhi_zazen':
  215.  #      reply = 'bodhi is an op in this channel, do what he says or incur his wrath ;)'
  216.   #  if cmd == 'ajmorris':
  217.    #    reply = 'ajmorris is an op in this channel, and my creator, do what he says or incur his wrath ;)'
  218.     ##if cmd == 'botsnack':
  219.      #  reply = 'This is old :/'
  220.     #if cmd == 'opera':
  221.      #  reply = "Opera is an internet browser. IMHO you're better off with Firefox, it renders faster"
  222. #    if cmd == 'joeb454':
  223. #       reply = 'Joe is an op in this channel, do what he says or incur his wrath ;)'
  224. #    if cmd == 'flood':
  225.  #      reply = 'If you flood this channel, i will shoot you :) Please have a nice day'
  226.    # if cmd == 'firefox':
  227.   #     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'
  228.    # if cmd == 'ubuntu':
  229.     #   reply = "Ubuntu is a Linux Distribution...chances are you're using it, given this is the help channel for the UBUNTU forums beginners team ;)"
  230.     #if cmd == 'recbot':
  231.      #  reply = "recbot, an annoying bot spawned from paultag's computer"
  232.  
  233.    ''' if cmd.find('kill')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  234.        reason = cmd.split(' ')
  235.        s.send('kick %s %s %s\r\n' % (channel, receiver, reason))
  236.        
  237. #    if cmd.find('time')!=-1:
  238. #       s.send('return time.strftime('%X on %x',time.localtime(time.time()))
  239.  
  240.     if cmd.find('join')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  241.        chan = cmd.split(' ')
  242.        print cmd
  243.        s.send('JOIN %s\r\n' % (chan[1]))
  244.        reply = 'done'
  245.        
  246.     #if cmd.find('kick')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  247.      #  target = cmd.split(' ')
  248.       # print cmd
  249.        #s.send('KICK %s %s\r\n' % (channel, target[1]))
  250.       # reply = 'with pleasure'
  251.  
  252.     if cmd.find('cs')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  253.        #chan = cmd.split(' ')
  254.        print cmd
  255.        s.send('PRIVMSG ChanServ :OP %s\r\n' % (channel))
  256.        reply = 'I feel the power!'
  257.  
  258.     #if cmd.find('op')!=-1 and cmd.find('op')!=2 and (sender[0] == OWNER or sender[0] == ADMIN and MODE[0] == '+e'):
  259.      #  target = cmd.split(' ')
  260.       # s.send('ChanServ :OP %s %s\r\n' % (channel, target[1]))
  261.      #  reply = "I hope you know what you're doing"
  262.  
  263.     #if cmd.find('deop')!=-1 and (sender[0] == OWNER or sender[0] == ADMIN and MODE[0] == '+e'):
  264.       # target = cmd.split(' ')
  265.      #  s.send('deop %s\r\n' % (target[1]))
  266.  
  267.     if cmd == 'quit' and (sender[0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  268.        s.send("PRIVMSG %s : Fine, if you don't want me :'(\r\n" % (channel))
  269.        s.send('QUIT \r\n')
  270.        
  271.     if cmd == 'part' and (sender[0] == OWNER):
  272.        reply = 'bye'
  273.        s.send('PART %s\r\n' % (channel))
  274.  
  275.     if cmd.find('identify')!=-1 and (sender [0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  276.        cmd = cmd.split(' ')
  277.        s.send('PRIVMSG NickServ: IDENTIFY %s\r\n' % (PASS))
  278.  
  279.     #if cmd.find('invite')!=-1 and (sender [0] == OWNER or sender[0] == ADMIN or sender[0] == ADMIN2 and MODE[0] == '+e'):
  280. #       target = cmd.split(' ')
  281. #       print cmd
  282. #       s.send('invite %s %s\r\n' % (target[0], channel))'''
  283.  
  284.     if receiver != None:
  285.         s.send('PRIVMSG %s :%s, %s\n' % (channel, receiver, reply))
  286.     elif receiver == None:
  287.         s.send('PRIVMSG %s :%s\n' % (channel, reply))
  288.  
  289. def syscmd(commandline,channel):
  290.         cmd=commandline.replace('sys ',' ')
  291.         cmd=cmd.rstrip()
  292.         os.system(cmd+' >temp.txt')
  293.         a=open('temp.txt')
  294.         ot=a.read()
  295.         ot.replace('n','|')
  296.         a.close()
  297.         s.send('PRIVMSG %s :%s\n' % (channel, ot))
  298.         return 0
  299.  
  300. #Connection
  301. s=socket.socket( )
  302. s.connect((HOST, PORT))
  303. s.send('NICK %s \n' % (NICK)) #Tells nick server nickname
  304. s.send('USER %s %s bla : %s \n' % (IDENT, HOST, REALNAME)) #Tells user Identity, current host, and actual name
  305. s.send('PRIVMSG NickServ :IDENTIFY %s\r\n' % (PASS))
  306. s.send('PRIVMSG ChanServ :OP %s\r\n' % (CHAN))
  307.  
  308.  
  309. while 1#While True
  310.     line=s.recv(4096)
  311.     print line # I believe this is for the bot owners information. It doesn't send anything to chatroom
  312.     log = file('log.txt', 'a')
  313.     log.write(line)
  314.     log.close()
  315.     if line.find('Welcome to the freenode IRC Network')!=-1: #If any line says this it will join the channel(s) put in CHAN
  316.         s.send('JOIN %s\n' % (CHAN))
  317.         s.send('PRIVMSG %s : Hello World.\r\n' % (CHAN))
  318.         s.send('PRIVMSG ChanServ :OP %s\r\n' % (CHAN))
  319.     if line.find('PRIVMSG')!=-1: # For private messaging, I do not know how this works
  320.         parsemsg(line)
  321.     line=line.rstrip()
  322.     line=line.split()
  323.     if(line[0]=='PING'):
  324.         s.send('PONG %s \n' %line[1])

Paste Details

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

fantasy-obligation