@Test public void testDecreaseMultiple() { ResponseKarmaFind responseKarmaFind = karmaPlugin.findKarmaChange(EventFactory.createPrivMsgEvent(network, "nick", "#channel", "nick-=10")); assertEquals(-5, responseKarmaFind.amount); assertEquals("nick", responseKarmaFind.sender); assertEquals("nick", responseKarmaFind.target); responseKarmaFind = karmaPlugin.findKarmaChange(EventFactory.createPrivMsgEvent(network, "nick", "#channel", "other-=5")); assertEquals(-5, responseKarmaFind.amount); assertEquals("nick", responseKarmaFind.sender); assertEquals("other", responseKarmaFind.target); }
protected ResponseKarmaFind findKarmaChange(PrivMsgEvent e) { Matcher matcher = karmaPattern.matcher(e.getMessage()); if (matcher.find()) { String nick = matcher.group(1); if (nick != null) { if (nick.equals(e.getSender())) { return new ResponseKarmaFind(nick, nick, -5); } Channel chan = e.getNetwork().getChannel(e.getChannel()); if (chan.isOnChannel(nick)) { if (matcher.group(2) != null) { String karmaDirection = matcher.group(2); if (karmaDirection.equals("++")) { return new ResponseKarmaFind(e.getSender(), nick, 1); } else if (karmaDirection.equals("--")) { return new ResponseKarmaFind(e.getSender(), nick, -1); } } if (matcher.group(3) != null) { Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), e.getChannel(), e.getSender()); if (flags.contains(controlFlag)) { String karmaDirection = matcher.group(3); int amount = Integer.parseInt(matcher.group(4)); if (karmaDirection.equals("+=")) { return new ResponseKarmaFind(e.getSender(), nick, amount); } else if (karmaDirection.equals("-=")) { return new ResponseKarmaFind(e.getSender(), nick, -amount); } } } } } } return null; }
KarmaPlugin implements PluginWithDependencies { protected ResponseKarmaFind findKarmaChange(PrivMsgEvent e) { Matcher matcher = karmaPattern.matcher(e.getMessage()); if (matcher.find()) { String nick = matcher.group(1); if (nick != null) { if (nick.equals(e.getSender())) { return new ResponseKarmaFind(nick, nick, -5); } Channel chan = e.getNetwork().getChannel(e.getChannel()); if (chan.isOnChannel(nick)) { if (matcher.group(2) != null) { String karmaDirection = matcher.group(2); if (karmaDirection.equals("++")) { return new ResponseKarmaFind(e.getSender(), nick, 1); } else if (karmaDirection.equals("--")) { return new ResponseKarmaFind(e.getSender(), nick, -1); } } if (matcher.group(3) != null) { Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), e.getChannel(), e.getSender()); if (flags.contains(controlFlag)) { String karmaDirection = matcher.group(3); int amount = Integer.parseInt(matcher.group(4)); if (karmaDirection.equals("+=")) { return new ResponseKarmaFind(e.getSender(), nick, amount); } else if (karmaDirection.equals("-=")) { return new ResponseKarmaFind(e.getSender(), nick, -amount); } } } } } } return null; } }
KarmaPlugin implements PluginWithDependencies { protected ResponseKarmaFind findKarmaChange(PrivMsgEvent e) { Matcher matcher = karmaPattern.matcher(e.getMessage()); if (matcher.find()) { String nick = matcher.group(1); if (nick != null) { if (nick.equals(e.getSender())) { return new ResponseKarmaFind(nick, nick, -5); } Channel chan = e.getNetwork().getChannel(e.getChannel()); if (chan.isOnChannel(nick)) { if (matcher.group(2) != null) { String karmaDirection = matcher.group(2); if (karmaDirection.equals("++")) { return new ResponseKarmaFind(e.getSender(), nick, 1); } else if (karmaDirection.equals("--")) { return new ResponseKarmaFind(e.getSender(), nick, -1); } } if (matcher.group(3) != null) { Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), e.getChannel(), e.getSender()); if (flags.contains(controlFlag)) { String karmaDirection = matcher.group(3); int amount = Integer.parseInt(matcher.group(4)); if (karmaDirection.equals("+=")) { return new ResponseKarmaFind(e.getSender(), nick, amount); } else if (karmaDirection.equals("-=")) { return new ResponseKarmaFind(e.getSender(), nick, -amount); } } } } } } return null; } KarmaPlugin(); }
KarmaPlugin implements PluginWithDependencies { protected ResponseKarmaFind findKarmaChange(PrivMsgEvent e) { Matcher matcher = karmaPattern.matcher(e.getMessage()); if (matcher.find()) { String nick = matcher.group(1); if (nick != null) { if (nick.equals(e.getSender())) { return new ResponseKarmaFind(nick, nick, -5); } Channel chan = e.getNetwork().getChannel(e.getChannel()); if (chan.isOnChannel(nick)) { if (matcher.group(2) != null) { String karmaDirection = matcher.group(2); if (karmaDirection.equals("++")) { return new ResponseKarmaFind(e.getSender(), nick, 1); } else if (karmaDirection.equals("--")) { return new ResponseKarmaFind(e.getSender(), nick, -1); } } if (matcher.group(3) != null) { Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), e.getChannel(), e.getSender()); if (flags.contains(controlFlag)) { String karmaDirection = matcher.group(3); int amount = Integer.parseInt(matcher.group(4)); if (karmaDirection.equals("+=")) { return new ResponseKarmaFind(e.getSender(), nick, amount); } else if (karmaDirection.equals("-=")) { return new ResponseKarmaFind(e.getSender(), nick, -amount); } } } } } } return null; } KarmaPlugin(); @Override String getDescription(); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); @Override void incomingEvent(Event e); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); }
KarmaPlugin implements PluginWithDependencies { protected ResponseKarmaFind findKarmaChange(PrivMsgEvent e) { Matcher matcher = karmaPattern.matcher(e.getMessage()); if (matcher.find()) { String nick = matcher.group(1); if (nick != null) { if (nick.equals(e.getSender())) { return new ResponseKarmaFind(nick, nick, -5); } Channel chan = e.getNetwork().getChannel(e.getChannel()); if (chan.isOnChannel(nick)) { if (matcher.group(2) != null) { String karmaDirection = matcher.group(2); if (karmaDirection.equals("++")) { return new ResponseKarmaFind(e.getSender(), nick, 1); } else if (karmaDirection.equals("--")) { return new ResponseKarmaFind(e.getSender(), nick, -1); } } if (matcher.group(3) != null) { Set<Flag> flags = flagsPlugin.getFlags(e.getNetwork(), e.getChannel(), e.getSender()); if (flags.contains(controlFlag)) { String karmaDirection = matcher.group(3); int amount = Integer.parseInt(matcher.group(4)); if (karmaDirection.equals("+=")) { return new ResponseKarmaFind(e.getSender(), nick, amount); } else if (karmaDirection.equals("-=")) { return new ResponseKarmaFind(e.getSender(), nick, -amount); } } } } } } return null; } KarmaPlugin(); @Override String getDescription(); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); @Override void incomingEvent(Event e); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin);  }