]> jfr.im git - irc/rizon/acid.git/commitdiff
Add the ability to get the users of a chanmode event
authorDwarf <redacted>
Tue, 14 Nov 2017 15:32:17 +0000 (16:32 +0100)
committerOrillion <redacted>
Sun, 26 Nov 2017 21:15:43 +0000 (22:15 +0100)
.gitignore
acid/src/main/java/net/rizon/acid/core/Acidictive.java
acid/src/main/java/net/rizon/acid/core/ChannelModeChange.java [new file with mode: 0644]
acid/src/main/java/net/rizon/acid/core/ChannelStatus.java [new file with mode: 0644]
acid/src/main/java/net/rizon/acid/events/EventChanMode.java
xmas/src/main/java/net/rizon/acid/plugins/xmas/Xmas.java

index 06655be38fbe86a64d026ad6ce4e5ff8fa6b11f0..a91303a280be48da6c85e78e76dd6eda8b0bbe57 100644 (file)
@@ -21,6 +21,9 @@ known_hosts
 .idea
 *.bak
 
+# GeoIP db
+*.mmdb
+
 # Netbeans stuff
 nb-configuration.xml
 nbactions.xml
index 1342c7c594a6f0f2acca42e9b0a45547c7ef3644..b504dff17a9ccb3cfe1d34f55cf646fb06f6c98c 100644 (file)
@@ -10,6 +10,7 @@ import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.ArrayList;
 import java.util.concurrent.TimeUnit;
 import net.rizon.acid.capab.QuitStorm;
 import net.rizon.acid.conf.Client;
