]> jfr.im git - irc/rizon/moo.git/commitdiff
Move !why dnsbls to the config
authorDwarf <redacted>
Wed, 19 Jul 2017 18:23:04 +0000 (20:23 +0200)
committerDwarf <redacted>
Wed, 19 Jul 2017 20:50:39 +0000 (22:50 +0200)
commands/commands.yml.template [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/commands.java
commands/src/main/java/net/rizon/moo/plugin/commands/conf/CommandsConfiguration.java [new file with mode: 0644]
commands/src/main/java/net/rizon/moo/plugin/commands/why/CommandWhy.java
commands/src/main/java/net/rizon/moo/plugin/commands/why/conf/WhyConfiguration.java [new file with mode: 0644]

diff --git a/commands/commands.yml.template b/commands/commands.yml.template
new file mode 100644 (file)
index 0000000..e735b8e
--- /dev/null
@@ -0,0 +1,4 @@
+why:
+ servers:
+  - rbl.efnetrbl.org
+  - dnsbl.dronebl.org
\ No newline at end of file
index 7d0277eab00cd1088f2365cccf1850d6b74292c6..b5e6bced1e9a5b2e5b6c8cc94d3f3d0671af9fe3 100644 (file)
@@ -1,6 +1,9 @@
 package net.rizon.moo.plugin.commands;
 
+import com.google.common.eventbus.Subscribe;
 import com.google.inject.Inject;
+import net.rizon.moo.events.OnReload;
+import net.rizon.moo.plugin.commands.conf.CommandsConfiguration;
 import net.rizon.moo.plugin.commands.why.CommandWhy;
 import net.rizon.moo.plugin.commands.version.CommandVersions;
 import com.google.inject.multibindings.Multibinder;
@@ -35,9 +38,15 @@ import net.rizon.moo.plugin.commands.version.Message351;
 import net.rizon.moo.plugin.commands.why.Message216;
 import net.rizon.moo.plugin.commands.why.Message219Why;
 import net.rizon.moo.plugin.commands.why.Message225;
+import org.slf4j.Logger;
 
 public class commands extends Plugin
 {
+       public static CommandsConfiguration conf;
+
+       @Inject
+       private static Logger logger;
+
        @Inject
        private CommandOline oline;
 
@@ -76,9 +85,10 @@ public class commands extends Plugin
 
        private ScheduledFuture checkTimesTimerFuture;
        
-       public commands()
+       public commands() throws Exception
        {
                super("Administation Commands", "Common IRC administration commands");
+               conf = CommandsConfiguration.load();
        }
 
        @Override
@@ -104,6 +114,8 @@ public class commands extends Plugin
        {
                bind(commands.class).toInstance(this);
 
+               bind(CommandsConfiguration.class).toInstance(conf);
+
                bind(CheckTimesTimer.class);
 
                Multibinder<Command> commandBinder = Multibinder.newSetBinder(binder(), Command.class);
@@ -144,4 +156,19 @@ public class commands extends Plugin
                commandBinder.addBinding().to(CommandUptime.class);
                messageBinder.addBinding().to(Message242.class);
        }
+
+       @Subscribe
+       public void onReload(OnReload evt)
+       {
+               try
+               {
+                       conf = CommandsConfiguration.load();
+               }
+               catch (Exception ex)
+               {
+                       evt.getSource().reply("Error reloading commands configuration: " + ex.getMessage());
+
+                       logger.warn("Unable to reload commands configuration", ex);
+               }
+       }
 }
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/conf/CommandsConfiguration.java b/commands/src/main/java/net/rizon/moo/plugin/commands/conf/CommandsConfiguration.java
new file mode 100644 (file)
index 0000000..5626214
--- /dev/null
@@ -0,0 +1,21 @@
+package net.rizon.moo.plugin.commands.conf;
+
+import net.rizon.moo.conf.Configuration;
+import net.rizon.moo.conf.ConfigurationException;
+import net.rizon.moo.plugin.commands.why.conf.WhyConfiguration;
+
+public class CommandsConfiguration extends Configuration
+{
+       public WhyConfiguration why;
+
+       public static CommandsConfiguration load() throws Exception
+       {
+               return Configuration.load("commands.yml", CommandsConfiguration.class);
+       }
+
+       @Override
+       public void validate() throws ConfigurationException
+       {
+               why.validate();
+       }
+}
index 1d9ff54cae7da9cca29e2ddb6ead5ddcff78fa37..fbc2b85bf68059e9932faa62fc58f75623d1365f 100644 (file)
@@ -6,16 +6,14 @@ import java.net.UnknownHostException;
 
 import net.rizon.moo.Command;
 import net.rizon.moo.CommandSource;
-import net.rizon.moo.Moo;
 import net.rizon.moo.conf.Config;
 import net.rizon.moo.irc.Protocol;
 import net.rizon.moo.irc.Server;
 import net.rizon.moo.irc.ServerManager;
+import net.rizon.moo.plugin.commands.commands;
 
 class DNSBLChecker extends Thread
 {
-       private static final String DNSBLs[] = { "rbl.efnetrbl.org", "dnsbl.dronebl.org" };
-
        private CommandSource source;
 
        private String ip;
@@ -35,7 +33,7 @@ class DNSBLChecker extends Thread
 
                String reverse_ip = octets[3] + "." + octets[2] + "." + octets[1] + "." + octets[0];
 
-               for (final String dnsbl : DNSBLs)
+               for (final String dnsbl : commands.conf.why.servers)
                {
                        String lookup_addr = reverse_ip + "." + dnsbl;
 
@@ -58,7 +56,7 @@ public class CommandWhy extends Command
 
        @Inject
        private Protocol protocol;
-       
+
        protected static CommandSource command_source;
        public static String host_ip = "", host_host = "";
        public static int requested = 0;
diff --git a/commands/src/main/java/net/rizon/moo/plugin/commands/why/conf/WhyConfiguration.java b/commands/src/main/java/net/rizon/moo/plugin/commands/why/conf/WhyConfiguration.java
new file mode 100644 (file)
index 0000000..a2cc6ba
--- /dev/null
@@ -0,0 +1,17 @@
+package net.rizon.moo.plugin.commands.why.conf;
+
+import net.rizon.moo.conf.Configuration;
+import net.rizon.moo.conf.ConfigurationException;
+
+import java.util.List;
+
+public class WhyConfiguration extends Configuration
+{
+       public List<String> servers;
+
+       @Override
+       public void validate() throws ConfigurationException
+       {
+
+       }
+}