Feature - Implemented Add new Fax(ing) bots

lostcalpolydude

Developer
Staff member
ASH and CLI commands will now find a bot that has the monster/command specified. This doesn't let you specify a bot to use, and (more importantly) won't try a second bot if the first one should have worked but failed (due to being offline or something). That will be an important issue in late July.
 

Veracity

Developer
Staff member
Revision 14139 makes the faxbot CLI command and ASH function skip bots that are offline.
It also sorts the monsters alphabetically ignoring case, rather than having capitalized monsters first and non-capitalized monsters next.
It also looks up monster and command via "canonical" name, so that the Salaminder from Faustbot can now be found, even though the actual KoL (and KoLmafia) monster name is "salaminder".
And lastly, since Easyfax does not categorize monsters - every monster is in category "None" - we won't make a category list named "None", since you can see everything in the "All Monsters" list. If you use categories and want an "everything else" list, name the category "Other" (or "Misc", like Faustbot).
 

lostcalpolydude

Developer
Staff member
The only case that isn't fully covered now (I think) is using another bot if the first bot isn't on your clan's whitelist. I don't think mafia needs to cover that case (but I wouldn't be surprised if someone disagrees and wants to support that), so I'm marking this Implemented.
 

metool

New member
I'm a bit late to responding to this thread, but thank you Veracity for adding support of FaustBot to KoLmafia.

If there is anything changes to FaustBot I can make to help out KoLmafia support, I'd be happy to update my code to help out.

Again, thanks a ton for adding the ability to request monsters from FaustBot in KoLmafia. FaustBot was started as a pet project and is becoming fairly popular.
 

Veracity

Developer
Staff member
Well, I would request that both Faustbot and Easyfax save their XML config file in UTF-8 - and that the XML header, if provided, say exactly that:

<?xml version="1.0" encoding="UTF-8"?>

FaxBot and EasyFax both say this:

<?xml version="1.0" encoding="ISO-8859-1"?>

Unfortunately, I have been unable to get Java's DocumentBuilder.parse to actually parse in anything other than UTF-8:

XML encoding = ISO-8859-1
input encoding = UTF-8

It starts reading the input in UTF-8, notices that it is ISO-8859-1 when it reads the XML directive, but continues reading the rest of the file in UTF-8. Since Java strings are UTF-8, we end up with bogus characters for the Art Teacher, for example. I suppose I could try converting the strings to a byte array and then rebuilding a string using the XML encoding, but, sheesh. Just write the config files in UTF-8, please.

How the heck are people supposed to deal with this?
 

xKiv

Active member
Since Java strings are UTF-8

Nitpick: all you should be able to say (and all that should matter) is that java strings are *unicode*.

BTW, quoting from my java's version of String.java (and it also follows from Strings being internally stored as char[]):
Code:
A String represents a string in the UTF-16 format

That's, of course, totally irrelevant to your point.

But, I just tried downloading faxbot's and easybots xml, using wget, and ... and while faxbot's appears to be consistent with iso-8859-1 (specifically, no weird characters in the art teacher), easybot's seems to be in utf-8 already? So the incorrect thing there is that it advertises iso-8859-1 encoding when it's actually in utf-8.
 

Crowther

Active member
I've changed Easybot's XML to specify UTF-8. However, "François Verte, Art Teacher" doesn't work right. Somehow it seems to change when sent via a PM, but looks the same. I think?

EDIT: When I say it doesn't work right, I mean just sending that as a PM. Not using the XML file at all, so even if the XML issue is fixed, it still won't work until I figure out what's wrong with the bot.
 

Crowther

Active member
So, when I look at a fax, I see "François Verte, Art Teacher". If someone sends me a PM containing, "François Verte, Art Teacher", I see "François Verte, Art Teacher". If someone sends me a text containing, "François Verte, Art Teacher", I see "Fran&ccedil;ois Verte, Art Teacher". Yes, Easybot is a KoLmafia script.

EDIT: "François Verte, Art Teacher" produces "François Verte, Art Teacher"
 
Last edited:

Veracity

Developer
Staff member
Nitpick: all you should be able to say (and all that should matter) is that java strings are *unicode*.
Yeah, yeah.

But, I just tried downloading faxbot's and easybots xml, using wget, and ... and while faxbot's appears to be consistent with iso-8859-1 (specifically, no weird characters in the art teacher), easybot's seems to be in utf-8 already? So the incorrect thing there is that it advertises iso-8859-1 encoding when it's actually in utf-8.
Here is what I get when I retrieve faxbot.xml:

Retrieved: http://www.hogsofdestiny.com/faxbot/faxbot.xml
8 header fields
Field: null = [HTTP/1.1 200 OK]
Field: Date = [Sat, 28 Jun 2014 22:20:13 GMT]
Field: Content-Length = [31952]
Field: Last-Modified = [Mon, 16 Dec 2013 21:19:40 GMT]
Field: Accept-Ranges = [bytes]
Field: Connection = [keep-alive]
Field: Content-Type = [application/xml]
Field: Server = [nginx/1.6.0][/quote]

Note that it doesn't say anything about the encoding in the HTML stream. We read it in UTF-8 - and it works because Faxbot's art teacher says this:

<monsterdata>
<name>Francois Verte, Art Teacher</name>
<actual_name>Francois Verte, Art Teacher</actual_name>
<command>art_teacher</command>
<category>KOLHS</category>
</monsterdata>

It really doesn't have a c-cedilla there. Since the Request Fax frame doesn't look up monsters, it doesn't care what you call it. Lets see what the faxbot() ASH function does with this monster:

> ash faxbot( $monster[ art teacher ] )

Changing "art teacher" to "François Verte\, Art Teacher" would get rid of this message ()
Configuring faxable monsters.
Configuring FaxBot (2194132)
Configuring FaustBot (2504770)
Configuring Easyfax (2504737)
Faxable monster lists fetched.
Returned: false
It can't find a faxbot that has anything that it recognizes as that monster name. So, how does KoL refer to this monster?

Retrieved: http://www.kingdomofloathing.com/desc_item.php?whichitem=835898159
10 header fields
Field: null = [HTTP/1.1 200 OK]
Field: Date = [Sat, 28 Jun 2014 22:31:11 GMT]
Field: Content-Length = [1919]
Field: Expires = [Thu, 19 Nov 1981 08:52:00 GMT]
Field: Connection = [keep-alive]
Field: Content-Type = [text/html; charset=UTF-8]
Field: X-Powered-By = [PHP/5.3.3]
Field: Server = [nginx/1.0.15]
Field: Pragma = [no-cache]
Field: Cache-Control = [no-store, no-cache, must-revalidate, post-check=0, pre-check=0]

The desc is specified to be charset=UTF-8

This is a sheet of copier paper with a grainy, blurry likeness of a François Verte, Art Teacher on it.
And, by golly, there is the UTF-8 character in the monster description.

So, if easyfax was trying to have the exact output from receiving the fax, it really needs UTF-8 characters, not ISO-8859-1 characters, since that's what KoL itself uses.

Now, when I typed this into easyfax's tab in the chat window, the browser submitted this:

Requesting: http://www.kingdomofloathing.com/submitnewchat.php?playerid=121572&graf=%2Fmsg+easyfax+Fran%E7ois+Verte%2C+Art+Teacher&pwd

Notice that are ISO-8859-1 characters, not Unicode characters. In fact, looking at GenericRequest.addFormField, I see this:

Code:
		String charset = this.isChatRequest ? "ISO-8859-1" : "UTF-8";
... so apparently that really is what we have to submit to chat. However, that echoed into the chat window like this:

Field: Content-Type = [text/html; charset=UTF-8]

<font color=blue><b>private to <a class=nounder target=mainpane href="showplayer.php?who=2504737"><font color=blue>Easyfax</font></a></b>: François Verte, Art Teacher</font></br>

Notice the HTML entity.

This is a can of worms. I'm going to have tho think about this a bit more.
 

Fluxxdog

Active member
Retrieved: http://www.hogsofdestiny.com/faxbot/faxbot.xml
8 header fields
Field: null = [HTTP/1.1 200 OK]
Field: Date = [Sat, 28 Jun 2014 22:20:13 GMT]
Field: Content-Length = [31952]
Field: Last-Modified = [Mon, 16 Dec 2013 21:19:40 GMT]
Field: Accept-Ranges = [bytes]
Field: Connection = [keep-alive]
Field: Content-Type = [application/xml]
Field: Server = [nginx/1.6.0]
Wait, application/xml? Shouldn't that be text/xml?
 

lostcalpolydude

Developer
Staff member
http://forums.kingdomofloathing.com/vb/showpost.php?p=4640213&postcount=34
Easyfax now accepts a proper substring of a monster as a request. The request must match one and only one monster. So you can request "art teacher" or "echo" and get a monster, but requesting "Black Crayon" won't get you one, because it matches more than one monster.
That makes it possible to request "François Verte, Art Teacher" from easyfax, but I'm not sure how to add support for that. I guess that would make the matching in hasCommand work the same as matching an item name or whatever, and using a field maybe in faxbots.txt to track whether exact matching is needed for the bot (and adjust the check in hasCommand based on that value). That doesn't help with the GUI or ASH command though.
 

Veracity

Developer
Staff member
That's a good solution for human interaction. I'm still wondering about how to recognize it properly from KoLmafia itself. Unfortunately, the art teacher doesn't seem to be listed on easyfax at the moment.

Well, we cache copies of the .xml files for each bot. I just edited the config for easyfax to have the art teacher complete with UTF-8 c-cedilla and disabled the line that downloads the config file. It should just read the saved config files. I'll see what I can come up with.
 

Veracity

Developer
Staff member
Oh, sweet.

> ash faxbot( $monster[ art teacher ] )

Changing "art teacher" to "François Verte\, Art Teacher" would get rid of this message ()
Visiting Fax Machine in clan VIP lounge
Asking Easyfax to send a fax of François Verte, Art Teacher: François Verte, Art Teacher
Configuration error: unknown command sent to Easyfax
Returned: false
It found the art teacher in easyfax's config file. We sent:

Requesting: http://www.kingdomofloathing.com/submitnewchat.php?playerid=1764512&graf=%2Fmsg+2504737+Fran%E7ois+Verte%2C+Art+Teacher&pwd

Notice the ISO-8859-1 character in there, as expected. Chat echoed:

<font color=blue><b>private to <a class=nounder target=mainpane href="showplayer.php?who=2504737"><font color=blue>Easyfax</font></a></b>: François Verte, Art Teacher</font></br>

... as expected. And then, by and by, Easyfax returned:

<a target=mainpane href="showplayer.php?who=2504737"><font color=blue><b>Easyfax (private):</b></font></a> <font color="blue">I couldn't find that monster. Try sending "list" for a list of monster names.</font><br><!--lastseen:1380241231-->

So, from this, I conclude:

- Having a UTF-8 special character in the config file does allow us to match the monster from an ASH $monster[] object. That is because we make a "key" out of fax "actual names" by canonicalizing them - converting them to lower case and making special characters into HTML entities - and that happens to match KoLmafia monster names.
- We store the command in its full UTF-8 glory, and when we send it as a chat command to the bot, GenericRequest adds it to the URL using ISO-8859-1 charset - just like a browser. That apparently converts the UTF-8 character to the other encoding just fine.

So, from the "sender" side, it looks like KoLmafia is doing the right thing. The issue seems to be at the "receiver" end, as Crowther was discussing. I expect that easyfax gets the message in the same format as I showed up above - with HTML entities.

I don't have time to experiment right now, but I will bet that some combination of ASH's url_encode(), url_decode(), entity_encode(), and entity_decode() would enable easyfax (and ASH "chat" script, right?) to munge the message received via chat PM into something that will match what it has in its config file.
 

Fluxxdog

Active member
UPDATE: Due to improper code, not buggy behavior. Feel free to ignore.

Got this using r14143:
Code:
Configuring faxable monsters.
Configuring FaxBot (2194132)
Configuring FaustBot (2504770)
Configuring Easyfax (2504737)
Faxable monster lists fetched.
Visiting Fax Machine in clan VIP lounge
Asking FaustBot to send a fax of Adventurer Echo: adventurer_echo
Receiving a fax.
You acquire an item: photocopied monster
You receive a photocopied Adventurer echo from the fax machine.
[COLOR="#FF0000"]No faxbots accept that command.[/COLOR]
I can confirm that I have the Adventurer Echo photocopy in my inventory. I used the ASH command inside an if statement and it caused an abort rather than return false, raising an error flag in my breakfast script. I ran a debug log and trimmed it to where the fax request starts to where it finishes.
 

Attachments

  • DEBUG_20140630.txt
    52.8 KB · Views: 21
Last edited:

Veracity

Developer
Staff member
I used the ASH command inside an if statement and it caused an abort rather than return false, raising an error flag in my breakfast script.
This cannot be true. Or, at least, it cannot be the whole story. Because:

No faxbots accept that command.
is printed by the "faxbot" CLI command, not by the ASH function.

Without seeing the relevant code in your breakfast script, I can say nothing about what happened here.
 

lostcalpolydude

Developer
Staff member
I don't understand how that can happen. First, "No faxbots accept that command." only shows up from the CLI command, not the ASH command (as far as I can tell). Second, that ABORT should only be reached if mafia never requests a fax (there's a return statement right after the request), but obviously it did.
 

