Search in sources :

Example 16 with PermissionLevel

use of de.nikos410.discordbot.framework.PermissionLevel 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 17 with PermissionLevel

use of de.nikos410.discordbot.framework.PermissionLevel 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 18 with PermissionLevel

use of de.nikos410.discordbot.framework.PermissionLevel 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 19 with PermissionLevel

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

the class UserGroups method command_removeGroup.

@CommandSubscriber(command = "removeGroup", help = "Gruppe entfernen", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR)
public void command_removeGroup(final IMessage message, final String groupName) {
    final IGuild guild = message.getGuild();
    // Validate group first
    validateGroup(guild, groupName);
    final JSONObject guildJSON = getJSONForGuild(guild);
    if (!guildJSON.has(groupName)) {
        DiscordIO.sendMessage(message.getChannel(), String.format(":x: Gruppe `%s` nicht gefunden!", groupName));
        return;
    }
    final IRole role = guild.getRoleByID(guildJSON.getLong(groupName));
    role.delete();
    guildJSON.remove(groupName);
    saveJSON();
    DiscordIO.sendMessage(message.getChannel(), String.format(":white_check_mark: Gruppe `%s` entfernt.", groupName));
    LOG.info(String.format("%s deleted group %s.", UserUtils.makeUserString(message.getAuthor(), guild), groupName));
}
Also used : JSONObject(org.json.JSONObject) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 20 with PermissionLevel

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

the class Rules method command_enableWelcome.

@CommandSubscriber(command = "enableWelcome", help = "Begrüßungsnachricht aktivieren", permissionLevel = PermissionLevel.ADMIN, pmAllowed = false)
public void command_enableWelcome(final IMessage message) {
    final IGuild guild = message.getGuild();
    final JSONObject guildJSON = getJSONForGuild(guild);
    guildJSON.put("on", true);
    saveJSON();
    DiscordIO.sendMessage(message.getChannel(), ":white_check_mark: Aktiviert!");
    LOG.info(String.format("%s enabled welcome messages for server %s (ID: %s)", UserUtils.makeUserString(message.getAuthor(), message.getGuild()), guild.getName(), guild.getStringID()));
}
Also used : JSONObject(org.json.JSONObject) IGuild(sx.blah.discord.handle.obj.IGuild) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Aggregations

CommandSubscriber (de.nikos410.discordbot.framework.annotations.CommandSubscriber)19 JSONObject (org.json.JSONObject)17 IGuild (sx.blah.discord.handle.obj.IGuild)11 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)4 ChronoUnit (java.time.temporal.ChronoUnit)4 CommandWrapper (de.nikos410.discordbot.framework.CommandWrapper)2 PermissionLevel (de.nikos410.discordbot.framework.PermissionLevel)2 CommandUtils (de.nikos410.discordbot.util.CommandUtils)2 Method (java.lang.reflect.Method)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 IChannel (sx.blah.discord.handle.obj.IChannel)2 IUser (sx.blah.discord.handle.obj.IUser)2 CommandModule (de.nikos410.discordBot.util.modular.annotations.CommandModule)1 InitializationException (de.nikos410.discordbot.exception.InitializationException)1 CommandModule (de.nikos410.discordbot.framework.CommandModule)1 ModuleWrapper (de.nikos410.discordbot.framework.ModuleWrapper)1 ModuleStatus (de.nikos410.discordbot.framework.ModuleWrapper.ModuleStatus)1 BotSetup (de.nikos410.discordbot.modules.BotSetup)1 Authorization (de.nikos410.discordbot.util.discord.Authorization)1 DiscordIO (de.nikos410.discordbot.util.discord.DiscordIO)1