[Twisted-Python] implementing NAMES in IRC

Glyph glyph at twistedmatrix.com
Tue Sep 11 00:05:05 EDT 2012

On Sep 10, 2012, at 6:24 PM, Art Scheel <ascheel at gmail.com> wrote:

> Now, is stackoverflow overriding that method or was it perhaps written prior to the implementation of the irc.py portion I linked to?

The StackOverflow answer is implementing a new method, on IRCClient.  The implementation in irc.py that you're linking to is from the IRC server protocol implementation.  They're not really related, except insofar as they are talking about the same protocol command - but they are opposite sides of the connection for that command.

For what it's worth, the StackOverflow answer really ought to be linking to a Twisted ticket for a method like .names() on IRCClient within Twisted itself.  This is important functionality, and we're missing it; the right thing to do is always to file a bug, not to implement it without tests in a forum post.

Such a bug may already exist - if you wouldn't mind, would you search for it, and if you can't find it, file a new one?

> My code is here.  I am attempting to parse the names list at line 110
> http://bpaste.net/show/Fll7at9Z3b8nD6GDNN14/
> I don't know if I should be using twisted/words/protocols/irc.py or twisted/words/im/ircsupport.py.

twisted.words.im.* implements a multi-protocol chat abstraction.  I don't think that your bot necessarily needs to be IRC specific, I think it would be a good idea for you to try to use twisted.words.im; you will probably discover a sad lack of documentation, but you can feel free to ask questions and file doc bugs.  Or perhaps even contribute doc patches, once you've figured out what's going on!

At the very least, twisted.words.im.ircsupport already implements irc_RPL_NAMREPLY to convert this message into a series of memberJoined/memberLeft API calls, so you don't have to do something like that yourself.  See here: <http://twistedmatrix.com/trac/browser/trunk/twisted/words/im/ircsupport.py#L160>.

> Can someone point me in the right direction as to what I need to do to grab the list of names at that particular spot using Twisted's in methods?  If it cannot be done with the Twisted's methods, am I to understand that's what the StackOverflow post was doing?

Yes, that's exactly what the SO post was doing.  It is using Twisted's methods though, so clearly it can be done with them, it's just a small matter of work :).

> Yes, I know the code is ugly.  I can clean it up after I understand what I'm doing more fully.

Ugliness is forgivable, but in the future, you should try to post much more minimal programs.  It's a lot easier to help if one can read the whole thing.  See <http://sscce.org> for details.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120910/2e4badda/attachment.htm 

More information about the Twisted-Python mailing list