<commit_before>package utils;

import sx.blah.discord.api.ClientBuilder;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.util.DiscordException;

/**
 * Contains important methods and variables for the Bot
 */
public final class BotUtils {

    /**
     * System's start time
     */
    private static long startTime;

    /**
     * Bot's user token
     */
    private static String botToken;

    /**
     * Only messages starting with this prefix will be tracked
     */
    public static final String BOT_PREFIX = "//";

    /**
     * Line comment in config file
     */
    public static final String CONFIG_COMMENT = "#";

    /**
     * Configuration's File Path
     */
    public static final String DEFAULT_CONFIG_PATH =
            System.getProperty("user.dir") + "/config/config.cfg";

    /**
     * Missing Token Error Message
     */
    public static final String MISSING_TOKEN = "RexCord: Please insert your "
            + "server's bot token in the configuration file.";

    /**
     * Config missing Error Message
     */
    public static final String CONFIG_NOT_FOUND_ERROR =
            "RexCord: Config file not found. "
                    + "Make sure it is created and located in "
                    + "the correct directory.";

    /**
     * Default Error Message
     */
    public static final String ERROR_MESSAGE =
            "RexCord: Unable to start RexCord!";

    /**
     * RexCord terminating message
     */
    public static final String TERMINATING_MESSAGE =
            "RexCord: Terminating RexCord...";

    /**
     * Private Constructor
     */
    private BotUtils() {

    }

    /**
     * Sets a new Bot Token
     * @param newToken new Bot Token to be set
     */
    public static void setBotToken(String newToken) {
        BotUtils.botToken = newToken;
    }

    /**
     * Gets system start time, in mm
     * @return system start time, in mm
     */
    public static long getStartTime() {
        return startTime;
    }

    /**
     * S system start time, in mm
     * @param startTime system start time, in mm
     */
    public static void setStartTime(long startTime) {
        BotUtils.startTime = startTime;
    }

    /**
     * Handles the creation of a Bot Client
     * @return A new Bot Client
     */
    public static IDiscordClient createDiscordClient() {
        return new ClientBuilder()
                .withToken(botToken)
                .build();
    }

    /**
     * Sends a text message
     * @param channel text channel
     * @param message message
     */
    public static void sendMessage(IChannel channel, String message) {
        try {
            channel.sendMessage(message);
        } catch (DiscordException de) {
            System.out.println("RexCord: Error sending message. Got error:");
            de.printStackTrace();
        }
    }
}<commit_msg>Added a method that detects if a certain user which triggered an event has a certain role on the server<commit_after>package utils;

import java.util.List;
import sx.blah.discord.api.ClientBuilder;
import sx.blah.discord.api.IDiscordClient;
import sx.blah.discord.handle.impl.events.guild.channel.message
        .MessageReceivedEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.util.DiscordException;

/**
 * Contains important methods and variables for the Bot
 */
public final class BotUtils {

    /**
     * System's start time
     */
    private static long startTime;

    /**
     * Bot's user token
     */
    private static String botToken;

    /**
     * Only messages starting with this prefix will be tracked
     */
    public static final String BOT_PREFIX = "//";

    /**
     * Line comment in config file
     */
    public static final String CONFIG_COMMENT = "#";

    /**
     * Configuration's File Path
     */
    public static final String DEFAULT_CONFIG_PATH
            = System.getProperty("user.dir") + "/config/config.cfg";

    /**
     * Missing Token Error Message
     */
    public static final String MISSING_TOKEN = "<PASSWORD>: Please insert your "
            + "server's bot token in the configuration file.";

    /**
     * Config missing Error Message
     */
    public static final String CONFIG_NOT_FOUND_ERROR
            = "RexCord: Config file not found. "
            + "Make sure it is created and located in "
            + "the correct directory.";

    /**
     * Default Error Message
     */
    public static final String ERROR_MESSAGE
            = "RexCord: Unable to start RexCord!";

    /**
     * RexCord terminating message
     */
    public static final String TERMINATING_MESSAGE
            = "RexCord: Terminating RexCord...";

    /**
     * Private Constructor
     */
    private BotUtils() {

    }

    /**
     * Sets a new Bot Token
     *
     * @param newToken new Bot Token to be set
     */
    public static void setBotToken(String newToken) {
        BotUtils.botToken = newToken;
    }

    /**
     * Gets system start time, in mm
     *
     * @return system start time, in mm
     */
    public static long getStartTime() {
        return startTime;
    }

    /**
     * S system start time, in mm
     *
     * @param startTime system start time, in mm
     */
    public static void setStartTime(long startTime) {
        BotUtils.startTime = startTime;
    }

    /**
     * Handles the creation of a Bot Client
     *
     * @return A new Bot Client
     */
    public static IDiscordClient createDiscordClient() {
        return new ClientBuilder()
                .withToken(botToken)
                .build();
    }

    /**
     * Sends a text message
     *
     * @param channel text channel
     * @param message message
     */
    public static void sendMessage(IChannel channel, String message) {
        try {
            channel.sendMessage(message);
        } catch (DiscordException de) {
            System.out.println("RexCord: Error sending message. Got error:");
            de.printStackTrace();
        }
    }

    /**
     * Returns the roles of a certain user that triggered an event
     *
     * @param event received event triggered by an user
     * @return List of Roles the user who triggered an event has
     */
    private static List<IRole> getRolesUserOnEvent(MessageReceivedEvent event) {
        return event.getGuild().getRolesForUser(event.getAuthor());
    }

    /**
     * Checks if a user has acess to a certain role
     *
     * @param event received event triggered by an user
     * @param role String with the desired role wanted to be compared
     * @return a boolean true if has acess, false if not
     */
    public static boolean hasUserAcessToRoleOnEvent(MessageReceivedEvent event,
            String role) {
        List<IRole> userRoles = getRolesUserOnEvent(event);
        for (int i = 0; i < userRoles.size(); i++) {
            if (userRoles.get(i).getName().replaceFirst("@", "")
                    .equalsIgnoreCase(role)) {
                return true;
            }
        }
        return false;
    }
}
{'fraction_non_alphanumeric': 0.09186241610738255, 'fraction_numerical': 0.00013982102908277405, 'mean_word_length': 2.037367303609342, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '908580', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1942, 'n_words': 630}