Updated devinsy-strings library. Improved code.

This commit is contained in:
Christian P. MOMON 2017-12-26 00:39:52 +01:00
parent 7025e74490
commit 7e0c4ab4ed
7 changed files with 67 additions and 46 deletions

View File

@ -37,10 +37,9 @@
<classpathentry kind="lib" path="lib/commons-cli-1.4.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.4.jar"/>
<classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.5.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.4.jar"/>
<classpathentry kind="lib" path="lib/commons-io-2.5.jar" sourcepath="lib/commons-io-2.5-src.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.4.jar" sourcepath="lib/commons-lang3-3.4-src.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.4.1.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.5.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.1.jar"/>
<classpathentry kind="lib" path="lib/jaxb-api-2.2.12.jar"/>
@ -48,5 +47,6 @@
<classpathentry kind="lib" path="lib/pircbot-1.5.0.jar"/>
<classpathentry kind="lib" path="lib/quartz-2.2.1.jar"/>
<classpathentry kind="lib" path="lib/scribe-1.3.7.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.4.2.jar" sourcepath="lib/devinsy-strings-0.4.2-sources.zip"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

Binary file not shown.

Binary file not shown.

View File

@ -136,8 +136,9 @@ public class HebdobotCLI
File aliasFile = new File(configFile.getParentFile(), DEFAULT_ALIAS_FILE);
logger.info("Aliases file loading… ({}).", aliasFile.getAbsolutePath());
UserAliases aliases = new UserAliases(aliasFile);
logger.info("Aliases file loaded.");
logger.info("Aliases file loaded (" + aliases.size() + " aliases).");
System.exit(0);
if (config.isValid())
{
logger.info("Bot configuring…");

View File

@ -46,6 +46,8 @@ import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.strings.StringsUtils;
/**
* The Class Hebdobot.
*/
@ -153,24 +155,25 @@ public class Hebdobot extends PircBot
{
String text = message.trim();
if (StringUtils.equalsIgnoreCase(text, "!help"))
if ((StringUtils.equalsIgnoreCase(text, "!aide")) || (StringUtils.equalsIgnoreCase(text, "!help")))
{
logger.info("!help caught.");
// Help.
sendMessage(sender, "Bienvenue " + sender);
sendMessage(sender, "Je suis " + getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL");
sendMessage(sender, "Je suis " + getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL.");
sendMessage(sender, "Voici les commandes que je comprends :");
sendMessage(sender, " ");
sendMessage(sender, "— !debut : commencer une nouvelle revue");
sendMessage(sender, "— !fin : terminer la revue en cours");
sendMessage(sender, "— # titre : démarrer un sujet individuel");
sendMessage(sender, "— ## titre : démarrer un sujet collectif");
sendMessage(sender, "— !courant : affiche le sujet en cours");
sendMessage(sender, "— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet");
sendMessage(sender, "— % message : un commentaire");
sendMessage(sender, "— !stop : abandonner la revue en cours");
sendMessage(sender, "— !vaten : faire partir le bot");
sendMessage(sender, " !debut : commencer une nouvelle revue");
sendMessage(sender, " !fin : terminer la revue en cours");
sendMessage(sender, " # titre : démarrer un sujet individuel");
sendMessage(sender, " ## titre : démarrer un sujet collectif");
sendMessage(sender, " !courant : affiche le sujet en cours");
sendMessage(sender, " !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet");
sendMessage(sender, " % message : un commentaire");
sendMessage(sender, " !stop : abandonner la revue en cours");
sendMessage(sender, " !vaten : faire partir le bot");
sendMessage(sender, " !aide : afficher cette aide");
}
else if (StringUtils.equalsIgnoreCase(text, "!vaten"))
{
@ -192,24 +195,25 @@ public class Hebdobot extends PircBot
}
else
{
sendMessage("% Une revue est en cours, arrêt impossible");
sendMessage("% Une revue est en cours, arrêt impossible.");
}
}
else if (StringUtils.equalsIgnoreCase(text, "!stop"))
{
logger.info("!stop caught.");
// Die.
// Stop.
if (this.review == null)
{
sendMessage("Aucune revue en cours, arrêt impossible");
sendMessage("Aucune revue en cours, arrêt impossible.");
}
else
{
sendMessage("Arrêt de la revue en cours.");
this.review = null;
}
}
else if ((StringUtils.equalsIgnoreCase(text, "!debut")) || (StringUtils.equalsIgnoreCase(text, "!début")))
else if (StringsUtils.equalsAnyIgnoreCase(text, "!debut", "!début"))
{
logger.info("!debut caught.");

View File

@ -22,31 +22,32 @@ package org.april.hebdobot.model;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.april.hebdobot.HebdobotException;
import org.april.hebdobot.util.HebdobotUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.strings.StringList;
/**
* The Class UserAliases.
*/
public class UserAliases
public class UserAliases extends HashMap<String, String>
{
private static final long serialVersionUID = -7563433397065777556L;
private static final Logger logger = LoggerFactory.getLogger(UserAliases.class);
private final Map<String, String> aliases;
/**
* Instantiates a new user aliases.
*/
public UserAliases()
{
this.aliases = new HashMap<String, String>();
super();
}
/**
@ -59,20 +60,24 @@ public class UserAliases
*/
public UserAliases(final File source) throws HebdobotException
{
this.aliases = new HashMap<String, String>();
super();
try
{
StringList lines = new StringList(FileUtils.readLines(source, StandardCharsets.UTF_8));
Properties users = HebdobotUtils.loadProperties(source);
for (String realName : users.stringPropertyNames())
for (String line : lines)
{
String[] nicks = users.getProperty(realName).split(",");
for (String nick : nicks)
if ((StringUtils.isNotBlank(line)) && (!line.startsWith("#")))
{
this.aliases.put(nick, realName);
String[] tokens = line.split("=");
String realName = tokens[0];
String[] nicks = tokens[1].split(",");
for (String nick : nicks)
{
put(nick, realName);
}
}
}
}
@ -97,12 +102,12 @@ public class UserAliases
{
String result;
result = this.aliases.get(nick);
String realName = get(nick);
if (result == null)
if (realName == null)
{
boolean ended = false;
Iterator<String> iterator = this.aliases.keySet().iterator();
Iterator<String> iterator = keySet().iterator();
while (!ended)
{
if (iterator.hasNext())
@ -112,29 +117,40 @@ public class UserAliases
if (nick.toLowerCase().contains(currentNick.toLowerCase()))
{
ended = true;
result = this.aliases.get(currentNick) + " ( " + nick + " )";
realName = get(currentNick);
}
}
else
{
result = nick;
realName = nick;
ended = true;
}
}
}
result = realName + " (" + nick + ")";
//
return result;
}
/**
* Put all.
*
* @param source
* the source
/* (non-Javadoc)
* @see java.util.AbstractMap#toString()
*/
public void putAll(final UserAliases source)
@Override
public String toString()
{
this.aliases.putAll(source.aliases);
String result;
StringList buffer = new StringList();
for (String nick : this.keySet())
{
buffer.appendln(getRealName(nick));
}
result = buffer.toString();
//
return result;
}
}