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();
}
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();
}
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);
}
}
}
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());
}
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();
}
Aggregations