turt2live

Untitled

Feb 22nd, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. public static void main(String[] args) throws Exception{
  2.         Config.load();
  3.  
  4.         Runnable daysRunnable = new Runnable(){
  5.             @Override
  6.             public void run(){
  7.                 while (true){
  8.                     System.out.println("Running runnable");
  9.  
  10.                     long lastReset = 0;
  11.                     long now = System.currentTimeMillis();
  12.  
  13.                     try{
  14.                         FileInputStream fis = new FileInputStream("lastReset");
  15.                         InputStreamReader in = new InputStreamReader(fis, "UTF-8");
  16.  
  17.                         Scanner scan = new Scanner(in);
  18.                         lastReset = scan.nextLong();
  19.  
  20.                         in.close();
  21.                         fis.close();
  22.                     }catch(Exception e){
  23.                         lastReset = now;
  24.                         try{
  25.                             Main.writeReset(now);
  26.                         }catch(IOException e1){
  27.                             e1.printStackTrace();
  28.                         }
  29.                     }
  30.  
  31.                     long waitTime = Config.countInDays ? 86400000 : 1000;
  32.  
  33.                     if(lastReset + waitTime <= now){
  34.                         try{
  35.                             String topic = Bot.topic;
  36.  
  37.                             String trail = Config.countInDays ? "days" : "seconds";
  38.                             System.out.println("Topic: " + topic);
  39.  
  40.                             Matcher matcher = Pattern.compile("([0-9]+) " + trail).matcher(topic);
  41.  
  42.                             matcher.find();
  43.  
  44.                             long newDays = Integer.valueOf(matcher.group(1)) + 1;
  45.  
  46.                             topic = matcher.replaceAll(newDays + " " + trail);
  47.  
  48.                             bot.setTopic("#mcmmodev", topic);
  49.  
  50.                             Main.writeReset(now);
  51.                         }catch(Exception e){
  52.                             e.printStackTrace();
  53.                             System.out.println("Could not change topic");
  54.                         }
  55.                     }else{
  56.                         waitTime = lastReset + waitTime - now + 1;
  57.                     }
  58.  
  59.                     try{
  60.                         // Reduce spam, less than 10k we wait 1 second, else do math
  61.                         Thread.sleep(waitTime < 10000 ? 1000 : waitTime / 1000);
  62.                     }catch(InterruptedException e){
  63.                         e.printStackTrace();
  64.                     }
  65.                 }
  66.             }
  67.         };
  68.  
  69.         daysTask = new Thread(daysRunnable);
  70.  
  71.         bot = new Bot();
  72.         bot.setVerbose(true);
  73.         bot.connect(Config.host, Config.port, Config.password);
  74.         for(String channel : Config.channels){
  75.             bot.joinChannel(channel);
  76.         }
  77.  
  78.         BufferedReader br = new BufferedReader(new FileReader(new File("builds")));
  79.         String line;
  80.         while ((line = br.readLine()) != null){
  81.             if(line.contains(","))
  82.                 ;
  83.             try{
  84.                 Integer build = Integer.parseInt(line.substring(line.indexOf(",") + 1));
  85.                 String sha = line.substring(0, line.indexOf(","));
  86.                 System.out.println(build + " " + sha);
  87.                 builds.put(build, sha);
  88.             }catch(Exception e){}
  89.         }
  90.         br.close();
  91.     }
Advertisement
Add Comment
Please, Sign In to add comment