Nouvelle version avec la config plus dévelopée
This commit is contained in:
parent
1ab160b5f6
commit
7741465a47
@ -11,16 +11,17 @@ import java.util.PrimitiveIterator.OfInt;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.bernard.juliabot.api.Command;
|
||||
import com.bernard.juliabot.api.JuLIAddon;
|
||||
import com.bernard.discord.api.Command;
|
||||
import com.bernard.julatex.JuliatexConfig;
|
||||
import com.bernard.julatex.StopEverythingException;
|
||||
import com.bernard.julatex.UserConfigManager;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.MessageBuilder;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.MessageChannel;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
|
||||
@JuLIAddon(name = "juliatex", devs="Mysaa", version = "20w33a")
|
||||
public class Juliatex {
|
||||
|
||||
//TODO globally add a check-null parsing to every method call
|
||||
@ -35,7 +36,7 @@ public class Juliatex {
|
||||
public static final String wipText = "Je suis super motivé mais les développeurs ont préféré perdre leur temps à écrire un texte disant qu'il ont pas fait leur taff plutot que de réellement faire le contenu ... Ah ben Bravo !";
|
||||
public static final LogMode DEFAULT_LOGMODE = LogMode.RISKY;
|
||||
|
||||
@Command(name = "£atex", admin = false, description = "Affiche une image a partir du latex")
|
||||
@Command(name = "£atex",grp="latex",group="Latex", admin = false, description = "Affiche une image a partir du latex")
|
||||
public void latex(Message message, User user, MessageChannel channel) {
|
||||
try {
|
||||
if(!userLogModes.containsKey(user.getIdLong()))
|
||||
@ -60,7 +61,9 @@ public class Juliatex {
|
||||
channel.sendMessage("Le moteur latex m'a renvoye une image neant, du coup, je vous l'affiche dans ce message. Bon visionnage (J'imagine) !");
|
||||
return;
|
||||
}
|
||||
channel.sendFile(f).complete();
|
||||
MessageBuilder outBuilder = new MessageBuilder();
|
||||
outBuilder.append(user.getName());
|
||||
channel.sendFile(f, outBuilder.build()).complete();
|
||||
} catch (IOException e) {
|
||||
System.err.println("AQueFichierProbleme");
|
||||
} catch (InterruptedException e) {
|
||||
@ -72,7 +75,7 @@ public class Juliatex {
|
||||
|
||||
}
|
||||
|
||||
@Command(name = "£atech", admin = true, description = "Règle les paramètres utilisateurs de JuL'IAtex")
|
||||
@Command(name = "£atech",grp="latex",group="Latex", admin = true, description = "Règle les paramètres utilisateurs de JuL'IAtex")
|
||||
public void latech(Message message, User user, MessageChannel channel) {
|
||||
String[] args = parseArguments(message.getContentRaw());
|
||||
if(args.length < 2) {
|
||||
@ -225,8 +228,8 @@ public class Juliatex {
|
||||
userLogModes = new HashMap<>();
|
||||
UserConfigManager.selecteds = new HashMap<>();
|
||||
|
||||
//XXX UserConfigManager.saveSelectedConfigs();
|
||||
//XXX UserConfigManager.saveUserLogModes();
|
||||
UserConfigManager.saveSelectedConfigs();
|
||||
UserConfigManager.saveUserLogModes();
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@ -30,10 +30,6 @@ public class JuliatexConfig implements Serializable{
|
||||
this.optimize = optimize;
|
||||
}
|
||||
|
||||
public static long getSerialversionuid() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return padding;
|
||||
}
|
||||
@ -118,6 +114,15 @@ public class JuliatexConfig implements Serializable{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
//TODO make a full-data to string (this.dump());
|
||||
return "JuliatexConfig [padding=" + padding + ", margin=" + margin + ", packages=" + packages + ", bgColor="
|
||||
+ bgColor + ", fgColor=" + fgColor + ", borderColor=" + borderColor + ", dpi=" + dpi
|
||||
+ ", environnement=" + environnement + ", header=" + header + ", optimize=" + optimize + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package com.bernard.julatex;
|
||||
|
||||
import static com.bernard.julatex.Juliatex.log;
|
||||
import static com.bernard.julatex.Juliatex.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -16,12 +16,18 @@ import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import com.bernard.julatex.Juliatex.LogMode;
|
||||
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
|
||||
public class UserConfigManager {
|
||||
|
||||
public static Map<Long,JuliatexConfig> selecteds = new HashMap<>();
|
||||
|
||||
static{
|
||||
retieveSelectedConfigs();
|
||||
}
|
||||
|
||||
public static final String varFolder = "/var/julia/juliatex/";
|
||||
public static final String juliatexConfigExtension = "juliatexconfig";
|
||||
public static final String defaultConfigName = "default";
|
||||
@ -76,12 +82,16 @@ public class UserConfigManager {
|
||||
JuliatexConfig config = parseConfig(fis);
|
||||
return config;
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated truc
|
||||
if(log(user,"Les devs ... y a un probleme avec l'enregistrement des userConfig, le fichier il est pas ouvrable"))
|
||||
return getDefaultConfig();
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
if(log(user,"Les devs ... y a un probleme avec l'enregistrement des userConfig"))
|
||||
return getDefaultConfig();
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
if(log(user,"Les devs ... y a un probleme avec l'enregistrement des userConfig, une IOException"))
|
||||
return getDefaultConfig();
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if(fis != null)
|
||||
@ -120,15 +130,102 @@ public class UserConfigManager {
|
||||
File saveFile = getUserConfigFilePath(user, configName).toFile();
|
||||
if(!(createIfDontExists || saveFile.exists()))
|
||||
throw new IllegalArgumentException("Le fichier "+saveFile.getAbsolutePath()+" n'existe pas et ne doit pas être créé");
|
||||
saveFile.getParentFile().mkdirs();
|
||||
saveFile.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(saveFile);
|
||||
dumpConfig(fos, config);
|
||||
fos.close();
|
||||
}
|
||||
|
||||
public static void saveSelectedConfigs() {
|
||||
File f = new File(varFolder,"selecteds");
|
||||
f.delete();
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(selecteds);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Impossible de sauvegarder les configs sélectionnées");
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(oos != null)
|
||||
try {
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void retieveSelectedConfigs() {
|
||||
File f = new File(varFolder,"selecteds");
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
ois = new ObjectInputStream(new FileInputStream(f));
|
||||
selecteds = (Map<Long, JuliatexConfig>) ois.readObject();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Impossible de retrouver les configs sélectionnées");
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException | ClassCastException e) {
|
||||
System.err.println("Y a un probleme avec la classe du fichier "+f.getAbsolutePath()+" ...");
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(ois != null)
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveUserLogModes() {
|
||||
File f = new File(varFolder,"userLogModes");
|
||||
f.delete();
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(Juliatex.userLogModes);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Impossible de sauvegarder les configs sélectionnées");
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(oos != null)
|
||||
try {
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void retieveUserLogModes() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
File f = new File(varFolder,"userLogModes");
|
||||
ObjectInputStream ois = null;
|
||||
try {
|
||||
ois = new ObjectInputStream(new FileInputStream(f));
|
||||
Juliatex.userLogModes = (Map<Long, LogMode>) ois.readObject();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Impossible de retrouver les configs sélectionnées");
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException | ClassCastException e) {
|
||||
System.err.println("Y a un probleme avec la classe du fichier "+f.getAbsolutePath()+" ...");
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
if(ois != null)
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user