@@ -567,6 +568,7 @@ public class Acidictive extends AcidCore
        public static void onChanMode(String creator, Channel chan, String modes)
        {
                String[] x = modes.split("\\s+");
+               List<ChannelModeChange> modeChanges = new ArrayList<>();
                if (x.length >= 1)
                {
                        boolean give = true;
@@ -622,6 +624,8 @@ public class Acidictive extends AcidCore
                                        if (target == null)
                                                continue;
 
+                                       modeChanges.add(new ChannelModeChange(target, ChannelStatus.fromString(m), give));
+
                                        Membership mem = chan.findUser(target);
                                        if (mem == null)
                                                continue;
@@ -645,6 +649,7 @@ public class Acidictive extends AcidCore
                event.setChan(chan);
                event.setModes(modes);
                event.setPrefix(creator);
+               event.setUserModes(modeChanges);
                eventBus.post(event);
        }
 
diff --git a/acid/src/main/java/net/rizon/acid/core/ChannelModeChange.java b/acid/src/main/java/net/rizon/acid/core/ChannelModeChange.java
new file mode 100644 (file)
index 0000000..8317171
--- /dev/null
@@ -0,0 +1,30 @@
+package net.rizon.acid.core;
+
+public class ChannelModeChange
+{
+       private User user;
+       private ChannelStatus mode;
+       private boolean given;
+
+       public ChannelModeChange(User user, ChannelStatus mode, boolean given)
+       {
+               this.user = user;
+               this.mode = mode;
+               this.given = given;
+       }
+
+       public User getUser()
+       {
+               return user;
+       }
+
+       public ChannelStatus getMode()
+       {
+               return mode;
+       }
+
+       public boolean isGiven()
+       {
+               return given;
+       }
+}
diff --git a/acid/src/main/java/net/rizon/acid/core/ChannelStatus.java b/acid/src/main/java/net/rizon/acid/core/ChannelStatus.java
new file mode 100644 (file)
index 0000000..0efc15b
--- /dev/null
@@ -0,0 +1,36 @@
+package net.rizon.acid.core;
+
+public enum ChannelStatus
+{
+       VOICE("v"),
+       HALFOP("h"),
+       OP("o"),
+       ADMIN("a"),
+       OWNER("q");
+
+       private final String modeChar;
+
+       ChannelStatus(String modeChar)
+       {
+               this.modeChar = modeChar;
+       }
+
+       @Override
+       public String toString()
+       {
+               return this.modeChar;
+       }
+
+       public static ChannelStatus fromString(String c)
+       {
+               for (ChannelStatus m : ChannelStatus.values())
+               {
+                       if (m.modeChar.equals(c))
+                       {
+                               return m;
+                       }
+               }
+
+               throw new IllegalArgumentException("No constant with text " + c + " found");
+       }
+}
index 3ec22e8658a086b5e247eae9f9de06e4f6ce8388..6d7f62188cb1734ea2276512c1b36cd1468c19dc 100644 (file)
@@ -1,6 +1,8 @@
 package net.rizon.acid.events;
 
+import java.util.List;
 import net.rizon.acid.core.Channel;
+import net.rizon.acid.core.ChannelModeChange;
 
 public class EventChanMode
 {
@@ -8,6 +10,19 @@ public class EventChanMode
        private Channel chan;
        private String modes;
 
+       public void setUserModes(List<ChannelModeChange> userModes)
+       {
+               this.userModes = userModes;
+       }
+
+       public List<ChannelModeChange> getUserModes()
+       {
+
+               return userModes;
+       }
+
+       private List<ChannelModeChange> userModes;
+
        public String getPrefix()
        {
                return prefix;
index a76f3d7996930b570534c65c96f460bc228964c8..dd0f2a6a76459a2fe637155e655e8c0fb3c50798 100644 (file)
@@ -2,17 +2,12 @@ package net.rizon.acid.plugins.xmas;
 
 import com.google.common.eventbus.Subscribe;
 import io.netty.util.concurrent.ScheduledFuture;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.time.ZoneOffset;
+import java.time.*;
 import java.time.format.DateTimeFormatter;
+import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
-import net.rizon.acid.core.Acidictive;
-import net.rizon.acid.core.Channel;
-import net.rizon.acid.core.User;
+import net.rizon.acid.core.*;
 import net.rizon.acid.events.EventChanMode;
 import net.rizon.acid.events.EventJoin;
 import net.rizon.acid.plugins.Plugin;
@@ -31,18 +26,33 @@ public class Xmas extends Plugin
        {
                return Acidictive.conf.getChannelNamed(conf.xmaschan);
        }
-       
+
        private static ZoneId getTimezone()
        {
                return ZoneId.of(conf.timezone);
        }
 
+       /**
+        * Return today's vhost, or {@code null} if we're not being festive
+        *
+        * @return String
+        */
+       public static String todaysVhost()
+       {
+               final LocalDateTime now = LocalDateTime.now(Xmas.getTimezone());
+               final String today = now.format(DateTimeFormatter.ofPattern("dd-MM"));
+               Optional<VhostDay> has = conf.vhosts.stream().filter((v) -> v.getDate().equals(today)).findFirst();
+               if (!has.isPresent())
+                       return null;
+               return has.get().getVhost();
+       }
+
        @Override
        public void start() throws Exception
        {
-               Acidictive.eventBus.register(this);
-               
                reload();
+
+               Acidictive.eventBus.register(this);
        }
 
        @Override
@@ -60,8 +70,10 @@ public class Xmas extends Plugin
                final User[] users = event.getUsers();
 
                if (!channel.getName().equalsIgnoreCase(getXmasChanName()) || users.length > 1)
+               {
                        return;
-               (new Vhost(users[0], false)).run();
+               }
+               new Vhost(users[0], false).run();
        }
 
        @Subscribe
@@ -69,21 +81,21 @@ public class Xmas extends Plugin
        {
                final Channel channel = event.getChan();
                if (!channel.getName().equalsIgnoreCase(getXmasChanName()))
+               {
                        return;
+               }
 
-               // todo Implement mode parsing in EventChanMode
-               final String mode = event.getModes();
-               final String[] split = mode.split(" ");
-               if (split.length != 2 || !split[0].equals("+v"))
-                       return;
-
-               final User voicedUser = User.findUser(split[1]);
-
-               // You're not real.
-               if (voicedUser == null)
+               List<ChannelModeChange> m = event.getUserModes();
+               if (m.size() < 1)
                        return;
-
-               (new Vhost(voicedUser, true)).run();
+               for (ChannelModeChange mode : m)
+               {
+                       if (!mode.isGiven() || !mode.getMode().equals(ChannelStatus.VOICE))
+                       {
+                               continue;
+                       }
+                       new Vhost(mode.getUser(), true).run();
+               }
        }
 
        @Override
@@ -106,10 +118,10 @@ public class Xmas extends Plugin
                final LocalDateTime tomorrowMidnight = LocalDateTime.of(LocalDate.now(Xmas.getTimezone()), LocalTime.MIDNIGHT).plusDays(1);
                final long untilMidnight = tomorrowMidnight.toEpochSecond(ZoneOffset.UTC) - LocalDateTime.now(Xmas.getTimezone()).toEpochSecond(ZoneOffset.UTC);
                topicTimer = Acidictive.schedule(() ->
-               {
-                       this.updateTopic();
-                       topicTimer = Acidictive.scheduleAtFixedRate(this::updateTopic, 24, TimeUnit.HOURS);
-               }, untilMidnight, TimeUnit.SECONDS);
+                               {
+                                       this.updateTopic();
+                                       topicTimer = Acidictive.scheduleAtFixedRate(this::updateTopic, 24, TimeUnit.HOURS);
+                               }, untilMidnight, TimeUnit.SECONDS);
        }
 
        /**
@@ -134,19 +146,4 @@ public class Xmas extends Plugin
                        Acidictive.privmsg("ChanServ", String.format("TOPIC %s %s", Xmas.getXmasChanName(), String.format(conf.topic, vhost)));
                }
        }
-
-       /**
-        * Return today's vhost, or {@code null} if we're not being festive
-        *
-        * @return String
-        */
-       public static String todaysVhost()
-       {
-               final LocalDateTime now = LocalDateTime.now(Xmas.getTimezone());
-               final String today = now.format(DateTimeFormatter.ofPattern("dd-MM"));
-               Optional<VhostDay> has = conf.vhosts.stream().filter((v) -> v.getDate().equals(today)).findFirst();
-               if (has.isPresent() == false)
-                       return null;
-               return has.get().getVhost();
-       }
-}
\ No newline at end of file
+}