Advertisement
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() {
- Client.checkPatrons();
- checkKeepAlive();
- ZonedDateTime timeNow = ZonedDateTime.now(ZoneOffset.UTC);
- String dailyFileName = Globals.dailyAvatarName.replace("#day#", timeNow.getDayOfWeek().toString());
- DayOfWeek day = timeNow.getDayOfWeek();
- File avatarFile;
- Random random = new Random();
- logger.info("Running Daily tasks for " + day);
- //sets Avatar.
- if (Globals.doDailyAvatars) {
- avatarFile = new File(Constants.DIRECTORY_GLOBAL_IMAGES + dailyFileName);
- } else {
- avatarFile = new File(Constants.DIRECTORY_GLOBAL_IMAGES + Globals.defaultAvatarFile);
- }
- Image avatar = Image.forFile(avatarFile);
- Utility.updateAvatar(avatar);
- //wait for the avatar to update properly
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- Utility.sendStack(e);
- }
- //backups
- Utility.backupConfigFile(Constants.FILE_CONFIG, Constants.FILE_CONFIG_BACKUP);
- Utility.backupConfigFile(Constants.FILE_GLOBAL_DATA, Constants.FILE_GLOBAL_DATA_BACKUP);
- Globals.getDailyMessages().backUp();
- for (GuildObject task : Globals.getGuilds()) {
- for (GuildFile f : task.guildFiles) {
- f.backUp();
- }
- GuildConfig guildconfig = task.config;
- if (guildconfig.modulePixels && guildconfig.xpDecay) {
- XpHandler.doDecay(task, nowUTC);
- }
- //daily messages
- List<IChannel> channels = guildconfig.getChannelsByType(Command.CHANNEL_GENERAL, task);
- IChannel generalChannel = null;
- if (channels.size() != 0) {
- generalChannel = channels.get(0);
- }
- if (generalChannel != null) {
- if (guildconfig.dailyMessage) {
- for (DailyMessageObject d : Globals.configDailyMessages) {
- if (day.equals(d.getDayOfWeek())) {
- if (timeNow.getDayOfMonth() == 25 && timeNow.getMonth().equals(Month.DECEMBER)) {
- Utility.sendMessage("> ***MERRY CHRISTMAS***", generalChannel);
- } else if (timeNow.getDayOfMonth() == 1 && timeNow.getMonth().equals(Month.JANUARY)) {
- Utility.sendMessage("> ***HAPPY NEW YEAR***", generalChannel);
- } else if (timeNow.getDayOfMonth() == 13 && timeNow.getMonth().equals(Month.JULY)) {
- int age = nowUTC.getYear() - 1996;
- String modifier = "th";
- if ((age + "").endsWith("1")) {
- modifier = "st";
- } else if ((age + "").endsWith("2")) {
- modifier = "nd";
- } else if ((age + "").endsWith("3")) {
- modifier = "rd";
- }
- Utility.sendMessage("> Happy " + age + modifier + " Birthday Mum.", generalChannel);
- } else {
- ArrayList<DailyUserMessageObject> dailyMessages = Globals.getDailyMessages().getDailyMessages(day);
- dailyMessages.add(new DailyUserMessageObject(d.getContents(), d.getDayOfWeek(), task.client.longID, 10000));
- DailyUserMessageObject toSend = dailyMessages.get(random.nextInt(dailyMessages.size()));
- if (toSend.getUserID() == task.client.longID) {
- task.config.lastDailyMessageID = -1;
- } else {
- task.config.lastDailyMessageID = toSend.getUID();
- }
- String message = toSend.getContents(new CommandObject(task, generalChannel));
- if (message.matches("^(> |\\*> |\\*\\*> |\\*\\*\\*> |_> |__> |`> |```> ).*$") || message.startsWith("> ")) {
- Utility.sendMessage(message, generalChannel);
- } else {
- Utility.sendMessage("> " + message, generalChannel);
- }
- }
- }
- }
- }
- }
- }
- }
- }, initialDelay * 1000, 24 * 60 * 60 * 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement