Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created the new localization system #8

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2bb80e1
feat(localization): created the new localization system
TheOnlyTails Jun 19, 2022
0d6fd72
Add a default case to emote and action command switches
TechnoVisionDev Jun 21, 2022
59dde33
feat(localization): migrated the levels commands to the new system
TheOnlyTails Jun 21, 2022
1060a0a
feat(l10n): added a maven plugin to auto-generate the Java schema
TheOnlyTails Jun 27, 2022
795d9da
refactor(economy): converted EconomyReply to record
TheOnlyTails Jun 27, 2022
9f35674
feature(l10n,music): migrated music commands to the new l10n system
TheOnlyTails Jun 27, 2022
a47dd93
feature(l10n,music): migrated the music listener to the new l10n system
TheOnlyTails Jun 27, 2022
806b48b
feature(l10n,staff): migrated the staff commands to the new l10n system
TheOnlyTails Jun 28, 2022
f05b744
feature(l10n,starboard): migrated the starboard commands to the new l…
TheOnlyTails Jun 28, 2022
6f535a8
feature(l10n,suggestions): migrated the suggestions commands to the n…
TheOnlyTails Jun 28, 2022
0f930da
feature(l10n,utility): migrated the utility commands to the new l10n …
TheOnlyTails Jun 28, 2022
c8bab51
chore(l10n): added descriptions to every generic parameter
TheOnlyTails Jun 28, 2022
20952d7
fix(l10n): i misspelled "boolean"
TheOnlyTails Jun 28, 2022
f62b876
fix(economy): replaced pojo methods with records methods
TheOnlyTails Jun 29, 2022
1c2fbbd
Merge remote-tracking branch 'upstream/master' into localization
TheOnlyTails Jun 29, 2022
ce87b4a
feat(l10): migrated all the new features to the l10n system
TheOnlyTails Jun 30, 2022
3c2e781
Merge branch 'master' of https://github.com/TechnoVisionDev/TechnoBot…
TheOnlyTails Jun 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .run/Generate Schema.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generate Schema" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings">
<MavenGeneralSettings>
<option name="alwaysUpdateSnapshots" value="false"/>
<option name="checksumPolicy" value="NOT_SET"/>
<option name="failureBehavior" value="NOT_SET"/>
<option name="localRepository" value=""/>
<option name="mavenHome" value="Bundled (Maven 3)"/>
<option name="nonRecursive" value="false"/>
<option name="outputLevel" value="INFO"/>
<option name="pluginUpdatePolicy" value="DEFAULT"/>
<option name="printErrorStackTraces" value="false"/>
<option name="showDialogWithAdvancedSettings" value="false"/>
<option name="threads"/>
<option name="useMavenConfig" value="true"/>
<option name="usePluginRegistry" value="false"/>
<option name="userSettingsFile" value=""/>
<option name="workOffline" value="false"/>
</MavenGeneralSettings>
</option>
<option name="myRunnerSettings">
<MavenRunnerSettings>
<option name="delegateBuildToMaven" value="false"/>
<option name="environmentProperties">
<map/>
</option>
<option name="jreName" value="#USE_PROJECT_JDK"/>
<option name="mavenProperties">
<map/>
</option>
<option name="passParentEnv" value="true"/>
<option name="runMavenInBackground" value="true"/>
<option name="skipTests" value="false"/>
<option name="vmOptions" value=""/>
</MavenRunnerSettings>
</option>
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set/>
</option>
<option name="goals">
<list>
<option value="org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.2:generate"/>
</list>
</option>
<option name="pomFileName" value="pom.xml"/>
<option name="profilesMap">
<map/>
</option>
<option name="resolveToWorkspace" value="false"/>
<option name="workingDirPath" value="$PROJECT_DIR$"/>
</MavenRunnerParameters>
</option>
</MavenSettings>
<method v="2"/>
</configuration>
</component>
Empty file modified database_init.sh
100644 → 100755
Empty file.
69 changes: 69 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>technobot</groupId>
<artifactId>TechnoBot</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/resources/localization/en_us.json</sourceDirectory>
<targetPackage>technobot.util.localization</targetPackage>
<includeAdditionalProperties>false</includeAdditionalProperties>
<includeConstructors>true</includeConstructors>
<includeGetters>false</includeGetters>
<includeSetters>false</includeSetters>
<annotationStyle>gson</annotationStyle>
<sourceType>json</sourceType>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<mainClass>technobot.TechnoBot</mainClass>
<maven.compiler.source>17</maven.compiler.source>
</properties>
</project>
33 changes: 29 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
<version>3.12.11</version>
</dependency>
<!-- https://github.com/cdimascio/dotenv-java -->
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>2.2.3</version>
<version>2.2.4</version>
</dependency>
<!-- https://github.com/Walkyst/lavaplayer-fork -->
<dependency>
Expand All @@ -67,7 +67,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
<version>4.10.0</version>
</dependency>
<!-- http://javaluator.sourceforge.net/en/home/ -->
<dependency>
Expand Down Expand Up @@ -98,14 +98,39 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<!-- https://github.com/pwall567/json-kotlin-maven -->
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<sourceDirectory>src/main/resources/localization/en_us.json</sourceDirectory>
<targetPackage>technobot.util.localization</targetPackage>
<includeAdditionalProperties>false</includeAdditionalProperties>
<includeConstructors>true</includeConstructors>
<includeGetters>false</includeGetters>
<includeSetters>false</includeSetters>
<annotationStyle>gson</annotationStyle>
<sourceType>json</sourceType>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
26 changes: 14 additions & 12 deletions src/main/java/technobot/commands/Category.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package technobot.commands;

