Search in sources :

Example 6 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method escapeRegex.

public static String escapeRegex(String args) {
    // [\^$.|?*+(){}
    StringHandler replace = new StringHandler(args);
    replace.replace("\\", "\\u005C");
    replace.replace("[", "\\u005B");
    replace.replace("^", "\\u005E");
    replace.replace("$", "\\u0024");
    replace.replace(".", "\\u002E");
    replace.replace("|", "\\u007C");
    replace.replace("?", "\\u003F");
    replace.replace("*", "\\u002A");
    replace.replace("+", "\\u002B");
    replace.replace("(", "\\u0028");
    replace.replace(")", "\\u0029");
    replace.replace("{", "\\u007B");
    replace.replace("}", "\\u007D");
    return replace.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Example 7 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method unFormatMentions.

public static String unFormatMentions(IMessage message) {
    StringHandler from = new StringHandler(message.getContent());
    from.replaceRegex("(?i)(@here|@everyone)", "**[REDACTED]**");
    for (IUser user : message.getMentions()) {
        if (user != null) {
            StringHandler regex = new StringHandler("<@!?").append(user.getLongID()).append(">");
            StringHandler replacement = new StringHandler("__@").append(user.getDisplayName(message.getGuild())).append("__");
            from.replaceRegex(regex, replacement);
        }
    }
    for (IRole role : message.getRoleMentions()) {
        StringHandler toReplace = new StringHandler("<@&").append(role.getLongID()).append(">");
        StringHandler replaceWith = new StringHandler("__**@").append(role.getName()).append("**__");
        from.replace(toReplace, replaceWith);
    }
    return from.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Example 8 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method sendGlobalAdminLogging.

public static void sendGlobalAdminLogging(Command command, String args, CommandObject commandObject) {
    for (GuildObject c : Globals.getGuilds()) {
        StringHandler message = new StringHandler("***GLOBAL LOGGING***\n> **@").append(commandObject.user.username).append("** Has Used Command `").append(command.names[0]).append("`");
        List<IChannel> adminlog = c.getChannelsByType(ChannelSetting.ADMIN_LOG);
        List<IChannel> serverLog = c.getChannelsByType(ChannelSetting.SERVER_LOG);
        IChannel channel = null;
        if (!(args == null || args.isEmpty())) {
            message.append(" with args: `" + args + "`");
        }
        if (serverLog.size() != 0) {
            channel = serverLog.get(0);
        }
        if (adminlog.size() != 0) {
            channel = adminlog.get(0);
        }
        if (channel != null) {
            RequestHandler.sendMessage(message.toString(), channel);
        }
    }
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 9 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method sendStack.

public static void sendStack(Exception e) {
    StringHandler s = new StringHandler(ExceptionUtils.getStackTrace(e));
    s.setContent(s.substring(0, s.length() - 2));
    if (!s.toString().endsWith(")")) {
        s.append(")");
    }
    StringHandler builder = new StringHandler();
    builder.addViaJoin(Globals.getAllLogs(), "\n");
    logger.error(s.toString() + "\n>> LAST " + Globals.getAllLogs().size() + " DEBUG LOGS<<\n" + builder.toString());
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Example 10 with StringHandler

use of com.github.vaerys.handlers.StringHandler in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method formatTimeDifference.

public static String formatTimeDifference(long difference) {
    StringHandler formatted = new StringHandler();
    try {
        long days = TimeUnit.SECONDS.toDays(difference);
        long hours = TimeUnit.SECONDS.toHours(difference);
        hours -= days * 24;
        long mins = TimeUnit.SECONDS.toMinutes(difference);
        mins -= (days * 24 + hours) * 60;
        if (days > 0) {
            if (days > 1) {
                formatted.append(days).append(" days, ");
            } else {
                formatted.append(days).append(" day, ");
            }
        }
        if (hours > 0) {
            if (hours > 1) {
                formatted.append(hours).append(" hours and ");
            } else {
                formatted.append(hours).append(" hour and ");
            }
        }
        if (mins > 1) {
            formatted.append(mins).append(" minutes ago");
        } else if (mins != 0) {
            formatted.append(mins).append(" minute ago");
        }
        if (difference < 60) {
            formatted.setContent("less than a minute ago");
        }
    } catch (NoSuchElementException e) {
        logger.error("Error getting Edited Message Timestamp.");
    }
    return formatted.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Aggregations

StringHandler (com.github.vaerys.handlers.StringHandler)23 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)5 SAILType (com.github.vaerys.enums.SAILType)3 GuildToggle (com.github.vaerys.templates.GuildToggle)3 IChannel (sx.blah.discord.handle.obj.IChannel)3 CommandObject (com.github.vaerys.commands.CommandObject)2 HelpModules (com.github.vaerys.commands.help.HelpModules)2 HelpSettings (com.github.vaerys.commands.help.HelpSettings)2 Utility (com.github.vaerys.main.Utility)2 UserObject (com.github.vaerys.masterobjects.UserObject)2 LinkedList (java.util.LinkedList)2 Collectors (java.util.stream.Collectors)2 Module (com.github.vaerys.commands.admin.Module)1 Toggle (com.github.vaerys.commands.admin.Toggle)1 ToggleInit (com.github.vaerys.guildtoggles.ToggleInit)1 ModuleLogging (com.github.vaerys.guildtoggles.modules.ModuleLogging)1 DebugMode (com.github.vaerys.guildtoggles.toggles.DebugMode)1 GuildHandler (com.github.vaerys.handlers.GuildHandler)1 RequestHandler (com.github.vaerys.handlers.RequestHandler)1 SetupHandler (com.github.vaerys.handlers.SetupHandler)1