[Twisted-Python] Re: Where is best place to put my custom code?
JD
lists at webcrunchers.com
Thu Jan 1 14:25:37 EST 2004
On Dec 31, 2003, at 7:43 PM, Eric Mangold wrote:
> On Wednesday 31 December 2003 04:58 pm, JD wrote:
>> Hi,
>>
>> I'm open for suggestions on where I can put my customized code. I
>> seem to have a choice
>> between putting it in the "factory" or in the "protocol", and I
>> cannot seem to decide where the
>> best place would be.
>
> Since this is IRC you shouldn't go issuing commands until your signed
> on, thus the signedOn method of your protocol would be the right place.
Ok, good point.... but how do I issue commands? let's say I have
a IRCClient class called "testIRC".
do I use: testIRC.sendLine('signedOn') to send the command to the
IRC server
to signon?
or do I: testIRC.register('mynick', 'myhost', 'irc.debian.com')
then, when I want to do the "who" command, would I do:
testIRC.sendLine('who')
then, i would expect to call me back, so I would override the
"action" method,
like so:
def action(self, user, channel, msg):
< extract the info I want from msg and store it somewhere, probably
in an instance variable in testIRC object >
reactor.stop() --- to exit the client and disconnect, or
would I have to put the reactor.stop() in the
factory's "clientConnectionFailed" method, which I would
override of course.
It's things like this that throw me totally for a loop. Where to put
things.... what gets the call back...
> Yeah, it's not obvious how to do that. I'll send another mail when I've
> a chance to test something, but New Years is coming up right now... :)
Yea - and while everyone is partying, i take this wonderful
opportunity to get some serious coding
done, because the place is so quiet, and I'm too broke to do anything
anyway.
> No. An ACTION in IRC terms is a user doing an /me.
Ok, if "action" isn't the callback which I override to get the output
of the who command,
then what is?
myInfo? luserClient?
luserChannels - Called with the number of channels existant on the
server (ALMOST what I want)
luserOp - Called with the number of ops logged on to the server
(GETTING CLOSER - NOT QUITE)
luserMe - Called with information about the server connected to.
(CLOSEST YET - but no IP address info)
Ok, so how do these get called? As far as I can tell,
"handleCommand" calls
method = getattr(self, "irc_%s" % command, None)
which it then somehow then calls back to:
def irc_RPL_LUSERME(self, prefix, params):
self.luserMe(params[1])
I really want: RPL_WHOISSERVER, but (sigh) it's not there. Nobody
bothered to finish this
module.
Could I add this to my IRCClient's subclass?
IE:
def irc_RPL_WHOISSERVER(self, prefix, params):
self.whois(params[1])
Then....
def whois(self, prefix, info):
< then in this code, get the info? - then after that do the
reactor.stop() so I can fall out of the reactor.run()
call. >
Is this all I have to do.... but then would 'getattr' as you see
above, know how to get the method name?
Or would I have to add this somehow to another dictionary?
If so, how do I do it? and if i have to do it, how do I find the
reference to the dictionary?
Anyway, other then being totally confused, is there any hope? I
think I'm just missing a few
critical steps. Or do I have them all?
>> There are a number of other callbacks for the private messages and
>> such. Which one
>> do I use? When testing the code, I'm not getting any callbacks to
>> the "action()" method.
>> Is this because something else is fucked up.
>
> Yeah, your code.
No shit sherlock.... now i got to figure out why it's not calling my
"whois" method.
John
More information about the Twisted-Python
mailing list