Advertisement
Vaerys_Dawn

Evil code

Nov 10th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.03 KB | None | 0 0
  1. private static void doEventDaily(ZonedDateTime nowUTC) {
  2.         ZonedDateTime midnightUTC = ZonedDateTime.now(ZoneOffset.UTC);
  3.         midnightUTC = midnightUTC.withHour(0).withSecond(0).withMinute(0).withNano(0).plusDays(1);
  4.         long initialDelay = midnightUTC.toEpochSecond() - nowUTC.toEpochSecond() + 4;
  5.         logger.trace("Now UTC = " + Utility.formatTimeSeconds(nowUTC.toEpochSecond()));
  6.         logger.trace("Midnight UTC = " + Utility.formatTimeSeconds(midnightUTC.toEpochSecond()));
  7.         logger.trace("Delay = " + Utility.formatTimeSeconds(initialDelay));
  8.         if (initialDelay < 120) {
  9.             initialDelay += 24 * 60 * 60;
  10.         }
  11.         Timer timer = new Timer();
  12.         timer.scheduleAtFixedRate(new TimerTask() {
  13.             @Override
  14.             public void run() {
  15.                 Client.checkPatrons();
  16.                 checkKeepAlive();
  17.                 ZonedDateTime timeNow = ZonedDateTime.now(ZoneOffset.UTC);
  18.                 String dailyFileName = Globals.dailyAvatarName.replace("#day#", timeNow.getDayOfWeek().toString());
  19.                 DayOfWeek day = timeNow.getDayOfWeek();
  20.                 File avatarFile;
  21.                 Random random = new Random();
  22.  
  23.                 logger.info("Running Daily tasks for " + day);
  24.  
  25.                 //sets Avatar.
  26.                 if (Globals.doDailyAvatars) {
  27.                     avatarFile = new File(Constants.DIRECTORY_GLOBAL_IMAGES + dailyFileName);
  28.                 } else {
  29.                     avatarFile = new File(Constants.DIRECTORY_GLOBAL_IMAGES + Globals.defaultAvatarFile);
  30.                 }
  31.                 Image avatar = Image.forFile(avatarFile);
  32.                 Utility.updateAvatar(avatar);
  33.  
  34.                 //wait for the avatar to update properly
  35.                 try {
  36.                     Thread.sleep(3000);
  37.                 } catch (InterruptedException e) {
  38.                     Utility.sendStack(e);
  39.                 }
  40.                 //backups
  41.                 Utility.backupConfigFile(Constants.FILE_CONFIG, Constants.FILE_CONFIG_BACKUP);
  42.                 Utility.backupConfigFile(Constants.FILE_GLOBAL_DATA, Constants.FILE_GLOBAL_DATA_BACKUP);
  43.                 Globals.getDailyMessages().backUp();
  44.                 for (GuildObject task : Globals.getGuilds()) {
  45.                     for (GuildFile f : task.guildFiles) {
  46.                         f.backUp();
  47.                     }
  48.                     GuildConfig guildconfig = task.config;
  49.  
  50.                     if (guildconfig.modulePixels && guildconfig.xpDecay) {
  51.                         XpHandler.doDecay(task, nowUTC);
  52.                     }
  53.  
  54.                     //daily messages
  55.                     List<IChannel> channels = guildconfig.getChannelsByType(Command.CHANNEL_GENERAL, task);
  56.                     IChannel generalChannel = null;
  57.                     if (channels.size() != 0) {
  58.                         generalChannel = channels.get(0);
  59.                     }
  60.                     if (generalChannel != null) {
  61.                         if (guildconfig.dailyMessage) {
  62.                             for (DailyMessageObject d : Globals.configDailyMessages) {
  63.                                 if (day.equals(d.getDayOfWeek())) {
  64.                                     if (timeNow.getDayOfMonth() == 25 && timeNow.getMonth().equals(Month.DECEMBER)) {
  65.                                         Utility.sendMessage("> ***MERRY CHRISTMAS***", generalChannel);
  66.                                     } else if (timeNow.getDayOfMonth() == 1 && timeNow.getMonth().equals(Month.JANUARY)) {
  67.                                         Utility.sendMessage("> ***HAPPY NEW YEAR***", generalChannel);
  68.                                     } else if (timeNow.getDayOfMonth() == 13 && timeNow.getMonth().equals(Month.JULY)) {
  69.                                         int age = nowUTC.getYear() - 1996;
  70.                                         String modifier = "th";
  71.                                         if ((age + "").endsWith("1")) {
  72.                                             modifier = "st";
  73.                                         } else if ((age + "").endsWith("2")) {
  74.                                             modifier = "nd";
  75.                                         } else if ((age + "").endsWith("3")) {
  76.                                             modifier = "rd";
  77.                                         }
  78.                                         Utility.sendMessage("> Happy " + age + modifier + " Birthday Mum.", generalChannel);
  79.                                     } else {
  80.                                         ArrayList<DailyUserMessageObject> dailyMessages = Globals.getDailyMessages().getDailyMessages(day);
  81.                                         dailyMessages.add(new DailyUserMessageObject(d.getContents(), d.getDayOfWeek(), task.client.longID, 10000));
  82.                                         DailyUserMessageObject toSend = dailyMessages.get(random.nextInt(dailyMessages.size()));
  83.                                         if (toSend.getUserID() == task.client.longID) {
  84.                                             task.config.lastDailyMessageID = -1;
  85.                                         } else {
  86.                                             task.config.lastDailyMessageID = toSend.getUID();
  87.                                         }
  88.                                         String message = toSend.getContents(new CommandObject(task, generalChannel));
  89.                                         if (message.matches("^(> |\\*> |\\*\\*> |\\*\\*\\*> |_> |__> |`> |```> ).*$") || message.startsWith("> ")) {
  90.                                             Utility.sendMessage(message, generalChannel);
  91.                                         } else {
  92.                                             Utility.sendMessage("> " + message, generalChannel);
  93.                                         }
  94.                                     }
  95.                                 }
  96.                             }
  97.                         }
  98.                     }
  99.                 }
  100.             }
  101.         }, initialDelay * 1000, 24 * 60 * 60 * 1000);
  102.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement