<commit_before>package stream.flarebot.flarebot.commands.administrator;

import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import stream.flarebot.flarebot.FlareBot;
import stream.flarebot.flarebot.MessageUtils;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.permissions.Group;
import stream.flarebot.flarebot.permissions.User;
import stream.flarebot.flarebot.util.Parser;

import java.io.IOException;
import java.util.stream.Collectors;

public class PermissionsCommand implements Command {

    @Override
    public void onCommand(net.dv8tion.jda.core.entities.User sender, TextChannel channel, Message message, String[] args, Member member) {
        if (args.length == 0) {
            channel.sendMessage(getDescription()).queue();
            return;
        }
        switch (args[0].toLowerCase()) {
            case "givegroup":
                if (args.length < 3) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription(getDescription()), channel);
                    return;
                }
                Member user = Parser.mention(args[1], channel.getGuild());
                if (user == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user).addGroup(group))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("User already had that group!"), channel);
                break;
            case "revokegroup":
                if (args.length < 3) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription(getDescription()), channel);
                    return;
                }
                Member user2 = Parser.mention(args[1], channel.getGuild());
                if (user2 == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group2 = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user2).removeGroup(group2))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("User never had that group!"), channel);
                break;
            case "groups":
                if (args.length == 1) {
                    channel.sendMessage(MessageUtils.getEmbed(sender)
                                                    .setDescription("Groups: " + getPermissions(channel).getGroups()
                                                                                                        .keySet()
                                                                                                        .stream()
                                                                                                        .collect(Collectors
                                                                                                                .joining(", ", "`", "`")))
                                                    .build()).queue();
                    return;
                }
                Member iUser = Parser.mention(args[1], channel.getGuild());
                if (iUser == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                User toList = getPermissions(channel).getUser(iUser);
                channel.sendMessage(MessageUtils.getEmbed(sender)
                                                .addField("User", iUser.getAsMention(), true)
                                                .setDescription("Groups: " + toList.getGroups().stream()
                                                                                   .collect(Collectors
                                                                                           .joining(", ", "`", "`")))
                                                .build()).queue();
                break;
            case "addpermission":
                if (args.length < 3) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                Group group3 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).addPermission(group3.getName(), args[2]))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("Group already had that permission"), channel);
                break;
            case "removepermission":
                if (args.length < 3) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                Group group4 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).removePermission(group4.getName(), args[2]))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("Group never had that permission"), channel);
                break;
            case "list":
                if (args.length < 2) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[1])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group5 = getPermissions(channel).getGroup(args[1]);
                StringBuilder perms = new StringBuilder("**Permissions for group ").append(group5.getName())
                                                                                   .append("**\n```fix\n");
                group5.getPermissions().forEach(perm -> perms.append(perm).append('\n'));
                perms.append("\n```");
                channel.sendMessage(perms.toString()).queue();
                break;
            case "save":
                if (getPermissions(channel).isCreator(sender))
                    try {
                        FlareBot.getInstance().getPermissions().save();
                    } catch (IOException e) {
                        MessageUtils.sendException("Could not save permissions!", e, channel);
                    }
                break;
            default:
                channel.sendMessage(getDescription()).queue();
                break;
        }
    }

    @Override
    public String getCommand() {
        return "permissions";
    }

    @Override
    public String[] getAliases() {
        return new String[]{"perm", "perms"};
    }

    @Override
    public String getDescription() {
        return "Manages server-wide permissions for FlareBot.";
    }

    @Override
    public String getUsage() {
        return "permissions <givegroup/revokegroup> <user> <group>\n"
                + "permissions <list>\n"
                + "permissions <addpermission/removepermission> <group> <permission>\n"
                + "permissions groups <user>";
    }

    @Override
    public CommandType getType() {
        return CommandType.MODERATION;
    }

    @Override
    public boolean isDefaultPermission() {
        return false;
    }
}
<commit_msg>Make usage more descriptive<commit_after>package stream.flarebot.flarebot.commands.administrator;

import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import stream.flarebot.flarebot.FlareBot;
import stream.flarebot.flarebot.MessageUtils;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.permissions.Group;
import stream.flarebot.flarebot.permissions.User;
import stream.flarebot.flarebot.util.Parser;

import java.io.IOException;
import java.util.stream.Collectors;

public class PermissionsCommand implements Command {

