(Mostly) Headless chatbot scripting

Lilac

Member
Hi! I hope this isn't a tender subject.

I'm trying to convert our clan chatbot from a collection of Perl scripts to Mafia, and preferably run it without the GUI up (i.e. from a terminal, kicked off after rollover by a script). I've got chatbotScript working, and it functions perfectly on a GUI'd Mafia, but on a command line the chat script throws a java.awt.HeadlessException, even with Djava.awt.headless=true. (The "chat" command works fine, but does not correctly cause my script to fire on messages.)

Is this a built-in limitation of Mafia, to prevent unattended chatbot use, or am I missing something?

Thanks. :)
 
I don't think there's any limitations intentionally put in the way to hinder you on this one.

Are you able to provide some snippets of what your chatbot script is actually doing?

Could you try turning on debug (debug on in the CLI) and then post the debug log?
 
Also, what version of mafia are you using? There have been several version with headless problems, but I believe it's expected to be working properly now...
 
I use headless, but haven't updated mafia on the server I use for a while now (as long as chat doesn't change, I see no reason for me to). I'm currently in the middle of my finals, so can't do any digging around for another few days, but if you post the output, that would be helpful. I'm sure you're aware of this, but suffixing "> outputfile" to the invoking code will pipe the output into a file. For example:

Code:
/usr/bin/nohup java -jar -Djava.awt.headless=true /home/User/KoLmafia.jar login.txt --CLI > /home/User/outputfile &

Also, what is your method of invoking mafia? I assume it's via cron, but your shell script/service code would be useful. I'll update my own version of mafia after exams to try and test this if I don't hear back from you.
 
Well, here's my Mafia debug output:

Code:
Unexpected error, debug log printed.
class java.awt.HeadlessException: null
java.awt.HeadlessException
	at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:197)
	at java.awt.Window.<init>(Window.java:534)
	at java.awt.Frame.<init>(Frame.java:420)
	at java.awt.Frame.<init>(Frame.java:385)
	at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1756)
	at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1831)
	at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1699)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:577)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:526)
	at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:476)
	at net.sourceforge.kolmafia.utilities.InputFieldUtilities.input(InputFieldUtilities.java:84)
	at net.sourceforge.kolmafia.textui.DataTypes.promptForValue(DataTypes.java:765)
	at net.sourceforge.kolmafia.textui.DataTypes.promptForValue(DataTypes.java:711)
	at net.sourceforge.kolmafia.textui.Interpreter.requestUserParams(Interpreter.java:362)
	at net.sourceforge.kolmafia.textui.Interpreter.executeScope(Interpreter.java:317)
	at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:249)
	at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:242)
	at net.sourceforge.kolmafia.textui.command.CallScriptCommand.call(CallScriptCommand.java:200)
	at net.sourceforge.kolmafia.textui.command.CallScriptCommand.run(CallScriptCommand.java:63)
	at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:532)
	at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:488)
	at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:391)
	at net.sourceforge.kolmafia.KoLmafiaCLI.listenForCommands(KoLmafiaCLI.java:201)
	at net.sourceforge.kolmafia.KoLmafia.main(KoLmafia.java:518)

My script isn't really executable from the command line; it's just a chatbotScript script. The above error happens when I manually call it, which I wouldn't do under normal circumstances. It definitely works on GUI'd Mafia in Windows, so I'm trying to figure out what's throwing the HeadlessException.

Here's the main function. Please ignore the horrible coding practices, I'm bad at this.

Code:
void main(string sender, string message, string channel)  {

	string firstWord = "";

	// Clean up message
		message = message.to_lower_case();

	// TODO: First, check if message is a PM and handle it appropriately.
	
	// Second, check if message is a "jw" command coming from clan chat and handle it appropriately.
		int spaceLoc = index_of(message, " ");
		if (spaceLoc != -1) {
			firstWord = substring(message, 0, spaceLoc);
		}
		else {
			firstWord = message;
		}
	
		if (jwTypes contains firstWord && channel == "/clan") { // the message is a JW command from clan
		
			// TODO: Check if sender is on the permissions list
			runJWCommand(substring(message, spaceLoc + 1));
		}
}

(I have other functions that do the printing to chat, but I don't think they're contributing to the problem.)
 
The above error happens when I manually call it

Why would you do that? You can't run a script that requires user input from headless mode. The concepts contradict one another. Headless means you have no means of responsive user input (keyboard, mouse, etc).

The problem seems to be caused the invocation of the script demanding string input and trying to call the string input dialog. If it's a chatbot script, then set it as such.
 
Why would you do that? You can't run a script that requires user input from headless mode. The concepts contradict one another. Headless means you have no means of responsive user input (keyboard, mouse, etc).

The problem seems to be caused the invocation of the script demanding string input and trying to call the string input dialog. If it's a chatbot script, then set it as such.

Sorry, I may not have communicated my situation properly. The script does not respond to chat, or indeed do anything at all, when set as chatbotScript from the CLI. I only manually called it to see if I could get it to work when manually feeding it a message, channel, and sender. Figured it would be able to prompt me for strings from the terminal, but apparently not.

As you and others have pointed out, "headless" is a bit of a misnomer, as I am manually on the server trying to get it to work. I just need it to work when "headed" so it will work later when properly headless. :)
 
Sorry, I may not have communicated my situation properly. The script does not respond to chat, or indeed do anything at all, when set as chatbotScript from the CLI. I only manually called it to see if I could get it to work when manually feeding it a message, channel, and sender. Figured it would be able to prompt me for strings from the terminal, but apparently not.

Okay. I think I need a bit of detail from you as to what you are doing. When you initially invoke mafia, how do you do it? Give me the exact command you use (it should have "java" and "-jar" somewhere in it). Secondly, do you run a login script? If so, what is it? Please don't omit anything. In particular, how do you initiate chat. More importantly, do you initiate chat? I currently cannot replicate your problem. That probably means I am doing something differently from you.

Finally, could you stick up some screenshots of your chat preferences? It would be useful to see if there's anything in there that could be throwing things off.

EDIT: Oh, almost forgot. If the headless exception is only coming up when you are doing something that you shouldn't be doing -- what exactly is the problem you are looking to fix? Is it that the chatbotScript isn't firing when you think it should, or is there another exception popping up when it is actually running headless?
 
Last edited:
Back
Top