Search in sources :

Example 21 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class Rules method command_setWelcome.

@CommandSubscriber(command = "setWelcome", help = "Begrüßungsnachricht ändern", permissionLevel = PermissionLevel.ADMIN, pmAllowed = false)
public void command_setWelcome(final IMessage message, final String welcomeMessage) {
    final IGuild guild = message.getGuild();
    final JSONObject guildJSON = getJSONForGuild(guild);
    guildJSON.put("welcome", welcomeMessage);
    saveJSON();
    DiscordIO.sendMessage(message.getChannel(), ":white_check_mark: Begrüßungs-Nachricht geändert:");
    DiscordIO.sendMessage(message.getChannel(), welcomeMessage);
}
Also used : JSONObject(org.json.JSONObject) IGuild(sx.blah.discord.handle.obj.IGuild) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 22 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class Rules method command_welcomeTest.

@CommandSubscriber(command = "welcomeTest", help = "Begrüßungsnachricht testen", permissionLevel = PermissionLevel.ADMIN, pmAllowed = false)
public void command_welcomeTest(final IMessage message) {
    final IGuild guild = message.getGuild();
    final JSONObject guildJSON = getJSONForGuild(guild);
    if (guildJSON.has("welcome") && guildJSON.has("rulesDE") && guildJSON.has("footer")) {
        DiscordIO.sendMessage(message.getChannel(), guildJSON.getString("welcome") + "\n\n" + guildJSON.getString("rulesDE") + "\n\n\n" + guildJSON.getString("footer"));
    }
}
Also used : JSONObject(org.json.JSONObject) IGuild(sx.blah.discord.handle.obj.IGuild) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 23 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class UserGroups method command_group.

@CommandSubscriber(command = "group", help = "Sich selbst eine Rolle zuweisen / wieder entfernen", pmAllowed = false)
public void command_group(final IMessage message, final String groupName) {
    final IGuild guild = message.getGuild();
    // Validate group first
    validateGroup(guild, groupName);
    final IUser user = message.getAuthor();
    final JSONObject guildJSON = getJSONForGuild(guild);
    if (guildJSON.has(groupName)) {
        final long roleID = guildJSON.getLong(groupName);
        final IRole role = message.getGuild().getRoleByID(roleID);
        if (UserUtils.hasRole(user, role, guild)) {
            user.removeRole(role);
            DiscordIO.sendMessage(message.getChannel(), String.format(":white_check_mark: Du wurdest aus der Gruppe `%s` entfernt.", groupName));
            LOG.info(String.format("%s left group %s.", UserUtils.makeUserString(message.getAuthor(), guild), groupName));
        } else {
            user.addRole(role);
            DiscordIO.sendMessage(message.getChannel(), String.format(":white_check_mark: Du wurdest zur Gruppe `%s` hinzugefügt.", groupName));
            LOG.info(String.format("%s joined group %s.", UserUtils.makeUserString(message.getAuthor(), guild), groupName));
        }
    } else {
        DiscordIO.sendMessage(message.getChannel(), String.format(":x: Gruppe `%s` nicht gefunden!", groupName));
    }
}
Also used : JSONObject(org.json.JSONObject) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 24 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber 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 = CommandPermissions.MODERATOR)
public void command_Mute(final IMessage message, final String muteUserString, final String muteDurationInput) {
    final List<IUser> mentions = message.getMentions();
    if (mentions.size() < 1) {
        Util.sendMessage(message.getChannel(), ":x: Fehler: Kein Nutzer angegeben!");
        return;
    } else if (mentions.size() > 1) {
        Util.sendMessage(message.getChannel(), ":x: Fehler: mehrere Nutzer erwähnt");
        return;
    }
    final IUser muteUser = mentions.get(0);
    if (muteUser == null) {
        Util.sendMessage(message.getChannel(), ":x: Fehler: Nutzer nicht gefunden!");
        return;
    }
    Pattern pattern = Pattern.compile("(\\d+)\\s?([smhd])\\s?(.*)");
    Matcher matcher = pattern.matcher(muteDurationInput);
    if (!matcher.matches()) {
        Util.sendMessage(message.getChannel(), "Ungültige Eingabe! Mögliche Zeitformate sind s, m, h und d.");
        return;
    }
    IRole muteRole = message.getGuild().getRoleByID(muteRoleID);
    // Wird ausgeführt, um Nutzer wieder zu entmuten
    Runnable unmuteTask = () -> {
        mutedUsers.remove(muteUser.getStringID());
        muteUser.removeRole(muteRole);
        System.out.println("Unmuted user " + Util.makeUserString(muteUser, message.getGuild()) + ".");
    };
    final int muteDuration = Integer.parseInt(matcher.group(1));
    final String muteDurationUnitString = matcher.group(2);
    ChronoUnit muteDurationUnit = parseChronoUnit(muteDurationUnitString);
    if (mutedUsers.containsKey(muteUser.getStringID())) {
        // Überprüfen, ob angegebener Zeitpunkt nach dem bisherigen Zeitpunkt liegt
        ScheduledFuture oldFuture = mutedUsers.get(muteUser.getStringID());
        LocalDateTime oldDateTime = LocalDateTime.now().plusSeconds(oldFuture.getDelay(TimeUnit.SECONDS));
        LocalDateTime newDateTime = LocalDateTime.now().plus(muteDuration, muteDurationUnit);
        if (newDateTime.isBefore(oldDateTime)) {
            // neuer Zeitpunkt ist vor altem -> nichts tun (längerer Mute bleibt bestehen)
            Util.sendMessage(message.getChannel(), "Nutzer ist bereits für einen längeren Zeitraum gemuted!");
            return;
        } else {
            // neuer Zeitpunkt ist nach altem -> neu schedulen
            mutedUsers.remove(muteUser.getStringID(), oldFuture);
            oldFuture.cancel(false);
        }
    } else {
        muteUser.addRole(muteRole);
        System.out.println("Muted user " + Util.makeUserString(muteUser, message.getGuild()) + ".");
    }
    ScheduledFuture newFuture = scheduler.schedule(unmuteTask, muteDuration, chronoUnitToTimeUnit(muteDurationUnit));
    mutedUsers.put(muteUser.getStringID(), newFuture);
    // :mute:
    message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
    String customMessage = matcher.group(3);
    if (customMessage.isEmpty()) {
        customMessage = "kein";
    }
    final String muteMessage = "**Du wurdest für " + muteDuration + ' ' + muteDurationUnitString + " gemuted!** \nHinweis: _" + customMessage + " _";
    if (!muteUser.isBot()) {
        Util.sendPM(muteUser, muteMessage);
    }
    // Modlog
    IChannel modLogChannel = message.getGuild().getChannelByID(this.modlogChannelID);
    final String modLogMessage = String.format("**%s** hat Nutzer **%s** für %s %s **gemuted**. \nHinweis: _%s _", Util.makeUserString(message.getAuthor(), message.getGuild()), Util.makeUserString(muteUser, message.getGuild()), muteDuration, muteDurationUnitString, customMessage);
    Util.sendMessage(modLogChannel, modLogMessage);
}
Also used : LocalDateTime(java.time.LocalDateTime) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ScheduledFuture(java.util.concurrent.ScheduledFuture) ChronoUnit(java.time.temporal.ChronoUnit) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 25 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_Selfmute.

