@Test public void testCreateSubscriptionInPublic() { assertEquals( "#channel is now subscribed to 'testlist'.", mailAnnouncerPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "#channel", "!mail testlist on")) ); assertEquals( "#channel is already subscribed to 'testlist'.", mailAnnouncerPlugin.handleCommand(EventFactory.createPrivMsgEvent(network, "melwil", "#channel", "!mail testlist on")) ); }
protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (!message.startsWith("!mail")) return null; if (message.startsWith("!mail alias")) { return handleAliases(e); } Matcher matcher = commandPattern.matcher(message); if (!matcher.find()) return null; 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. +a is required to view subscriptions and +A to edit."; } String mailinglist = matcher.group(1).toLowerCase(); String setting = matcher.group(3); MailCallbackListener mcl = mailCallbackManager.get(mailinglist); if (mcl == null) { mcl = new MailCallbackListener(); mailCallbackManager.put(mailinglist, mcl); } if (matcher.group(3) == null) { if (mcl.isSubscribed(e.getNetwork(), channel)) { return channel + " is subscribed to '" + mailinglist + "'."; } return channel + " is not subscribed to '" + mailinglist + "'."; } if (!flags.contains(editorFlag)) { return "You do not have access to use this command. It requires +A to edit subscriptions."; } if (matcher.group(3).equals("on")) { if (!mcl.createSubscription(e.getNetwork(), channel)) { return channel + " is already subscribed to '" + mailinglist + "'."; } return channel + " is now subscribed to '" + mailinglist + "'."; } else if (matcher.group(3).equals("off")) { if (!mcl.deleteSubscription(e.getNetwork(), channel)) { return channel + " is not subscribed to '" + mailinglist + "'."; } return channel + " is no longer subscribed to '" + mailinglist + "'."; } return null; }
MailAnnouncerPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (!message.startsWith("!mail")) return null; if (message.startsWith("!mail alias")) { return handleAliases(e); } Matcher matcher = commandPattern.matcher(message); if (!matcher.find()) return null; 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. +a is required to view subscriptions and +A to edit."; } String mailinglist = matcher.group(1).toLowerCase(); String setting = matcher.group(3); MailCallbackListener mcl = mailCallbackManager.get(mailinglist); if (mcl == null) { mcl = new MailCallbackListener(); mailCallbackManager.put(mailinglist, mcl); } if (matcher.group(3) == null) { if (mcl.isSubscribed(e.getNetwork(), channel)) { return channel + " is subscribed to '" + mailinglist + "'."; } return channel + " is not subscribed to '" + mailinglist + "'."; } if (!flags.contains(editorFlag)) { return "You do not have access to use this command. It requires +A to edit subscriptions."; } if (matcher.group(3).equals("on")) { if (!mcl.createSubscription(e.getNetwork(), channel)) { return channel + " is already subscribed to '" + mailinglist + "'."; } return channel + " is now subscribed to '" + mailinglist + "'."; } else if (matcher.group(3).equals("off")) { if (!mcl.deleteSubscription(e.getNetwork(), channel)) { return channel + " is not subscribed to '" + mailinglist + "'."; } return channel + " is no longer subscribed to '" + mailinglist + "'."; } return null; } }
MailAnnouncerPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (!message.startsWith("!mail")) return null; if (message.startsWith("!mail alias")) { return handleAliases(e); } Matcher matcher = commandPattern.matcher(message); if (!matcher.find()) return null; 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. +a is required to view subscriptions and +A to edit."; } String mailinglist = matcher.group(1).toLowerCase(); String setting = matcher.group(3); MailCallbackListener mcl = mailCallbackManager.get(mailinglist); if (mcl == null) { mcl = new MailCallbackListener(); mailCallbackManager.put(mailinglist, mcl); } if (matcher.group(3) == null) { if (mcl.isSubscribed(e.getNetwork(), channel)) { return channel + " is subscribed to '" + mailinglist + "'."; } return channel + " is not subscribed to '" + mailinglist + "'."; } if (!flags.contains(editorFlag)) { return "You do not have access to use this command. It requires +A to edit subscriptions."; } if (matcher.group(3).equals("on")) { if (!mcl.createSubscription(e.getNetwork(), channel)) { return channel + " is already subscribed to '" + mailinglist + "'."; } return channel + " is now subscribed to '" + mailinglist + "'."; } else if (matcher.group(3).equals("off")) { if (!mcl.deleteSubscription(e.getNetwork(), channel)) { return channel + " is not subscribed to '" + mailinglist + "'."; } return channel + " is no longer subscribed to '" + mailinglist + "'."; } return null; } MailAnnouncerPlugin(); }
MailAnnouncerPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (!message.startsWith("!mail")) return null; if (message.startsWith("!mail alias")) { return handleAliases(e); } Matcher matcher = commandPattern.matcher(message); if (!matcher.find()) return null; 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. +a is required to view subscriptions and +A to edit."; } String mailinglist = matcher.group(1).toLowerCase(); String setting = matcher.group(3); MailCallbackListener mcl = mailCallbackManager.get(mailinglist); if (mcl == null) { mcl = new MailCallbackListener(); mailCallbackManager.put(mailinglist, mcl); } if (matcher.group(3) == null) { if (mcl.isSubscribed(e.getNetwork(), channel)) { return channel + " is subscribed to '" + mailinglist + "'."; } return channel + " is not subscribed to '" + mailinglist + "'."; } if (!flags.contains(editorFlag)) { return "You do not have access to use this command. It requires +A to edit subscriptions."; } if (matcher.group(3).equals("on")) { if (!mcl.createSubscription(e.getNetwork(), channel)) { return channel + " is already subscribed to '" + mailinglist + "'."; } return channel + " is now subscribed to '" + mailinglist + "'."; } else if (matcher.group(3).equals("off")) { if (!mcl.deleteSubscription(e.getNetwork(), channel)) { return channel + " is not subscribed to '" + mailinglist + "'."; } return channel + " is no longer subscribed to '" + mailinglist + "'."; } return null; } MailAnnouncerPlugin(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override String getDescription(); @Override void incomingEvent(Event e); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand); }
MailAnnouncerPlugin implements PluginWithDependencies { protected String handleCommand(PrivMsgEvent e) { String message = e.getMessage().toLowerCase(); if (!message.startsWith("!mail")) return null; if (message.startsWith("!mail alias")) { return handleAliases(e); } Matcher matcher = commandPattern.matcher(message); if (!matcher.find()) return null; 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. +a is required to view subscriptions and +A to edit."; } String mailinglist = matcher.group(1).toLowerCase(); String setting = matcher.group(3); MailCallbackListener mcl = mailCallbackManager.get(mailinglist); if (mcl == null) { mcl = new MailCallbackListener(); mailCallbackManager.put(mailinglist, mcl); } if (matcher.group(3) == null) { if (mcl.isSubscribed(e.getNetwork(), channel)) { return channel + " is subscribed to '" + mailinglist + "'."; } return channel + " is not subscribed to '" + mailinglist + "'."; } if (!flags.contains(editorFlag)) { return "You do not have access to use this command. It requires +A to edit subscriptions."; } if (matcher.group(3).equals("on")) { if (!mcl.createSubscription(e.getNetwork(), channel)) { return channel + " is already subscribed to '" + mailinglist + "'."; } return channel + " is now subscribed to '" + mailinglist + "'."; } else if (matcher.group(3).equals("off")) { if (!mcl.deleteSubscription(e.getNetwork(), channel)) { return channel + " is not subscribed to '" + mailinglist + "'."; } return channel + " is no longer subscribed to '" + mailinglist + "'."; } return null; } MailAnnouncerPlugin(); @Override String[] getDependencies(); @Override void loadDependency(Plugin plugin); @Override String getDescription(); @Override void incomingEvent(Event e); @Override void addEventDistributor(EventDistributor eventDistributor); @Override void addWand(Wand wand);  }