February 9th, 2004, 08:56 AM
Strike, quick and dirty nothing more
February 9th, 2004, 02:53 PM
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 .
February 9th, 2004, 04:07 PM
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.
February 9th, 2004, 04:33 PM
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.
February 9th, 2004, 05:06 PM
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.
February 9th, 2004, 06:07 PM
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
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:
Then all self.sock.send(...) would be replaced with self.transmitCommand('COMMAND',arg1,arg2,arg3,ar4)
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))
But that is just extra code that puts off dealing with the protocol.
The choice is yours
February 10th, 2004, 02:17 PM
February 10th, 2004, 05:53 PM
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.
February 10th, 2004, 07:14 PM
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 don't know if you know this but Python already has a reload() function built-in which you can use to... well, reload modules .
Last edited by netytan; February 10th, 2004 at 07:17 PM.
February 11th, 2004, 03:10 AM
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:
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
self.sock = sock
self.sock = socket....
So in the main module you could step through your Bots:
temp = parseCommand(self.sock)
#now stuff to make temp look like self
for x in range(len(mybots_list)):
mybots_list[x] = mybots_list[x].reload()
February 11th, 2004, 02:19 PM
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