Skip to content

Commit

Permalink
Add Hootenanny data management functionality
Browse files Browse the repository at this point in the history
Introduce the `HootenannyDataManager` to manage hootenanny data, including methods to save and retrieve this data. Modify `FlamesServer` and `Conversation` classes to incorporate hootenanny data operations, ensuring that relevant data is persisted correctly. A new method in `FlamesServer` checks if today is a hootenanny day.
  • Loading branch information
SeveralCircles committed Aug 14, 2024
1 parent f87293b commit e97b5af
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.severalcircles.flames.data.FlamesDataManager;
import com.severalcircles.flames.data.global.GlobalData;
import com.severalcircles.flames.data.server.FlamesServer;
import com.severalcircles.flames.data.server.HootenannyDataManager;
import com.severalcircles.flames.data.user.FlamesUser;
import com.severalcircles.flames.data.user.UserEntities;
import com.severalcircles.flames.exception.ConsentException;
Expand Down Expand Up @@ -146,8 +147,17 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
user.addScore((int) score);
System.out.println("Score: " + score);
FlamesDataManager.saveServer(server);

GlobalData.globalScore += (int) score;
GlobalData.averageScore = GlobalData.globalScore / GlobalData.participants;
if (server.todayIsHootenannyDay()) {
server.getHootenannyData().addScore(user.getDiscordId(), (int) score);
}
try {
HootenannyDataManager.saveData(server.getHootenannyData(), message.getGuildId());
} catch (IOException e) {
throw new RuntimeException(e);
}
if (user.getScore() > Today.highScore) {
Today.highUser = message.getAuthor().getName() + " (" + user.getScore() + ")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public static void addChannelWord(String word, Channel channel) {
}
public static FlamesServer getServer(String id) {
File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + ".fl");
File serverHootenannyDataFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + "-hootenannyData.fl");
try {
serverHootenannyDataFile.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
FlamesServer server;
try {
if (serverFile.createNewFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@

package com.severalcircles.flames.data.server;

import java.io.IOException;
import java.util.Properties;
import java.util.Random;

public class FlamesServer {
private int score;
private String id;
private int hootenannyDay;

ServerHootenannyData hootenannyData;
public FlamesServer(int score, String id, int hootenannyDay) {
this.score = score;
this.id = id;
this.hootenannyDay = hootenannyDay;

try {
hootenannyData = HootenannyDataManager.getData(id);
} catch (IOException e) {
e.printStackTrace();
hootenannyData = new ServerHootenannyData();
}
}
public FlamesServer(String id) {
this.id = id;
Expand All @@ -30,6 +36,10 @@ public Properties createData() {
data.put("hootenannyDay", String.valueOf(hootenannyDay));
return data;
}
public boolean todayIsHootenannyDay() {
return hootenannyDay == new java.util.Date().getDate();
}

public int getHootenannyDay() {
return hootenannyDay;
}
Expand All @@ -49,6 +59,10 @@ public String getId() {
return id;
}

public ServerHootenannyData getHootenannyData() {
return hootenannyData;
}

public void setId(String id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@

package com.severalcircles.flames.data.server;

public class HootenannyDataManager {

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

public class HootenannyDataManager {
public static ServerHootenannyData getData(String serverId) throws IOException {
Properties data = new Properties();
data.load(Files.newInputStream(Paths.get("server/" + serverId + "-hootenannyData.fl")));
ServerHootenannyData hootenannyData = new ServerHootenannyData();
for (String key : data.stringPropertyNames()) {
hootenannyData.addScore(key, Integer.parseInt(data.getProperty(key)));
}
return hootenannyData;
}
public static void saveData(ServerHootenannyData hootenannyData, String serverId) throws IOException {
Properties data = hootenannyData.createData();
data.store(Files.newOutputStream(Paths.get("server/" + serverId + "-hootenannyData.fl")), "Hootenanny Data for " + serverId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
package com.severalcircles.flames.data.server;

public enum HootenannyTitle {
SERVER_FAN(0), SERVER_ENJOYER(100), SERVER_FIEND(500), SERVER_DEFENDER(1000), SERVER_CHAMPION(2500), SERVER_RULER(5000)
SERVER_FAN(0), SERVER_ENJOYER(100), SERVER_FIEND(500),
SERVER_DEFENDER(1000), SERVER_CHAMPION(2500), SERVER_RULER(5000)
;
final int scoreThresh;
HootenannyTitle(int scoreThresh) {
Expand Down

0 comments on commit e97b5af

Please sign in to comment.