Browse Source

Multiple modifications

Martin Passard 6 years ago
parent
commit
c33c8dbc6b

+ 8 - 0
src/main/java/bot/irc/main/Config.java

@@ -11,6 +11,7 @@ public class Config {
 	  public final static String DEFAULT_PROPERTIES_FILE = "default.properties";
 	  public final static String PROPERTIES_FILE = "config.properties";
 	  public final static String here = (new File(".")).getAbsolutePath();
+	  private static boolean isDebug = false;
 	  
 	  static {
 	    try {
@@ -22,6 +23,7 @@ public class Config {
 	        props.load(in);
 	        in.close();
 	        System.out.println("Config ready");
+	        isDebug=Boolean.parseBoolean(Config.getProperty("Debug"));
 	        for(String s:defaultProp.stringPropertyNames()) System.out.println(s+"="+getProperty(s));
 	       
 	    } catch (Exception e) {
@@ -29,6 +31,10 @@ public class Config {
 	    }
 	  }
 	  
+	  public static boolean isDebug() {
+		  return isDebug;
+	  }
+	  
 	  public static String getProperty(String key) {
 		  return props.getProperty(key);
 	  }
@@ -87,4 +93,6 @@ public class Config {
 		}
 		
 		
+		
+		
 }

+ 7 - 5
src/main/java/bot/irc/main/Main.java

@@ -35,11 +35,10 @@ public class Main {
 
 			CONFIG = new Config();
 			CR = new CacheReloader(Config.getPropertyAsUnsignedInt("CacheReloader_timeout")); // Met à jour la base toute les heures.
-			// Get All the infomations and store in a cache
+
 			Cache c = Cache.getInstance();
 			
-			
-			// Now start our bot up.
+			// Now start our bots up.
 			IRCBOT = new IRCBot();
 			BOTS.add(IRCBOT);
 			
@@ -61,7 +60,7 @@ public class Main {
 
 			
 
-			// Join the #pircbot channel.
+			// Join the channels.
 			for(int i = 0; i< CHANNELS.length; i++) {
 				IRCBOT.joinChannel(CHANNELS[i]);
 			}
@@ -71,13 +70,16 @@ public class Main {
 			System.out.println("Debug? "+DEBUG);
 			
 			rcheck.start();
+			RSS_DATA_REMAINDER.addObserver(IRCBOT);
+			RSS_DATA_REMAINDER.addObserver(TWITTER);
+			RSS_DATA_REMAINDER.addObserver(MASTODON);
 			
 			
 		}catch(ConnectException ce) {
 			failures++;
 			System.err.println("Erreur numéro "+failures);
 			System.err.println("La connection a l'adresse "+SERVER+":"+PORT+" a échoué. Le Bot retentera de se connecter dans "+TIMEOUT_BEFORE_RECONNECTING+" secondes");
-			Thread.sleep(TIMEOUT_BEFORE_RECONNECTING*1000);
+			Thread.sleep(TIMEOUT_BEFORE_RECONNECTING*(1000*failures));
 			main(args);
 		}
 	}

+ 3 - 1
src/main/java/bot/irc/socials/MastodonBot.java

@@ -156,7 +156,9 @@ public class MastodonBot implements Bot, Runnable,Observer {
 		int len = json.length();
 		for(int i=0;i<len;++i) {
 			JSONObject jo = json.getJSONObject(i);
-			System.out.println("traitement de "+jo.toString());
+			if(Config.isDebug()) {
+				System.out.println("traitement de "+jo.toString());
+			}
 			lastDmId = jo.getString("id");
 		}
 	}