public void onMessage(IMMessage msg) {
// is it a command for me ? (returns null if not, the payload if so)
String payload = retrieveMessagePayLoad(msg.getBody());
if (payload != null) {
Sender s = getSender(msg);
try {
if (!this.commandsAccepted) {
this.chat.sendMessage(s.getNickname() + " you may not issue bot commands in this chat!");
return;
} else if (!msg.isAuthorized()) {
this.chat.sendMessage(s.getNickname() + " you're not a buddy of me. I won't take any commands from you!");
return;
}
} catch (IMException e) {
LOGGER.warning(ExceptionHelper.dump(e));
return;
}
// split words
String[] args = MessageHelper.extractCommandLine(payload);
if (args.length > 0) {
// first word is the command name
String cmd = args[0];
try {
BotCommand command = this.cmdsAndAliases.get(cmd);
if (command != null) {
Authentication oldAuthentication = SecurityContextHolder.getContext().getAuthentication();
try {
if (this.authentication != null) {
SecurityContextHolder.getContext().setAuthentication(this.authentication.getAuthentication());
}
command.executeCommand(this, this.chat, msg, s, args);
} finally {
if (this.authentication != null) {
SecurityContextHolder.getContext().setAuthentication(oldAuthentication);
}
}
} else {
this.chat.sendMessage(s.getNickname() + " did you mean me? Unknown command '" + cmd
+ "'\nUse '" + this.commandPrefix + " help' to get help!");
}
} catch (IMException e) {
LOGGER.warning(ExceptionHelper.dump(e));
}