Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ shadowJar {
}

dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.jetbrains:annotations:23.0.0'

implementation project(':database')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.jetbrains.annotations.NotNull;
import net.dv8tion.jda.api.requests.GatewayIntent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.togetherjava.tjbot.commands.Features;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.commands.system.BotCore;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;

import javax.security.auth.login.LoginException;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -114,8 +111,7 @@ private static void onShutdown() {
logger.info("Bot has been stopped");
}

private static void onUncaughtException(@NotNull Thread failingThread,
@NotNull Throwable failure) {
private static void onUncaughtException(Thread failingThread, Throwable failure) {
logger.error("Unknown error in thread {}.", failingThread.getName(), failure);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.JDA;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.basic.PingCommand;
import org.togetherjava.tjbot.commands.basic.RoleSelectCommand;
import org.togetherjava.tjbot.commands.basic.SuggestionsUpDownVoter;
Expand Down Expand Up @@ -32,6 +31,7 @@
import org.togetherjava.tjbot.moderation.ModAuditLogWriter;
import org.togetherjava.tjbot.routines.ModAuditLogRoutine;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;

Expand Down Expand Up @@ -59,8 +59,8 @@ private Features() {
* @param config the configuration features should use
* @return a collection of all features
*/
public static @NotNull Collection<Feature> createFeatures(@NotNull JDA jda,
@NotNull Database database, @NotNull Config config) {
@Nonnull
public static Collection<Feature> createFeatures(JDA jda, Database database, Config config) {
TagSystem tagSystem = new TagSystem(database);
ModerationActionsStore actionsStore = new ModerationActionsStore(database);
ModAuditLogWriter modAuditLogWriter = new ModAuditLogWriter(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.regex.Pattern;

/**
Expand All @@ -28,7 +28,7 @@ public interface MessageReceiver extends Feature {
*
* @return the pattern matching the names of relevant channels
*/
@NotNull
@Nonnull
Pattern getChannelNamePattern();

/**
Expand All @@ -38,7 +38,7 @@ public interface MessageReceiver extends Feature {
* @param event the event that triggered this, containing information about the corresponding
* message that was sent and received
*/
void onMessageReceived(@NotNull MessageReceivedEvent event);
void onMessageReceived(MessageReceivedEvent event);

/**
* Triggered by the core system whenever an existing message was edited in a text channel of a
Expand All @@ -47,5 +47,5 @@ public interface MessageReceiver extends Feature {
* @param event the event that triggered this, containing information about the corresponding
* message that was edited
*/
void onMessageUpdated(@NotNull MessageUpdateEvent event);
void onMessageUpdated(MessageUpdateEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.regex.Pattern;

/**
Expand All @@ -24,24 +24,25 @@ public abstract class MessageReceiverAdapter implements MessageReceiver {
* @param channelNamePattern the pattern matching names of channels interested in, only messages
* from matching channels will be received
*/
protected MessageReceiverAdapter(@NotNull Pattern channelNamePattern) {
protected MessageReceiverAdapter(Pattern channelNamePattern) {
this.channelNamePattern = channelNamePattern;
}

@Override
public final @NotNull Pattern getChannelNamePattern() {
@Nonnull
public final Pattern getChannelNamePattern() {
return channelNamePattern;
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
public void onMessageReceived(MessageReceivedEvent event) {
// Adapter does not react by default, subclasses may change this behavior
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onMessageUpdated(@NotNull MessageUpdateEvent event) {
public void onMessageUpdated(MessageUpdateEvent event) {
// Adapter does not react by default, subclasses may change this behavior
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.togetherjava.tjbot.commands;

import net.dv8tion.jda.api.JDA;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -24,15 +24,15 @@ public interface Routine extends Feature {
*
* @return the schedule of this routine
*/
@NotNull
@Nonnull
Schedule createSchedule();

/**
* Triggered by the core system on the schedule defined by {@link #createSchedule()}.
*
* @param jda the JDA instance the bot is operating with
*/
void runRoutine(@NotNull JDA jda);
void runRoutine(JDA jda);

/**
* The schedule of routines.
Expand All @@ -46,8 +46,7 @@ public interface Routine extends Feature {
* @param unit the time unit for both, {@link #initialDuration} and {@link #duration}, e.g.
* seconds
*/
record Schedule(@NotNull ScheduleMode mode, long initialDuration, long duration,
@NotNull TimeUnit unit) {
record Schedule(ScheduleMode mode, long initialDuration, long duration, TimeUnit unit) {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import org.togetherjava.tjbot.commands.componentids.Lifespan;

import javax.annotation.Nonnull;
import java.util.List;

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ public interface SlashCommand extends UserInteractor {
*
* @return the description of the command
*/
@NotNull
@Nonnull
String getDescription();

/**
Expand All @@ -59,7 +59,7 @@ public interface SlashCommand extends UserInteractor {
*
* @return the visibility of the command
*/
@NotNull
@Nonnull
SlashCommandVisibility getVisibility();

/**
Expand All @@ -77,7 +77,7 @@ public interface SlashCommand extends UserInteractor {
*
* @return the command data of this command
*/
@NotNull
@Nonnull
SlashCommandData getData();

/**
Expand Down Expand Up @@ -118,5 +118,5 @@ public interface SlashCommand extends UserInteractor {
*
* @param event the event that triggered this
*/
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);
void onSlashCommand(SlashCommandInteractionEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Range;
import org.jetbrains.annotations.Unmodifiable;
import org.togetherjava.tjbot.commands.componentids.ComponentId;
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
import org.togetherjava.tjbot.commands.componentids.Lifespan;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -55,7 +55,7 @@
* }
*
* &#64;Override
* public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
* public void onSlashCommand(SlashCommandInteractionEvent event) {
* event.reply("Pong!").queue();
* }
* }
Expand All @@ -80,7 +80,7 @@ public abstract class SlashCommandAdapter implements SlashCommand {
* {@link SlashCommandData#setDescription(String)}
* @param visibility the visibility of the command
*/
protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
protected SlashCommandAdapter(String name, String description,
SlashCommandVisibility visibility) {
this.name = name;
this.description = description;
Expand All @@ -90,40 +90,43 @@ protected SlashCommandAdapter(@NotNull String name, @NotNull String description,
}

@Override
public final @NotNull String getName() {
@Nonnull
public final String getName() {
return name;
}

@Override
public final @NotNull String getDescription() {
@Nonnull
public final String getDescription() {
return description;
}

@Override
public final @NotNull SlashCommandVisibility getVisibility() {
@Nonnull
public final SlashCommandVisibility getVisibility() {
return visibility;
}

@Override
public final @NotNull SlashCommandData getData() {
@Nonnull
public final SlashCommandData getData() {
return data;
}

@Override
public final void acceptComponentIdGenerator(@NotNull ComponentIdGenerator generator) {
public final void acceptComponentIdGenerator(ComponentIdGenerator generator) {
componentIdGenerator = generator;
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onButtonClick(@NotNull ButtonInteractionEvent event, @NotNull List<String> args) {
public void onButtonClick(ButtonInteractionEvent event, List<String> args) {
// Adapter does not react by default, subclasses may change this behavior
}

@SuppressWarnings("NoopMethodInAbstractClass")
@Override
public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
@NotNull List<String> args) {
public void onSelectionMenu(SelectMenuInteractionEvent event, List<String> args) {
// Adapter does not react by default, subclasses may change this behavior
}

Expand All @@ -142,7 +145,8 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
* @return the generated component ID
*/
@SuppressWarnings("OverloadedVarargsMethod")
protected final @NotNull String generateComponentId(@NotNull String... args) {
@Nonnull
protected final String generateComponentId(String... args) {
return generateComponentId(Lifespan.REGULAR, args);
}

Expand All @@ -159,8 +163,8 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
* @return the generated component ID
*/
@SuppressWarnings({"OverloadedVarargsMethod", "WeakerAccess"})
protected final @NotNull String generateComponentId(@NotNull Lifespan lifespan,
@NotNull String... args) {
@Nonnull
protected final String generateComponentId(Lifespan lifespan, String... args) {
return Objects.requireNonNull(componentIdGenerator)
.generate(new ComponentId(getName(), Arrays.asList(args)), lifespan);
}
Expand Down Expand Up @@ -190,8 +194,9 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
* @return the generated list of options
*/
@Unmodifiable
protected static @NotNull List<OptionData> generateMultipleOptions(
@NotNull OptionData optionData, @Range(from = 1, to = 25) int amount) {
@Nonnull
protected static List<OptionData> generateMultipleOptions(OptionData optionData,
@Range(from = 1, to = 25) int amount) {
String baseName = optionData.getName();

Function<String, OptionData> nameToOption =
Expand All @@ -211,8 +216,9 @@ public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
* @return all options with the given prefix
*/
@Unmodifiable
protected static @NotNull List<OptionMapping> getMultipleOptionsByNamePrefix(
@NotNull CommandInteractionPayload event, @NotNull String namePrefix) {
@Nonnull
protected static List<OptionMapping> getMultipleOptionsByNamePrefix(
CommandInteractionPayload event, String namePrefix) {
return event.getOptions()
.stream()
.filter(option -> option.getName().startsWith(namePrefix))
Expand Down
Loading