Skip to content

Release v2.7 #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 10, 2022
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 @@ -53,6 +53,7 @@ dependencies {
implementation 'org.scilab.forge:jlatexmath-font-cyrillic:1.0.7'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.13.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'

implementation 'com.github.freva:ascii-table:1.2.0'
Expand Down
2 changes: 2 additions & 0 deletions application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"tagManageRolePattern": "Moderator|Staff Assistant|Top Helpers .+",
"freeCommand": [
{
"inactiveChannelDuration": "PT2H",
"messageRetrieveLimit": 10,
"statusChannel": <put_a_channel_id_here>,
"monitoredChannels": [
<put_a_channel_id_here>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.togetherjava.tjbot.commands.basic.RoleSelectCommand;
import org.togetherjava.tjbot.commands.basic.SuggestionsUpDownVoter;
import org.togetherjava.tjbot.commands.basic.VcActivityCommand;
import org.togetherjava.tjbot.commands.free.AutoFreeRoutine;
import org.togetherjava.tjbot.commands.free.FreeChannelMonitor;
import org.togetherjava.tjbot.commands.free.FreeCommand;
import org.togetherjava.tjbot.commands.mathcommands.TeXCommand;
import org.togetherjava.tjbot.commands.moderation.*;
Expand Down Expand Up @@ -59,6 +61,7 @@ public enum Features {
ModerationActionsStore actionsStore = new ModerationActionsStore(database);
ModAuditLogWriter modAuditLogWriter = new ModAuditLogWriter(config);
ScamHistoryStore scamHistoryStore = new ScamHistoryStore(database);
FreeChannelMonitor freeChannelMonitor = new FreeChannelMonitor(config);

// 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
Expand All @@ -71,6 +74,7 @@ public enum Features {
features.add(new TopHelpersPurgeMessagesRoutine(database));
features.add(new RemindRoutine(database));
features.add(new ScamHistoryPurgeRoutine(scamHistoryStore));
features.add(new AutoFreeRoutine(freeChannelMonitor));

// Message receivers
features.add(new TopHelpersMessageListener(database, config));
Expand Down Expand Up @@ -100,9 +104,10 @@ public enum Features {
features.add(new RemindCommand(database));
features.add(new QuarantineCommand(actionsStore, config));
features.add(new UnquarantineCommand(actionsStore, config));
features.add(new WhoIsCommand());

// Mixtures
features.add(new FreeCommand(config));
features.add(new FreeCommand(config, freeChannelMonitor));

return features;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.togetherjava.tjbot.commands.free;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import org.jetbrains.annotations.NotNull;
import org.togetherjava.tjbot.commands.Routine;

import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* Routine that automatically marks busy help channels free after a certain time without any
* activity.
*/
public final class AutoFreeRoutine implements Routine {
private final FreeChannelMonitor channelMonitor;

/**
* Creates a new instance.
*
* @param channelMonitor used to monitor and control the free-status of channels
*/
public AutoFreeRoutine(@NotNull FreeChannelMonitor channelMonitor) {
this.channelMonitor = channelMonitor;
}

@Override
public void runRoutine(@NotNull JDA jda) {
channelMonitor.guildIds()
.map(jda::getGuildById)
.filter(Objects::nonNull)
.forEach(this::processGuild);
}

private void processGuild(@NotNull Guild guild) {
// Mark inactive channels free
Collection<TextChannel> inactiveChannels = channelMonitor.freeInactiveChannels(guild);

// Then update the status
channelMonitor.displayStatus(guild);

// Finally, send the messages (the order is important to ensure sane behavior in case of
// crashes)
inactiveChannels.forEach(inactiveChannel -> inactiveChannel
.sendMessage(UserStrings.AUTO_MARK_AS_FREE.message())
.queue());
}

@Override
public @NotNull Schedule createSchedule() {
return new Schedule(ScheduleMode.FIXED_RATE, 1, 5, TimeUnit.MINUTES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ private void setName(@NotNull final String name) {
*
* @param guild the {@link Guild} that the channel belongs to, to retrieve its name from.
* @throws IllegalArgumentException if the guild has not been added, see
* {@link ChannelMonitor#addChannelForStatus(TextChannel)}
* {@link FreeChannelMonitor#addChannelForStatus(TextChannel)}
* @throws IllegalStateException if a channel was added, see
* {@link ChannelMonitor#addChannelToMonitor(long)}, that is not a {@link TextChannel}.
* Since addChannelToMonitor does not access the {@link JDA} the entry can only be
* validated before use instead of on addition.
* {@link FreeChannelMonitor#addChannelToMonitor(long)}, that is not a
* {@link TextChannel}. Since addChannelToMonitor does not access the {@link JDA} the
* entry can only be validated before use instead of on addition.
*/
public void updateChannelName(@NotNull final Guild guild) {
GuildChannel channel = guild.getGuildChannelById(channelId);
Expand Down
Loading