@Override protected void onMessage(String channel, String sender, String login, String hostname, String message) { if (!channel.equals("#jenkins")) return; // not in this channel if (sender.equals("jenkinsci_builds")) return; // ignore messages from other bots message = message.trim(); String prefix = getNick() + ":"; if (!message.startsWith(prefix)) { // not send to me Matcher m = Pattern.compile("(?:hudson-|jenkins-|bug )([0-9]+)",CASE_INSENSITIVE).matcher(message); while (m.find()) { replyBugStatus(channel,m.group(1)); } return; } String payload = message.substring(prefix.length(), message.length()).trim(); // replace duplicate whitespace with a single space payload = payload.replaceAll("\\s+", " "); Matcher m; m = Pattern.compile("(?:create|make|add) (\\S+)(?: repository)? (?:on|in) github(?: for (\\S+))?",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { createGitHubRepository(channel, m.group(1), m.group(2)); return; } m = Pattern.compile("fork (\\S+)/(\\S+)(?: on github)?(?: as (\\S+))?",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { forkGitHub(channel, m.group(1),m.group(2),m.group(3)); return; } m = Pattern.compile("(?:make|give|grant|add) (\\S+)(?: as)? (?:a )?(?:committ?er|commit access) (?:of|on|to|at) (\\S+)",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { addGitHubCommitter(channel,sender,m.group(1),m.group(2)); return; } m = Pattern.compile("(?:make|give|grant|add) (\\S+)(?: as)? (a )?(committ?er|commit access).*",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { addGitHubCommitter(channel,sender,m.group(1),null); return; } m = Pattern.compile("(?:create|make|add) (\\S+)(?: component)? in (?:the )?(?:issue|bug)(?: tracker| database)? for (\\S+)",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { createComponent(channel, sender, m.group(1), m.group(2)); return; } m = Pattern.compile("(?:make|set) (\\S+) (?:the |as )?(?:lead|default assignee) (?:for|of) (\\S+)",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { setDefaultAssignee(channel, sender, m.group(2), m.group(1)); return; } m = Pattern.compile("(?:make|give|grant|add) (\\S+) voice(?: on irc)?",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { grantAutoVoice(channel,sender,m.group(1)); return; } m = Pattern.compile("(?:rem|remove|ungrant|del|delete) (\\S+) voice(?: on irc)?",CASE_INSENSITIVE).matcher(payload); if (m.matches()) { removeAutoVoice(channel,sender,m.group(1)); return; } if (payload.equalsIgnoreCase("version")) { version(channel); return; } if (payload.equalsIgnoreCase("help")) { help(channel); return; } if (payload.equalsIgnoreCase("refresh")) { // get the updated list sendRawLine("NAMES #jenkins"); return; } sendMessage(channel,"I didn't understand the command"); try { PrintWriter w = new PrintWriter(new FileWriter(unknownCommands, true)); w.println(payload); w.close(); } catch (IOException e) {// if we fail to write, let it be. e.printStackTrace(); } }
private void insufficientPermissionError(String channel) { sendMessage(channel,"Only people with + or @ can run this command."); // I noticed that sometimes the bot just get out of sync, so ask the sender to retry sendRawLine("NAMES #jenkins"); sendMessage(channel,"I'll refresh the member list, so if you think this is an error, try again in a few seconds."); }