@CommandSubscriber(command = "selfmute", help = "Schalte dich selber für die angegebene Zeit stumm", pmAllowed = false)
public void command_Selfmute(final IMessage message, final String muteDurationInput) {
    IUser muteUser = message.getAuthor();
    Pattern pattern = Pattern.compile("(\\d+)\\s?([smhd])\\s?(.*)");
    Matcher matcher = pattern.matcher(muteDurationInput);
    if (!matcher.matches()) {
        Util.sendMessage(message.getChannel(), "Ungültige Eingabe! Mögliche Zeitformate sind s, m, h und d.");
        return;
    }
    IRole muteRole = message.getGuild().getRoleByID(muteRoleID);
    // Wird ausgeführt, um Nutzer wieder zu entmuten
    Runnable unmuteTask = () -> {
        mutedUsers.remove(muteUser.getStringID());
        muteUser.removeRole(muteRole);
        System.out.println("Unmuted user " + Util.makeUserString(muteUser, message.getGuild()) + ". (was selfmuted)");
    };
    final int muteDuration = Integer.parseInt(matcher.group(1));
    final String muteDurationUnitString = matcher.group(2);
    ChronoUnit muteDurationUnit = parseChronoUnit(muteDurationUnitString);
    if (mutedUsers.containsKey(muteUser.getStringID())) {
        // Überprüfen, ob angegebener Zeitpunkt nach dem bisherigen Zeitpunkt liegt
        ScheduledFuture oldFuture = mutedUsers.get(muteUser.getStringID());
        LocalDateTime oldDateTime = LocalDateTime.now().plusSeconds(oldFuture.getDelay(TimeUnit.SECONDS));
        LocalDateTime newDateTime = LocalDateTime.now().plus(muteDuration, muteDurationUnit);
        if (newDateTime.isBefore(oldDateTime)) {
            // neuer Zeitpunkt ist vor altem -> nichts tun (längerer Mute bleibt bestehen)
            Util.sendMessage(message.getChannel(), "Nutzer ist bereits für einen längeren Zeitraum gemuted!");
            return;
        } else {
            // neuer Zeitpunkt ist nach altem -> neu schedulen
            mutedUsers.remove(muteUser.getStringID(), oldFuture);
            oldFuture.cancel(false);
        }
    } else {
        muteUser.addRole(muteRole);
        System.out.println("User " + Util.makeUserString(muteUser, message.getGuild()) + " selfmuted.");
    }
    ScheduledFuture newFuture = scheduler.schedule(unmuteTask, muteDuration, chronoUnitToTimeUnit(muteDurationUnit));
    mutedUsers.put(muteUser.getStringID(), newFuture);
    // :mute:
    message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
}
Also used : LocalDateTime(java.time.LocalDateTime) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ScheduledFuture(java.util.concurrent.ScheduledFuture) ChronoUnit(java.time.temporal.ChronoUnit) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Aggregations

CommandSubscriber (de.nikos410.discordbot.framework.annotations.CommandSubscriber)30 JSONObject (org.json.JSONObject)23 IGuild (sx.blah.discord.handle.obj.IGuild)14 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)12 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)11 ChronoUnit (java.time.temporal.ChronoUnit)5 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)5 LocalDateTime (java.time.LocalDateTime)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 ModuleWrapper (de.nikos410.discordbot.framework.ModuleWrapper)3 CommandUtils (de.nikos410.discordbot.util.CommandUtils)3 Method (java.lang.reflect.Method)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)3 JSONArray (org.json.JSONArray)3 IUser (sx.blah.discord.handle.obj.IUser)3 CommandModule (de.nikos410.discordBot.util.modular.annotations.CommandModule)2 CommandWrapper (de.nikos410.discordbot.framework.CommandWrapper)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2