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;
{
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
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
{
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
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);
}
/**
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
+}