@Test public void testOperations() { assertEquals( "All annoucement triggers have been turned on for test/test in #channel.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel all on")) ); assertEquals( "No subscriptions updated.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel branches on")) ); assertEquals( "No subscriptions updated.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel commits on")) ); assertEquals( "No subscriptions updated.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel issues on")) ); assertEquals( "No subscriptions updated.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel pullrequests on")) ); assertEquals( "All annoucement triggers have been turned off for test/test in #channel.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel all off")) ); assertEquals( "Announcing of branch creating and deletion for test/test in #channel turned on.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel branches on")) ); assertEquals( "Announcing of commits for test/test in #channel turned on.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel commits on")) ); assertEquals( "Announcing of issue activity for test/test in #channel turned on.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel issues on")) ); assertEquals( "Announcing of pull request activity for test/test in #channel turned on.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel pullrequests on")) ); assertEquals( "Invalid operation 'notvalidoperation'.", githubPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "notinachannel", "!github test/test #channel notvalidoperation on")) ); }
protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (message.startsWith("!github ")) { Matcher matcher = commandPattern.matcher(e.getMessage()); if (matcher.find()) { String channel = matcher.group(2); if (channel == null) { if (e.isChannelMessage()) { channel = e.getChannel(); } else { return "You must specify a channel when using this command in private messages."; } } Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), channel, e.getSender()); if (!flags.contains(peekingFlag) && !flags.contains(Flag.A)) { return "You do not have access to use this command. It requires +a for info and +A to edit."; } String repo = matcher.group(1).toLowerCase(); String setting = matcher.group(9); GithubCallbackListener gcl = githubCallbackListeners.get("https: if (gcl == null) { gcl = new GithubCallbackListener(); githubCallbackListeners.put("https: } AnnounceSubscription as = gcl.getOrCreateSubscription(e.getNetwork().getServerAlias(), channel); if (matcher.group(3) != null) { if (setting == null || !setting.equalsIgnoreCase("on")) { setting = "off"; } else { setting = setting.toLowerCase(); } if (!flags.contains(editorFlag)) { return "You do not have access to this feature. It requires +A."; } else { if (matcher.group(4) != null) { if (as.setWantsAll(setting.equals("on"))) return "All annoucement triggers have been turned " + setting + " for " + repo + " in " + channel + "."; } else if (matcher.group(5) != null) { if (as.setWantsBranches(setting.equals("on"))) return "Announcing of branch creating and deletion for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(6) != null) { if (as.setWantsCommits(setting.equals("on"))) return "Announcing of commits for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(7) != null) { if (as.setWantsIssues(setting.equals("on"))) return "Announcing of issue activity for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(8) != null) { if (as.setWantsPullRequests(setting.equals("on"))) return "Announcing of pull request activity for " + repo + " in " + channel + " turned " + setting + "."; } return "No subscriptions updated."; } } else if (e.getMessage().split(" ").length > 2 && matcher.group(2) == null) { return "Invalid operation '" + e.getMessage().split(" ")[2] + "'."; } else if (e.getMessage().split(" ").length > 3 && matcher.group(2) != null) { return "Invalid operation '" + e.getMessage().split(" ")[3] + "'."; } else { return String.format("Subscriptions for %s: %s", channel, as.toString()); } } else { return "Unrecognized syntax. See !help !github for correct syntax."; } } return null; }
GithubPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (message.startsWith("!github ")) { Matcher matcher = commandPattern.matcher(e.getMessage()); if (matcher.find()) { String channel = matcher.group(2); if (channel == null) { if (e.isChannelMessage()) { channel = e.getChannel(); } else { return "You must specify a channel when using this command in private messages."; } } Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), channel, e.getSender()); if (!flags.contains(peekingFlag) && !flags.contains(Flag.A)) { return "You do not have access to use this command. It requires +a for info and +A to edit."; } String repo = matcher.group(1).toLowerCase(); String setting = matcher.group(9); GithubCallbackListener gcl = githubCallbackListeners.get("https: if (gcl == null) { gcl = new GithubCallbackListener(); githubCallbackListeners.put("https: } AnnounceSubscription as = gcl.getOrCreateSubscription(e.getNetwork().getServerAlias(), channel); if (matcher.group(3) != null) { if (setting == null || !setting.equalsIgnoreCase("on")) { setting = "off"; } else { setting = setting.toLowerCase(); } if (!flags.contains(editorFlag)) { return "You do not have access to this feature. It requires +A."; } else { if (matcher.group(4) != null) { if (as.setWantsAll(setting.equals("on"))) return "All annoucement triggers have been turned " + setting + " for " + repo + " in " + channel + "."; } else if (matcher.group(5) != null) { if (as.setWantsBranches(setting.equals("on"))) return "Announcing of branch creating and deletion for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(6) != null) { if (as.setWantsCommits(setting.equals("on"))) return "Announcing of commits for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(7) != null) { if (as.setWantsIssues(setting.equals("on"))) return "Announcing of issue activity for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(8) != null) { if (as.setWantsPullRequests(setting.equals("on"))) return "Announcing of pull request activity for " + repo + " in " + channel + " turned " + setting + "."; } return "No subscriptions updated."; } } else if (e.getMessage().split(" ").length > 2 && matcher.group(2) == null) { return "Invalid operation '" + e.getMessage().split(" ")[2] + "'."; } else if (e.getMessage().split(" ").length > 3 && matcher.group(2) != null) { return "Invalid operation '" + e.getMessage().split(" ")[3] + "'."; } else { return String.format("Subscriptions for %s: %s", channel, as.toString()); } } else { return "Unrecognized syntax. See !help !github for correct syntax."; } } return null; } }
GithubPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (message.startsWith("!github ")) { Matcher matcher = commandPattern.matcher(e.getMessage()); if (matcher.find()) { String channel = matcher.group(2); if (channel == null) { if (e.isChannelMessage()) { channel = e.getChannel(); } else { return "You must specify a channel when using this command in private messages."; } } Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), channel, e.getSender()); if (!flags.contains(peekingFlag) && !flags.contains(Flag.A)) { return "You do not have access to use this command. It requires +a for info and +A to edit."; } String repo = matcher.group(1).toLowerCase(); String setting = matcher.group(9); GithubCallbackListener gcl = githubCallbackListeners.get("https: if (gcl == null) { gcl = new GithubCallbackListener(); githubCallbackListeners.put("https: } AnnounceSubscription as = gcl.getOrCreateSubscription(e.getNetwork().getServerAlias(), channel); if (matcher.group(3) != null) { if (setting == null || !setting.equalsIgnoreCase("on")) { setting = "off"; } else { setting = setting.toLowerCase(); } if (!flags.contains(editorFlag)) { return "You do not have access to this feature. It requires +A."; } else { if (matcher.group(4) != null) { if (as.setWantsAll(setting.equals("on"))) return "All annoucement triggers have been turned " + setting + " for " + repo + " in " + channel + "."; } else if (matcher.group(5) != null) { if (as.setWantsBranches(setting.equals("on"))) return "Announcing of branch creating and deletion for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(6) != null) { if (as.setWantsCommits(setting.equals("on"))) return "Announcing of commits for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(7) != null) { if (as.setWantsIssues(setting.equals("on"))) return "Announcing of issue activity for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(8) != null) { if (as.setWantsPullRequests(setting.equals("on"))) return "Announcing of pull request activity for " + repo + " in " + channel + " turned " + setting + "."; } return "No subscriptions updated."; } } else if (e.getMessage().split(" ").length > 2 && matcher.group(2) == null) { return "Invalid operation '" + e.getMessage().split(" ")[2] + "'."; } else if (e.getMessage().split(" ").length > 3 && matcher.group(2) != null) { return "Invalid operation '" + e.getMessage().split(" ")[3] + "'."; } else { return String.format("Subscriptions for %s: %s", channel, as.toString()); } } else { return "Unrecognized syntax. See !help !github for correct syntax."; } } return null; } GithubPlugin(); }
GithubPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (message.startsWith("!github ")) { Matcher matcher = commandPattern.matcher(e.getMessage()); if (matcher.find()) { String channel = matcher.group(2); if (channel == null) { if (e.isChannelMessage()) { channel = e.getChannel(); } else { return "You must specify a channel when using this command in private messages."; } } Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), channel, e.getSender()); if (!flags.contains(peekingFlag) && !flags.contains(Flag.A)) { return "You do not have access to use this command. It requires +a for info and +A to edit."; } String repo = matcher.group(1).toLowerCase(); String setting = matcher.group(9); GithubCallbackListener gcl = githubCallbackListeners.get("https: if (gcl == null) { gcl = new GithubCallbackListener(); githubCallbackListeners.put("https: } AnnounceSubscription as = gcl.getOrCreateSubscription(e.getNetwork().getServerAlias(), channel); if (matcher.group(3) != null) { if (setting == null || !setting.equalsIgnoreCase("on")) { setting = "off"; } else { setting = setting.toLowerCase(); } if (!flags.contains(editorFlag)) { return "You do not have access to this feature. It requires +A."; } else { if (matcher.group(4) != null) { if (as.setWantsAll(setting.equals("on"))) return "All annoucement triggers have been turned " + setting + " for " + repo + " in " + channel + "."; } else if (matcher.group(5) != null) { if (as.setWantsBranches(setting.equals("on"))) return "Announcing of branch creating and deletion for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(6) != null) { if (as.setWantsCommits(setting.equals("on"))) return "Announcing of commits for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(7) != null) { if (as.setWantsIssues(setting.equals("on"))) return "Announcing of issue activity for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(8) != null) { if (as.setWantsPullRequests(setting.equals("on"))) return "Announcing of pull request activity for " + repo + " in " + channel + " turned " + setting + "."; } return "No subscriptions updated."; } } else if (e.getMessage().split(" ").length > 2 && matcher.group(2) == null) { return "Invalid operation '" + e.getMessage().split(" ")[2] + "'."; } else if (e.getMessage().split(" ").length > 3 && matcher.group(2) != null) { return "Invalid operation '" + e.getMessage().split(" ")[3] + "'."; } else { return String.format("Subscriptions for %s: %s", channel, as.toString()); } } else { return "Unrecognized syntax. See !help !github for correct syntax."; } } return null; } GithubPlugin(); @Override String getDescription(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override void incomingEvent(Event e); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); }
GithubPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (message.startsWith("!github ")) { Matcher matcher = commandPattern.matcher(e.getMessage()); if (matcher.find()) { String channel = matcher.group(2); if (channel == null) { if (e.isChannelMessage()) { channel = e.getChannel(); } else { return "You must specify a channel when using this command in private messages."; } } Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), channel, e.getSender()); if (!flags.contains(peekingFlag) && !flags.contains(Flag.A)) { return "You do not have access to use this command. It requires +a for info and +A to edit."; } String repo = matcher.group(1).toLowerCase(); String setting = matcher.group(9); GithubCallbackListener gcl = githubCallbackListeners.get("https: if (gcl == null) { gcl = new GithubCallbackListener(); githubCallbackListeners.put("https: } AnnounceSubscription as = gcl.getOrCreateSubscription(e.getNetwork().getServerAlias(), channel); if (matcher.group(3) != null) { if (setting == null || !setting.equalsIgnoreCase("on")) { setting = "off"; } else { setting = setting.toLowerCase(); } if (!flags.contains(editorFlag)) { return "You do not have access to this feature. It requires +A."; } else { if (matcher.group(4) != null) { if (as.setWantsAll(setting.equals("on"))) return "All annoucement triggers have been turned " + setting + " for " + repo + " in " + channel + "."; } else if (matcher.group(5) != null) { if (as.setWantsBranches(setting.equals("on"))) return "Announcing of branch creating and deletion for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(6) != null) { if (as.setWantsCommits(setting.equals("on"))) return "Announcing of commits for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(7) != null) { if (as.setWantsIssues(setting.equals("on"))) return "Announcing of issue activity for " + repo + " in " + channel + " turned " + setting + "."; } else if (matcher.group(8) != null) { if (as.setWantsPullRequests(setting.equals("on"))) return "Announcing of pull request activity for " + repo + " in " + channel + " turned " + setting + "."; } return "No subscriptions updated."; } } else if (e.getMessage().split(" ").length > 2 && matcher.group(2) == null) { return "Invalid operation '" + e.getMessage().split(" ")[2] + "'."; } else if (e.getMessage().split(" ").length > 3 && matcher.group(2) != null) { return "Invalid operation '" + e.getMessage().split(" ")[3] + "'."; } else { return String.format("Subscriptions for %s: %s", channel, as.toString()); } } else { return "Unrecognized syntax. See !help !github for correct syntax."; } } return null; } GithubPlugin(); @Override String getDescription(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override void incomingEvent(Event e); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand);  }