Sorry it's taken me so long to get around to this. I had my last final today, so have finally had some time to get to things.
No problem. Thanks for the attention now, though.
I don't think I have the expertise to produce an infallible way of determining whether we are in chat or not, unfortunately. Chat messages either come in through mafia hitting newchatmessages.php directly via the ChatPoller when our internal chat is used, or (and this is the catch) the relay browser sending requests. They are dealt with separately -- RelayRequest.java [1439] handleChat() is the function for how we handle the relay messages, while ChatPoller [63] run() is how we handle it internally.
What prompts the relay browser to send a chat request? Yes, the user typing something will submit a message, but what prompts it to poll to get incoming messages? Is it Javascript running in the chat frame, or something?
We could detect when the user opened lchat.php, since we see that being submitted, but they can close it - by closing the browser window, if nothing else - undetectably, I think.
One method (a bit of a hack) would be to have an internal boolean that is true if the user opens mafia chat or accesses lchat.php for the first time. However, it would be prone to error, as closing the relay browser wouldn't (I don't think) be able to turn it to false, despite closing chat.
...and I typed the above before reading this. Heh.
What I could do is make the altar check simpler (only hitting chatlaunch.php if we haven't previously found it to be completed) and separate it off as a function so it can be used elsewhere.
That would be useful, anyway. Have a KoLCharacter.canChat(), say, which accesses a reset-upon-login variable. Note that when we log in, we access all pages of the Quest Log - and the altar of literacy is a miscellaneous accomplishment. The only reason for actually looking at the altar is that we don't detect when you complete it in a session.
Frono would appreciate it if scripts could call an ASH can_chat() function and not bother his illiterate character. Perhaps we could call it is_illiterate().
Could the Faxbot request check if the ChatManager is running and initialize it if not, remembering to reset it at the end if needed?
Isn't ChatManager intimately connected to the Chat Frame? Is it possible to run ChatManager without LoathingChat being open?
I was concerned about starting chat - and appearing in a chat channel and accepting messages until FaxBot writes to you - and then simply discarding the other messages. But, you know, if you weren't in chat, you obviously didn't care about those messages, anyway, so that shouldn't be a problem.
Could we then do something with the faxbot messages received? Chat could be made to check to see if faxbot is being requested and send those message somewhere to be accessed when they arrive. It's convoluted, but I can't see a simple method of doing it. I think it has to be at the point of receipt rather than separating the requests.
We already do this. The message is stored in ChatManager.faxbotMessage. It's a kludge, but it works. Perhaps "convoluted" = "kludge"?
I like the idea of simplifying the altar of literacy check, reading it from the quest log and setting a flag, detecting when you become literate and setting a flag, and having ChatManager look at that flag rather than hitting the server to look at the Altar of Literacy.
I like the idea of starting ChatManager (if not running), doing Fax work, and stopping it (if not previously running).
I like the idea of having a mode of operation for ChatManger that does not require the Loathing Chat frame to be open.