In this case the bug is that it waits for 60 seconds and then timing out.
Originally Posted by Veracity
Instead it should immediately print to the CLI an error message that says "chat window not open, you must enter chat to use faxbot feature"
Tell me how we can detect if you have the chat window open in the Relay Browser.
I'm all ears.
Could mafia issue some innocuous command like "/channels" and see is if it quickly gets a response? And, if not, assume the browser chat is closed and open the mafia chat?
Originally Posted by Veracity
Not that I care...but it sounds like an interesting problem to solve!
I was hoping for a solution based on KoLmafia's internal state which would not require a server hit.
KoLmafia's ChatManager is open if you have the GUI Chat Frame open - or if the Relay Browser is open and chat requests/responses come from the browser. In both of those cases, we have a ChatPoller running to listen for asynchronous chat stuff coming from KoL.
Additionally, I believe (having not looked at the code in years), when you issue a Chat command in the GUI, it also opens the ChatManager if necessary, but doesn't start a ChatPoller. Some commands return right away and we get the results. Others essentially redirect into a different Request - things like "/eat" or "/equip".
The ideal solution - which I couldn't figure out years ago when I added FaxBot support - would know exactly when we have a ChatPoller running to examine the chat responses coming asynchronously from KoL and detect when the FaxBot says "here it is" or "nopers".
I am probably the only remaining "expert" on KoLmafia's chat support, since I am the one who integrated KoLmafia's chat support with mchat, many years ago, but since I don't chat, I haven't been motivated to keep that knowledge up to date - or to dive deep enough to fully come up with a solution for this particular issue.
I will look at any proffered patches, but am unlikely to spend time working on it in my own time; simply making sure the chat window is open when I ask for a fax is good enough for my needs.
Obviously you're much more familiar with this than I am but would it be possible to have a piece of JS running in the main window that watches the chatpane frame to see when it's title changes (or some other factor) and then hit something like "http://127.0.0.1:60080/KoLmafia/submitCommand?cmd=relay_chat open&pwd" (or "relay_chat closed" of course). I'd be happy to write it up if you think it sounds sensible.
The regular requests to newchatmessages.php are not a good enough indicator?
(assuming that "new" chat is the only chat good enough for our purposes)
Unless this stuff if going to open a chat window and handle your chats for you (which is not ideal as that can wipe PMs), I am not sure how this solves the issue. The 60 second timeout might be considered a "hack" but it works (it could be faster sure, but the faxbot itself can be delayed so you can't really do much about it), you ultimately still need a timeout.
If Mafia could detect that the chat window was open and rejected the fax request until it was open, that breaks implementations that don't or can't open a chat window (they'll have to revert to visit_url and timers).
I'm not going to say I wasn't initially frustrated the first time I encountered this and was like "why do I need chat open? why can't it do it for me?". But it makes sense and as currently implemented, it still makes the request regardless of chat opened status - this is the important part.
If I am not mistaken, should it not be possible to have mafia aware of that initial time where you manually click the button to enter chat in the first place (after all, something must be launching the current existing code)? If it is, then one could make deductions on the current status.
A. If the player, after logging in to mafia, never clicked to enter chat, then chat has to be closed
B. If the player, after opening a new relay window via the button on mafia that does that has not entered chat, then the chat has to be closed
C. If the player has at some point in the past, during the current session, clicked on the button to enter chat, then the chat status is unknown, but likely to be open. unless the player closed the relay browser and is playing purely in mafia without a browser, or something else happened to log them out of chat but not mafia. Or the chat login failed after the button was clicked.
Basically set bool to false on login, and to true on launching chat. If bool is on true, then chat status is unknown, but probably open. If bool is false, then chat is certain to be closed.
Last edited by taltamir; 09-23-2018 at 01:25 AM.
Whatever happens it will be tested with a character with access to a fax but had not visited the Altar of Literacy :-)
I have accounts where I can guarantee that it will be false according to this paradigm and some of them run in places where I can't open chat (no GUI, headless). I'd really like if this doesn't break that things already work.
Originally Posted by taltamir