Well, my bot is finally reacting to PC stanzas.
And today's episode of
Stupid Dyne Errors shall be called:
String Formatting Considered HarmfulWhen it came time to register the handlers for the custom stanzas, both
Arcana and
this example used a matcher like:
MatchXPath( '{%s}presence/{%s}pc' % (self.default_ns, pcPresenceStanza.namespace) )
That uses python's string formatting. See, in the versions of Python 2 that I am familiar with, the %s patterns get expanded to the values of the variables after the % operator. In Python 3 (and 2.7), this old way still works, but the preferred syntax for this has changed to
"{}".format(variable) and -- having learned my lesson with the Byte slicing earlier -- I was just habitually converting this sort of thing as I went along.
Can you guess what I did? Look closely at what is present in both the XPath call above and in Python 3's syntax, yet
absent from my description of the old Python 2 syntax.
Yep. It probably took you about 1/100th the time it took me.
I saw the braces in the original version. But, thanks to their presence in exactly the same spots in the new syntax, I didn't
see them see them. When I converted to the new syntax
in situ, they were there already so I just called it a day.
My version ended up like:
MatchXPath( '{}presence/{}pc'.format(self.default_ns, pcPresenceStanza.namespace) )
Instead of "{jabber:client}presence/{pc:presence}pc", it was trying to match "jabber:clientpresence/pc:presencepc". Until I managed to get around the blind spot induced by the syntax change, I couldn't even figure out how the
original version could have produced anything valid. Bad Dyne, no cookie.
(In my defense, I was distracted by other things that seemed more likely. I kept glancing at that MatchXPath, frowning, and then checking something else. After all, two different sources had used string formatting, and one would have to be a complete idiot to mess up a syntax conversion
that simple, right?)
Unrelated, but I also discovered that joining the meta channel from Pidgin while also testing an invisible bot that chokes and dies (for a different issue) can confuse either Paragon Chat or Openfire, not sure which. It resulted in a duplicate of my character; it looked like me and followed my movements, emotes, etc. It's almost like I had a bot that would mirror my appearance and movements, without doing any of the work to get there.