Skip to content

Commit

Permalink
Fix many data handling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SeveralCircles committed May 9, 2024
1 parent 8b404a8 commit 9b84095
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 161 deletions.
Binary file modified .gradle/8.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.5/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
11 changes: 3 additions & 8 deletions src/main/java/com/severalcircles/flames/amiguito/Amiguito.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public Amiguito(FlamesUser caretaker, double bond, double mood, double energy, d
}
public Amiguito(FlamesUser caretaker, String name) {
this.caretaker = caretaker;
if (this.caretaker == null) throw new IllegalArgumentException("Caretaker cannot be null. Why are you making me sad?");
this.bond = INIT_BOND;
this.mood = INIT_MOOD;
this.energy = INIT_ENERGY;
Expand All @@ -119,14 +120,7 @@ public void setCreated(Instant created) {

public static Amiguito fromProperties(Properties properties) throws ConsentException, IOException {
System.out.println(properties.toString());
User user;
try {
user = Flames.api.getUserById(properties.getProperty("caretaker"));
} catch (IllegalArgumentException e) {
Logger.getGlobal().warning("User " + properties.getProperty("caretaker") + " not found");
return null;
}
FlamesUser caretaker = FlamesDataManager.readUser(properties.getProperty("caretaker"));
FlamesUser caretaker = FlamesDataManager.readUser(properties.getProperty("caretaker"), false);
double bond = Double.parseDouble(properties.getProperty("bond"));
double mood = Double.parseDouble(properties.getProperty("mood"));
double energy = Double.parseDouble(properties.getProperty("energy"));
Expand Down Expand Up @@ -285,6 +279,7 @@ public Properties createProperties() {
properties.setProperty("food", String.valueOf(food));
properties.setProperty("water", String.valueOf(water));
properties.setProperty("deviance", String.valueOf(deviance));
properties.setProperty("created", String.valueOf(created.toEpochMilli()));
entities.forEach((entity, value) -> properties.setProperty("entity." + entity, String.valueOf(value)));
friends.forEach((friend, value) -> properties.setProperty("friend." + friend, String.valueOf(value)));
properties.setProperty("name", name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import com.severalcircles.flames.data.FlamesDataManager;
import com.severalcircles.flames.exception.ConsentException;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.*;
import java.util.logging.Logger;

Expand Down Expand Up @@ -60,6 +57,9 @@ public static void saveAll() {
public static Amiguito load(String discordId) throws IOException, ConsentException {
final File userDir = new File(FlamesDataManager.USER_DIRECTORY + "/" + discordId);
final File amiguitoFile = new File(userDir + "/amiguito.fl");
if (!amiguitoFile.exists()) {
throw new FileNotFoundException("Amiguito file not found for user " + discordId);
}
Properties properties = new Properties();
properties.load(new FileReader(amiguitoFile));
Amiguito result = Amiguito.fromProperties(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
public class AmiguitoNewCommand implements FlamesCommand {
@Override
public void execute(SlashCommandInteractionEvent event, FlamesUser sender) throws ConsentException, IOException {
if (AmiguitoDataManager.load(sender.getDiscordId()) != null) {
event.reply("You already have an Amiguito!").queue();
return;
}
if (event.getOption("name") == null) {
event.reply("You need to provide a name for your Amiguito!").queue();
return;
}
AmiguitoDataManager.save(new Amiguito(sender, Objects.requireNonNull(event.getOption("name")).getAsString()));
event.reply("Amiguito created!").queue();
try {
AmiguitoDataManager.load(sender.getDiscordId());
event.reply("You already have an Amiguito!").queue();
} catch (IOException | ConsentException e) {
AmiguitoDataManager.save(new Amiguito(sender, Objects.requireNonNull(event.getOption("name")).getAsString()));
event.reply("Amiguito created!").queue();
}
}
}
183 changes: 47 additions & 136 deletions src/main/java/com/severalcircles/flames/data/FlamesDataManager.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void setConsent(int consent) {
this.consent = consent;
}

public FlamesUser() {
public FlamesUser(String discordId) {
this.score = 0;
this.emotion = 0;
this.lastSeen = Instant.now();
Expand All @@ -99,6 +99,7 @@ public FlamesUser() {
this.relationships = new UserRelationships();
this.dataVersion = 2.2;
this.entities = new UserEntities();
this.discordId = discordId;
}

public void addScore(int amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class FlamesHandlerEmbed implements FlamesEmbed {
private String code;
private final String message;
private String message;
private Locale locale = Locale.ENGLISH;
private final String causedByImage;
final ResourceBundle rsc;
Expand Down Expand Up @@ -64,10 +64,11 @@ public FlamesHandlerEmbed(Exception e) {
e.printStackTrace();
this.causedByImage = "https://media.tenor.com/PkbRg6xWSuAAAAAC/shit-snake.gif";
this.message = e.getMessage();
color = Color.BLUE;
color = Color.RED;
}

public MessageEmbed get() {
if (message == null) message = "Please kill me";
return new EmbedBuilder()
.setAuthor(code)
.setThumbnail(causedByImage)
Expand Down

0 comments on commit 9b84095

Please sign in to comment.