    @Override
    public void onCommand(net.dv8tion.jda.core.entities.User sender, TextChannel channel, Message message, String[] args, Member member) {
        if (args.length == 0) {
            channel.sendMessage(getDescription()).queue();
            return;
        }
        switch (args[0].toLowerCase()) {
            case "givegroup":
                if (args.length < 3) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription(getDescription()), channel);
                    return;
                }
                Member user = Parser.mention(args[1], channel.getGuild());
                if (user == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user).addGroup(group))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("User already had that group!"), channel);
                break;
            case "revokegroup":
                if (args.length < 3) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription(getDescription()), channel);
                    return;
                }
                Member user2 = Parser.mention(args[1], channel.getGuild());
                if (user2 == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group2 = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user2).removeGroup(group2))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("User never had that group!"), channel);
                break;
            case "groups":
                if (args.length == 1) {
                    channel.sendMessage(MessageUtils.getEmbed(sender)
                                                    .setDescription("Groups: " + getPermissions(channel).getGroups()
                                                                                                        .keySet()
                                                                                                        .stream()
                                                                                                        .collect(Collectors
                                                                                                                .joining(", ", "`", "`")))
                                                    .build()).queue();
                    return;
                }
                Member iUser = Parser.mention(args[1], channel.getGuild());
                if (iUser == null) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such user!"), channel);
                    return;
                }
                User toList = getPermissions(channel).getUser(iUser);
                channel.sendMessage(MessageUtils.getEmbed(sender)
                                                .addField("User", iUser.getAsMention(), true)
                                                .setDescription("Groups: " + toList.getGroups().stream()
                                                                                   .collect(Collectors
                                                                                           .joining(", ", "`", "`")))
                                                .build()).queue();
                break;
            case "addpermission":
                if (args.length < 3) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                Group group3 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).addPermission(group3.getName(), args[2]))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("Group already had that permission"), channel);
                break;
            case "removepermission":
                if (args.length < 3) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                Group group4 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).removePermission(group4.getName(), args[2]))
                    channel.sendMessage("Success").queue();
                else
                    MessageUtils.sendErrorMessage(MessageUtils.getEmbed(sender)
                                                              .setDescription("Group never had that permission"), channel);
                break;
            case "list":
                if (args.length < 2) {
                    channel.sendMessage(getDescription()).queue();
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[1])) {
                    MessageUtils
                            .sendErrorMessage(MessageUtils.getEmbed(sender).setDescription("No such group!"), channel);
                    return;
                }
                Group group5 = getPermissions(channel).getGroup(args[1]);
                StringBuilder perms = new StringBuilder("**Permissions for group ").append(group5.getName())
                                                                                   .append("**\n```fix\n");
                group5.getPermissions().forEach(perm -> perms.append(perm).append('\n'));
                perms.append("\n```");
                channel.sendMessage(perms.toString()).queue();
                break;
            case "save":
                if (getPermissions(channel).isCreator(sender))
                    try {
                        FlareBot.getInstance().getPermissions().save();
                    } catch (IOException e) {
                        MessageUtils.sendException("Could not save permissions!", e, channel);
                    }
                break;
            default:
                channel.sendMessage(getDescription()).queue();
                break;
        }
    }

    @Override
    public String getCommand() {
        return "permissions";
    }

    @Override
    public String[] getAliases() {
        return new String[]{"perm", "perms"};
    }

    @Override
    public String getDescription() {
        return "Manages server-wide permissions for FlareBot.";
    }

    @Override
    public String getUsage() {
        return "permissions <givegroup/revokegroup> <user> <group> - Add/Remove a user from a group\n"
                + "permissions <list> <group> - Lists permissions for a group\n"
                + "permissions <addpermission/removepermission> <group> <permission> - Add/Remove Permissions From group\n"
                + "permissions groups [user] - List groups [for a user]";
    }

    @Override
    public CommandType getType() {
        return CommandType.MODERATION;
    }

    @Override
    public boolean isDefaultPermission() {
        return false;
    }
}

{'fraction_non_alphanumeric': 0.09934727292842128, 'fraction_numerical': 0.004093373160747871, 'mean_word_length': 1.2556456643792888, 'pattern_counts': {'":': 14, '<': 29, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 90, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1923001', 'n_tokens_mistral': 3975, 'n_tokens_neox': 3720, 'n_words': 686}