Search in sources :

Example 41 with ChronoUnit

use of java.time.temporal.ChronoUnit in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_channelMute.

@CommandSubscriber(command = "channelMute", help = "Nutzer in einem Channel für eine bestimmte Zeit stummschalten", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR)
public void command_channelMute(final IMessage message, final String userInput, final String channelInput, final String muteDurationInput) {
    // Parse user
    final IUser muteUser = UserUtils.getUserFromMessage(message, userInput);
    if (muteUser == null) {
        DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Kein gültiger Nutzer angegeben!");
        return;
    }
    // Parse channel
    final IChannel muteChannel = ChannelUtils.getChannelFromMessage(message, channelInput);
    if (muteChannel == null) {
        DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Kein gültiger Kanal angegeben!");
        return;
    }
    // Parse mute duration and message
    final CommandUtils.DurationParameters durationParameters = CommandUtils.parseDurationParameters(muteDurationInput);
    if (durationParameters == null) {
        DiscordIO.sendMessage(message.getChannel(), "Ungültige Dauer angegeben. Mögliche Einheiten sind: s, m, h, d");
        return;
    }
    final int muteDuration = durationParameters.getDuration();
    final ChronoUnit muteDurationUnit = durationParameters.getDurationUnit();
    String customMessage = durationParameters.getMessage();
    if (customMessage == null || customMessage.isEmpty()) {
        customMessage = "kein";
    }
    // Mute user and schedule unmute
    final String output = muteUserForChannel(muteUser, muteChannel, muteDuration, muteDurationUnit);
    if (output.isEmpty()) {
        // :mute:
        message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
    } else {
        DiscordIO.sendMessage(message.getChannel(), output);
        return;
    }
    final IGuild guild = message.getGuild();
    // Do not notify a bot user
    if (!muteUser.isBot()) {
        final List<String> muteMessage = new ArrayList<>();
        muteMessage.add(String.format("**Du wurdest für %s %s für den Kanal %s auf dem Server %s gemuted!**", muteDuration, muteDurationUnit.name(), muteChannel.getName(), guild.getName()));
        muteMessage.add(String.format("Hinweis: _%s_", customMessage));
        DiscordIO.sendMessage(muteUser.getOrCreatePMChannel(), muteMessage);
    }
    // Modlog
    LOG.info("Guild '{}': User {} was muted for {} {} for the channel {}. Message: {}", guild.getName(), UserUtils.makeUserString(muteUser, guild), muteDuration, muteDurationUnit.name(), muteChannel.getName(), customMessage);
    final IChannel modLogChannel = getModlogChannelForGuild(guild);
    if (modLogChannel != null) {
        final List<String> modLogMessage = new ArrayList<>();
        modLogMessage.add(String.format("Nutzer **%s** wurde im Kanal %s für %s %s für den Kanal %s **gemuted**.", UserUtils.makeUserString(muteUser, message.getGuild()), message.getChannel().mention(), muteDuration, muteDurationUnit.name(), muteChannel.mention()));
        modLogMessage.add(String.format("Hinweis: _%s _", customMessage));
        DiscordIO.sendMessage(modLogChannel, modLogMessage);
    }
}
Also used : CommandUtils(de.nikos410.discordbot.util.CommandUtils) ChronoUnit(java.time.temporal.ChronoUnit) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 42 with ChronoUnit

use of java.time.temporal.ChronoUnit in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_mute.

@CommandSubscriber(command = "mute", help = "Einen Nutzer für eine bestimmte Zeit muten", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR, ignoreParameterCount = true)
public void command_mute(final IMessage message, final String userString, final String muteDurationInput) {
    // Find the user to mute
    final IUser muteUser = UserUtils.getUserFromMessage(message, userString);
    if (muteUser == null) {
        DiscordIO.sendMessage(message.getChannel(), ":x: Fehler: Nutzer nicht gefunden!");
        return;
    }
    // Check if mute duration was specified
    if (muteDurationInput == null) {
        DiscordIO.sendMessage(message.getChannel(), "Fehler! Es muss eine Mute-Dauer angegeben werden.");
        return;
    }
    // Parse mute duration
    final CommandUtils.DurationParameters durationParameters = CommandUtils.parseDurationParameters(muteDurationInput);
    if (durationParameters == null) {
        DiscordIO.sendMessage(message.getChannel(), "Ungültige Dauer angegeben. Mögliche Einheiten sind: s, m, h, d");
        return;
    }
    final int muteDuration = durationParameters.getDuration();
    final ChronoUnit muteDurationUnit = durationParameters.getDurationUnit();
    String customMessage = durationParameters.getMessage();
    if (customMessage == null || customMessage.isEmpty()) {
        customMessage = "kein";
    }
    final IGuild guild = message.getGuild();
    // Mute the user and schedule unmute
    muteUserForGuild(muteUser, guild, muteDuration, muteDurationUnit, message.getChannel());
    // :mute:
    message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
    // Do not notify a bot user
    if (!muteUser.isBot()) {
        final List<String> muteMessage = Arrays.asList(String.format("**Du wurdest auf dem Server %s für %s %s gemuted!**", guild.getName(), muteDuration, muteDurationUnit.name()), String.format("Hinweis: _%s_", customMessage));
        DiscordIO.sendMessage(muteUser.getOrCreatePMChannel(), muteMessage);
    }
    // Modlog
    LOG.info("Guild '{}': User {} was muted for {} {}. Message: {}", guild.getName(), UserUtils.makeUserString(muteUser, message.getGuild()), muteDuration, muteDurationUnit.name(), customMessage);
    final IChannel modLogChannel = getModlogChannelForGuild(guild);
    if (modLogChannel != null) {
        final List<String> modLogMessage = new ArrayList<>();
        modLogMessage.add(String.format("Nutzer **%s** wurde im Kanal %s für %s %s **gemuted**.", UserUtils.makeUserString(muteUser, guild), message.getChannel().mention(), muteDuration, muteDurationUnit.name()));
        modLogMessage.add(String.format("Hinweis: _%s_", customMessage));
        DiscordIO.sendMessage(modLogChannel, modLogMessage);
    }
    saveUserMutes();
}
Also used : CommandUtils(de.nikos410.discordbot.util.CommandUtils) ChronoUnit(java.time.temporal.ChronoUnit) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Aggregations

ChronoUnit (java.time.temporal.ChronoUnit)42 Test (org.junit.jupiter.api.Test)11 Test (org.junit.Test)6 LocalDateTime (java.time.LocalDateTime)5 Matcher (java.util.regex.Matcher)5 Duration (java.time.Duration)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 Given (cucumber.api.java.en.Given)2 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)2 CommandSubscriber (de.nikos410.discordbot.framework.annotations.CommandSubscriber)2 CommandUtils (de.nikos410.discordbot.util.CommandUtils)2 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)2 Instant (java.time.Instant)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2