Crowther

Active member
That's a good solution for human interaction. I'm still wondering about how to recognize it properly from KoLmafia itself. Unfortunately, the art teacher doesn't seem to be listed on easyfax at the moment.
Lots of people type part of a monster name, so I figured that would help them and at least make a path for getting the Art Teacher, but it doesn't fix the real problem.

I don't have time to experiment right now, but I will bet that some combination of ASH's url_encode(), url_decode(), entity_encode(), and entity_decode() would enable easyfax (and ASH "chat" script, right?) to munge the message received via chat PM into something that will match what it has in its config file.
That sounds like a good plan. I'll see if I can at least get a test setup and try a few things.
 

Crowther

Active member
I did some testing and it looks like entity_decode() will convert a PM back to the way Easyfax expects things to be. At least for the Art Teacher.
Code:
void main()
{
    string a1 = "François Verte, Art Teacher";
    string a2 = "François Verte, Art Teacher";
    print(a1 == a2);
    print(a1 == entity_decode(a2));
    print(entity_encode(a1) == a2);
}
Produces:
Code:
false
true
true
I've adjusted Easyfax, although it won't go into effect until rollover and there's no Art Teacher to test with anyway.
 

Veracity

Developer
Staff member
I'll load an art teacher into one of my clans and advertise it to you. We shall see.

Edit: It is done. I put an art teacher into the fax, unwhitelisted Easyfax, and then re-whitelisted him. If I understand correctly, when he gets the "you have been added to a whitelist" notification, he will go to take a look at the fax and, by and by, it will appear on his configuration.
 
Last edited:
Top