Skip to content

Commit 59947b2

Browse files
generate javadocs
1 parent 9bbcdda commit 59947b2

File tree

271 files changed

+8635
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+8635
-259
lines changed

src/main/java/de/chojo/repbot/ReputationBot.java

+18
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,26 @@
1717
import java.io.IOException;
1818
import java.sql.SQLException;
1919

20+
/**
21+
* Main class for the ReputationBot application.
22+
*/
2023
public class ReputationBot {
2124
private static ReputationBot instance;
2225

26+
/**
27+
* Creates a new ReputationBot instance.
28+
*/
29+
private ReputationBot() {
30+
}
31+
32+
/**
33+
* Main method to start the ReputationBot application.
34+
*
35+
* @param args the command line arguments
36+
* @throws SQLException If the database connection fails.
37+
* @throws IOException If the configuration file fails to load.
38+
* @throws LoginException If the bot login fails.
39+
*/
2340
public static void main(String[] args) throws SQLException, IOException, LoginException {
2441
ReputationBot.instance = new ReputationBot();
2542
instance.start();
@@ -30,6 +47,7 @@ public static void main(String[] args) throws SQLException, IOException, LoginEx
3047
*
3148
* @throws SQLException If the database connection fails.
3249
* @throws IOException If the configuration file fails to load.
50+
* @throws LoginException If the bot login fails.
3351
*/
3452
private void start() throws SQLException, IOException, LoginException {
3553
var configuration = Configuration.create();

src/main/java/de/chojo/repbot/actions/messages/log/MessageLog.java

+13
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@
1111
import de.chojo.repbot.dao.provider.Guilds;
1212
import net.dv8tion.jda.api.Permission;
1313

14+
/**
15+
* Provides a message log functionality for the bot.
16+
*/
1417
public class MessageLog implements MessageProvider<Message> {
1518
private final Guilds guilds;
1619

20+
/**
21+
* Constructs a MessageLog with the specified guilds provider.
22+
*
23+
* @param guilds the guilds provider
24+
*/
1725
public MessageLog(Guilds guilds) {
1826
this.guilds = guilds;
1927
}
2028

29+
/**
30+
* Returns a configured message for logging.
31+
*
32+
* @return the configured message
33+
*/
2134
@Override
2235
public Message message() {
2336
return Message.of("Message Log")

src/main/java/de/chojo/repbot/actions/messages/log/handler/MessageAnalyzer.java

+14
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@
1111
import de.chojo.repbot.dao.provider.Guilds;
1212
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
1313

14+
/**
15+
* Handler for analyzing messages in the context of a guild.
16+
*/
1417
public class MessageAnalyzer implements MessageHandler {
1518
private final Guilds guilds;
1619

20+
/**
21+
* Constructs a new MessageAnalyzer handler.
22+
*
23+
* @param guilds the Guilds provider
24+
*/
1725
public MessageAnalyzer(Guilds guilds) {
1826
this.guilds = guilds;
1927
}
2028

29+
/**
30+
* Handles the message context interaction event.
31+
*
32+
* @param event the MessageContextInteractionEvent
33+
* @param eventContext the EventContext
34+
*/
2135
@Override
2236
public void onMessage(MessageContextInteractionEvent event, EventContext eventContext) {
2337
Analyzer.sendAnalyzerLog(event, guilds, event.getTarget().getIdLong(), eventContext);

src/main/java/de/chojo/repbot/actions/user/donated/received/UserDonated.java

+16
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@
1111
import de.chojo.repbot.dao.provider.Guilds;
1212
import net.dv8tion.jda.api.Permission;
1313

14+
/**
15+
* Class for handling user donated actions.
16+
*/
1417
public class UserDonated implements UserProvider<User> {
18+
/**
19+
* Provider for accessing guild data.
20+
*/
1521
private final Guilds guilds;
1622

23+
/**
24+
* Constructs a new UserDonated instance.
25+
*
26+
* @param guilds the guilds provider
27+
*/
1728
public UserDonated(Guilds guilds) {
1829
this.guilds = guilds;
1930
}
2031

32+
/**
33+
* Creates and returns a User object configured for donated reputation.
34+
*
35+
* @return the configured User object
36+
*/
2137
@Override
2238
public User user() {
2339
return User.of("Given Reputation").handler(new DonatedReputation(guilds))

src/main/java/de/chojo/repbot/actions/user/donated/received/handler/DonatedReputation.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@
88
import de.chojo.jdautil.interactions.user.UserHandler;
99
import de.chojo.jdautil.wrapper.EventContext;
1010
import de.chojo.repbot.commands.log.handler.Donated;
11-
import de.chojo.repbot.commands.log.handler.Received;
1211
import de.chojo.repbot.dao.provider.Guilds;
1312
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
1413

14+
/**
15+
* Handles the donated reputation user context interaction.
16+
*/
1517
public class DonatedReputation implements UserHandler {
1618
private final Guilds guilds;
1719

20+
/**
21+
* Constructs a new DonatedReputation handler.
22+
*
23+
* @param guilds the Guilds provider
24+
*/
1825
public DonatedReputation(Guilds guilds) {
1926
this.guilds = guilds;
2027
}
2128

22-
29+
/**
30+
* Handles the user context interaction event.
31+
*
32+
* @param event the user context interaction event
33+
* @param eventContext the event context
34+
*/
2335
@Override
2436
public void onUser(UserContextInteractionEvent event, EventContext eventContext) {
2537
Donated.send(event, event.getTargetMember(), guilds, eventContext);

src/main/java/de/chojo/repbot/actions/user/received/UserReceived.java

+16
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@
1111
import de.chojo.repbot.dao.provider.Guilds;
1212
import net.dv8tion.jda.api.Permission;
1313

14+
/**
15+
* Class for handling user received actions.
16+
*/
1417
public class UserReceived implements UserProvider<User> {
18+
/**
19+
* Provider for accessing guild data.
20+
*/
1521
private final Guilds guilds;
1622

23+
/**
24+
* Constructs a new UserReceived instance.
25+
*
26+
* @param guilds the guilds provider
27+
*/
1728
public UserReceived(Guilds guilds) {
1829
this.guilds = guilds;
1930
}
2031

32+
/**
33+
* Creates and returns a User object configured for received reputation.
34+
*
35+
* @return the configured User object
36+
*/
2137
@Override
2238
public User user() {
2339
return User.of("Received Reputation").handler(new ReceivedReputation(guilds))

src/main/java/de/chojo/repbot/actions/user/received/handler/ReceivedReputation.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,27 @@
1111
import de.chojo.repbot.dao.provider.Guilds;
1212
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
1313

14+
/**
15+
* Handles the received reputation user context interaction.
16+
*/
1417
public class ReceivedReputation implements UserHandler {
1518
private final Guilds guilds;
1619

20+
/**
21+
* Constructs a ReceivedReputation handler with the specified guilds provider.
22+
*
23+
* @param guilds the guilds provider
24+
*/
1725
public ReceivedReputation(Guilds guilds) {
1826
this.guilds = guilds;
1927
}
2028

21-
29+
/**
30+
* Handles the user context interaction event.
31+
*
32+
* @param event the user context interaction event
33+
* @param eventContext the event context
34+
*/
2235
@Override
2336
public void onUser(UserContextInteractionEvent event, EventContext eventContext) {
2437
Received.send(event, event.getTargetMember(), guilds, eventContext);

src/main/java/de/chojo/repbot/analyzer/ContextResolver.java

+72-16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
import static org.slf4j.LoggerFactory.getLogger;
3333

34+
/**
35+
* Class responsible for resolving context for messages and voice states.
36+
*/
3437
public class ContextResolver {
3538
private static final Logger log = getLogger(ContextResolver.class);
3639
private final Voice voiceData;
@@ -46,6 +49,12 @@ public class ContextResolver {
4649
.expireAfterWrite(10, TimeUnit.SECONDS)
4750
.build();
4851

52+
/**
53+
* Constructs a ContextResolver instance with the specified voice data and configuration.
54+
*
55+
* @param voiceData the voice data provider
56+
* @param configuration the configuration settings
57+
*/
4958
public ContextResolver(Voice voiceData, Configuration configuration) {
5059
this.voiceData = voiceData;
5160
this.configuration = configuration;
@@ -57,20 +66,29 @@ public ContextResolver(Voice voiceData, Configuration configuration) {
5766
* Only members which have written in the last 100 messages which are not older than the max history and are not
5867
* send before the first message of the message author are returned
5968
*
60-
* @param message message to determine channel, author and start time
61-
* @param settings setting sof the guild.
62-
* @return list of members which have written in this channel
69+
* @param target the target member
70+
* @param message the message to determine channel, author, and start time
71+
* @param settings the settings of the guild
72+
* @return the message context
6373
*/
6474
@NotNull
6575
public MessageContext getChannelContext(Member target, Message message, @Nullable Settings settings) {
6676
try {
6777
return messageContextCache.get(message.getIdLong(), () -> retrieveChannelContext(target, message, settings).resolve());
6878
} catch (ExecutionException e) {
69-
log.error("Could not conpute channel context.", e);
79+
log.error("Could not compute channel context.", e);
7080
}
7181
return MessageContext.byMessageAndMember(message, target);
7282
}
7383

84+
/**
85+
* Retrieves the channel context for the specified message.
86+
*
87+
* @param target the target member
88+
* @param message the message to determine channel, author, and start time
89+
* @param settings the settings of the guild
90+
* @return the message context
91+
*/
7492
private MessageContext retrieveChannelContext(Member target, Message message, Settings settings) {
7593
var history = message.getChannel().getHistoryBefore(message, configuration.analyzerSettings().historySize())
7694
.complete();
@@ -92,12 +110,12 @@ private MessageContext retrieveChannelContext(Member target, Message message, Se
92110
}
93111

94112
/**
95-
* Add the latest authors.
113+
* Adds the latest authors to the context.
96114
* <p>
97-
* Authors are considered latest when they have written a message in the last {@link AbuseProtection#minMessages()}
115+
* Authors are considered latest when they have written a message in the last {@link AbuseProtection#minMessages()}.
98116
*
99-
* @param context context to add
100-
* @param settings settings
117+
* @param context the message context
118+
* @param settings the settings of the guild
101119
*/
102120
private void addLatestAuthors(MessageContext context, @Nullable Settings settings) {
103121
var maxAge = Instant.now().minus(configuration.analyzerSettings().latestMaxHours(), ChronoUnit.HOURS);
@@ -111,12 +129,12 @@ private void addLatestAuthors(MessageContext context, @Nullable Settings setting
111129
}
112130

113131
/**
114-
* Add the recent authors.
132+
* Adds the recent authors to the context.
115133
* <p>
116-
* Authors are considered recent when they have written a message in the {@link AbuseProtection#maxMessageAge()}
134+
* Authors are considered recent when they have written a message in the {@link AbuseProtection#maxMessageAge()}.
117135
*
118-
* @param context context to add
119-
* @param settings settings
136+
* @param context the message context
137+
* @param settings the settings of the guild
120138
*/
121139
private void addRecentAuthors(MessageContext context, Settings settings) {
122140
var maxAge = Instant.now().minus(settings == null ? Long.MAX_VALUE : settings.abuseProtection()
@@ -128,11 +146,11 @@ private void addRecentAuthors(MessageContext context, Settings settings) {
128146
}
129147

130148
/**
131-
* Add the ids and messages which were newer than oldest to the context
149+
* Adds the IDs and messages which were newer than the oldest to the context.
132150
*
133-
* @param messages messages
134-
* @param context context
135-
* @param oldest oldest allowed message
151+
* @param messages the messages
152+
* @param context the message context
153+
* @param oldest the oldest allowed message
136154
*/
137155
private void addMembersAfter(Collection<Message> messages, MessageContext context, Instant oldest) {
138156
// filter message for only recent messages and after the first message of the user.
@@ -151,6 +169,13 @@ private void addMembersAfter(Collection<Message> messages, MessageContext contex
151169
context.addIds(memberIds);
152170
}
153171

172+
/**
173+
* Finds the oldest message by the target member in the context.
174+
*
175+
* @param context the message context
176+
* @param maxAge the maximum age of the message
177+
* @return the oldest message instant
178+
*/
154179
private Instant findOldestMessageByTarget(MessageContext context, Instant maxAge) {
155180
return context.rawMessages().stream()
156181
.filter(mes -> Verifier.equalSnowflake(mes.getAuthor(), context.user()))
@@ -160,6 +185,14 @@ private Instant findOldestMessageByTarget(MessageContext context, Instant maxAge
160185
.orElse(maxAge);
161186
}
162187

188+
/**
189+
* Gets the voice context for the specified message.
190+
*
191+
* @param target the target member
192+
* @param message the message to determine channel, author, and start time
193+
* @param settings the settings of the guild
194+
* @return the message context
195+
*/
163196
public MessageContext getVoiceContext(Member target, Message message, @Nullable Settings settings) {
164197
try {
165198
return voiceContextCache.get(message.getIdLong(), () -> retrieveVoiceContext(target, message, settings).resolve()
@@ -170,6 +203,14 @@ public MessageContext getVoiceContext(Member target, Message message, @Nullable
170203
return MessageContext.byMessageAndMember(message, target);
171204
}
172205

206+
/**
207+
* Retrieves the voice context for the specified message.
208+
*
209+
* @param target the target member
210+
* @param message the message to determine channel, author, and start time
211+
* @param settings the settings of the guild
212+
* @return the message context
213+
*/
173214
private MessageContext retrieveVoiceContext(Member target, Message message, @Nullable Settings settings) {
174215
var context = MessageContext.byMessageAndMember(message, target);
175216
var voiceState = target.getVoiceState();
@@ -193,10 +234,25 @@ private MessageContext retrieveVoiceContext(Member target, Message message, @Nul
193234
return context;
194235
}
195236

237+
/**
238+
* Gets the combined context for the specified message.
239+
*
240+
* @param message the message to determine channel, author, and start time
241+
* @param settings the settings of the guild
242+
* @return the combined message context
243+
*/
196244
public MessageContext getCombinedContext(Message message, @Nullable Settings settings) {
197245
return getCombinedContext(message.getMember(), message, settings);
198246
}
199247

248+
/**
249+
* Gets the combined context for the specified member and message.
250+
*
251+
* @param target the target member
252+
* @param message the message to determine channel, author, and start time
253+
* @param settings the settings of the guild
254+
* @return the combined message context
255+
*/
200256
public MessageContext getCombinedContext(Member target, Message message, @Nullable Settings settings) {
201257
return getChannelContext(target, message, settings)
202258
.combine(getVoiceContext(target, message, settings));

0 commit comments

Comments
 (0)