Skip to content

Commit

Permalink
Update project configurations, user data handling, and text resources
Browse files Browse the repository at this point in the history
Refactored project to JDK 20, modified user consent actions, enhanced user data storage, and fixed 'hootenanny' spelling inconsistencies. Added new data management classes and adjusted localization files accordingly.
  • Loading branch information
SeveralCircles committed Aug 5, 2024
1 parent 4570de6 commit f87293b
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 57 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.
4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/resourceBundles.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
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 @@ -26,7 +26,7 @@
import java.util.logging.Logger;

public class Conversation {
public static final int HOOTANANNY_BONUS = 2;
public static final int hootenanny_BONUS = 2;
public static final List<String> entityList = new LinkedList<>();
private final Map<String, Integer> entities;
private final GuildMessageChannel channel;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
if (finishedAnalysis.getSentiment().getScore() + finishedAnalysis.getSentiment().getMagnitude() > quoteScore | Math.round(Math.random() * 10) == 6) {
this.quote = new String[]{message.getContentRaw(), message.getAuthor().getName()};
this.quoteScore = finishedAnalysis.getSentiment().getScore() + finishedAnalysis.getSentiment().getMagnitude();
if (Math.round(Math.random() * 10) == 6) newFavorite = true;
if (Math.round(Math.random() * 5) <= 2) newFavorite = true;
}
if (!userList.contains(message.getAuthor())) userList.add(message.getAuthor());
finishedAnalysis.getEntityList().forEach((element) -> {
Expand Down Expand Up @@ -121,10 +121,15 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
if (user == null) return;
userList.forEach((member) -> user.getRelationships().addRelationship(member.getId(), 1));
if (user.getDiscordId().equals(message.getAuthor().getId())) {
if ((finalNewFavorite | user.getFunFacts().getFavoriteQuote().equals("This is me.")) && user.getConfig().isFavQuoteAllowed())
user.getFunFacts().setFavoriteQuote(message.getContentRaw());
Logger.getGlobal().info(String.valueOf(finalNewFavorite | user.getFunFacts().getFavoriteQuote().equals("This is me.")));
if (finalNewFavorite | user.getFunFacts().getFavoriteQuote().equals("This is me."))
Logger.getGlobal().info(user.getConfig().isFavQuoteAllowed() + "");
if (user.getConfig().isFavQuoteAllowed()) {
user.getFunFacts().setFavoriteQuote(message.getContentRaw());
Logger.getGlobal().info("Set favorite quote to " + message.getContentRaw());
}
double score = Math.round(finishedAnalysis.getEmotion() * 15);
if (new Date().getDate() == server.getHootanannyDay()) score *= HOOTANANNY_BONUS;
if (new Date().getDate() == server.getHootenannyDay()) score *= hootenanny_BONUS;
if (score < 0) score *= 5;
user.setEmotion(user.getEmotion() + (float) emotion);
if (user.getEmotion() > user.getFunFacts().getHighestEmotion()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void run() {
finish();
}
}, minutes * 60000L);
channel.asTextChannel().getManager().setSlowmode(minutes * 60).complete();
// channel.asTextChannel().getManager().setSlowmode(minutes * 60).complete();
}
void finish() {
AtomicReference<String> answer = new AtomicReference<>("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,22 @@ public static boolean newUser(User user) throws IOException {
File userl = new File(udir.getAbsolutePath() + "/user.fl");
File config = new File(udir.getAbsolutePath() + "/config.fl");
File entities = new File(udir.getAbsolutePath() + "/entities.fl");
File stats = new File(udir.getAbsolutePath() + "/stats.fl");
File funfacts = new File(udir.getAbsolutePath() + "/funfacts.fl");
// If any of the user data files don't exist, we're just going to assume that the data either doesn't exist or is corrupted and start from scratch because it shouldn't ever happen normally.
if (udir.mkdir() | userl.createNewFile()) {
FlamesUser flamesUser = new FlamesUser(user.getId());
Logger.getGlobal().log(Level.INFO, "User Data for " + discordId + " does not exist. Creating it now.");
FileOutputStream os1 = new FileOutputStream(userl);
FileOutputStream os2 = new FileOutputStream(stats);
FileOutputStream os3 = new FileOutputStream(funfacts);
FileOutputStream os4 = new FileOutputStream(config);
FileOutputStream os5 = new FileOutputStream(entities);
flamesUser.setDiscordId(discordId);
flamesUser.createData().store(os1, "User Data for " + name);
flamesUser.getConfig().createData().store(os4, "Configuration for " + name);
flamesUser.getEntities().createData().store(os5, "Entities for " + name);
flamesUser.getFunFacts().createData().store(os3, "Fun Facts for " + name);
// Consent.getConsent(user);
return true;
} else if (config.createNewFile()) {
Expand All @@ -100,17 +105,22 @@ public static void save(FlamesUser flamesUser) throws IOException {
File user = new File(udir.getAbsolutePath() + "/user.fl");
File config = new File(udir.getAbsolutePath() + "/config.fl");
File entities = new File(udir.getAbsolutePath() + "/entities.fl");
File stats = new File(udir.getAbsolutePath() + "/stats.fl");
File funfacts = new File(udir.getAbsolutePath() + "/funfacts.fl");
// If any of the user data files don't exist, we're just going to assume that the data either doesn't exist or is corrupted and start from scratch because it shouldn't ever happen normally.
if (udir.mkdir() | user.createNewFile() | config.createNewFile() | entities.createNewFile()) {
Logger.getGlobal().log(Level.INFO, "User Data for " + discordId + " does not exist. Creating it now.");
}
flamesUser.setDiscordId(discordId);
FileOutputStream os1 = new FileOutputStream(user);
FileOutputStream os3 = new FileOutputStream(funfacts);
FileOutputStream os4 = new FileOutputStream(config);
FileOutputStream os6 = new FileOutputStream(entities);
flamesUser.createData().store(os1, "User Data for " + name);
flamesUser.getConfig().createData().store(os4, "Configuration for " + name);
flamesUser.getFunFacts().createData().store(os3, "Fun Facts for " + name);
flamesUser.getEntities().getEntities().forEach((key, value) -> {

System.out.println(key + " | " + value);
});
System.out.println(flamesUser.getEntities().createData());
Expand All @@ -137,25 +147,29 @@ public static FlamesUser readUser(User user, boolean skipConsent) throws IOExcep
*/
public static FlamesUser readUser(String id, boolean skipConsent) throws IOException, ConsentException {
FlamesUser fluser = new FlamesUser(id);
UserFunFacts funFacts = new UserFunFacts();
File udir = new File(USER_DIRECTORY.getAbsolutePath() + "/" + id);
if (id == null) throw new IllegalArgumentException("User ID cannot be null. Did you really think you were going to get away with that?");
if (udir.mkdir() && !skipConsent) {
throw new ConsentException(0, Flames.api.retrieveUserById(id).complete());
}
File userfl = new File(udir.getAbsolutePath() + "/user.fl");
File config = new File(udir.getAbsolutePath() + "/config.fl");
File funfacts = new File(udir.getAbsolutePath() + "/funfacts.fl");
File entities = new File(udir.getAbsolutePath() + "/entities.fl");
if (userfl.createNewFile() | config.createNewFile() | entities.createNewFile()) {
if (userfl.createNewFile() | config.createNewFile() | entities.createNewFile() | funfacts.createNewFile()) {
Logger.getGlobal().log(Level.INFO, "User Data for " + id + " something something doesn't exist. Creating it now.");
}
FileInputStream inputStream1 = new FileInputStream(userfl);
FileInputStream inputStream4 = new FileInputStream(config);
FileInputStream inputStream6 = new FileInputStream(entities);
FileInputStream inputStream7 = new FileInputStream(funfacts);

// Prepare Properties() objects
Properties data = new Properties();
Properties configdata = new Properties();
Properties entitiesData = new Properties();
Properties funfactsdata = new Properties();
// Load data from properties files
data.load(inputStream1);
if (data.isEmpty()) data = new FlamesUser(id).createData();
Expand All @@ -164,13 +178,23 @@ public static FlamesUser readUser(String id, boolean skipConsent) throws IOExcep
entitiesData.load(inputStream6);
if (entitiesData.isEmpty()) entitiesData = new UserEntities().createData();
// Set data from properties files for FlamesUser
funfactsdata.load(inputStream7);
if (funfactsdata.isEmpty()) funfactsdata = new UserFunFacts().createData();
fluser.setScore(Integer.parseInt(String.valueOf(data.get("score"))));
fluser.setEmotion(Float.parseFloat(String.valueOf(data.get("emotion"))));
fluser.setDiscordId(id);
fluser.setDataVersion(Double.parseDouble(String.valueOf(data.get("version"))));
fluser.setConsent(Integer.parseInt(String.valueOf(data.get("consent"))));
fluser.setStreak(Integer.parseInt(String.valueOf(data.get("streak"))));
fluser.setLastSeen(Instant.parse(String.valueOf(data.get("lastSeen"))));
// Set data from properties files for UserFunFacts
funFacts.setLowestFlamesScore(Integer.parseInt(String.valueOf(funfactsdata.get("lowScore"))));
funFacts.setHighestFlamesScore(Integer.parseInt(String.valueOf(funfactsdata.get("highScore"))));
funFacts.setSadDay(Instant.parse(String.valueOf(funfactsdata.get("sadDay"))));
funFacts.setHappyDay(Instant.parse(String.valueOf(funfactsdata.get("happyDay"))));
funFacts.setHighestEmotion(Float.parseFloat(String.valueOf(funfactsdata.get("highestEmotion"))));
funFacts.setLowestEmotion(Float.parseFloat(String.valueOf(funfactsdata.get("lowestEmotion"))));
funFacts.setFavoriteQuote(String.valueOf(funfactsdata.get("favoriteQuote")));
// Set data from properties files for UserConfig
UserConfig config1;
try {
Expand All @@ -195,6 +219,7 @@ public static FlamesUser readUser(String id, boolean skipConsent) throws IOExcep
});
userEntities.setEntities(e);
fluser.setEntities(userEntities);
fluser.setFunFacts(funFacts);
if (fluser.getConsent() != 1 && !skipConsent) throw new ConsentException(fluser.getConsent(), Flames.api.getUserById(id));
return fluser;
}
Expand Down Expand Up @@ -249,9 +274,9 @@ public static FlamesServer getServer(String id) {
Properties data = new Properties();
data.load(inputStream);
int score = Integer.parseInt(data.get("score").toString());
int hootanannyDay = Integer.parseInt(data.get("hootanannyDay").toString());
int hootenannyDay = Integer.parseInt(data.get("hootenannyDay").toString());
String id2 = data.get("id").toString();
return new FlamesServer(score, id2, hootanannyDay);
return new FlamesServer(score, id2, hootenannyDay);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@

package com.severalcircles.flames.data.server;

import java.time.Instant;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Properties;
import java.util.Random;

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

public FlamesServer(int score, String id, int hootananyDay) {
public FlamesServer(int score, String id, int hootenannyDay) {
this.score = score;
this.id = id;
this.hootanannyDay = hootananyDay;
this.hootenannyDay = hootenannyDay;

}
public FlamesServer(String id) {
this.id = id;
this.score = 0;
this.hootanannyDay = new Random().nextInt(28) + 1; // Randomly select a day of the month for Hootanany Day
this.hootenannyDay = new Random().nextInt(28) + 1; // Randomly select a day of the month for Hootanany Day
}
public Properties createData() {
Properties data = new Properties();
data.put("score", String.valueOf(score));
data.put("id", id);
data.put("hootanannyDay", String.valueOf(hootanannyDay));
data.put("hootenannyDay", String.valueOf(hootenannyDay));
return data;
}
public int getHootanannyDay() {
return hootanannyDay;
public int getHootenannyDay() {
return hootenannyDay;
}
public int getScore() {
return score;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2024 Several Circles.
*/

package com.severalcircles.flames.data.server;

public class HootenannyDataManager {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024 Several Circles.
*/

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)
;
final int scoreThresh;
HootenannyTitle(int scoreThresh) {
this.scoreThresh = scoreThresh;
}
public int getScoreThresh() {
return scoreThresh;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Several Circles.
*/

package com.severalcircles.flames.data.server;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class ServerHootenannyData {
final Map<String, Integer> userScores = new HashMap<>();
public void addUser(String userId) {
userScores.put(userId, 0);
}
public void addScore(String userId, int score) {
if (!userScores.containsKey(userId)) addUser(userId);
userScores.put(userId, userScores.get(userId) + score);
}
HootenannyTitle getTitle(String userId) {
int score = userScores.get(userId);
HootenannyTitle title = HootenannyTitle.SERVER_FAN;
for (HootenannyTitle value : HootenannyTitle.values()) {
if (score >= value.getScoreThresh()) {
title = value;
}
}
return title;
}
public int getScore(String userId) {
return userScores.get(userId);
}
public void setScore(String userId, int score) {
userScores.put(userId, score);
}
public Properties createData() {
Properties data = new Properties();
for (String userId : userScores.keySet()) {
data.put(userId, String.valueOf(userScores.get(userId)));
}
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

package com.severalcircles.flames.data.user;

import com.severalcircles.flames.data.FlamesData;

import java.time.Instant;
import java.util.Properties;

/**
* Object used to represent a user in reference to their Flames Data
*/
public class FlamesUser implements FlamesData {
public class FlamesUser {

private int score;
private float emotion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void setFavQuoteAllowed(boolean favQuoteAllowed) {

public UserConfig() {
this.locale = Locale.getDefault();
this.qotdAllowed = true;
this.favQuoteAllowed = true;
}

public Locale getLocale() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConsentException extends FlamesException {
public final int consentLevel;

public ConsentException(int consentLevel, User user) throws InsufficientPermissionException {
super("That user hasn't started using Flames yet.");
super("Operation not allowed.");
this.consentLevel = consentLevel;
if (consentLevel == 0) {
Consent.getConsent(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static List<Entity> analyzeEntities(String message) throws IOException {

AnalyzeEntitiesResponse response = language.analyzeEntities(request);
// Print the response
List<Entity> finalList = response.getEntitiesList();
List<Entity> finalList = new ArrayList<>(response.getEntitiesList());
finalList.removeIf(entity -> entity.getName().matches("\\d+"));
finalList.forEach((element) -> {
if (!entityCache.containsKey(element.getName())) entityCache.put(element.getName(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SparkStartEmbed implements FlamesEmbed {
final String question;
final int minutes;
public SparkStartEmbed(FlamesUser fluser, User user, String question, int minutes) {
local = Flames.local();
local = Flames.local(fluser.getConfig().getLocale());
this.fluser = fluser;
this.user = user;
this.question = question;
Expand Down
Loading

0 comments on commit f87293b

Please sign in to comment.