Skip to content

Commit 41560b6

Browse files
[translate] Finish implementation
1 parent dbbad76 commit 41560b6

15 files changed

Lines changed: 52 additions & 21 deletions

src/main/java/de/chojo/repbot/commands/abuseprotection/AbuseProtection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public AbuseProtection(GuildRepository guildRepository) {
6767
.asRequired()))
6868
.subCommand(SubCommand.of("get", "command.abuseprotection.cooldown.get.description")
6969
.handler(new GetCooldown(guildRepository)))
70-
.subCommand(SubCommand.of("once", "command.abuseptorection.cooldown.once.description")
70+
.subCommand(SubCommand.of("once", "command.abuseprotection.cooldown.once.description")
7171
.handler(new OnceCooldown(guildRepository)))
7272
.subCommand(SubCommand.of("direction", "command.abuseprotection.cooldown.direction.description")
7373
.handler(new SetCooldownDirection(guildRepository))

src/main/java/de/chojo/repbot/commands/abuseprotection/handler/cooldown/GetCooldown.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ public GetCooldown(GuildRepository guildRepository) {
1717
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) {
1818
var guild = guildRepository.guild(event.getGuild());
1919
var abuseSettings = guild.settings().abuseProtection();
20+
String message="";
2021
if(abuseSettings.cooldown() == 0){
21-
// disabled
22-
event.reply(context.localize("command.abuseprotection.cooldown.get.message.disabled")).queue();
22+
message = context.localize("command.abuseprotection.cooldown.get.message.disabled");
23+
}else if(abuseSettings.cooldown() < 0){
24+
message = context.localize("command.abuseprotection.cooldown.once.message.set");
25+
}else {
26+
message = context.localize("command.abuseprotection.cooldown.get.message.get",
27+
Replacement.create("MINUTES", abuseSettings.cooldown()));
2328
}
24-
if(abuseSettings.cooldown() < 0){
25-
event.reply(context.localize("command.abuseprotection.cooldown.once.message.set")).queue();
26-
return;
27-
}
28-
event.reply(context.localize("command.abuseprotection.cooldown.get.message.get",
29-
Replacement.create("MINUTES", abuseSettings.cooldown()))).queue();
29+
message = message + "\n$words.direction$: $%s$".formatted(abuseSettings.cooldownDirection().localCode());
30+
event.reply(context.localize(message)).setEphemeral(true).queue();
3031
}
3132
}

src/main/java/de/chojo/repbot/commands/abuseprotection/handler/cooldown/OnceCooldown.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
1919
var abuseSettings = guild.settings().abuseProtection();
2020

2121
event.reply(context.localize("command.abuseprotection.cooldown.once.message.set",
22-
Replacement.create("MINUTES", abuseSettings.cooldown(-1)))).queue();
22+
Replacement.create("MINUTES", abuseSettings.cooldown(-1)))).setEphemeral(true).queue();
2323

2424
}
2525
}

src/main/java/de/chojo/repbot/commands/abuseprotection/handler/cooldown/SetCooldown.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
2525
var cooldown = event.getOption("minutes").getAsLong();
2626

2727
event.reply(context.localize("command.abuseprotection.cooldown.set.message.set",
28-
Replacement.create("MINUTES", abuseSettings.cooldown((int) cooldown)))).queue();
28+
Replacement.create("MINUTES", abuseSettings.cooldown((int) cooldown)))).setEphemeral(true).queue();
2929
}
3030
}

src/main/java/de/chojo/repbot/commands/abuseprotection/handler/cooldown/SetCooldownDirection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import de.chojo.jdautil.wrapper.EventContext;
77
import de.chojo.repbot.dao.access.guild.settings.sub.CooldownDirection;
88
import de.chojo.repbot.dao.provider.GuildRepository;
9+
import de.chojo.repbot.util.Parser;
910
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
1011
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
1112

@@ -20,10 +21,10 @@ public SetCooldownDirection(GuildRepository guildRepository) {
2021
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) {
2122
var guild = guildRepository.guild(event.getGuild());
2223
var abuseSettings = guild.settings().abuseProtection();
23-
var cooldown = CooldownDirection.valueOf(event.getOption("direction").getAsString());
24+
var cooldown = Parser.parseEnum(event.getOption("direction").getAsString(), CooldownDirection.class);
2425

2526
event.reply(context.localize("command.abuseprotection.cooldown.direction.message.set",
26-
Replacement.create("DIRECTION", abuseSettings.cooldownDirection(cooldown)))).queue();
27+
Replacement.create("DIRECTION", abuseSettings.cooldownDirection(cooldown).localCode()))).setEphemeral(true).queue();
2728
}
2829

