Skip to content

Commit

Permalink
Fix URL filtering, enhance data management, update embeds
Browse files Browse the repository at this point in the history
Restored URL filtering in `MessageEvent`. Added methods and documentation for `FlamesDataManager`. Simplified ordinal day logic and updated several strings in resources.
  • Loading branch information
SeveralCircles committed Aug 27, 2024
1 parent c1217d1 commit ff03ba0
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 30 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.
20 changes: 20 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 modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package com.severalcircles.flames.data;

import com.severalcircles.flames.data.legacy.server.LegacyFlamesServer;
import com.severalcircles.flames.data.user.FlamesUser;
import org.yaml.snakeyaml.Yaml;

Expand All @@ -14,8 +13,20 @@
import java.util.logging.Logger;

/**
* The FlamesDataManager class is responsible for managing the data of FlamesUser and FlamesServer objects.
* It is capable of saving, retrieving and preparing necessary directories
* The FlamesDataManager class is responsible for managing Flames data such as users and servers.
* It provides methods to prepare the Flames data, retrieve and save user information, and retrieve and save server information.
*
* <p>Usage:</p>
* <pre>
* FlamesDataManager.prepare();
* FlamesUser user = FlamesDataManager.getUser("123456789");
* FlamesDataManager.saveUser(user);
* FlamesServer server = FlamesDataManager.getServer("987654321");
* FlamesDataManager.saveServer(server);
* </pre>
*
* @see FlamesUser
* @see FlamesServer
*/
public class FlamesDataManager {
private static final Logger LOGGER = Logger.getLogger(FlamesDataManager.class.getName());
Expand All @@ -24,16 +35,44 @@ public class FlamesDataManager {
public static final File USER_DIRECTORY = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/users");
public static final File SERVER_DIRECTORY = new File(FLAMES_DIRECTORY.getAbsolutePath() + "/servers");

/**
* Prepares the Flames data by creating necessary directories.
* It creates the Flames directory, Users directory, and Servers directory.
* This method is typically called before performing any data operations.
*
* Example usage:
*
* DataUpgradeUtil.upgradeData();
*
* This method does not return any value.
*/
public static void prepare() {
LOGGER.info("Preparing Flames Data");
if (FLAMES_DIRECTORY.mkdir()) LOGGER.info("Created Flames directory");
if (USER_DIRECTORY.mkdir()) LOGGER.info("Created Users directory");
if (SERVER_DIRECTORY.mkdir()) LOGGER.info("Created Servers directory");
}
/**
* Retrieves the FlamesUser object associated with the given ID.
*
* @param id The ID of the user.
* @return The FlamesUser object for the given ID.
* @throws ConsentException If the user's consent level is not sufficient.
* @throws IOException If an I/O error occurs while accessing the user file.
*/
public static FlamesUser getUser(String id) throws ConsentException, IOException {
return getUser(id, false);
}

/**
* Retrieves a FlamesUser object based on the given ID.
*
* @param id The ID of the user.
* @param skipConsent If true, skips the consent check.
* @return The FlamesUser object corresponding to the given ID.
* @throws ConsentException If the user's consent level is not sufficient and skipConsent is false.
* @throws IOException If there is an error reading the user file.
*/
public static FlamesUser getUser(String id, boolean skipConsent) throws ConsentException, IOException {
File userFile = new File(USER_DIRECTORY.getAbsolutePath() + "/" + id + ".yml");
Yaml yaml = new Yaml();
Expand All @@ -50,16 +89,27 @@ public static FlamesUser getUser(String id, boolean skipConsent) throws ConsentE
else return user;
}

/**
* Saves the FlamesUser object to a YAML file.
*
* @param flamesUser the FlamesUser object to be saved
* @throws IOException if an I/O error occurs while writing the file
*/
public static void saveUser(FlamesUser flamesUser) throws IOException {
File userFile = new File(USER_DIRECTORY.getAbsolutePath() + "/" + flamesUser.getID() + ".yml");
Yaml yaml = new Yaml();
Files.write(userFile.toPath(), yaml.dump(flamesUser).getBytes());
}
/**
* Retrieves a FlamesServer object based on the given ID.
*
* @param id The ID of the server.
* @return The FlamesServer object for the specified ID, or null if there was an error.
*/
public static FlamesServer getServer(String id) {
try {
File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + id + ".yml");
Yaml yaml = new Yaml();

if (!serverFile.exists()) {
FlamesServer newServer = new FlamesServer(id);
Files.write(serverFile.toPath(), yaml.dump(newServer).getBytes());
Expand All @@ -74,6 +124,11 @@ public static FlamesServer getServer(String id) {
}
}

/**
* Saves a FlamesServer object to a YAML file.
*
* @param flamesServer the FlamesServer object to be saved
*/
public static void saveServer(FlamesServer flamesServer) {
try {
File serverFile = new File(SERVER_DIRECTORY.getAbsolutePath() + "/" + flamesServer.getId() + ".yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FlamesServer extends FlamesDatatype {
public FlamesServer(LegacyFlamesServer legacyFlamesServer) {
this.id = legacyFlamesServer.getId();
this.score = legacyFlamesServer.getScore();
this.hootenannyDay = legacyFlamesServer.getHootenannyDay();;
this.hootenannyDay = legacyFlamesServer.getHootenannyDay();
}

public void setId(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MessageEvent extends ListenerAdapter implements FlamesDiscordEvent
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
Logger.getGlobal().log(Level.FINE,event.getAuthor().getId() + " Triggered Message Event");
// if (event.getMessage().getContentRaw().matches("[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)")) return; // Don't process URLs
if (event.getMessage().getContentRaw().matches("[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)")) return; // Don't process URLs
super.onMessageReceived(event);
User user = event.getAuthor();
Logger logger = Logger.getGlobal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@ public ServerDataEmbed(LegacyFlamesServer server, FlamesUser user, GuildChannel
}
@Override
public MessageEmbed get() {
StringBuilder hootenannyDay = new StringBuilder() ;
hootenannyDay.append(server.getHootenannyDay());
String rd = "3";
String nd = "2";
String st = "1";
String end = hootenannyDay.toString().toCharArray()[hootenannyDay.toString().length()-1] + "";
if (rd.equals(end)) hootenannyDay.append("rd");
else if (nd.equals(end)) hootenannyDay.append("nd");
else if (st.equals(end)) hootenannyDay.append("st");
else hootenannyDay.append("th");
Color color = Color.GRAY;
String description = String.format(local.getString("hootenanny"), hootenannyDay);
String description = String.format(local.getString("hootenanny"), ordinal(server.getHootenannyDay()));
String title = origin.getGuild().getName();
if (new Date().getDate() == server.getHootenannyDay()) {
color = Color.RED;
Expand All @@ -59,4 +49,16 @@ public MessageEmbed get() {
.build();
return embed;
}
public static String ordinal(int i) {
String[] suffixes = new String[] { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" };
switch (i % 100) {
case 11:
case 12:
case 13:
return i + "th";
default:
return i + suffixes[i % 10];

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AboutEmbed(FlamesUser user) {
}
public MessageEmbed get() {
return new EmbedBuilder()
.setTitle(Flames.api.getSelfUser().getName() + " " + Flames.version)
.setTitle(String.format(local.getString("title"), Flames.version))
.setAuthor(local.getString("author"), null, Flames.api.getSelfUser().getAvatarUrl())
.setDescription(String.format(local.getString("description"), Flames.version))
.setImage(FlamesAssets.getVersionIcon())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
author.earlyafternoon=Hi, %s
author.earlymorning=What's up, %s?
author.evening=Howdy, %s
author.lateafternoon=What a day, %s.
author.lateafternoon=Good afternoon, %s.
author.morning=Good Morning, %s
author.night=Have a good night, %s
author.thanksgiving=Happy Thanksgiving, %s
dailyBonus=Daily Bonus
description=It's so nice to see you again!
description=\ ## It's so nice to see you again!
score=Your Flames Score
title=Welcome Back to Flames
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
author.earlyafternoon=Hi, %s
author.earlymorning=What's up, %s?
author.evening=Howdy, %s
author.lateafternoon=What a day, %s.
author.lateafternoon=Good afternoon, %s.
author.morning=Good Morning, %s
author.night=Have a good night, %s
author.thanksgiving=Happy Thanksgiving, %s
dailyBonus=Daily Bonus
description=It's so nice to see you again!
description=\ ## It's so nice to see you again!
score=Your Flames Score
title=Welcome Back to Flames
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# Copyright (c) 2021 Several Circles.
#
author.earlyafternoon=Hola, %s
author.earlymorning=¡Estas llenas de energia, %s!
author.earlymorning=¿Que pasa, %s?
author.evening=Buenas, %s
author.lateafternoon=¡Buen trabajo, %s!
author.lateafternoon=Buenas tardes, %s
author.morning=Buenos dias, %s
author.night=Buenos noches, %s
author.thanksgiving=Feliz día de acción de gracias, %s
dailyBonus=Bonus diario
description=¡Que alegra verte!
description=\ ## ¡Que alegra verte!
score=Tu puntuación de Flames
title=Bienvenido de nuevo a Flames
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ author.morning=Hello !. Hello!., %s.
author.night=It's quiet at night., %s
author.thanksgiving=Liquid, %s.
dailyBonus=When there will be a bonus
description=It's better to see it again, and then.
description=\ ## It's better to see it again, and then.
score=Evaluate your flame
title=I like that name.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
#
author=About Me
created=Birthday
description=version %s
description=© 2021-2024 Several Circles\
title=**Flames** version %s
users=Flames Users
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#
author=About Me
created=Birthday
description=by Several Circles
description=© 2021-2024 Several Circles
title=**Flames** version %s
users=Flames Users
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#
author=Acerca de mí
created=Cumpleaños
description=por Several Circles
description=© 2021-2024 Several Circles
title=**Flames** versión %s
users=Usuarios de Flames
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#
author=Everything for me
created=Dal ku
description=by Several Circles
description=© 2021-2024 Several Circles
title=**Flames** version %s
users=Fire operator

0 comments on commit ff03ba0

Please sign in to comment.