Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Strike, quick and dirty nothing more

    Grim
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    I wouldn't take offense to that, Grim . I'm quit new to Python and I greatly appreciate any help. Thanks for taking the time to restructure my bot, I think it's alot better now .
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Originally posted by Grim Archon
    Strike, quick and dirty nothing more

    Grim
    Good But only as long as it stays as "nothing more". I'm not afraid to lay the verbal smack down on using it for anything else.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    One more quick question : As you can see, I pass mapCommand a bunch of arguments. What I was wondering is if it's better to use 'self.' instead of passing arguments, in this context. I pass arguments to authManagement and chanManagement too, so they would use 'self.' too.

    Make that two : Grim, you mentioned a 'send' function to keep the methods from working with the underlying socket, but would you know a way to implement this considering I have quit a range of different calls to sock.send(). (i.e. MODE, KICK, BAN, NICK, and also a varying number of arguments.)
    Last edited by XxChris; February 9th, 2004 at 04:56 PM.
  8. #20
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Thats a good one.
    In my view you got it right the first time:
    1. You are encapsulating and keeping clean interfaces.
    2. It's easier to document. (Try to describe the other way!)
    3. In 6 months time you don't have remember how the self.xxx got there.
    4. You're putting them in different modules, it will save file hopping.

  10. #21
  11. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Really you only have one call:
    self.send(astring) and it is astring that has different contents dependent on the protocol requirements.
    So all I propose is you replace self.sock.send with self.send
    where:
    Code:
    #in socketDriver
    def send(self,data):
        self.socket.send(data)
    Not a big improvement in code, just a restructure that does isolation.

    It is allmost inevitable that the closer the code gets to the real world the less ideal it's structure becomes - it has to deal with human decisions that making tidy code difficult!

    However, in parseCommand you might consider adding a new function like:
    Code:
    def transmitCommand(self,command,arg1,arg2,arg3='',arg4=''):
       if command == 'PRIMSG':
         self.send('%s %s : %s\n\r' % (command,arg1l, arg))
      elif command in['MODE', 'KICK']:
         self.sock.send('%s %s %s %s\n\r' % (command,arg1, arg2,arg3))
     elif command =='QUIT':
        self.send('QUIT : %s\n\r'% (command,arg1))
    etc...
    Then all self.sock.send(...) would be replaced with self.transmitCommand('COMMAND',arg1,arg2,arg3,ar4)

    But that is just extra code that puts off dealing with the protocol.
    The choice is yours
    Grim
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    Thanks alot Grim! ;D
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    I'm back

    The OOP structure is all sorted now and everything is split into modules. It all seems to work, but I've implemented a function to reload modules so I can dynamicaly make changes without disconnecting. I added a print statement right under the class statement in one module to test if everything was reloading properly and tt seemed to work, but when I put the print in a function or edited anything in functions in general it doesn't seem to have an effect if I reload that module. Any ideas?

    Edit: This came to me shortly after I posted: Correct me if I'm wrong, but I am only changing the class when I do this, so all the functions in my instance remain the same and this is why I don't see any difference. If so, is there any way around this?
    Last edited by XxChris; February 10th, 2004 at 05:56 PM.
  16. #24
  17. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    As far as i know the only way you're gonna get around with is to recreate all you're instances. Possibly do the inisalising inside a function to reduce code length.

    Note: i dont clame to be infalable . Infact i may be wrong on this one.

    I've implemented a function to reload modules so I can dynamicaly make changes without disconnecting
    I don't know if you know this but Python already has a reload() function built-in which you can use to... well, reload modules .

    Mark.
    Last edited by netytan; February 10th, 2004 at 07:17 PM.
    programming language development: www.netytan.com Hula

  18. #25
  19. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Just a few thoughts and I have'nt used IRC but I guess the thing you need to preserve is the socket instance.
    You could rewrite the __init__ function to optionally take a socket object if one exists already:
    Code:
    def __init__(self,sock=None):
        if sock:
           self.sock = sock
        else:
           self.sock = socket....
    It might be possible to do further OO by builiding a reload method in the class, this could return a new class object based on the reloaded module. There may be issues with namespace - time to experiment
    Code:
    def reload(self):
         reload("module")
         temp = parseCommand(self.sock)
         #now stuff to make temp look like self
         return temp
    So in the main module you could step through your Bots:
    Code:
    for x in range(len(mybots_list)):
        mybots_list[x] = mybots_list[x].reload()
    Grim
  20. #26
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    Thanks again guys.

    Grim, I'll experiment a bit with this when I get the time, and i'll get back to you when I can. It looks promising
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo