Martin Passard il y a 7 ans
Parent
commit
6a715ed4a2

+ 35 - 6
src/IRC/Server.java

@@ -1,10 +1,17 @@
 package IRC;
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
 import main.AffichableSurIRC;
 
+/**
+ * Cette classe à pour but de stocker les serveurs/channels pour les FAI
+ * @author Marmat
+ *
+ */
+
 public class Server implements AffichableSurIRC{
 	private String address;
 	private int port;
@@ -36,6 +43,12 @@ public class Server implements AffichableSurIRC{
 		
 		
 	}
+	
+	/**
+	 * Extrait le port d'une URI. par exemple irc://geeknode.net:6789#marmat renveira 6789
+	 * @param s URI sur laquelle extraire le numéro de port
+	 * @return Le numéro de port
+	 */
 	private int getSrvPort(String s) {
 		int res;
 		if(s.contains(":")) {
@@ -53,6 +66,11 @@ public class Server implements AffichableSurIRC{
 		return res;
 	}
 
+	/**
+	 * Extrait l'addresse d'une URI. par exemple irc://geeknode.net:789#marmat renveira geeknode.net
+	 * @param s URI 
+	 * @return L'addresse 
+	 */
 	private String getSrvAddr(String s) {
 		String res="";
 		String serv=s.substring(7); // on enleve irc://
@@ -64,6 +82,11 @@ public class Server implements AffichableSurIRC{
 		return res;
 	}
 	
+	/**
+	 * Extrait le chan d'une URI. par exemple irc://geeknode.net:789#marmat renveira #marmat
+	 * @param s URI 
+	 * @return L'addresse 
+	 */
 	private String getSrvChan(String s) {
 		int idxcar = s.indexOf('#');
 		return s.substring(idxcar+1);
@@ -98,15 +121,21 @@ public class Server implements AffichableSurIRC{
 		return this.t.equals(Type.IRC);
 	}
 
-	@Override
-	public List<String> toStringIRC() {
-		List<String> s = new LinkedList<>();
+	public List<String> toStringIRC(){
+		List<String> res = new ArrayList<>();
+		res.add(toString());
+		return res;
+	}
+
+	
+	public String toString() {
+		
 		if(isIRC()) {
-			s.add("IRC://"+address+" chan:"+chan+" port:"+port);
+			return "IRC://"+address+" chan:"+chan+" port:"+port;
 		}else {
-			s.add(address);
+			return address;
 		}
-		return s;
+		
 	}
 	
 	

+ 19 - 2
src/data/CoveredAreas.java

@@ -7,19 +7,28 @@ public class CoveredAreas {
 
 	private final List<TechnoCoverage> technos;
 	private final String name;
+	private ISP isp;
 	
-	public CoveredAreas(String name, List<TechnoCoverage> techno) {
+	public CoveredAreas(String name, ISP isp, List<TechnoCoverage> techno) {
 		technos=techno;
 		this.name=name;
+		this.isp = isp;
 		
 	}
-	public CoveredAreas(String name, TechnoCoverage...techno) {
+	
+	public CoveredAreas(String name, List<TechnoCoverage> techno) {
+		this(name,null,techno);
+	}
+	
+	public CoveredAreas(String name, ISP isp, TechnoCoverage...techno) {
 		ArrayList<TechnoCoverage> l = new ArrayList<>();
 		for(int i=0;i<techno.length;++i) {
 			l.add(techno[i]);
 		}
 		this.technos=l;
 		this.name=name;
+		this.isp=isp;
+		
 		
 	}
 	
@@ -38,9 +47,17 @@ public class CoveredAreas {
 		for (TechnoCoverage tc: technos) {
 			res+=tc+" ";
 		}
+		res+="par "+isp.getBetterName();
 		
 		return res;
 	}
+	public ISP getIsp() {
+		return isp;
+	}
+	public void setIsp(ISP isp) {
+		this.isp = isp;
+	}
+	
 	
 	
 

+ 87 - 19
src/data/ISP.java

@@ -1,13 +1,16 @@
 package data;
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
+import IRC.Server;
 import main.AffichableSurIRC;
 import main.Cache;
+import main.Main;
 
 public class ISP implements AffichableSurIRC {
-	
+
 	private String name;
 	private int id;
 	private boolean isFFDNMember;
@@ -15,9 +18,18 @@ public class ISP implements AffichableSurIRC {
 	private String last_update;
 	private ISPdata data;
 	private CoveredAreas [] coveredAreas;
-	
-	
-	
+
+	/**
+	 *  Constructeur principal de la classe.
+	 * @param name
+	 * @param id
+	 * @param isFFDNMember
+	 * @param date_added
+	 * @param last_update
+	 * @param data
+	 * @param ca
+	 */
+
 	public ISP(String name, int id, boolean isFFDNMember, String date_added, String last_update, ISPdata data, CoveredAreas [] ca) {
 		super();
 		this.name = name;
@@ -27,8 +39,15 @@ public class ISP implements AffichableSurIRC {
 		this.last_update = last_update;
 		this.data = data;
 		this.coveredAreas = ca;
+		for(int i=0; i<coveredAreas.length;++i) {
+			coveredAreas[i].setIsp(this);
+		}
 	}
-	
+
+	/**
+	 * Méthode pour récuperer le plus court des noms du FAI, c'est à dire, si il existe shortname, sinon name
+	 * @return 
+	 */
 	public String getShortestName() {
 		if(data.hasShortName()) {
 			return data.getShortname();
@@ -36,7 +55,7 @@ public class ISP implements AffichableSurIRC {
 			return name;
 		}
 	}
-	
+
 	/**
 	 * Méthode pour récuperer le nom le plus correct pour afficher les informations.
 	 * Si il n'y a pas de Shortname alors name sera utilisé.
@@ -56,7 +75,7 @@ public class ISP implements AffichableSurIRC {
 		}else {
 			return name;
 		}
-		
+
 	}
 	/**
 	 * Inverse de getBetterName. Le but est dans le cadre de l'affichage de plusieurs noms
@@ -70,12 +89,12 @@ public class ISP implements AffichableSurIRC {
 			}else {
 				return shortname;
 			}
-			
+
 		}else {
 			return name;
 		}
 	}
-	
+
 	public void setName(String name) {
 		this.name = name;
 	}
@@ -105,7 +124,7 @@ public class ISP implements AffichableSurIRC {
 		this.isFFDNMember = isFFDNMember;
 	}
 
-	
+
 	public String getDate_added() {
 		return date_added;
 	}
@@ -133,7 +152,7 @@ public class ISP implements AffichableSurIRC {
 	public int getSubscribersCount() {
 		return data.getSubscribersCount();
 	}
-	
+
 	public String toString() {
 		String res="";
 		res+=name+" : ";
@@ -141,20 +160,20 @@ public class ISP implements AffichableSurIRC {
 		res+="Nombre de membres: "+getMembersCount()+" Nombre d'abonnements:"+getSubscribersCount(); 
 		return res;
 	}
-	
+
 	private String booleanToOuiNon(boolean b) {
 		if(b) {
 			return "oui";
 		}
 		return "non";
-		
+
 	}
-	
+
 	/**
 	 * Renvoie une Liste de chaine de caractères pour permettre l'affichage sur IRC ligne par ligne, bien que le \n ne soit pas interprété.
 	 * @return Une Liste de chaine correspondant à toutes les lignes que le bot doit écrire
 	 */
-	
+
 	public List<String> toStringIRC () {
 		Cache c = Cache.getInstance();
 		List<String> res = new LinkedList<>();
@@ -167,11 +186,11 @@ public class ISP implements AffichableSurIRC {
 			res.add(preface+"Nombre de Membres : "+getMembersCount());
 			res.add(preface+"Nombre d'abonnements : "+getSubscribersCount());
 		}
-		
-		
+
+
 		return res;
 	}
-	
+
 	private String getShortName() {
 		return data.getShortname();
 	}
@@ -180,5 +199,54 @@ public class ISP implements AffichableSurIRC {
 		return coveredAreas;
 	}
 
-	
+	/**
+	 * Récupere la zone couverte correspondante au paramètre
+	 * @param name Nom de la zone
+	 * @return	la première Zone correspondante au nom.
+	 */
+	public CoveredAreas getCoveredArea(String name) {
+		for(CoveredAreas ca : coveredAreas) {
+			if(ca.getName().equalsIgnoreCase(name)) {
+				return ca;
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Récupere la zone couverte correspondante au paramètre
+	 * @param name Nom de la zone
+	 * @return	toutes les Zones correspondante au nom.
+	 */
+	public List<CoveredAreas> getCoveredAreas(String name){
+		List<CoveredAreas> lca = new ArrayList<>(4);
+		for(CoveredAreas ca : coveredAreas) {
+			if(ca.getName().equalsIgnoreCase(name)) {
+				lca.add(ca);
+			}
+		}
+		return lca;
+
+	}
+
+	public List<String> contact() {
+		List<String> s = new ArrayList<>();
+		s.add( "["+this.getBetterName()+"] est joignable par:");
+		s.add("Site web: "+getData().getWebsite());
+		s.add("Mail: "+getData().emailSyntaxer());
+		String chats="Chat : ";
+		Server[] chans = getData().getIrcChan();
+		if(chans != null) {
+			for(int i=0; i<chans.length; i++) {
+				chats+=chans[i].toString()+" ";
+			}
+			s.add(chats);
+		} else {
+			if(Main.isDebug()) {
+			s.add("Chans a Null");
+			}
+		}
+		return s;
+	}
+
 }

+ 36 - 6
src/data/ISPDAO.java

@@ -26,17 +26,20 @@ import main.Main;
 public class ISPDAO {
 
 	/**
-	 * This class implements the Sigleton Design Patern and is the DataAcess Object. It's role is to get informations from <a href="db.ffdn.org"> db.ffdn.org </a> and transform the into data Objects.
+	 * Cette classe implémente le design patern singleton. Son role est de récuperer les données de <a href="db.ffdn.org"> db.ffdn.org </a> et de les transformer en objets utilisables ensuite.
 	 */
 
 	public static volatile ISPDAO instance = null;
 	private final String dbAdress = "https://db.ffdn.org/api/v1/isp/";
 
-
+	// Ceci permet de rendre impossible l'instanciation de la classe, conformement au design patern singleton.
 	private ISPDAO() {
 
 	}
-
+	/**
+	 * Cette méthode est celle permettant de récuperer l'instance de la classe. Si cette dernière n'est pas initialisée, elle l'initialise avant.
+	 * @return L'instance de la classe a utiliser ensuite
+	 */
 	public final static ISPDAO getInstance() {
 		if (ISPDAO.instance == null) {
 			synchronized (ISPDAO.class) {
@@ -48,10 +51,22 @@ public class ISPDAO {
 		return ISPDAO.instance;
 	}
 
+	/**
+	 * Version simplifiée : Execute une requette de type GET en HTTPS simplement avec l'addresse et avec les paramètres par défault pour du https
+	 * @param https_url URL a récuperer en HTTPS
+	 * @return La chaine de caractères correspondant à la page demandée par l'URL.
+	 */
 	private String executeGet(String https_url) {
 		return executeGet(https_url, "", 443);
 	}
 	
+	/**
+	 * Implementation reele de la requete HTTPS.
+	 * @param https_url URL sur laquelle récuperer la ressource
+	 * @param proxyName Le nom du proxy, si besoin
+	 * @param port le port sur lequel faire la demande
+	 * @return La chaine de caractères correspondant à la page demandée par l'URL.
+	 */
 	@SuppressWarnings("resource")
 	private String executeGet(final String https_url, final String proxyName, final int port) {
 	    String ret = "";
@@ -98,8 +113,8 @@ public class ISPDAO {
 
 
 	/**
-	 * 
-	 * @return List of ISPs constructed.
+	 * Récupere tous les FAI possibles. Dans le cas ou il y a des Fails consécutifs, c'est que peut-être DB.ffdn est deffectueux, car on a pas atteint le nombre de fai annoncés par total_items, mais on n'as que des réponses indiquant que la ressource est incorrecte.
+	 * @return la liste de tous les FAIs possibles.
 	 */
 	public List<ISP> getISPs() throws Exception{
 		
@@ -125,7 +140,12 @@ public class ISPDAO {
 		return ar;
 
 	}
-
+	
+	/**
+	 * Récupere le FAI qui a pour id dans db.ffdn.org le paramètre number
+	 * @param number numéro correspondna tà l'id a aller chercher dans db
+	 * @return le FAI construit correspondant, ou null si l'id n'est pas ou plus occupé par un FAI
+	 */
 
 	public ISP getISP(int number) {
 		String json = executeGet(dbAdress+number+'/');
@@ -220,10 +240,18 @@ public class ISPDAO {
 		return res;
 	}
 	
+	/**
+	 * Récupere les données
+	 * @param json objet récupéré depuis db.ffdn
+	 * @return Tableau des zones couvertes
+	 */
 	private CoveredAreas [] getCoveredAreas(JSONObject json) {
+		json = json.getJSONObject("ispformat");
 		CoveredAreas [] res=null;
 		try {
+			
 			JSONArray ja = json.getJSONArray("coveredAreas");
+		
 			res = new CoveredAreas [ja.length()];
 			for(int i=0;i<ja.length();i++) {
 				JSONObject jo = ja.getJSONObject(i);
@@ -239,6 +267,8 @@ public class ISPDAO {
 			}
 			return res;
 		}catch(JSONException jo) {
+			System.err.println("erreur GetCoveredAreas pour "+getName(json));
+			jo.printStackTrace(System.err);
 			return null;
 		}
 		

+ 29 - 1
src/data/ISPdata.java

@@ -5,6 +5,7 @@ import org.json.JSONException;
 import org.json.JSONObject;
 
 import IRC.Server;
+import main.Main;
 
 public class ISPdata {
 
@@ -52,8 +53,13 @@ public class ISPdata {
 
 			}
 		}catch(JSONException jsonE) {	// Si il n'y a pas de chatroom
+			if(Main.isDebug()) {
+				System.err.println("Warning : Pas de chatroom pour "+this.shortname);
+				jsonE.printStackTrace(System.err);
+			}
 			chatrooms = new Server[0];
 		}
+		this.ircChan = chatrooms;
 		this.progressStatus = getInt(jo,"progressStatus");
 		this.membersCount = getInt(jo,"memberCount",0);
 		this.subscribersCount = getInt(jo,"subscriberCount",0);
@@ -63,6 +69,7 @@ public class ISPdata {
 			this.joinDate = "?";
 		}
 		this.creationDate = getString(jo,"creationDate","?");
+		this.email = getString(jo,"email","?");
 
 	}
 	
@@ -148,5 +155,26 @@ public class ISPdata {
 		return shortname;
 	}
 	
-	
+	/**
+	 * Transforme l'addresse mail. Si l'adresse est a null, alors renvoie la chaine vide a la place.
+	 * @return L'adresse Email modifiée pour ne pas être en clair.
+	 */
+	public String emailSyntaxer() {
+		String email = this.getEmail();
+		String res="";
+		if(email==null) {
+			return res;
+		}
+		for(int i=0; i<email.length(); ++i) {
+			if(email.charAt(i) == '@' ) {
+				res +=" <at> ";
+			}else if( email.charAt(i) == '.' ) {
+				res +=" <dot> ";
+			}else {
+				res +=email.charAt(i);
+			}
+		}
+		return res;
+		
+	}
 }

+ 4 - 0
src/data/TechnoCoverage.java

@@ -1,6 +1,10 @@
 package data;
 
 public enum TechnoCoverage {
+	/**
+	 * Cette enum permet de de transformer toutes les techno annoncée dans les zones couvertes en une valeur.
+	 */
+	
 	VPN,FTTH,ADSL,VDSL,xDSL,WIFI,PIGEON,CABLE,AUTRE;
 	
 	public String toString() {

+ 45 - 4
src/main/Bot.java

@@ -6,6 +6,7 @@ import java.util.List;
 
 import org.jibble.pircbot.PircBot;
 
+import data.CoveredAreas;
 import data.ISP;
 import data.ISPDAO;
 import verif_saisie.EntierPositifNonVide;
@@ -19,6 +20,11 @@ public class Bot extends PircBot {
 	public Bot() {
 		this.setName("UneFede2");
 		this.setMessageDelay(TIME_BETWEEN_MESSAGES);
+		if(Main.isDebug()) {
+			this.setVerbose(true);
+		}else {
+			this.setVerbose(false);
+		}
 		idao = ISPDAO.getInstance();
 	}
 
@@ -29,16 +35,21 @@ public class Bot extends PircBot {
 			sendMessage(channel, sender + ": Nous sommes le " + time);
 		}
 
-		if (message.substring(0, 5).equalsIgnoreCase("+info")) {
+		if (message.length()>6 && message.substring(0, 5).equalsIgnoreCase("+info")) {
 			info(channel,sender,login,hostname,message);
 		}
+		
+		if (message.length()>9 && message.substring(0, 8).equalsIgnoreCase("+contact")) {
+			contact(channel,sender,login,hostname,message);
+		}
+		
 
 		if (message.equalsIgnoreCase("+source") || message.equalsIgnoreCase("+code") || message.equalsIgnoreCase("+sources")) {
 			sendMessage(channel, sender+": mes sources sont disponibles ici: https://code.ffdn.org/marmat8951/bot-irc2");
 		}
 
 
-		if (message.substring(0, 6).equals("+liste")) {
+		if (message.length()>= 6 && message.substring(0, 6).equals("+liste")) {
 			list(channel, sender, login, hostname, message);
 		}
 
@@ -137,8 +148,25 @@ public class Bot extends PircBot {
 	}
 
 
+	public void contact(String channel, String sender,
+			String login, String hostname, String message) {
+		
+		String s = message.substring(message.indexOf(' ')+1);
+		if(!EntierPositifNonVide.verifie(s)) {					// +contact suivi d'un mot
+			Cache c = Cache.getInstance();
+			ISP fai = c.getISPWithName(s);
+			if(fai == null) {
+				sendMessage(channel, "Aucun FAI "+s);
+			}else {
+				sendMessage(channel, fai.contact());
+			}
+		}
+		
+		
+	}
 
-
+	
+	
 	public void info(String channel, String sender,
 			String login, String hostname, String message) {
 
@@ -177,7 +205,20 @@ public class Bot extends PircBot {
 				Cache c = Cache.getInstance();
 				ISP i = c.getISPWithName(s);
 				if(i == null) {
-					sendMessage(channel, "Le FAI "+s+" est Inconnu, désolé");
+					sendMessage(channel, "Recherche d'une zone "+s);
+					ISP j = c.getISPWithGeoZone(s);
+					if(j == null)
+					sendMessage(channel, "Le FAI "+s+" est Inconnu, désolé. Et aucun FAI n'opère sur une sone dénomée "+s+" ...");
+					else {
+						sendMessage(channel, "Un FAI opère sur la zone "+s+" : ");
+						sendMessage(channel, j.toStringIRC());
+						List<CoveredAreas> cas = j.getCoveredAreas(s);
+						String technos = "";
+						for(CoveredAreas ca: cas) {
+							technos+=ca.getTechnos()+" ";
+						}
+						sendMessage(channel, "Avec pour techno "+technos);
+					}
 				}else {
 					sendMessage(channel, i.toStringIRC());
 				}

+ 43 - 30
src/main/Cache.java

@@ -5,6 +5,7 @@ import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 
+import data.CoveredAreas;
 import data.ISP;
 import data.ISPDAO;
 
@@ -13,11 +14,11 @@ public class Cache implements AffichableSurIRC {
 	 * Cette classe sert de cache pour les infos de DB
 	 * Elle implemente le Design Pattern Singleton dans la mesure où cette classe doit être l'unique instance de référence peu importe le Thread l'utilisant, et que le cache est unique.
 	 */
-	
+
 	public static volatile Cache instance = null;
 	private Date lastCacheUpdate;
 	private List<ISP> cache;
-	
+
 	private Cache() {
 		ISPDAO idao = ISPDAO.getInstance();
 		try {
@@ -28,8 +29,8 @@ public class Cache implements AffichableSurIRC {
 			e.printStackTrace();
 		}
 	}
-	
-	
+
+
 	public  Date getLastCacheUpdate() {
 		return lastCacheUpdate;
 	}
@@ -44,14 +45,14 @@ public class Cache implements AffichableSurIRC {
 			synchronized (ISPDAO.class) {
 				if(Cache.instance == null) {
 					Cache.instance = new Cache();
-					
-					
+
+
 				}
 			}
 		}
 		return Cache.instance;
 	}
-	
+
 	/**
 	 * Cette methode vient mettre à jour le cache des FAI. Pour cela, il récupere l'instance du DAO et récupère la liste des ISP. Si tout cse passe correctement, il supprime le cache précédent et le remplace par les nouvelles valeurs. Sinon, il maaintient le cache précédent.
 	 * @return True si l'operation s'est passée correctement, False sinon et affiche la cause
@@ -71,7 +72,7 @@ public class Cache implements AffichableSurIRC {
 		lastCacheUpdate = new Date();
 		return true;
 	}
-	
+
 	public int size() {
 		return cache.size();
 	}
@@ -79,7 +80,7 @@ public class Cache implements AffichableSurIRC {
 	public List<ISP> getListe(){
 		return cache;
 	}
-	
+
 	public int getMemberCountInFede() {
 		int i = 0;
 		for(ISP isp : getListe()) {
@@ -89,7 +90,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		return i;
 	}
-	
+
 	public int getSubscribersCountInFede() {
 		int i = 0;
 		for(ISP isp : getListe()) {
@@ -99,7 +100,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		return i;
 	}
-	
+
 	public int getMemberCountOutFede() {
 		int i = 0;
 		for(ISP isp : getListe()) {
@@ -109,7 +110,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		return i;
 	}
-	
+
 	public int getSubscribersCountOutFede() {
 		int i = 0;
 		for(ISP isp : getListe()) {
@@ -119,7 +120,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		return i;
 	}
-	
+
 	public String getSubscribersPercents(int val) {
 		NumberFormat nf = NumberFormat.getInstance();
 		nf.setMaximumFractionDigits(2);
@@ -128,7 +129,7 @@ public class Cache implements AffichableSurIRC {
 		Double nbSubscribers = 0.0+getSubscribersCountInFede();
 		return nf.format((val2/nbSubscribers)*100)+" %";
 	}
-	
+
 	public String getMembersPercents(int val) {
 		NumberFormat nf = NumberFormat.getInstance();
 		nf.setMaximumFractionDigits(2);
@@ -137,9 +138,9 @@ public class Cache implements AffichableSurIRC {
 		Double nbMembers = 0.0+getMemberCountInFede();
 		return nf.format((val2/nbMembers)*100)+" %";
 	}
-	
-	
-	
+
+
+
 	/**
 	 * Donne le nombre de FAI de la fédé en parcourant le cache.
 	 * @param ffdn_member Si = null alors on s'en fout, si =true, seuls les FAI de la fédé, si = false, seuls les FAI non membres
@@ -156,24 +157,24 @@ public class Cache implements AffichableSurIRC {
 				}
 			}
 			return count;
-			
+
 		}
-			
+
 	}
-	
+
 	public ISP getISPWithName(String s) {
 		for(ISP i : cache) {
-			if(i.getShortestName().equalsIgnoreCase(s) || i.getName().equalsIgnoreCase(s)) {
+			if(i.getShortestName().toLowerCase().contains(s.toLowerCase()) || i.getName().toLowerCase().contains(s.toLowerCase())) {
 				return i;
 			}
 		}
 		return null;
 	}
-	
+
 	public String toString() {
 		return "Cache de "+cache.size()+" FAI";
 	}
-	
+
 	public List<String> toStringIRC() {
 		List<String> liste = new LinkedList<String>();
 		liste.add("Il y a "+cache.size()+" FAI dont "+getISPCount(Boolean.TRUE)+" dans la fédé");
@@ -181,16 +182,28 @@ public class Cache implements AffichableSurIRC {
 		liste.add("Et hors fédé : "+getSubscribersCountOutFede()+" Abonné.e.s et "+getMemberCountOutFede()+" Membres");
 		return liste;
 	}
-	
-	
+
+
 	public ISP getISPWithGeoZone(String s) {
+
 		for(ISP i: cache) {
-			
+			if(Main.isDebug()) {
+				System.out.println("Recherche sur "+i.getBetterName());
+			}
+			if(i.getCoveredAreas()!= null) for(CoveredAreas ca : i.getCoveredAreas()) {
+				if(Main.isDebug()) {
+					ca.getName();
+				}
+				if(s.equalsIgnoreCase(ca.getName())) {
+					return i;
+				}
+			}
+
 		}
-		
+
 		return null;
-		
+
 	}
-	
-	
+
+
 }

+ 31 - 35
src/main/Main.java

@@ -3,59 +3,55 @@ package main;
 import java.net.ConnectException;
 
 public class Main {
-	
+
 	public static final String SERVER = "irc.geeknode.net";
 	public static final int PORT = 6667;
 	public static final String[] CHANNELS = { "#marmat" };
 	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final Cache cache = Cache.getInstance();
 	public static int failures = 0;
-	private static boolean DEBUG;
-	
+	private static boolean DEBUG=true;
+
 	public static void main(String[] args) throws Exception {
-		
-		for(int i=0;i<args.length;i++) {
-			if(args[i].equals("-debug")) {
-				DEBUG = true;
-			}
-			DEBUG = false;
-		}
-		
+
 		try {
-        // Now start our bot up.
-        Bot bot = new Bot();
-        
-        if(isDebug()) {
-        // Enable debugging output.
-        	bot.setVerbose(true);
-        }else {
-        	bot.setVerbose(false);
-        }
-        
-        // Connect to the IRC server.
-        bot.connect(SERVER,PORT);
-        
-        // Get All the infomations and store in a cache
-        Cache c = Cache.getInstance();
-        
-        // Join the #pircbot channel.
-        for(int i = 0; i< CHANNELS.length; i++) {
-        bot.joinChannel(CHANNELS[i]);
-        }
-        CacheReloader cacheReloader = new CacheReloader(3600); // Met à jour la base toute les heures.
-        cacheReloader.start();
+			setDebug(args[0].equals("-debug"));
+
+			// Now start our bot up.
+			Bot bot = new Bot();
+
+			// Connect to the IRC server.
+			bot.connect(SERVER,PORT);
+
+			// Get All the infomations and store in a cache
+			Cache c = Cache.getInstance();
+
+			// Join the #pircbot channel.
+			for(int i = 0; i< CHANNELS.length; i++) {
+				bot.joinChannel(CHANNELS[i]);
+			}
+			CacheReloader cacheReloader = new CacheReloader(3600); // Met à jour la base toute les heures.
+			cacheReloader.start();
+			
+			System.out.println("Debug? "+DEBUG);
+			
+
 		}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);
 			main(args);
 		}
 	}
 
-	
+
 	public static boolean isDebug () {
 		return Main.DEBUG;
 	}
+
+	private static void setDebug(boolean b) {
+		System.out.println("Mise de debug à "+b);
+		DEBUG=b;
+	}
 }