public void onMessage(final MessageEvent<RhqIrcBot> event) throws Exception {
if (event.getUser().getNick().toLowerCase().contains("bot")) {
return; // never talk with artificial forms of life
}
final PircBotX bot = event.getBot();
if (!bot.getNick().equals(bot.getName())) {
bot.changeNick(bot.getName());
}
String message = event.getMessage();
// react to BZs in the messages
Matcher bzMatcher = BZ_PATTERN.matcher(message);
while (bzMatcher.find()) {
final String response = bzResolver.resolve(bzMatcher.group(2));
bot.sendMessage(event.getChannel(), response);
}
// react to Jira bugs in the messages
Matcher jiraMatcher = JIRA_PATTERN.matcher(message);
while (jiraMatcher.find()) {
// final String response = jiraResolver.resolve(bzMatcher.group(1));
// bot.sendMessage(event.getChannel(), response);
final String bugId = jiraMatcher.group(1);
final Promise<Issue> issuePromise = jiraResolver.resolveAsync(bugId);
issuePromise.done(new Effect<Issue>() {
@Override
public void apply(Issue a) {
bot.sendMessage(event.getChannel(), bugId + ": " + Color.RED + a.getSummary() + Color.NORMAL
+ ", priority: " + Color.GREEN + a.getPriority().getName() + Color.NORMAL + ", created: "
+ a.getCreationDate().toString("YYYY-MM-DD") + " [ " + JiraResolver.JIRA_URL + "/browse/"
+ bugId + " ]");
}
});
issuePromise.fail(new Effect<Throwable>() {
@Override
public void apply(Throwable e) {
bot.sendMessage(event.getChannel(),
"Failed to access bug " + bugId + " Cause: " + shorten(e.getMessage()));
}
});
}
// react to the commit hashs included in the messages
Matcher commitMatcher = COMMIT_PATTERN.matcher(message);
while (commitMatcher.find()) {
String shaHash = commitMatcher.group(2);
String response = String.format(COMMIT_LINK, shaHash);
bot.sendMessage(event.getChannel(), event.getUser().getNick() + ": " + response);
}
if (message.startsWith(event.getBot().getNick())) {
// someone asked bot directly, we have to remove that from message
message = message.substring(event.getBot().getNick().length());
message = message.replaceFirst("[^ ]*", "");
}
// react to commands included in the messages
Matcher commandMatcher = commandPattern.matcher(message);
while (commandMatcher.find()) {
Command command = Command.valueOf(commandMatcher.group(1).toUpperCase());
String response = prepareResponseForCommand(command);
if (response != null) {
bot.sendMessage(event.getChannel(), event.getUser().getNick() + ": " + shorten(response));
}
}
// ping JON devs
if (message.matches(".*\\b(jon-team|jboss-on-team)\\b.*")) {
Set<User> users = bot.getUsers(event.getChannel());
StringBuilder presentJonDevs = new StringBuilder();
for (User user : users) {
String nick = user.getNick();
if (JON_DEVS.contains(nick) && !nick.equals(event.getUser().getNick())) {
presentJonDevs.append(nick).append(' ');
}
}
bot.sendMessage(event.getChannel(), presentJonDevs + ": see message from " + event.getUser().getNick()
+ " above");
}
}