Skip to content

Commit adae49c

Browse files
[translate] Update locale
1 parent 8d98397 commit adae49c

21 files changed

Lines changed: 327 additions & 134 deletions

File tree

build.gradle.kts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
2+
import org.jetbrains.gradle.ext.runConfigurations
3+
import org.jetbrains.gradle.ext.settings
24
import java.time.ZoneOffset
35
import java.time.ZonedDateTime
46
import java.time.format.DateTimeFormatter
57

68
plugins {
79
alias(libs.plugins.shadow)
810
alias(libs.plugins.spotless)
11+
id("org.jetbrains.gradle.plugin.idea-ext") version "1.3"
912
java
1013
}
1114

@@ -28,7 +31,7 @@ spotless {
2831
}
2932

3033
dependencies {
31-
//discord
34+
// discord
3235
implementation("de.chojo", "cjda-util", "2.12.0+jda-6.0.0") {
3336
exclude(group = "club.minnced", module = "opus-java")
3437
}
@@ -68,25 +71,43 @@ java {
6871
withJavadocJar()
6972
}
7073

74+
idea {
75+
project {
76+
settings {
77+
runConfigurations {
78+
register<org.jetbrains.gradle.ext.Application>("App-Testing") {
79+
mainClass = "de.chojo.repbot.ReputationBot"
80+
jvmArgs = listOf("-Dbot.config=config/config-testing.json",
81+
"-Dlog4j2.configurationFile=docker/config/log4j2-testing.xml",
82+
"-Dcjda.localisation.error.name=false",
83+
"-Dcjda.interactions.cleanguildcommands=true",
84+
"-Dcjda.interactions.testmode=true").joinToString(" ")
85+
moduleName = "rep-bot.main"
86+
}
87+
}
88+
}
89+
}
90+
}
91+
7192
tasks {
7293
processResources {
7394
from(sourceSets.main.get().resources.srcDirs) {
7495
filesMatching("version") {
7596
var version = project.version.toString()
76-
var workflow = (System.getenv("GITHUB_ACTIONS")?: "false") == "true"
77-
if(workflow){
97+
var workflow = (System.getenv("GITHUB_ACTIONS") ?: "false") == "true"
98+
if (workflow) {
7899
val now = ZonedDateTime.now(ZoneOffset.UTC)
79100
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
80101
val formattedDate = now.format(formatter)
81102

82-
version = when(System.getenv("GITHUB_REF_TYPE")){
103+
version = when (System.getenv("GITHUB_REF_TYPE")) {
83104
"branch" -> "$version ${System.getenv("GITHUB_REF_NAME")}-${System.getenv("GITHUB_SHA").substring(0, 7)} @ $formattedDate"
84105
"tag" -> "$version ${System.getenv("GITHUB_REF_NAME").substring(1)} @ $formattedDate"
85106
else -> "$version snapshot"
86107
}
87108
}
88109
expand(
89-
"version" to version
110+
"version" to version
90111
)
91112
}
92113
duplicatesStrategy = DuplicatesStrategy.INCLUDE

docker/config/log4j2-testing.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN" shutdownHook="disable" packages="de.chojo.logutil.appender">
3+
<Appenders>
4+
<!-- Console logger for debugging (prints stacktrace) -->
5+
<Console name="ConsoleDebug" target="SYSTEM_OUT">
6+
<PatternLayout
7+
pattern="%highlight{[%d{HH:mm:ss]}[%p{length=3}][%c] %m%n}{FATAL=black, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue, TRACE=white}"
8+
disableAnsi="false"/>
9+
</Console>
10+
11+
<RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd}.log">
12+
<PatternLayout pattern="[%d{HH:mm:ss]}[%p{length=3}][%15.15c{1}] %m%ex%n"/>
13+
<Policies>
14+
<OnStartupTriggeringPolicy/>
15+
<TimeBasedTriggeringPolicy/>
16+
</Policies>
17+
<DefaultRolloverStrategy max="10"/>
18+
</RollingFile>
19+
</Appenders>
20+
<Loggers>
21+
<!-- remove too verbose library logging -->
22+
<Logger name="net.dv8tion.jda" level="INFO"/>
23+
<Logger name="org.eclipse.jetty" level="INFO"/>
24+
<Logger name="com.zaxxer.hikari" level="INFO"/>
25+
26+
<Root level="TRACE">
27+
<AppenderRef ref="ConsoleDebug"/>
28+
<AppenderRef ref="RollingFile"/>
29+
</Root>
30+
</Loggers>
31+
</Configuration>

src/main/java/de/chojo/repbot/commands/bot/handler/Sample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ON CONFLICT(guild_id, donor_id, receiver_id, message_id)
9494
AnalyzerResult.answer(receiver.getEffectiveName(), donor, receiver, build(refMessage, channel, receiver));
9595
case DIRECT, EMBED, REACTION ->
9696
AnalyzerResult.empty(receiver.getEffectiveName(), EmptyResultReason.NO_MATCH);
97+
case COMMAND -> null;
9798
};
9899

99100
addAnalyzerResult(receiver.getGuild(), channel, messageId, result);
@@ -112,6 +113,7 @@ private Message build(long messageId, TextChannel channel, Member member) {
112113
}
113114

114115
public void addAnalyzerResult(Guild guild, TextChannel guildChannel, long messageId, AnalyzerResult result) {
116+
if(result == null) return;
115117
String resultString;
116118
try {
117119
resultString = MAPPER.writeValueAsString(result.toSnapshot());

src/main/java/de/chojo/repbot/commands/messages/handler/States.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
4141
"command.messages.states.message.option.reactionconfirmation.name",
4242
"command.messages.states.message.choice.reactionConfirmation.true",
4343
"command.messages.states.message.choice.reactionConfirmation.false",
44-
settings.reputation().isReactionActive());
44+
settings.messages().isReactionConfirmation());
45+
var commandReply = getMenu("reaction_confirmation",
46+
"command.messages.states.message.option.reactionconfirmation.name",
47+
"command.messages.states.message.choice.reactionConfirmation.true",
48+
"command.messages.states.message.choice.reactionConfirmation.false",
49+
settings.messages().isReactionConfirmation());
4550

4651
context.registerMenu(MenuAction.forCallback(getSettings(context, settings), event)
4752
.addComponent(MenuEntry.of(setting, ctx -> {
@@ -58,6 +63,9 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
5863
.addComponent(MenuEntry.of(reactions, ctx -> refresh(ctx, res -> settings.messages()
5964
.reactionConfirmation(res), context, settings))
6065
.hidden())
66+
.addComponent(MenuEntry.of(commandReply, ctx -> refresh(ctx, res -> settings.messages()
67+
.commandReputationEphemeral(res), context, settings))
68+
.hidden())
6169
.asEphemeral()
6270
.build());
6371
}

src/main/java/de/chojo/repbot/commands/repsettings/handler/Info.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
4141
.addOption("command.repsettings.info.message.option.bymention.name", "mention", "command.repsettings.info.message.option.bymention.description")
4242
.addOption("command.repsettings.info.message.option.byfuzzy.name", "fuzzy", "command.repsettings.info.message.option.byfuzzy.description")
4343
.addOption("command.repsettings.info.message.option.byembed.name", "embed", "command.repsettings.info.message.option.byembed.description")
44-
.addOption("command.repsettings.info.message.option.emojidebug.name", "emojidebug", "command.repsettings.info.message.option.emojidebug.description")
44+
.addOption("command.repsettings.info.message.option.bycommand.name", "command", "command.repsettings.info.message.option.bycommand.description")
4545
.addOption("command.repsettings.info.message.option.skipsingletarget.name", "directembed", "command.repsettings.info.message.option.skipsingletarget.description")
4646
.addOption("command.repsettings.info.message.option.reputationmode.name", "reputationmode", "command.repsettings.info.message.option.reputationmode.description")
4747
.build();
@@ -70,6 +70,11 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
7070
"command.repsettings.info.message.embed.true",
7171
"command.repsettings.info.message.embed.false",
7272
guildSettings.reputation().isEmbedActive());
73+
var command = getMenu("command",
74+
"command.repsettings.info.message.option.bycommand.description",
75+
"command.repsettings.info.message.bycommand.true",
76+
"command.repsettings.info.message.bycommand.false",
77+
guildSettings.reputation().isCommandActive());
7378
var skipSingleEmbed = getMenu("directembed",
7479
"command.repsettings.info.message.option.skipsingletarget.description",
7580
"command.repsettings.info.message.skipsingleembed.true",
@@ -113,6 +118,12 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
113118
.addComponent(MenuEntry.of(embed, ctx -> refresh(ctx, res -> guildSettings.reputation()
114119
.embedActive(res), context, guildSettings))
115120
.hidden())
121+
.addComponent(MenuEntry.of(command, ctx -> refresh(ctx, res -> {
122+
guildSettings.reputation().commandActive(res);
123+
// The command needs to be hidden or enabled additionally
124+
context.interactionHub().refreshGuildCommands(event.getGuild());
125+
}, context, guildSettings))
126+
.hidden())
116127
.addComponent(MenuEntry.of(skipSingleEmbed, ctx -> refresh(ctx, res -> guildSettings.reputation()
117128
.directActive(res), context, guildSettings))
118129
.hidden())

src/main/java/de/chojo/repbot/commands/rep/Rep.java renamed to src/main/java/de/chojo/repbot/commands/reputation/Reputation.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,32 @@
33
*
44
* Copyright (C) RainbowDashLabs and Contributor
55
*/
6-
package de.chojo.repbot.commands.rep;
6+
package de.chojo.repbot.commands.reputation;
77

8-
import de.chojo.jdautil.interactions.slash.Argument;
98
import de.chojo.jdautil.interactions.slash.Slash;
109
import de.chojo.jdautil.interactions.slash.provider.SlashProvider;
11-
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler;
12-
import de.chojo.jdautil.wrapper.EventContext;
13-
import de.chojo.repbot.commands.rep.handler.Give;
10+
import de.chojo.repbot.commands.reputation.handler.Give;
1411
import de.chojo.repbot.dao.provider.GuildRepository;
1512
import de.chojo.repbot.service.reputation.ReputationService;
16-
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
17-
import net.dv8tion.jda.api.interactions.commands.Command;
1813

1914
import static de.chojo.jdautil.interactions.slash.Argument.user;
2015

21-
public class Rep implements SlashProvider<Slash> {
16+
public class Reputation implements SlashProvider<Slash> {
2217
private final GuildRepository guildRepository;
2318
private ReputationService reputationService;
2419

25-
public Rep(GuildRepository guildRepository, ReputationService reputationService) {
20+
public Reputation(GuildRepository guildRepository, ReputationService reputationService) {
2621
this.guildRepository = guildRepository;
2722
this.reputationService = reputationService;
2823
}
2924

3025

3126
@Override
3227
public Slash slash() {
33-
return Slash.of("rep", "commands.rep.description")
28+
return Slash.of("reputation", "command.reputation.description")
29+
.privateCommand()
3430
.command(new Give(guildRepository, reputationService))
35-
.argument(user("user", "commands.rep.options.user.description"))
31+
.argument(user("user", "command.reputation.user.description"))
3632
.build();
3733
}
3834
}

src/main/java/de/chojo/repbot/commands/rep/handler/Give.java renamed to src/main/java/de/chojo/repbot/commands/reputation/handler/Give.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
package de.chojo.repbot.commands.rep.handler;
1+
/*
2+
* SPDX-License-Identifier: AGPL-3.0-only
3+
*
4+
* Copyright (C) RainbowDashLabs and Contributor
5+
*/
6+
package de.chojo.repbot.commands.reputation.handler;
27

38
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler;
9+
import de.chojo.jdautil.localization.util.Replacement;
410
import de.chojo.jdautil.wrapper.EventContext;
511
import de.chojo.repbot.analyzer.results.match.ThankType;
612
import de.chojo.repbot.dao.access.guild.RepGuild;
713
import de.chojo.repbot.dao.provider.GuildRepository;
14+
import de.chojo.repbot.service.reputation.ReputationContext;
815
import de.chojo.repbot.service.reputation.ReputationService;
16+
import de.chojo.repbot.service.reputation.SubmitResultType;
917
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
1018
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
1119

@@ -27,8 +35,11 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
2735
return;
2836
}
2937

30-
event.getIdLong()
31-
32-
reputationService.submitReputation(event.getGuild(), event.getMember(), event.getOption("user", OptionMapping::getAsMember), null, null, ThankType.ANSWER);
38+
var result = reputationService.submitReputation(event.getGuild(), event.getMember(), event.getOption("user", OptionMapping::getAsMember), ReputationContext.fromInteraction(event), null, ThankType.ANSWER);
39+
if (result.type() == SubmitResultType.SUCCESS) {
40+
event.reply("success").setEphemeral(guild.settings().messages().isReactionConfirmation()).queue();
41+
} else {
42+
event.reply(context.guildLocale(result.type().localeKey(), result.replacements().toArray(Replacement[]::new))).setEphemeral(true).queue();
43+
}
3344
}
3445
}

src/main/java/de/chojo/repbot/core/Bot.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import de.chojo.repbot.commands.prune.Prune;
3232
import de.chojo.repbot.commands.ranking.Ranking;
3333
import de.chojo.repbot.commands.reactions.Reactions;
34-
import de.chojo.repbot.commands.rep.Rep;
34+
import de.chojo.repbot.commands.reputation.Reputation;
3535
import de.chojo.repbot.commands.repadmin.RepAdmin;
3636
import de.chojo.repbot.commands.repsettings.RepSettings;
3737
import de.chojo.repbot.commands.roles.Roles;
@@ -132,7 +132,7 @@ private void initShardManager() throws LoginException {
132132

133133
repBotCachePolicy = new RepBotCachePolicy(scan, roles);
134134
shardManager = DefaultShardManagerBuilder
135-
.createDefault(SysVar.envOrProp("BOT_TOKEN","bot.token",configuration.baseSettings().token()))
135+
.createDefault(SysVar.envOrProp("BOT_TOKEN", "bot.token", configuration.baseSettings().token()))
136136
.setEventPassthrough(true)
137137
.enableIntents(
138138
// Required to retrieve reputation emotes
@@ -245,7 +245,7 @@ private void initInteractions() {
245245
new Messages(guilds),
246246
botAdmin,
247247
new Ranking(guilds, configuration),
248-
new Rep(guilds, reputationService)/*TODO: remove rep command*/,
248+
new Reputation(guilds, reputationService)/*TODO: remove rep command*/,
249249
new Supporter(premiumService, configuration, guilds))
250250
.withMessages(new MessageLog(guilds))
251251
.withUsers(new UserReceived(guilds, configuration),
@@ -266,7 +266,11 @@ private void initInteractions() {
266266
log.error(LogNotify.NOTIFY_ADMIN, "Command execution of {} failed\n{}",
267267
context.interaction().meta().name(), context.args(), throwable);
268268
})
269-
.withGuildCommandMapper(cmd -> Collections.singletonList(configuration.baseSettings().botGuild()))
269+
.withGuildCommandMapper(cmd -> switch (cmd.name()) {
270+
case "bot" -> Collections.singletonList(configuration.baseSettings().botGuild());
271+
case "rep" -> data.guilds().byCommandReputationEnabled();
272+
default -> Collections.emptyList();
273+
})
270274
.withDefaultMenuService()
271275
.withPostCommandHook(result -> data.metrics().commands()
272276
.logCommand(result.context().interaction().meta().name()))

src/main/java/de/chojo/repbot/dao/access/guild/reputation/sub/RepUser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import de.chojo.repbot.dao.snapshots.ChannelStats;
1616
import de.chojo.repbot.dao.snapshots.RepProfile;
1717
import de.chojo.repbot.dao.snapshots.ReputationLogEntry;
18+
import de.chojo.repbot.service.reputation.ReputationContext;
1819
import de.chojo.repbot.util.QueryLoader;
1920
import net.dv8tion.jda.api.entities.Guild;
2021
import net.dv8tion.jda.api.entities.Member;
@@ -111,7 +112,7 @@ INSERT INTO reputation_offset(guild_id, user_id, amount) VALUES (?,?,?)
111112
* @param type type of reputation
112113
* @return true if the reputation was logged.
113114
*/
114-
public boolean addReputation(@Nullable Member donor, @NotNull Message message, @Nullable Message refMessage, ThankType type) {
115+
public boolean addReputation(@Nullable Member donor, @NotNull ReputationContext message, @Nullable Message refMessage, ThankType type) {
115116
var success = query("""
116117
INSERT INTO
117118
reputation_log(guild_id, donor_id, receiver_id, message_id, ref_message_id, channel_id, cause) VALUES(?,?,?,?,?,?,?)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import de.chojo.repbot.dao.access.guild.settings.Settings;
99
import de.chojo.repbot.dao.components.GuildHolder;
10+
import de.chojo.repbot.service.reputation.ReputationContext;
1011
import de.chojo.sadu.mapper.wrapper.Row;
1112
import de.chojo.sadu.queries.api.call.Call;
1213
import net.dv8tion.jda.api.entities.Guild;
@@ -207,6 +208,11 @@ public int maxMessageReputation(int maxMessageReputation) {
207208
return this.maxMessageReputation;
208209
}
209210

211+
public boolean isOldMessage(ReputationContext context) {
212+
if(context.isInteraction()) return false;
213+
return isOldMessage(context.asMessage());
214+
}
215+
210216
public boolean isOldMessage(Message message) {
211217
if (maxMessageAge == 0) return false;
212218
var until = message.getTimeCreated().toInstant().until(Instant.now(), ChronoUnit.MINUTES);

0 commit comments

Comments
 (0)