Search in sources :

Example 31 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber 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 32 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 = 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)

Example 33 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) {
    // The author of the message will be muted
    final IUser muteUser = message.getAuthor();
    // 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;
    }
    // Users can only mute themself for a maximum of one day
    final LocalDateTime muteEnd = LocalDateTime.now().plus(durationParameters.getDuration(), durationParameters.getDurationUnit());
    if (muteEnd.isAfter(LocalDateTime.now().plusDays(1))) {
        DiscordIO.sendMessage(message.getChannel(), "Du kannst dich für maximal einen Tag selbst muten!");
        return;
    }
    final IGuild guild = message.getGuild();
    // Mute the user and schedule unmute
    muteUserForGuild(muteUser, guild, durationParameters.getDuration(), durationParameters.getDurationUnit(), message.getChannel());
    // :mute:
    message.addReaction(ReactionEmoji.of("\uD83D\uDD07"));
}
Also used : LocalDateTime(java.time.LocalDateTime) CommandUtils(de.nikos410.discordbot.util.CommandUtils) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 34 with CommandSubscriber

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

the class UserGroups method command_createGroup.

@CommandSubscriber(command = "createGroup", help = "Neue Gruppe erstellen", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR)
public void command_createGroup(final IMessage message, final String groupName) {
    final IGuild guild = message.getGuild();
    final JSONObject guildJSON = getJSONForGuild(guild);
    if (guildJSON.has(groupName)) {
        DiscordIO.sendMessage(message.getChannel(), ":x: Gruppe existiert bereits!");
        return;
    }
    final IRole role = message.getGuild().createRole();
    role.changePermissions(EnumSet.noneOf(Permissions.class));
    role.changeName(groupName);
    if (!groupName.startsWith(NON_GAME_GROUP_NAME_PREFIX)) {
        role.changeMentionable(true);
    }
    guildJSON.put(groupName, role.getLongID());
    saveJSON();
    DiscordIO.sendMessage(message.getChannel(), String.format(":white_check_mark: Gruppe `%s` erstellt.", groupName));
    LOG.info(String.format("%s created new group %s.", UserUtils.makeUserString(message.getAuthor(), guild), groupName));
}
Also used : JSONObject(org.json.JSONObject) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 35 with CommandSubscriber

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

the class UserGroups method command_groups.

@CommandSubscriber(command = "groups", help = "Alle Rollen auflisten", pmAllowed = false)
public void command_groups(final IMessage message) {
    final IGuild guild = message.getGuild();
    // Validate all groups first
    validateAllGroupsForGuild(guild);
    final JSONObject guildJSON = getJSONForGuild(guild);
    final StringBuilder stringBuilder = new StringBuilder();
    final List<String> keyList = new LinkedList<>();
    keyList.addAll(guildJSON.keySet());
    Collections.sort(keyList);
    for (String key : keyList) {
        if (stringBuilder.length() != 0) {
            stringBuilder.append('\n');
        }
        stringBuilder.append(key);
    }
    if (stringBuilder.length() == 0) {
        stringBuilder.append("_Keine_");
    }
    final EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.appendField("Verfügbare Gruppen:", stringBuilder.toString(), false);
    embedBuilder.withFooterText(String.format("Weise dir mit '%sgroup <Gruppe> selbst eine dieser Gruppen zu'", bot.configJSON.getString("prefix")));
    DiscordIO.sendEmbed(message.getChannel(), embedBuilder.build());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) JSONObject(org.json.JSONObject) CommandSubscriber(de.nikos410.discordbot.framework.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