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.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.bernard.juliabot.api.Command;
|
import com.bernard.discord.api.Command;
|
||||||
import com.bernard.juliabot.api.JuLIAddon;
|
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.core.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.MessageBuilder;
|
import net.dv8tion.jda.core.MessageBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.core.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.core.entities.MessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
|
||||||
@JuLIAddon(name = "juliatex", devs="Mysaa", version = "20w33a")
|
|
||||||
public class Juliatex {
|
public class Juliatex {
|
||||||
|
|
||||||
//TODO globally add a check-null parsing to every method call
|
//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 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;
|
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) {
|
public void latex(Message message, User user, MessageChannel channel) {
|
||||||
try {
|
try {
|
||||||
if(!userLogModes.containsKey(user.getIdLong()))
|
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) !");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
channel.sendFile(f).complete();
|
MessageBuilder outBuilder = new MessageBuilder();
|
||||||
|
outBuilder.append(user.getName());
|
||||||
|
channel.sendFile(f, outBuilder.build()).complete();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("AQueFichierProbleme");
|
System.err.println("AQueFichierProbleme");
|
||||||
} catch (InterruptedException e) {
|
} 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) {
|
public void latech(Message message, User user, MessageChannel channel) {
|
||||||
String[] args = parseArguments(message.getContentRaw());
|
String[] args = parseArguments(message.getContentRaw());
|
||||||
if(args.length < 2) {
|
if(args.length < 2) {
|
||||||
@ -225,8 +228,8 @@ public class Juliatex {
|
|||||||
userLogModes = new HashMap<>();
|
userLogModes = new HashMap<>();
|
||||||
UserConfigManager.selecteds = new HashMap<>();
|
UserConfigManager.selecteds = new HashMap<>();
|
||||||
|
|
||||||
//XXX UserConfigManager.saveSelectedConfigs();
|
UserConfigManager.saveSelectedConfigs();
|
||||||
//XXX UserConfigManager.saveUserLogModes();
|
UserConfigManager.saveUserLogModes();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@ -30,10 +30,6 @@ public class JuliatexConfig implements Serializable{
|
|||||||
this.optimize = optimize;
|
this.optimize = optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getSerialversionuid() {
|
|
||||||
return serialVersionUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPadding() {
|
public int getPadding() {
|
||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
@ -117,6 +113,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;
|
package com.bernard.julatex;
|
||||||
|
|
||||||
import static com.bernard.julatex.Juliatex.log;
|
import static com.bernard.julatex.Juliatex.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -16,12 +16,18 @@ import java.nio.file.Paths;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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 class UserConfigManager {
|
||||||
|
|
||||||
public static Map<Long,JuliatexConfig> selecteds = new HashMap<>();
|
public static Map<Long,JuliatexConfig> selecteds = new HashMap<>();
|
||||||
|
|
||||||
|
static{
|
||||||
|
retieveSelectedConfigs();
|
||||||
|
}
|
||||||
|
|
||||||
public static final String varFolder = "/var/julia/juliatex/";
|
public static final String varFolder = "/var/julia/juliatex/";
|
||||||
public static final String juliatexConfigExtension = "juliatexconfig";
|
public static final String juliatexConfigExtension = "juliatexconfig";
|
||||||
public static final String defaultConfigName = "default";
|
public static final String defaultConfigName = "default";
|
||||||
@ -76,12 +82,16 @@ public class UserConfigManager {
|
|||||||
JuliatexConfig config = parseConfig(fis);
|
JuliatexConfig config = parseConfig(fis);
|
||||||
return config;
|
return config;
|
||||||
} catch (FileNotFoundException e) {
|
} 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) {
|
} 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();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
if(fis != null)
|
if(fis != null)
|
||||||
@ -120,15 +130,102 @@ public class UserConfigManager {
|
|||||||
File saveFile = getUserConfigFilePath(user, configName).toFile();
|
File saveFile = getUserConfigFilePath(user, configName).toFile();
|
||||||
if(!(createIfDontExists || saveFile.exists()))
|
if(!(createIfDontExists || saveFile.exists()))
|
||||||
throw new IllegalArgumentException("Le fichier "+saveFile.getAbsolutePath()+" n'existe pas et ne doit pas être créé");
|
throw new IllegalArgumentException("Le fichier "+saveFile.getAbsolutePath()+" n'existe pas et ne doit pas être créé");
|
||||||
|
saveFile.getParentFile().mkdirs();
|
||||||
saveFile.createNewFile();
|
saveFile.createNewFile();
|
||||||
FileOutputStream fos = new FileOutputStream(saveFile);
|
FileOutputStream fos = new FileOutputStream(saveFile);
|
||||||
dumpConfig(fos, config);
|
dumpConfig(fos, config);
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void retieveUserLogModes() {
|
public static void saveSelectedConfigs() {
|
||||||
// TODO Auto-generated method stub
|
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() {
|
||||||
|
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