Search in sources :

Example 11 with StringHandler

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

the class SubCommandObject method getHelpDesc.

public String getHelpDesc(CommandObject command) {
    StringHandler builder = new StringHandler();
    builder.append(description + "\n");
    builder.append("**Type: **" + type.toString() + ".");
    // display permissions
    if (permissions != null && permissions.length != 0) {
        builder.append("\n**Perms: **");
        ArrayList<String> permList = new ArrayList<>(permissions.length);
        for (Permissions p : permissions) {
            permList.add(Utility.enumToString(p));
        }
        builder.append(Utility.listFormatter(permList, true));
    }
    if (names.length > 1) {
        List<String> aliases = Arrays.asList(names).stream().map(s -> command.guild.config.getPrefixCommand() + s).collect(Collectors.toList());
        aliases.remove(0);
        builder.append("\n**Aliases:** " + Utility.listFormatter(aliases, true));
    }
    return builder.toString();
}
Also used : Arrays(java.util.Arrays) List(java.util.List) CommandObject(com.github.vaerys.commands.CommandObject) StringHandler(com.github.vaerys.handlers.StringHandler) SAILType(com.github.vaerys.enums.SAILType) Permissions(sx.blah.discord.handle.obj.Permissions) Pattern(java.util.regex.Pattern) GuildHandler(com.github.vaerys.handlers.GuildHandler) Utility(com.github.vaerys.main.Utility) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Permissions(sx.blah.discord.handle.obj.Permissions) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 12 with StringHandler

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

the class RemindMe method execute.

@Override
public String execute(String args, CommandObject command) {
    StringHandler contents = new StringHandler(args);
    long timeSecs = Utility.getRepeatTimeValue(contents);
    if (timeSecs == -1) {
        return "> Could not find a valid time value.\n" + Utility.getCommandInfo(this, command);
    }
    if (timeSecs < 30) {
        return "> You can't set a reminder for less than 30 seconds.";
    }
    if (timeSecs > 60 * 24 * 365 * 60) {
        return "> What are you doing... that reminder is set for over a year from now... you cant do that.";
    }
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    now = now.plusSeconds(timeSecs);
    String response = TimerHandler.addReminder(command.user.longID, command.channel.longID, now.toEpochSecond(), contents.toString());
    int maxSlots = Globals.maxReminderSlots;
    if (command.user.isPatron) {
        maxSlots += maxSlots;
    }
    String timeValue = Utility.formatTime(timeSecs, true);
    switch(response) {
        case "MAX":
            return "> You can only have " + maxSlots + " reminders.";
        case "INTERRUPTS":
            return "> Reminders cannot be within 5 minutes of each other.";
        default:
            return "> Reminder set for " + timeValue + " from now.";
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 13 with StringHandler

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

the class ModNote method createListEmbed.

private String createListEmbed(ProfileObject user, CommandObject command) {
    if (user.modNotes == null || user.modNotes.size() == 0) {
        return "> " + user.getUser(command.guild).displayName + " doesn't have any notes yet.";
    }
    UserObject userObject = user.getUser(command.guild);
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withColor(userObject.color);
    builder.withTitle("Notes for " + userObject.displayName);
    // avatar
    if (userObject.get() != null)
        builder.withThumbnail(userObject.get().getAvatarURL());
    else
        builder.withThumbnail(user.getDefaultAvatarURL());
    // get all notes and put together the bits and bobs
    int counter = 0;
    String noteLine = "**Note #%d:**\n%s\n";
    StringHandler content = new StringHandler();
    for (ModNoteObject noteObject : user.modNotes) {
        String shortNote = Utility.truncateString(Utility.removeFun(noteObject.getNote()), 65);
        if (noteObject.getStrike()) {
            content.append("⚠ ");
        }
        content.append(String.format(noteLine, ++counter, shortNote));
    }
    builder.withDesc(content.toString());
    // finalize and send message:
    builder.withFooterText("Total Notes: " + user.modNotes.size());
    builder.send(command.channel);
    return null;
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 14 with StringHandler

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

the class Client method refreshPatreonToken.

public static void refreshPatreonToken(String clientID, String clientSecret, String refreshToken) {
    try {
        patreonOAuth = new PatreonOAuth(clientID, clientSecret, "");
        PatreonOAuth.TokensResponse refresh = patreonOAuth.refreshTokens(refreshToken);
        StringHandler tokenData = new StringHandler();
        tokenData.append(refresh.getAccessToken() + "\n");
        tokenData.append(clientID + "\n");
        tokenData.append(clientSecret + "\n");
        tokenData.append(refresh.getRefreshToken());
        FileHandler.writeToFile(Constants.FILE_PATREON_TOKEN, tokenData.toString(), true);
        patreonApi = new PatreonAPI(refresh.getAccessToken());
    } catch (HttpStatusException e) {
        if (e.getStatusCode() == 401) {
            logger.error("Refresh Token is invalid.");
            return;
        }
        Utility.sendStack(e);
    } catch (IOException e) {
        Utility.sendStack(e);
    }
}
Also used : PatreonOAuth(com.patreon.PatreonOAuth) HttpStatusException(org.jsoup.HttpStatusException) IOException(java.io.IOException) StringHandler(com.github.vaerys.handlers.StringHandler) PatreonAPI(com.github.vaerys.objects.PatreonAPI)

Example 15 with StringHandler

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

the class Utility method removePrep.

public static String removePrep(String args) {
    StringHandler replace = new StringHandler(args);
    replace.replace("<u007B>", "{");
    replace.replace("<u007D>", "}");
    replace.replace("<u0028>", "(");
    replace.replace("<u0029>", ")");
    replace.replace("<u003A>", ":");
    replace.replace("<u003B>", ";");
    return replace.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