Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7ba661d
Skipping audit logs against bot message deletions (#395)
Zabuzard Feb 28, 2022
16d66b5
Utility for in-app URL's (#391)
Tais993 Feb 28, 2022
dff6068
Adding /quarantine and /unquarantine (#398)
Zabuzard Mar 7, 2022
dfa3696
Added ModAuditLogWriter and logging /tag changes
interacsion Mar 14, 2022
e00ac74
colorblind support for help system emojis (#410)
Zabuzard Mar 14, 2022
eecb610
Bugfix - Handling blocked users gracefully when reacting to their mes…
interacsion Mar 15, 2022
92bd32c
Upgrade JDA to alpha 3
Mar 17, 2022
98d7a9a
Upgrade JDA to alpha 5
Mar 17, 2022
3ea40dc
Upgrade JDA to alpha 9
Mar 17, 2022
e5cd2c2
Removed code duplication from role based moderation actions. (#417)
interacsion Mar 31, 2022
b9b047a
Adding UserInteractor to the core system
Zabuzard Mar 14, 2022
d517ccc
Added scam detector and scam blocker
Zabuzard Mar 14, 2022
d576850
false-positive shouldnt be tracked by TODO-tracker
Zabuzard Mar 11, 2022
5c33639
CR Tais
Zabuzard Mar 15, 2022
6952930
unit tests for ScamDetector
Zabuzard Mar 15, 2022
b6b9fca
Removed obsolete channel lookup (CR Tais)
Zabuzard Mar 15, 2022
dba7495
Using single nullable ActionRow instead of list (CR Tais)
Zabuzard Mar 15, 2022
21e031b
Using JDAs Error Handler (CR Tais)
Zabuzard Mar 29, 2022
91401dd
missing Javadoc (CR Tais)
Zabuzard Mar 29, 2022
9b0045a
Using proper button factories (CR Tais)
Zabuzard Mar 29, 2022
3a835c3
Fixed issues after rebase
Zabuzard Mar 29, 2022
d336182
Month selection for top-helpers
Zabuzard Mar 30, 2022
d14a7bc
Added missing javadoc
Zabuzard Apr 6, 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
2 changes: 1 addition & 1 deletion PP.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ This policy is not applicable to any information collected by **bot** instances

People may get in contact through e-mail at [[email protected]](mailto:[email protected]), or through **Together Java**'s [official Discord](https://discord.com/invite/XXFUXzK).

Other ways of support may be provided but are not guaranteed.
Other ways of support may be provided but are not guaranteed.
8 changes: 2 additions & 6 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ plugins {

repositories {
mavenCentral()
maven {
name 'm2-dv8tion'
url 'https://m2.dv8tion.net/releases'
}
}

var outputImage = 'togetherjava.duckdns.org:5001/togetherjava/tjbot:' + System.getenv('BRANCH_NAME') ?: 'latest'
Expand Down Expand Up @@ -45,7 +41,7 @@ shadowJar {
dependencies {
implementation project(':database')

implementation 'net.dv8tion:JDA:4.4.0_352'
implementation 'net.dv8tion:JDA:5.0.0-alpha.9'

implementation 'org.apache.logging.log4j:log4j-core:2.16.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0'
Expand All @@ -64,8 +60,8 @@ dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.4'

testImplementation 'org.mockito:mockito-core:4.0.0'
testRuntimeOnly 'org.mockito:mockito-core:4.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

Expand Down
9 changes: 9 additions & 0 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@
"channelPattern": "tj_suggestions",
"upVoteEmoteName": "peepo_yes",
"downVoteEmoteName": "peepo_no"
},
"quarantinedRolePattern": "Quarantined",
"scamBlocker": {
"mode": "AUTO_DELETE_BUT_APPROVE_QUARANTINE",
"reportChannelPattern": "commands",
"hostWhitelist": ["discord.com", "discord.gg", "discord.media", "discordapp.com", "discordapp.net", "discordstatus.com"],
"hostBlacklist": ["bit.ly"],
"suspiciousHostKeywords": ["discord", "nitro", "premium"],
"isHostSimilarToKeywordDistanceThreshold": 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Main class of the application. Use {@link #main(String[])} to start an instance of it.
* <p>
* New commands can be created by implementing
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandEvent} or extending
* {@link net.dv8tion.jda.api.events.interaction.SlashCommandInteractionEvent} or extending
* {@link org.togetherjava.tjbot.commands.SlashCommandAdapter}. They can then be registered in
* {@link Features}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.togetherjava.tjbot.commands.free.FreeCommand;
import org.togetherjava.tjbot.commands.mathcommands.TeXCommand;
import org.togetherjava.tjbot.commands.moderation.*;
import org.togetherjava.tjbot.commands.moderation.scam.ScamBlocker;
import org.togetherjava.tjbot.commands.moderation.scam.ScamHistoryPurgeRoutine;
import org.togetherjava.tjbot.commands.moderation.scam.ScamHistoryStore;
import org.togetherjava.tjbot.commands.moderation.temp.TemporaryModerationRoutine;
import org.togetherjava.tjbot.commands.reminder.RemindCommand;
import org.togetherjava.tjbot.commands.reminder.RemindRoutine;
Expand All @@ -22,6 +25,7 @@
import org.togetherjava.tjbot.commands.tophelper.TopHelpersPurgeMessagesRoutine;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.moderation.ModAuditLogWriter;
import org.togetherjava.tjbot.routines.ModAuditLogRoutine;

import java.util.ArrayList;
Expand Down Expand Up @@ -53,30 +57,34 @@ public enum Features {
@NotNull Database database, @NotNull Config config) {
TagSystem tagSystem = new TagSystem(database);
ModerationActionsStore actionsStore = new ModerationActionsStore(database);
ModAuditLogWriter modAuditLogWriter = new ModAuditLogWriter(config);
ScamHistoryStore scamHistoryStore = new ScamHistoryStore(database);

// NOTE The system can add special system relevant commands also by itself,
// hence this list may not necessarily represent the full list of all commands actually
// available.
Collection<Feature> features = new ArrayList<>();

// Routines
features.add(new ModAuditLogRoutine(database, config));
features.add(new ModAuditLogRoutine(database, config, modAuditLogWriter));
features.add(new TemporaryModerationRoutine(jda, actionsStore, config));
features.add(new TopHelpersPurgeMessagesRoutine(database));
features.add(new RemindRoutine(database));
features.add(new ScamHistoryPurgeRoutine(scamHistoryStore));

// Message receivers
features.add(new TopHelpersMessageListener(database, config));
features.add(new SuggestionsUpDownVoter(config));
features.add(new ScamBlocker(actionsStore, scamHistoryStore, config));

// Event receivers
features.add(new RejoinMuteListener(actionsStore, config));
features.add(new RejoinModerationRoleListener(actionsStore, config));

// Slash commands
features.add(new PingCommand());
features.add(new TeXCommand());
features.add(new TagCommand(tagSystem));
features.add(new TagManageCommand(tagSystem, config));
features.add(new TagManageCommand(tagSystem, config, modAuditLogWriter));
features.add(new TagsCommand(tagSystem));
features.add(new VcActivityCommand());
features.add(new WarnCommand(actionsStore, config));
Expand All @@ -90,6 +98,8 @@ public enum Features {
features.add(new RoleSelectCommand());
features.add(new NoteCommand(actionsStore, config));
features.add(new RemindCommand(database));
features.add(new QuarantineCommand(actionsStore, config));
features.add(new UnquarantineCommand(actionsStore, config));

// Mixtures
features.add(new FreeCommand(config));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.togetherjava.tjbot.commands;

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

import java.util.regex.Pattern;
Expand Down Expand Up @@ -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 GuildMessageReceivedEvent event);
void onMessageReceived(@NotNull 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 GuildMessageUpdateEvent event);
void onMessageUpdated(@NotNull MessageUpdateEvent event);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.togetherjava.tjbot.commands;

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

import java.util.regex.Pattern;
Expand All @@ -10,8 +10,8 @@
* Adapter implementation of a {@link MessageReceiver}. A new receiver can then be registered by
* adding it to {@link Features}.
* <p>
* {@link #onMessageReceived(GuildMessageReceivedEvent)} and
* {@link #onMessageUpdated(GuildMessageUpdateEvent)} can be overridden if desired. The default
* {@link #onMessageReceived(MessageReceivedEvent)} and
* {@link #onMessageUpdated(MessageUpdateEvent)} can be overridden if desired. The default
* implementation is empty, the adapter will not react to such events.
*/
public abstract class MessageReceiverAdapter implements MessageReceiver {
Expand All @@ -35,13 +35,13 @@ protected MessageReceiverAdapter(@NotNull Pattern channelNamePattern) {

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

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

import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
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;
Expand All @@ -28,32 +30,19 @@
* is then to be returned by {@link #getData()} where the system will then pick it up from.
* <p>
* After registration, the system will notify a command whenever one of its corresponding slash
* commands ({@link #onSlashCommand(SlashCommandEvent)}), buttons
* ({@link #onButtonClick(ButtonClickEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectionMenuEvent, List)}) have been triggered.
* commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
* <p>
* <p>
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
*/
public interface SlashCommand extends Feature {

/**
* Gets the name of the command.
* <p>
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
* <p>
* <p>
* After registration of the command, the name must not change anymore.
*
* @return the name of the command
*/
@NotNull
String getName();
public interface SlashCommand extends UserInteractor {

/**
* Gets the description of the command.
* <p>
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
* Requirements for this are documented in {@link Commands#slash(String, String)}.
* <p>
* <p>
* After registration of the command, the description must not change anymore.
Expand Down Expand Up @@ -89,7 +78,7 @@ public interface SlashCommand extends Feature {
* @return the command data of this command
*/
@NotNull
CommandData getData();
SlashCommandData getData();

/**
* Triggered by the core system when a slash command corresponding to this implementation (based
Expand All @@ -104,8 +93,8 @@ public interface SlashCommand extends Feature {
* <p>
* Buttons or menus have to be created with a component ID (see
* {@link ComponentInteraction#getComponentId()},
* {@link net.dv8tion.jda.api.interactions.components.Button#of(ButtonStyle, String, Emoji)}) in
* a very specific format, otherwise the core system will fail to identify the command that
* {@link net.dv8tion.jda.api.interactions.components.buttons.Button#of(ButtonStyle, String, Emoji)})
* in a very specific format, otherwise the core system will fail to identify the command that
* corresponded to the button or menu click event and is unable to route it back.
* <p>
* The component ID has to be a UUID-string (see {@link java.util.UUID}), which is associated to
Expand All @@ -115,8 +104,8 @@ public interface SlashCommand extends Feature {
* given to {@link #acceptComponentIdGenerator(ComponentIdGenerator)} during system setup. The
* required {@link ComponentId} instance accepts optional extra arguments, which, if provided,
* can be picked up during the corresponding event (see
* {@link #onButtonClick(ButtonClickEvent, List)},
* {@link #onSelectionMenu(SelectionMenuEvent, List)}).
* {@link #onButtonClick(ButtonInteractionEvent, List)},
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)}).
* <p>
* Alternatively, if {@link SlashCommandAdapter} has been extended, it also offers a handy
* {@link SlashCommandAdapter#generateComponentId(String...)} method to ease the flow.
Expand All @@ -129,55 +118,5 @@ public interface SlashCommand extends Feature {
*
* @param event the event that triggered this
*/
void onSlashCommand(@NotNull SlashCommandEvent event);

/**
* Triggered by the core system when a button corresponding to this implementation (based on
* {@link #getData()}) has been clicked.
* <p>
* This method may be called multi-threaded. In particular, there are no guarantees that it will
* be executed on the same thread repeatedly or on the same thread that other event methods have
* been called on.
* <p>
* Details are available in the given event and the event also enables implementations to
* respond to it.
* <p>
* This method will be called in a multi-threaded context and the event may not be hold valid
* forever.
*
* @param event the event that triggered this
* @param args the arguments transported with the button, see
* {@link #onSlashCommand(SlashCommandEvent)} for details on how these are created
*/
void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List<String> args);

/**
* Triggered by the core system when a selection menu corresponding to this implementation
* (based on {@link #getData()}) has been clicked.
* <p>
* This method may be called multi-threaded. In particular, there are no guarantees that it will
* be executed on the same thread repeatedly or on the same thread that other event methods have
* been called on.
* <p>
* Details are available in the given event and the event also enables implementations to
* respond to it.
* <p>
* This method will be called in a multi-threaded context and the event may not be hold valid
* forever.
*
* @param event the event that triggered this
* @param args the arguments transported with the selection menu, see
* {@link #onSlashCommand(SlashCommandEvent)} for details on how these are created
*/
void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args);

/**
* Triggered by the core system during its setup phase. It will provide the command a component
* id generator through this method, which can be used to generate component ids, as used for
* button or selection menus. See {@link #onSlashCommand(SlashCommandEvent)} for details on how
* to use this.
*
* @param generator the provided component id generator
*/
void acceptComponentIdGenerator(@NotNull ComponentIdGenerator generator);
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);
}
Loading