2930
@Override

src/main/java/de/chojo/repbot/dao/access/guild/settings/sub/AbuseProtection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public AbuseProtection(Settings settings, int cooldown, CooldownDirection cooldo
3939
int maxGiven, int maxGivenHours, int maxReceived, int maxReceivedHours, int maxMessageReputation) {
4040
this.settings = settings;
4141
this.cooldown = cooldown;
42+
this.cooldownDirection = cooldownDirection;
4243
this.maxMessageAge = maxMessageAge;
4344
this.minMessages = minMessages;
4445
this.donorContext = donorContext;

src/main/java/de/chojo/repbot/dao/access/guild/settings/sub/CooldownDirection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public enum CooldownDirection {
55
BIDIRECTIONAL;
66

77
public String localCode() {
8-
return getClass().getSimpleName().toLowerCase() + "." + this.name().toLowerCase();
8+
return "$%s$".formatted(getClass().getSimpleName().toLowerCase() + "." + this.name().toLowerCase());
99
}
1010
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.chojo.repbot.util;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
import java.util.Objects;
6+
7+
public final class Parser {
8+
private Parser() {
9+
throw new UnsupportedOperationException("This is a utility class.");
10+
}
11+
12+
@Nullable
13+
public static <T extends Enum<T>> T parseEnum(String value, Class<T> enumClass) {
14+
for (T constant : enumClass.getEnumConstants()) {
15+
if (constant.name().equalsIgnoreCase(value)) {
16+
return constant;
17+
}
18+
}
19+
return null;
20+
}
21+
22+
public static <T extends Enum<T>> Enum<T> parseEnum(String value, Class<T> enumClass, Enum<T> defaultValue) {
23+
return Objects.requireNonNullElse(parseEnum(value, enumClass), defaultValue);
24+
}
25+
}

src/main/resources/locale.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ command.abuseprotection.message.min.options.messages.description=
4848
command.abuseprotection.message.reputation.description=
4949
command.abuseprotection.message.reputation.message.get=
5050
command.abuseprotection.message.reputation.options.amount.description=
51-
command.abuseptorection.cooldown.once.description=
51+
command.abuseprotection.cooldown.once.description=
5252
command.channel.add.description=
5353
command.channel.add.message.added=
5454
command.channel.add.options.channel.description=
@@ -533,3 +533,4 @@ words.reputationOffset=
533533
words.role=
534534
words.subscription=
535535
words.unknown=
536+
words.direction=

src/main/resources/locale_de.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ command.abuseprotection.message.min.options.messages.description=Die Mindestanza
4848
command.abuseprotection.message.reputation.description=Legt die maximale Menge an gegebener Reputation mit einer einzelnen Nachricht fest.
4949
command.abuseprotection.message.reputation.message.get=Es kann maximal %VALUE% Reputation mit einer einzigen Nachricht vergeben werden.
5050
command.abuseprotection.message.reputation.options.amount.description=Die maximale Reputation pro Nachricht.
51-
command.abuseptorection.cooldown.once.description=Leg die Abklingzeit fest, damit die Reputation nur einmal an einen bestimmten Nutzer vergeben werden kann.
51+
command.abuseprotection.cooldown.once.description=Leg die Abklingzeit fest, damit die Reputation nur einmal an einen bestimmten Nutzer vergeben werden kann.
5252
command.channel.add.description=Fügt einen Reputationskanal hinzu.
5353
command.channel.add.message.added=Der folgende Kanal oder die folgende Kategorie wurde zu den Reputationskanälen hinzugefügt:\n%CHANNEL%
5454
command.channel.add.options.channel.description=Der neue Reputationskanal oder die neue Kategorie.
@@ -533,3 +533,4 @@ words.reputationOffset=Reputationsversatz
533533
words.role=Rolle
534534
words.subscription=Abonnement
535535
words.unknown=Unbekannt
536+
words.direction=Richtung

0 commit comments

Comments
 (0)