Search in sources :

Example 16 with StringHandler

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

the class Utility method prepArgs.

public static String prepArgs(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)

Example 17 with StringHandler

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

the class ModuleJoinMessages method stats.

@Override
public String stats(CommandObject command) {
    IChannel channel = command.guild.getChannelByType(ChannelSetting.JOIN_CHANNEL);
    StringHandler builder = new StringHandler();
    if (channel != null) {
        builder.append("Join Channel: " + channel.mention());
    }
    if (!builder.isEmpty())
        builder.append("\n");
    builder.append("Message count: " + command.guild.channelData.getJoinMessages().size());
    return builder.toString();
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) StringHandler(com.github.vaerys.handlers.StringHandler)

Example 18 with StringHandler

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

the class SubCommandObject method getCommandUsage.

public String getCommandUsage(CommandObject command) {
    StringHandler usage = new StringHandler();
    StringHandler regexHandler = new StringHandler(regex);
    usage.append(command.guild.config.getPrefixCommand());
    usage.append(names[0]);
    regexHandler.replace("(", "[");
    regexHandler.replace(")", "]");
    regexHandler.replace("|", "/");
    usage.append(regexHandler);
    usage.append(" ");
    if (this.usage != null && !this.usage.isEmpty()) {
        usage.append(this.usage);
    }
    return usage.toString();
}
Also used : StringHandler(com.github.vaerys.handlers.StringHandler)

Example 19 with StringHandler

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

the class Mute method execute.

@Override
public String execute(String args, CommandObject command) {
    SplitFirstObject userCall = new SplitFirstObject(args);
    IRole mutedRole = command.guild.getMutedRole();
    UserObject muted = Utility.getUser(command, userCall.getFirstWord(), false, false);
    if (muted == null)
        return "> Could not find user";
    if (muted.getProfile(command.guild) == null)
        muted.addProfile(command.guild);
    if (mutedRole == null)
        return "> Muted role is not configured.";
    // Un mute subtype
    if (UN_MUTE.isSubCommand(command)) {
        if (!muted.roles.contains(mutedRole))
            return "> " + muted.displayName + " is not muted.";
        command.guild.users.unMuteUser(muted.longID, command.guild.longID);
        return "> " + muted.displayName + " was UnMuted.";
    }
    if (muted.longID == command.user.longID)
        return "> Don't try to mute yourself you numpty.";
    if (!Utility.testUserHierarchy(command.client.bot.get(), mutedRole, command.guild.get()))
        return "> Cannot Mute " + muted.displayName + ". **" + mutedRole.getName() + "** role has a higher hierarchy than me.";
    if (!Utility.testUserHierarchy(command.user.get(), muted.get(), command.guild.get()))
        return "> Cannot Mute/UnMute " + muted.displayName + ". User hierarchy higher than yours.";
    StringHandler reason = new StringHandler(userCall.getRest());
    long timeSecs = Utility.getRepeatTimeValue(reason);
    boolean isStrike = false;
    // if (reason.toString().isEmpty()) return "> Reason Cannot be empty";
    // mute the offender
    command.guild.users.muteUser(muted.longID, timeSecs, command.guild.longID);
    // build the response
    // time value
    String timeValue = "";
    if (timeSecs > 0) {
        timeValue = Utility.formatTime(timeSecs, true);
    }
    if (Pattern.compile("(^⚠ | ⚠|⚠)").matcher(reason.toString()).find()) {
        reason.replaceRegex("(^⚠ | ⚠|⚠)", "");
        isStrike = true;
    }
    // setup muted messages
    // name was muted for timevalue;
    String msgFormat = "> **%s** was muted%s";
    // > name was muted for timevalue by mod in channel with `reason`;
    String adminMsg = " by %s in %s with reason `%s`.";
    // name muted with reason `reason` for timevalue in channel;
    String modnote = "Muted by %s. Reason: `%s`. Time: %s. Channel: %s.";
    IChannel adminChannel = command.guild.getChannelByType(ChannelSetting.ADMIN);
    if (reason.toString().isEmpty())
        reason.setContent("No reason given");
    // final responses:
    String responseTime = !timeValue.isEmpty() ? " for " + timeValue : "";
    String response = String.format(msgFormat, muted.mention(), responseTime);
    if (adminChannel != null) {
        RequestHandler.sendMessage(response + String.format(adminMsg, command.user.displayName, command.channel.mention, reason), adminChannel);
    }
    muted.getProfile(command.guild).addSailModNote(String.format(modnote, command.user.displayName, reason, timeValue, command.channel.mention), command, isStrike);
    return response + ".";
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) UserObject(com.github.vaerys.masterobjects.UserObject) StringHandler(com.github.vaerys.handlers.StringHandler) SplitFirstObject(com.github.vaerys.objects.SplitFirstObject)

Example 20 with StringHandler

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

the class ListJoinMessages method execute.

@Override
public String execute(String args, CommandObject command) {
    XEmbedBuilder builder = new XEmbedBuilder(command);
    StringHandler handler = new StringHandler();
    List<JoinMessage> messages = command.guild.channelData.getJoinMessages();
    if (messages.size() == 0) {
        return "> No Messages exist right now, you can create some with **" + new NewJoinMessage().getUsage(command) + "**";
    }
    int page = 1;
    try {
        page = Integer.parseInt(args);
        if (page <= 0)
            return "> Invalid Page.";
    } catch (NumberFormatException e) {
        if (args != null && !args.isEmpty()) {
            return "> Not a valid number";
        }
    }
    page--;
    List<String> pages = new LinkedList<>();
    int index = 1;
    int i = 0;
    for (JoinMessage m : messages) {
        if (i == 10) {
            i = 0;
            pages.add(handler.toString());
            handler.emptyContent();
        }
        String shortNote = Utility.truncateString(Utility.removeFun(m.getContent()), 65);
        handler.append("**> Message #" + index + "**");
        handler.append("\n" + shortNote);
        handler.append("\n");
        i++;
        index++;
    }
    pages.add(handler.toString());
    if (page >= pages.size()) {
        return "> Invalid Page.";
    }
    builder.withTitle("> Join Message list");
    builder.withDesc(pages.get(page) + "\n\n" + missingArgs(command));
    builder.withFooterText("Page " + (page + 1) + "/" + pages.size() + " | Total Join Messages: " + messages.size());
    builder.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) JoinMessage(com.github.vaerys.objects.JoinMessage) StringHandler(com.github.vaerys.handlers.StringHandler) LinkedList(java.util.LinkedList)

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