Skip to content

Commit

Permalink
FLR-25 Have a Hootanany at Milk
Browse files Browse the repository at this point in the history
  • Loading branch information
SeveralCircles committed Jul 31, 2024
1 parent ef41c31 commit c488d1e
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 39 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.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

11 changes: 11 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 not shown.
Binary file not shown.
Binary file modified build/classes/java/main/org/json/XML$1$1.class
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/main/java/com/severalcircles/flames/ExitFlames.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ExitFlames extends Thread {
@Override
public void run() {
Logger.getGlobal().log(Level.INFO, "Preparing to exit Flames");
Logger.getGlobal().log(Level.INFO, Flames.reportHeader + Instant.now().toString() + "\n" +
"Flames Exit Report\n" +
Logger.getGlobal().log(Level.INFO,
"***Flames Exit Report***\n" +
"Messages Processed: " + FlamesRunStats.messageCount + "\n" +
"Commands Used: " + FlamesRunStats.commandCount + "\n" +
"Buttons Pressed: " + FlamesRunStats.buttonCount + "\n\n" +
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/com/severalcircles/flames/Flames.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.severalcircles.flames.frontend.conversations.ConversationCommand;
import com.severalcircles.flames.frontend.conversations.SparkCommand;
import com.severalcircles.flames.frontend.data.other.GlobalDataCommand;
import com.severalcircles.flames.frontend.data.other.ServerDataCommand;
import com.severalcircles.flames.frontend.data.user.HiCommand;
import com.severalcircles.flames.frontend.data.user.LocaleCommand;
import com.severalcircles.flames.frontend.data.user.MyDataCommand;
Expand Down Expand Up @@ -64,16 +65,6 @@ public class Flames {
public static ResourceBundle getCommonRsc(Locale locale) {
return ResourceBundle.getBundle("Common", locale);
}
public static String reportHeader;

static {
try {
reportHeader = "OP:" + System.getProperty("user.name") + " HN:" + InetAddress.getLocalHost().getHostName() + " OS:" + System.getProperty("os.name") + " JRE:" + System.getProperty("java.vendor") + " FV:%s" + " IN:";
} catch (UnknownHostException e) {
e.printStackTrace();
System.exit(1);
}
}

/**
* Bootloader function
Expand All @@ -86,7 +77,6 @@ public static void main(String[] args) throws IOException {
properties.load(is);
version = properties.getProperty("version");
FlamesDataManager.prepare();
reportHeader = String.format(reportHeader, version);
String logName = "Flames " + version + "@" + InetAddress.getLocalHost().getHostName() + " " + Instant.now().truncatedTo(ChronoUnit.SECONDS).toString().replace(":", " ").replace("T", " T") + ".log";
File logDir = new File(FlamesDataManager.FLAMES_DIRECTORY.getAbsolutePath() + "/logs");
//noinspection ResultOfMethodCallIgnored
Expand All @@ -97,8 +87,7 @@ public static void main(String[] args) throws IOException {
FileHandler handler = new FileHandler(logFile.getAbsolutePath());
handler.setFormatter(new SimpleFormatter());
Logger.getGlobal().addHandler(handler);
Logger.getGlobal().log(Level.INFO, "Flames");
Logger.getGlobal().info(reportHeader + Instant.now());
Logger.getGlobal().log(Level.INFO, "Flames " + version);
if (version.contains("-beta") | version.contains("-alpha") | version.contains("-SNAPSHOT")) {
Logger.getGlobal().log(Level.WARNING, "This is a development version of Flames. It may be too based for you to handle.");
}
Expand All @@ -122,7 +111,7 @@ public static void main(String[] args) throws IOException {
} catch (InterruptedException e) {
e.printStackTrace();
}
AmiguitoDataManager.prepare();
// AmiguitoDataManager.prepare(); <---- Don't worry about that
// --- Events ---
new CommandEvent().register(api);
new MessageEvent().register(api);
Expand Down Expand Up @@ -156,7 +145,9 @@ public static void main(String[] args) throws IOException {
commandDataList.add(Commands.slash("about", "Who cooked here?"));
commandMap.put("spark", new SparkCommand());
commandDataList.add(Commands.slash("spark", "Start a Spark conversation").addOption(OptionType.STRING, "question", "The question you want to ask", true).addOption(OptionType.INTEGER, "minutes", "Time limit for the conversation in minutes.", true));
commandDataList.add(Commands.slash("amiguito", "Interact with your Amiguito character").addOption(OptionType.STRING, "name", "The name of your Amiguito", true));
commandMap.put("server", new ServerDataCommand());
commandDataList.add(Commands.slash("server", "Catch up on this server's stats"));
// commandDataList.add(Commands.slash("amiguito", "Interact with your Amiguito character").addOption(OptionType.STRING, "name", "The name of your Amiguito", true));

// Commands.context(Command.Type.MESSAGE, "SparkVote");
api.updateCommands()
Expand All @@ -183,9 +174,9 @@ public static void incrementErrorCount() {
e.printStackTrace();
System.exit(3);
}
String log = reportHeader + "\n" +
String log =
"Flames has detected a recurring fatal issue. Similar issues are known to cause damage to Flames, so Flames has been shut down.\n" +
"Please report this issue to the developers at https://github.com/colorfulFlames/flames/issues/new?assignees=SeveralCircles&labels=bug&template=bug_report.md&title=Flames Protect Exception\n" +
"Please report this issue to the developers at severalcircles.youtrack.cloud\n" +
"Thank you for your cooperation.";
FileWriter writer;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.severalcircles.flames.Flames;
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.user.FlamesUser;
import com.severalcircles.flames.data.user.UserEntities;
import com.severalcircles.flames.exception.ConsentException;
Expand All @@ -20,14 +21,12 @@
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Conversation {
public static final int HOOTANANNY_BONUS = 2;
public static final List<String> entityList = new LinkedList<>();
private final Map<String, Integer> entities;
private final GuildMessageChannel channel;
Expand Down Expand Up @@ -70,7 +69,7 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
expired = true;
throw new ExpiredConversationException();
}

FlamesServer server = FlamesDataManager.getServer(message.getGuildId());
expires = Instant.now().plus(5, ChronoUnit.MINUTES);
emotion += finishedAnalysis.getSentiment().getScore() + finishedAnalysis.getSentiment().getMagnitude();
if (finishedAnalysis.getSentiment().getScore() + finishedAnalysis.getSentiment().getMagnitude() > quoteScore | Math.round(Math.random() * 10) == 6) {
Expand All @@ -97,12 +96,11 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
userEntities.addEntity(key, finishedAnalysis.getSentiment().getScore() > 0);
});
user.setEntities(userEntities);
user.getEntities().getEntities().forEach((key, value) -> {
});
// user.getEntities().getEntities().forEach((key, value) -> {});
try {
user.getEntities().getEntities().forEach((key, value) -> {
System.out.println(key + " / " + value);
});
// user.getEntities().getEntities().forEach((key, value) -> {
// System.out.println(key + " / " + value);
// });
FlamesDataManager.save(user);
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -118,15 +116,16 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
} catch (Exception e) {
new ExceptionHandler(e).handle();
}
}
FlamesUser user = conversationCache.get(element.getId());
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());
double score = Math.round(finishedAnalysis.getEmotion() * 15);
if (new Date().getDate() == server.getHootanannyDay()) score *= HOOTANANNY_BONUS;
if (score < 0) score *= 5;
user.setScore(user.getScore() + (int) score);
user.setEmotion(user.getEmotion() + (float) emotion);
if (user.getEmotion() > user.getFunFacts().getHighestEmotion()) {
user.getFunFacts().setHighestEmotion(user.getEmotion());
Expand All @@ -138,6 +137,10 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
}
if (user.getScore() > user.getFunFacts().getHighestFlamesScore())
user.getFunFacts().setHighestFlamesScore(user.getScore());
server.addScore((int) score);
user.addScore((int) score);
System.out.println("Score: " + score);
FlamesDataManager.saveServer(server);
GlobalData.globalScore += (int) score;
GlobalData.averageScore = GlobalData.globalScore / GlobalData.participants;
if (user.getScore() > Today.highScore) {
Expand All @@ -150,7 +153,6 @@ public void processMessage(Message message, FinishedAnalysis finishedAnalysis) t
} catch (IOException e) {
throw new RuntimeException(e);
}
}
conversationCache.forEach((key, value) -> {
try {
FlamesDataManager.save(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package com.severalcircles.flames.data;

import com.severalcircles.flames.Flames;
import com.severalcircles.flames.data.server.FlamesServer;
import com.severalcircles.flames.data.user.*;
import com.severalcircles.flames.exception.ConsentException;
import com.severalcircles.flames.exception.FlamesMetaException;
import com.severalcircles.flames.util.Rank;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
Expand All @@ -28,7 +28,7 @@ public class FlamesDataManager {
*/
public static final File FLAMES_DIRECTORY = new File(System.getProperty("user.dir") + "/Flames");
public static final File USER_DIRECTORY = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/user");
public static final File GUILD_DIRECTORY = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/guild");
public static final File SERVER_DIRECTORY = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/server");
public static final File WILDFIRE_FILE = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/wildfire.fl");
// static List<File> openFiles = new LinkedList<>();

Expand All @@ -42,7 +42,7 @@ public static void prepare() {
//noinspection ResultOfMethodCallIgnored
USER_DIRECTORY.mkdir();
//noinspection ResultOfMethodCallIgnored
GUILD_DIRECTORY.mkdir();
SERVER_DIRECTORY.mkdir();
try {
//noinspection ResultOfMethodCallIgnored
WILDFIRE_FILE.createNewFile();
Expand All @@ -61,8 +61,6 @@ public static boolean newUser(User user) throws IOException {
String discordId = user.getId();
File udir = new File(USER_DIRECTORY.getAbsolutePath() + "/" + discordId);
File userl = new File(udir.getAbsolutePath() + "/user.fl");
File stats = new File(udir.getAbsolutePath() + "/stats.fl");
File funfacts = new File(udir.getAbsolutePath() + "/funfacts.fl");
File config = new File(udir.getAbsolutePath() + "/config.fl");
File entities = new File(udir.getAbsolutePath() + "/entities.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.
Expand Down Expand Up @@ -201,7 +199,7 @@ public static FlamesUser readUser(String id, boolean skipConsent) throws IOExcep
return fluser;
}
public static String[] getChannelWords(Channel channel) {
File channelFile = new File(GUILD_DIRECTORY.getAbsolutePath() + "/" + ((GuildChannel) channel).getGuild().getId() + "/channels/" + channel.getId() + ".flx");
File channelFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + ((GuildChannel) channel).getGuild().getId() + "/channels/" + channel.getId() + ".flx");
try {
if (channelFile.createNewFile()) return new String[0];
if (channelFile.getParentFile().mkdirs()) return new String[0];
Expand All @@ -218,7 +216,7 @@ public static String[] getChannelWords(Channel channel) {
}
}
public static void addChannelWord(String word, Channel channel) {
File channelFile = new File(GUILD_DIRECTORY.getAbsolutePath() + "/" + ((GuildChannel) channel).getGuild().getId() + "/channels/" + channel.getId() + ".flx");
File channelFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + ((GuildChannel) channel).getGuild().getId() + "/channels/" + channel.getId() + ".flx");
String[] channelWords = getChannelWords(channel);
String[] newChannelWords = new String[channelWords.length + 1];
newChannelWords[channelWords.length] = word;
Expand All @@ -234,5 +232,44 @@ public static void addChannelWord(String word, Channel channel) {
throw new RuntimeException(e);
}
}
public static FlamesServer getServer(String id) {
File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + ".fl");
FlamesServer server;
try {
if (serverFile.createNewFile()) {
server = new FlamesServer(id);
saveServer(server);
return server;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
FileInputStream inputStream = new FileInputStream(serverFile);
Properties data = new Properties();
data.load(inputStream);
int score = Integer.parseInt(data.get("score").toString());
int hootanannyDay = Integer.parseInt(data.get("hootanannyDay").toString());
String id2 = data.get("id").toString();
return new FlamesServer(score, id2, hootanannyDay);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void saveServer(FlamesServer server) {
File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + server.getId() + ".fl");
try {
if (serverFile.createNewFile()) return;
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
FileOutputStream os = new FileOutputStream(serverFile);
server.createData().store(os, "Flames Server Data");
os.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

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

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;

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

}
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
}
public Properties createData() {
Properties data = new Properties();
data.put("score", String.valueOf(score));
data.put("id", id);
data.put("hootanannyDay", String.valueOf(hootanannyDay));
return data;
}
public int getHootanannyDay() {
return hootanannyDay;
}
public int getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

public void addScore(int score) {
this.score += score;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class FlamesUser implements FlamesData {
private Instant lastSeen;
private int streak;
private String discordId;
// private UserStats stats;
private int consent;
private UserFunFacts funFacts;
private double dataVersion;
Expand Down
Loading

0 comments on commit c488d1e

Please sign in to comment.