<commit_before>package com.bwfcwalshy.flarebot.commands.administrator;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.bwfcwalshy.flarebot.permissions.Group;
import com.bwfcwalshy.flarebot.util.Parser;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;

import java.io.IOException;

public class PermissionsCommand implements Command {

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if (args.length == 0) {
            MessageUtils.sendMessage(channel, getDescription());
            return;
        }
        switch (args[0].toLowerCase()) {
            case "givegroup":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                IUser user = Parser.mention(args[1]);
                if (user == null) {
                    MessageUtils.sendMessage(channel, "No such user!");
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    return;
                }
                Group group = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user).addGroup(group))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "User already had that group!");
                break;
            case "revokegroup":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                IUser user2 = Parser.mention(args[1]);
                if (user2 == null) {
                    MessageUtils.sendMessage(channel, "No such user!");
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    return;
                }
                Group group2 = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user2).removeGroup(group2))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "User never had that group!");
                break;
            case "addpermission":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                Group group3 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).addPermission(group3.getName(), args[2]))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "Group already had that permission");
                break;
            case "removepermission":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                Group group4 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).removePermission(group4.getName(), args[2]))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "Group never had that permission");
                break;
            case "list":
                if (args.length < 2) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[1])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    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```");
                MessageUtils.sendMessage(channel, perms);
                break;
            case "save":
                try {
                    FlareBot.getInstance().getPermissions().save();
                } catch (IOException e) {
                    MessageUtils.sendException("Could not save permissions!", e, channel);
                }
                break;
            default:
                MessageUtils.sendMessage(channel, getDescription());
                break;
        }
    }

    @Override<commit_msg>Add a _perms save check<commit_after>package com.bwfcwalshy.flarebot.commands.administrator;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.bwfcwalshy.flarebot.permissions.Group;
import com.bwfcwalshy.flarebot.util.Parser;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;

import java.io.IOException;

public class PermissionsCommand implements Command {

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if (args.length == 0) {
            MessageUtils.sendMessage(channel, getDescription());
            return;
        }
        switch (args[0].toLowerCase()) {
            case "givegroup":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                IUser user = Parser.mention(args[1]);
                if (user == null) {
                    MessageUtils.sendMessage(channel, "No such user!");
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    return;
                }
                Group group = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user).addGroup(group))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "User already had that group!");
                break;
            case "revokegroup":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                IUser user2 = Parser.mention(args[1]);
                if (user2 == null) {
                    MessageUtils.sendMessage(channel, "No such user!");
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[2])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    return;
                }
                Group group2 = getPermissions(channel).getGroup(args[2]);
                if (getPermissions(channel).getUser(user2).removeGroup(group2))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "User never had that group!");
                break;
            case "addpermission":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                Group group3 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).addPermission(group3.getName(), args[2]))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "Group already had that permission");
                break;
            case "removepermission":
                if (args.length < 3) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                Group group4 = getPermissions(channel).getGroup(args[1]);
                if (getPermissions(channel).removePermission(group4.getName(), args[2]))
                    MessageUtils.sendMessage(channel, "Success");
                else MessageUtils.sendMessage(channel, "Group never had that permission");
                break;
            case "list":
                if (args.length < 2) {
                    MessageUtils.sendMessage(channel, getDescription());
                    return;
                }
                if (!getPermissions(channel).hasGroup(args[1])) {
                    MessageUtils.sendMessage(channel, "No such group!");
                    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```");
                MessageUtils.sendMessage(channel, perms);
                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:
                MessageUtils.sendMessage(channel, getDescription());
                break;
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.10716059191578112, 'fraction_numerical': 0.0061575131592015095, 'mean_word_length': 1.6402726796014682, 'pattern_counts': {'":': 12, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3144723', 'n_tokens_mistral': 2531, 'n_tokens_neox': 2376, 'n_words': 459}