[Twisted-Python] how to get an idle callback while running a reactor?
Joe Strout
joe at strout.net
Sat Dec 20 07:10:53 MST 2008
I'm trying to make a simple AIM bot that, in addition to responding when
I talk to it, can also send me a message on its own initiative. My code
is based on SkippyTalkBot [1], but I confess that I don't understand it
very well, and though I've been crawling the Twisted documentation for a
few days now, it's still rather mysterious to me.
So I'm at a loss as to how to add an "idle" function that will allow my
bot to periodically see whether it has something new to say to the user.
My code looks like this:
class B(oscar.BOSConnection):
capabilities = [oscar.CAP_CHAT]
...
def receiveMessage(self, user, multiparts, flags):
"respond to an incoming message from the user"
# (by calling self.sendMessage)
...
class OA(oscar.OscarAuthenticator):
BOSClass = B
protocol.ClientCreator(reactor, OA, SN, PASS,
icq=icqMode).connectTCP(*hostport)
reactor.run()
Now, from trawling the docs, I guess that I want to call
reactor.callWhenRunning... but then I'd like to pass in a bound method
of my B class, so it can call sendMessage on myself. But I'm stumped as
to how my B class is even being instantiated, let alone how to get a
reference to that instance. And the callWhenRunning idea is only a wild
guess and probably wrong.
I'm sure the answer is in the Twisted docs or examples somewhere, but I
haven't been able to find it. Will someone have pity and share a clue?
Thanks,
- Joe
[1] http://www.gilesgoatboy.org/python/skippy.html
More information about the Twisted-Python
mailing list