Commits

Fuco  committed a683b22

+ added ability to ignore certain plugins on certain channels
+ added chaninfo command
+ added Channel entity
+ added ChannelConfig entity

  • Participants
  • Parent commits 34aee17

Comments (0)

Files changed (4)

File src/cz/dasnet/dasik/Dasik.java

 import cz.dasnet.dasik.config.ConfigException;
 import cz.dasnet.dasik.dao.LearnDao;
 import cz.dasnet.dasik.dao.UserDaoImpl;
+import cz.dasnet.dasik.entities.ChannelConfig;
 import cz.dasnet.dasik.util.ChannelLogger;
 import cz.dasnet.dasik.util.Functions;
 import java.io.IOException;
     private Map<String, String> maskToNick = newHashMap();
     private Map<String, ChannelEventListener> channelListeners = new LinkedHashMap<String, ChannelEventListener>();
     private Map<String, Channel> activeChannels = newHashMap();
+    private Map<String, ChannelConfig> channelConfigs = newHashMap();
     private Set<String> plugins = newHashSet();
     private ChannelLogger chanlog;
     private PluginLoader pluginLoader;
         Map<String, Plugin> loadedPlugins = pluginLoader.loadPlugins(plugins);
         channelListeners.putAll(loadedPlugins);
 
+        log.info("Loading channel configs ...");
+        for (String plugin : plugins) {
+            String ignore = config.getProperty("command.ignoreOn." + plugin);
+            if (ignore != null) {
+                String[] chans = ignore.split("\\s+");
+                for (String chan : chans) {
+                    ChannelConfig c = channelConfigs.get(chan);
+                    if (c == null) {
+                        c = new ChannelConfig(chan);
+                        channelConfigs.put(chan, c);
+                    }
+                    c.ignorePlugin(plugin);
+                }
+            }
+        }
+
         log.info("Bot created");
     }
 
         return ignoredHosts;
     }
 
+    public Map<String, ChannelConfig> getChannelConfigs() {
+        return channelConfigs;
+    }
+
     public DataSource getDataSource() {
         return dataSource;
     }
                         send(channel, "An error occured while reloading plugins: " + failed);
                     }
                     return;
+                } else if ("ignore".equals(subcommand) && token.length >= 3) {
+                    String pluginName = token[2];
+                    List<String> chans = newArrayList();
+                    for (int i = 3; i < token.length; i++) {
+                        chans.add(token[i]);
+                    }
+                    if (chans.isEmpty()) {
+                        chans.add(channel);
+                    }
+
+                    for (String chan : chans) {
+                        ChannelConfig c = channelConfigs.get(chan);
+                        if (c == null) {
+                            c = new ChannelConfig(chan);
+                            channelConfigs.put(chan, c);
+                        }
+                        c.ignorePlugin(pluginName);
+                        if (plugins.contains(pluginName)) {
+                            send(channel, "Ignoring plugin " + pluginName + " on " + chan);
+                        } else {
+                            send(channel, "Ignoring plugin " + pluginName + " on " + chan
+                                    + " (warning: plugin with such name does not exist)");
+                        }
+                    }
+                } else if ("unignore".equals(subcommand) && token.length >= 3) {
+                    String pluginName = token[2];
+                    List<String> chans = newArrayList();
+                    for (int i = 3; i < token.length; i++) {
+                        chans.add(token[i]);
+                    }
+                    if (chans.isEmpty()) {
+                        chans.add(channel);
+                    }
+
+                    for (String chan : chans) {
+                        ChannelConfig c = channelConfigs.get(chan);
+                        if (c == null) {
+                            continue;
+                        }
+                        c.unignorePlugin(pluginName);
+                        if (plugins.contains(pluginName)) {
+                            send(channel, "Unignoring plugin " + pluginName + " on " + chan);
+                        } else {
+                            send(channel, "Unignoring plugin " + pluginName + " on " + chan
+                                    + " (warning: plugin with such name does not exist)");
+                        }
+                    }
                 }
             }
         }
             return;
         }
 
-        for (ChannelEventListener cl : channelListeners.values()) {
-            cl.onMessage(channel, sender, login, hostname, message, this);
+        ChannelConfig c = channelConfigs.get(channel);
+        for (Map.Entry<String, ChannelEventListener> cl : channelListeners.entrySet()) {
+            if (c == null || !c.isIgnoringPlugin(cl.getKey()) || cl.getKey().equals("AdminCommand")) {
+                cl.getValue().onMessage(channel, sender, login, hostname, message, this);
+            }
         }
     }
 

File src/cz/dasnet/dasik/entities/Channel.java

+/*
+ *  Copyright (C) 2011 Matus Goljer
+ *  This file is a part of Project DASik, an IRC bot.
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package cz.dasnet.dasik.entities;
+
+/**
+ * Class representing one IRC Channel.
+ *
+ * @author Matus Goljer
+ * @version 1.0
+ */
+public class Channel {
+
+    private String topic;
+    private String name;
+
+    public Channel() {
+    }
+
+    public Channel(String name) {
+        this.name = name;
+    }
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

File src/cz/dasnet/dasik/entities/ChannelConfig.java

+/*
+ *  Copyright (C) 2011 Matus Goljer
+ *  This file is a part of Project DASik, an IRC bot.
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package cz.dasnet.dasik.entities;
+
+import java.util.Collections;
+import java.util.Set;
+import static cz.dasnet.dasik.util.CollectionUtils.newHashSet;
+
+/**
+ *
+ * @author Matus
+ */
+public class ChannelConfig {
+
+    private String name;
+    private Set<String> ignoredPlugins = newHashSet();
+
+    public ChannelConfig(String name) {
+        this.name = name;
+    }
+
+    public void ignorePlugin(String name) {
+        ignoredPlugins.add(name);
+    }
+
+    public void unignorePlugin(String name) {
+        ignoredPlugins.remove(name);
+    }
+
+    public boolean isIgnoringPlugin(String name) {
+        return ignoredPlugins.contains(name);
+    }
+
+    public Set<String> getIgnoredPlugins() {
+        return Collections.unmodifiableSet(ignoredPlugins);
+    }
+
+    public String getName() {
+        return name;
+    }
+}

File src/cz/dasnet/dasik/plugin/AdminCommand.java

 import java.util.List;
 import cz.dasnet.dasik.Dasik;
 import cz.dasnet.dasik.config.ConfigException;
+import cz.dasnet.dasik.entities.ChannelConfig;
 import cz.dasnet.dasik.entities.User;
 import org.apache.log4j.Logger;
 import static cz.dasnet.dasik.util.CollectionUtils.newArrayList;
                 if (bot.getIgnoredHosts().remove(mask.toLowerCase())) {
                     bot.send(channel, "Unignoring " + mask + "!");
                 }
+            } else if ("chaninfo".equals(command)) {
+                String chan = channel;
+                if (token.length >= 2) {
+                    chan = token[1];
+                }
+                ChannelConfig c = bot.getChannelConfigs().get(chan);
+                if (c == null) {
+                    bot.send(channel, "Channel not found");
+                    return;
+                }
+
+                bot.send(channel, "Ignoring plugins: " + c.getIgnoredPlugins());
             }
         }
     }
+
+    @Override
+    public void onPrivateMessage(String sender, String login, String hostname, String message, Dasik bot) {
+        onMessage(sender, sender, login, hostname, message, bot);
+    }
 }