Skip to main content
edited for clarity
Source Link
Senthil Kumaran
  • 57.3k
  • 15
  • 99
  • 139

Into this file def MainLoop(self): #MainLoop is used to make the commands executable ie !google !say etc; try: while True: # This method sends a ping to the server and if it pings it will send a pong back #in other clients they keep receiving till they have a complete line however mine does not as of right now #The PING command is used to test the presence of an active client or #server at the other end of the connection. Servers send a PING #message at regular intervals if no other activity detected coming #from a connection. If a connection fails to respond to a PING #message within a set amount of time, that connection is closed. A #PING message MAY be sent even if the connection is active. #PONG message is a reply to PING message. If parameter is #given, this message will be forwarded to given target. The #parameter is the name of the entity who has responded to PING message #and generated this message.

def MainLoop(self): #MainLoop is used to make the commands executable ie !google !say etc;
                try:
                    while True:
                        # This method sends a ping to the server and if it pings it will send a pong back
                        #in other clients they keep receiving till they have a complete line however mine does not as of right now
                        #The PING command is used to test the presence of an active client or
                        #server at the other end of the connection.  Servers send a PING
                        #message at regular intervals if no other activity detected coming
                        #from a connection.  If a connection fails to respond to a PING
                        #message within a set amount of time, that connection is closed. A
                        #PING message MAY be sent even if the connection is active.
                        #PONG message is a reply to PING message.  If parameter <server2> is
                        #given, this message will be forwarded to given target.  The <server>
                        #parameter is the name of the entity who has responded to PING message
                        #and generated this message.

                        self.data = self.irc.recv( 4096 )
                        print self.data
                        if self.data.find ( 'PING' ) != -1:
                            self.irc.send(( "PONG %s \r\n" ) % (self.data.split() [ 1 ])) #Possible overflow problem

                        if "!chat" in self.data:
                            ..... 

Into this file def MainLoop(self): #MainLoop is used to make the commands executable ie !google !say etc; try: while True: # This method sends a ping to the server and if it pings it will send a pong back #in other clients they keep receiving till they have a complete line however mine does not as of right now #The PING command is used to test the presence of an active client or #server at the other end of the connection. Servers send a PING #message at regular intervals if no other activity detected coming #from a connection. If a connection fails to respond to a PING #message within a set amount of time, that connection is closed. A #PING message MAY be sent even if the connection is active. #PONG message is a reply to PING message. If parameter is #given, this message will be forwarded to given target. The #parameter is the name of the entity who has responded to PING message #and generated this message.

                    self.data = self.irc.recv( 4096 )
                    print self.data
                    if self.data.find ( 'PING' ) != -1:
                        self.irc.send(( "PONG %s \r\n" ) % (self.data.split() [ 1 ])) #Possible overflow problem

                    if "!chat" in self.data:
                        ..... 

Into this file

def MainLoop(self): #MainLoop is used to make the commands executable ie !google !say etc;
                try:
                    while True:
                        # This method sends a ping to the server and if it pings it will send a pong back
                        #in other clients they keep receiving till they have a complete line however mine does not as of right now
                        #The PING command is used to test the presence of an active client or
                        #server at the other end of the connection.  Servers send a PING
                        #message at regular intervals if no other activity detected coming
                        #from a connection.  If a connection fails to respond to a PING
                        #message within a set amount of time, that connection is closed. A
                        #PING message MAY be sent even if the connection is active.
                        #PONG message is a reply to PING message.  If parameter <server2> is
                        #given, this message will be forwarded to given target.  The <server>
                        #parameter is the name of the entity who has responded to PING message
                        #and generated this message.

                        self.data = self.irc.recv( 4096 )
                        print self.data
                        if self.data.find ( 'PING' ) != -1:
                            self.irc.send(( "PONG %s \r\n" ) % (self.data.split() [ 1 ])) #Possible overflow problem

                        if "!chat" in self.data:
                            ..... 
Source Link
21days
  • 55
  • 2
  • 9

Importing a script into another script

I am trying to import this file

http://pastebin.com/bEss4J6Q

Into this file def MainLoop(self): #MainLoop is used to make the commands executable ie !google !say etc; try: while True: # This method sends a ping to the server and if it pings it will send a pong back #in other clients they keep receiving till they have a complete line however mine does not as of right now #The PING command is used to test the presence of an active client or #server at the other end of the connection. Servers send a PING #message at regular intervals if no other activity detected coming #from a connection. If a connection fails to respond to a PING #message within a set amount of time, that connection is closed. A #PING message MAY be sent even if the connection is active. #PONG message is a reply to PING message. If parameter is #given, this message will be forwarded to given target. The #parameter is the name of the entity who has responded to PING message #and generated this message.

                    self.data = self.irc.recv( 4096 )
                    print self.data
                    if self.data.find ( 'PING' ) != -1:
                        self.irc.send(( "PONG %s \r\n" ) % (self.data.split() [ 1 ])) #Possible overflow problem

                    if "!chat" in self.data:
                        ..... 

So that I can successfully call upon the imported file (ipibot) whenever '!chat' in self.data: # is called.

But I'm not sure how to write it. This is what I have so far

 if "!chat" in self.data:
      user = ipibot.ipibot()
      user.respond

I'd like to state I have taken a look at the module portion of Python as well as Importing I just can't seem to grasp it I guess?

file -> class -> function is what I understand it to be.