Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void doEventDaily(ZonedDateTime nowUTC) {
- ZonedDateTime midnightUTC = ZonedDateTime.now(ZoneOffset.UTC);
- midnightUTC = midnightUTC.withHour(0).withSecond(0).withMinute(0).withNano(0).plusDays(1);
- long initialDelay = midnightUTC.toEpochSecond() - nowUTC.toEpochSecond() + 4;
- logger.trace("Now UTC = " + Utility.formatTimeSeconds(nowUTC.toEpochSecond()));
- logger.trace("Midnight UTC = " + Utility.formatTimeSeconds(midnightUTC.toEpochSecond()));
- logger.trace("Delay = " + Utility.formatTimeSeconds(initialDelay));
- if (initialDelay < 120) {
- initialDelay += 24 * 60 * 60;
- }
- Timer timer = new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- //init vars
- ZonedDateTime timeNow = ZonedDateTime.now(ZoneOffset.UTC);
- DayOfWeek day = timeNow.getDayOfWeek();
- Random random = new Random();
- //do checks
- Client.checkPatrons();
- checkKeepAlive();
- //update Active Event
- Globals.updateEvent();
- TimedEvent event = Globals.getCurrentEvent();
- //handle avatars
- Client.handleAvatars();
- //backups
- Globals.backupAll();
- logger.info("Running Daily tasks for " + day);
- for (GuildObject task : Globals.getGuilds()) {
- GuildConfig guildconfig = task.config;
- //do decay
- XpHandler.doDecay(task, nowUTC);
- //get general channel
- IChannel generalChannel = task.getChannelByType(Command.CHANNEL_GENERAL);
- //do daily messages
- if (generalChannel != null && guildconfig.dailyMessage) {
- DailyMessage finalMessage = Globals.getDailyMessage(day);
- List<DailyMessage> messages;
- if (event != null && event.doSpecialMessages() && event.getMessagesDay(day).size() != 0) {
- messages = event.getMessagesDay(day);
- } else {
- messages = new ArrayList<>(Globals.getDailyMessages().getMessages());
- messages.add(Globals.getDailyMessage(day));
- }
- int randomMessage = random.nextInt(messages.size());
- finalMessage = messages.get(randomMessage);
- task.config.setLastDailyMessage(finalMessage);
- CommandObject command = new CommandObject(task,generalChannel);
- Utility.sendMessage(finalMessage.getContents(command),generalChannel);
- }
- }
- }
- }, initialDelay * 1000, 24 * 60 * 60 * 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment