Move testbot auth location in config (doesnt break old configs)

This commit is contained in:
blackilykat 2024-11-04 23:39:20 +01:00
parent 23c4b60f00
commit bf46a9ef4f
3 changed files with 26 additions and 5 deletions

View file

@ -1,5 +1,7 @@
package land.chipmunk.chipmunkmod;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.GsonBuilder;
import land.chipmunk.chipmunkmod.memory.ModuleMemory;
import land.chipmunk.chipmunkmod.util.Keybinds;
@ -28,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
// what the fuck is this indentation who is responsible for this nightmare
public class ChipmunkMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
@ -90,11 +93,29 @@ public class ChipmunkMod implements ModInitializer {
InputStream is = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
return gson.fromJson(reader, Configuration.class);
Configuration configuration = gson.fromJson(reader, Configuration.class);
if(configuration.bots.testbot.webhookUrl == null && configuration.testbotWebhook != null) {
LOGGER.info("Updating testbot auth url location in config!");
configuration.bots.testbot.webhookUrl = configuration.testbotWebhook;
configuration.testbotWebhook = null;
}
return configuration;
}
public static void saveConfig() throws IOException {
Gson otherGson = new GsonBuilder().serializeNulls().setLenient().setPrettyPrinting().create();
// to migrate old configs and avoid confusion on which field to use. Exclusion strategy should be removed once no one has the old auth location
// in their configs anymore
Gson otherGson = new GsonBuilder().serializeNulls().setLenient().setPrettyPrinting().addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getName().equals("testbotWebhook");
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
}).create();
String defaultConfig = otherGson.toJson(CONFIG);
BufferedWriter configWriter = new BufferedWriter(new FileWriter(CONFIG_FILE));
configWriter.write(defaultConfig);

View file

@ -11,8 +11,8 @@ public class Configuration {
public Bots bots = new Bots();
public CustomChat customChat = new CustomChat();
public AntiSpam antiSpam = new AntiSpam();
public boolean fullbright = true; // unused, but it is here for old configs
public String autoSkinUsername = "off";
// here so old configs can be migrated
public String testbotWebhook = null;
public String defaultUsername = null;
public Memory memory = new Memory();

View file

@ -65,10 +65,10 @@ public class ChatScreenMixin extends Screen {
if (addToHistory) {
client.inGameHud.getChatHud().addToMessageHistory(chatText);
}
if(ChipmunkMod.CONFIG.testbotWebhook != null && chatText.startsWith("-")) {
if(ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith("-")) {
Executor.service.submit(() -> {
try {
Webhook.send(ChipmunkMod.CONFIG.testbotWebhook, ChipmunkMod.CONFIG.defaultUsername);
Webhook.send(ChipmunkMod.CONFIG.bots.testbot.webhookUrl, ChipmunkMod.CONFIG.defaultUsername);
} catch (IOException e) {
ChipmunkMod.LOGGER.error("fard webhook url !!!t");
e.printStackTrace();