import static technobot.util.Localization.get;

/**
* Category that represents a group of similar commands.
* Each category has a name and an emoji.
*
* @author TechnoVision
*/
public enum Category {
STAFF(":computer:", "Staff"),
LEVELS(":chart_with_upwards_trend:", "Levels"),
MUSIC(":musical_note:", "Music"),
ECONOMY(":moneybag:", "Economy"),
STARBOARD(":star:", "Starboard"),
FUN(":smile:", "Fun"),
AUTOMATION(":gear:", "Automation"),
UTILITY(":tools:", "Utility"),
GREETINGS(":wave:", "Greetings"),
SUGGESTIONS(":thought_balloon:", "Suggestions"),
CASINO(":game_die:", "Casino"),
PETS(":dog:", "Pets");
STAFF(":computer:", get(s -> s.utility.help.categories.staff)),
LEVELS(":chart_with_upwards_trend:", get(s -> s.utility.help.categories.levels)),
MUSIC(":musical_note:", get(s -> s.utility.help.categories.music)),
ECONOMY(":moneybag:", get(s -> s.utility.help.categories.economy)),
STARBOARD(":star:", get(s -> s.utility.help.categories.starboard)),
FUN(":smile:", get(s -> s.utility.help.categories.fun)),
AUTOMATION(":gear:", get(s -> s.utility.help.categories.automation)),
UTILITY(":tools:", get(s -> s.utility.help.categories.utility)),
GREETINGS(":wave:", get(s -> s.utility.help.categories.greetings)),
SUGGESTIONS(":thought_balloon:", get(s -> s.utility.help.categories.suggestions)),
CASINO(":game_die:", get(s -> s.utility.help.categories.casino)),
PETS(":dog:", get(s -> s.utility.help.categories.pets));

public final String emoji;
public final String name;
Expand Down
30 changes: 20 additions & 10 deletions src/main/java/technobot/commands/automation/AutoRoleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.Set;

import static technobot.util.Localization.get;

/**
* Command that sets roles to be given on user join.
*
Expand Down Expand Up @@ -48,27 +50,35 @@ public void execute(SlashCommandInteractionEvent event) {
case "add" -> {
Role role = event.getOption("role").getAsRole();
if (role.isManaged() || role.isPublicRole() || role.getPosition() >= event.getGuild().getBotRole().getPosition()) {
event.replyEmbeds(EmbedUtils.createError("I cannot give out roles that have a higher position than me!")).setEphemeral(true).queue();
event.replyEmbeds(EmbedUtils.createError(
get(s -> s.automation.autoRole.add.higherLevel)
)).setEphemeral(true).queue();
return;
}
if (configHandler.getConfig().getAutoRoles().size() >= 1 && !configHandler.isPremium()) {
event.replyEmbeds(EmbedUtils.createError("You can set multiple auto-roles with premium! For more info, use `/premium`.")).setEphemeral(true).queue();
event.replyEmbeds(EmbedUtils.createError(
get(s -> s.automation.autoRole.add.premium)
)).setEphemeral(true).queue();
return;
}
if (configHandler.getConfig().getAutoRoles().size() == MAX_AUTO_ROLES) {
event.replyEmbeds(EmbedUtils.createError("You have hit the maximum number of auto-roles for this guild!")).setEphemeral(true).queue();
event.replyEmbeds(EmbedUtils.createError(
get(s -> s.automation.autoRole.add.maxRolesReached)
)).setEphemeral(true).queue();
return;
}
embed = EmbedUtils.createDefault(EmbedUtils.BLUE_TICK + " The <@&"+role.getId()+"> role will be given to all new members when they join the server.");
embed = EmbedUtils.createDefault(get(s -> s.automation.autoRole.add.roleAdded, role.getId()));
configHandler.addAutoRole(role.getIdLong());
}
case "remove" -> {
Role role = event.getOption("role").getAsRole();
if (!configHandler.getConfig().getAutoRoles().contains(role.getIdLong())) {
event.replyEmbeds(EmbedUtils.createError("The <@&"+role.getId()+"> role is not set as an auto-role.")).setEphemeral(true).queue();
event.replyEmbeds(EmbedUtils.createError(
get(s -> s.automation.autoRole.remove.failure, role.getId())
)).setEphemeral(true).queue();
return;
}
embed = EmbedUtils.createDefault(EmbedUtils.BLUE_X + " The <@&"+role.getId()+"> role will no longer be given to new members when they join the server.");
embed = EmbedUtils.createDefault(get(s -> s.automation.autoRole.remove.success, role.getId()));
if (!configHandler.isPremium()) {
configHandler.clearAutoRoles();
} else {
Expand All @@ -79,19 +89,19 @@ public void execute(SlashCommandInteractionEvent event) {
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Auto Roles").setColor(EmbedColor.DEFAULT.color);
Set<Long> roles = configHandler.getConfig().getAutoRoles();
if (roles == null || roles.isEmpty()) {
embedBuilder.setDescription("Use `/auto-role add <role>` to set your first auto role!");
embedBuilder.setDescription(get(s -> s.automation.autoRole.list.noAutoRoles));
} else {
int max = configHandler.isPremium() ? MAX_AUTO_ROLES : 1;
if (max == 1) {
embedBuilder.appendDescription("Add additional roles with `/premium`\n");
embedBuilder.appendDescription(get(s -> s.automation.autoRole.list.premium) + "\n");
} else {
embedBuilder.appendDescription("There are "+roles.size()+" auto roles given to new members:\n");
embedBuilder.appendDescription(get(s -> s.automation.autoRole.list.roleCount, roles.size()) + "\n");
}
int count = 0;
for (long roleID : roles) {
if (event.getGuild().getRoleById(roleID) != null) {
count++;
embedBuilder.appendDescription("\n**"+count+".** <@&"+roleID+">");
embedBuilder.appendDescription("\n" + get(s -> s.automation.autoRole.list.role, count, roleID));
if (count == max) break;
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/technobot/commands/economy/BalanceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import technobot.handlers.economy.EconomyHandler;
import technobot.util.embeds.EmbedColor;

import static technobot.util.Localization.get;

/**
* Command that shows your current cash and bank balance on the server.
*
Expand All @@ -31,8 +33,7 @@ public BalanceCommand(TechnoBot bot) {

public void execute(SlashCommandInteractionEvent event) {
// Get user
OptionMapping userOption = event.getOption("user");
User user = (userOption != null) ? userOption.getAsUser() : event.getUser();
User user = event.getOption("user", event.getUser(), OptionMapping::getAsUser);

// Get balance and bank values
EconomyHandler economyHandler = GuildData.get(event.getGuild()).economyHandler;
Expand All @@ -54,12 +55,12 @@ public void execute(SlashCommandInteractionEvent event) {
// Send embed message
String currency = economyHandler.getCurrency();
EmbedBuilder embed = new EmbedBuilder()
.setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl())
.setDescription("Leaderboard Rank: #" + economyHandler.getRank(user.getIdLong()))
.addField("Cash:", currency + " " + EconomyHandler.FORMATTER.format(balance), true)
.addField("Bank:", currency + " " + EconomyHandler.FORMATTER.format(bank), true)
.addField("Total:", currency + " " + EconomyHandler.FORMATTER.format(total), true)
.setColor(EmbedColor.DEFAULT.color);
.setAuthor(user.getAsTag(), null, user.getEffectiveAvatarUrl())
.setDescription(get(s -> s.economy.balance.leaderboardRank, economyHandler.getRank(user.getIdLong())))
.addField(get(s -> s.economy.balance.cash), currency + " " + EconomyHandler.FORMATTER.format(balance), true)
.addField(get(s -> s.economy.balance.bank), currency + " " + EconomyHandler.FORMATTER.format(bank), true)
.addField(get(s -> s.economy.balance.total), currency + " " + EconomyHandler.FORMATTER.format(total), true)
.setColor(EmbedColor.DEFAULT.color);
event.replyEmbeds(embed.build()).queue();
}
}
12 changes: 7 additions & 5 deletions src/main/java/technobot/commands/economy/BuyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import technobot.util.placeholders.Placeholder;
import technobot.util.placeholders.PlaceholderFactory;

import static technobot.util.Localization.get;

/**
* Command that buys an item from the server shop.
*
Expand All @@ -40,7 +42,9 @@ public void execute(SlashCommandInteractionEvent event) {
String itemName = event.getOption("item").getAsString();
Item item = guildData.configHandler.getItem(itemName);
if (item == null) {
event.replyEmbeds(EmbedUtils.createError("That item doesn't exist! See all valid items with `/shop`")).setEphemeral(true).queue();
event.replyEmbeds(EmbedUtils.createError(
get(s -> s.economy.buy.noItem)
)).setEphemeral(true).queue();
return;
}

Expand All @@ -59,8 +63,7 @@ public void execute(SlashCommandInteractionEvent event) {
// Purchase was successful
econ.buyItem(event.getUser().getIdLong(), item);
if (item.getShowInInventory()) {
String price = econ.getCurrency() + " " + item.getPrice();
String text = EmbedUtils.GREEN_TICK + " You have bought 1 " + item.getName() + " for " + price + "! This is now in your inventory.\nUse this item with the `/use <item>` command.";
String text = get(s -> s.economy.buy.success, item.getName(), item.getPrice());
EmbedBuilder embed = new EmbedBuilder()
.setColor(EmbedColor.SUCCESS.color)
.setAuthor(event.getUser().getAsTag(), null, event.getUser().getEffectiveAvatarUrl())
Expand All @@ -81,8 +84,7 @@ public void execute(SlashCommandInteractionEvent event) {
}
} else {
// Not enough money to purchase
String value = econ.getCurrency() + " " + EconomyHandler.FORMATTER.format(balance);
String text = " You do not have enough money to buy this item. You currently have "+value+" on hand.";
String text = get(s -> s.economy.buy.noMoney, EconomyHandler.FORMATTER.format(balance));
EmbedBuilder embed = new EmbedBuilder().setDescription(EmbedUtils.RED_X + text).setColor(EmbedColor.ERROR.color);
event.replyEmbeds(embed.build()).setEphemeral(true).queue();
}
Expand Down
Loading