Results 1 to 4 of 4

Thread: IRC Bot with python help

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default IRC Bot with python help

    i'm trying to make an irc bot with python, but i'm having trouble having it respond.

    how do you fix it, and how does it work and all that good stuff?



    python Code:
    import socket
     
    class Bot :

          def __init__(self, server="milamber.ny.us.swiftirc.net", port=6667):
                """creates the socket object and connects to the server"""
                self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                address = (server, port)
                self.sock.connect(address)
                self.input = self.sock.makefile('rb',0)
                self.output = self.sock.makefile('wb',0)
               
          def identify(self, nick = 'AkwardBot', realname = 'AkwardBot'):
                """passes nickname and username to the server"""
                self.nick = nick
                self.output.write('NICK '+nick+'\r\n')
                self.output.write('USER '+nick+' 8 * :'+realname+'\r\n')
               
          def join_channel(self, channel = '#ethan') :
                """ Join the channel. """
                self.channel = channel
                done = False
                while not done :
                      inMsg = self.input.readline().strip()
                      print inMsg
                      if inMsg.find('PRIVMSG') != -1 :
                            done = True
                self.output.write('JOIN '+self.channel+'\r\n')
                print self.input.readline().strip()
               
          def work(self):
                """Stay in the channel"""  
                message = self.input.readline().strip()
                while True:
                      if message.find('PRIVMSG') != -1:
                            self.parseMessage(message)
                            message = message.split()
                            if message[0] is 'PING':
                                  self.output.write('PONG '+message[1]+'\n')

                      message = self.input.readline().strip()
         #this is the responding function, whats it do, and how do i fix it?            
          def parseMessage(self,message):
              msg = message.split(':')[2]
              author = message.split(':')[1].split('!')[0]
              print "%s : %s" % (author,msg)
              if msg.find('hi '+self.nick) != -1 :
                  self.output.write('PRIVMSG '+self.channel+' : '+author+', hi\r\n')


    bot = Bot()
    bot.identify()
    bot.join_channel()
    bot.work()
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Ask NxTitle. He is python wiz :S
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  3. #3
    Join Date
    Jun 2007
    Location
    Canuckistan
    Posts
    306
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    LMAO thanks noidea.

    This is the weirdest bot I have ever seen. Why would anything ever redirect standard input and output to sockets, and not just use the sockets? That stops it from allowing you to have debugging output. Either way, it should be something I can work around (after all, there is standard error output as well :P )

    I'll definitely take a look at it and come back if I can get it to work.

    PS. is this original work?

  4. #4
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by NxTitle View Post
    LMAO thanks noidea.

    This is the weirdest bot I have ever seen. Why would anything ever redirect standard input and output to sockets, and not just use the sockets? That stops it from allowing you to have debugging output. Either way, it should be something I can work around (after all, there is standard error output as well :P )

    I'll definitely take a look at it and come back if I can get it to work.

    PS. is this original work?
    no, its not my original work. i studied it from a tut, and may have copypasta'd a few lines

    also, me != sockets, so i might have to read up on them later
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •