]> jfr.im git - irc/rizon/moo.git/commitdiff
Accept commands directed at the bot
authorAdam <redacted>
Wed, 30 Mar 2022 01:34:41 +0000 (21:34 -0400)
committerAdam <redacted>
Wed, 30 Mar 2022 01:34:41 +0000 (21:34 -0400)
moo/src/main/java/net/rizon/moo/CommandManager.java

index b4db51c147cdcfb08ed8544d1750948fb18cbd13..3d0c62c41037519a1a3e72eeda8d96dccf792e85 100644 (file)
@@ -1,5 +1,6 @@
 package net.rizon.moo;
 
+import net.rizon.moo.conf.Config;
 import net.rizon.moo.irc.User;
 import com.google.inject.Inject;
 import java.util.Set;
@@ -17,6 +18,9 @@ public class CommandManager
 
        @Inject
        private Protocol protocol;
+
+       @Inject
+       private Config config;
        
        private Command find(String name)
        {
@@ -28,25 +32,38 @@ public class CommandManager
        
        public void run(IRCMessage m)
        {
-               String[] message = m.getParams();
-               
-               if (message.length < 2 || message[0].startsWith("#") == false || (message[1].startsWith("!") == false && message[1].startsWith(".") == false))
+               final String[] params = m.getParams();
+
+               if (params.length < 2)
+                       return;
+
+               final String target = params[0];
+               final String message = params[1];
+
+               if (!target.startsWith("#"))
+                       return;
+
+               if (!message.startsWith("!")
+                       && !message.startsWith(".")
+                       && !message.startsWith(config.general.nick + ": ")
+                       && !message.startsWith(config.general.nick + " "))
                        return;
 
-               String tokens[] = message[1].split(" ");
-               Command c = find(tokens[0]);
+               final String[] tokens = message.split(" ");
+               final String cmd = message.startsWith(config.general.nick) ? "!" + tokens[1] : tokens[0];
+
+               Command c = find(cmd);
                if (c == null)
                        return;
 
-               if (!c.isRequiredChannel(message[0]))
+               if (!c.isRequiredChannel(target))
                        return;
 
                User user = irc.findUser(m.getNick());
                if (user == null)
                        user = new User(m.getNick());
 
-               CommandSource csource = new CommandSource(protocol, user, irc.findChannel(message[0]));
-
+               CommandSource csource = new CommandSource(protocol, user, irc.findChannel(target));
                c.execute(csource, tokens);
        }
 }