Search in sources :

Example 41 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class QueueHandler method addToQueue.

public static void addToQueue(CommandObject object, String content, DayOfWeek dayOfWeek, String type) {
    ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
    ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
    IChannel channel = object.client.get().getChannelByID(Globals.queueChannelID);
    if (channel != null) {
        switch(type) {
            case Constants.QUEUE_DAILY:
                long uID = Globals.getDailyMessages().newDailyMsgUID();
                if (uID == -1) {
                    object.client.creator.sendDm("> Max limit of Daily messages hit.");
                    break;
                }
                XEmbedBuilder embedBuilder = new XEmbedBuilder(object);
                embedBuilder.withAuthorName("New Daily Message - " + object.guild.get().getName());
                embedBuilder.withFooterText(object.user.longID + "");
                embedBuilder.withTitle(object.user.username);
                embedBuilder.withDesc(content);
                embedBuilder.appendField(dowString, dayOfWeek + "", true);
                embedBuilder.appendField(uIDString, uID + "", true);
                IMessage message = RequestHandler.sendEmbedMessage("", embedBuilder, channel).get();
                RequestBuffer.request(() -> message.addReaction(thumbsUp)).get();
                RequestBuffer.request(() -> message.addReaction(thumbsDown)).get();
                Globals.getDailyMessages().getQueue().add(new QueueObject(message.getLongID(), uID, type));
                checkQueue();
                return;
            default:
                return;
        }
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) QueueObject(com.github.vaerys.objects.QueueObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji)

Example 42 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class RequestHandler method sendEmbededImage.

public static RequestBuffer.RequestFuture<IMessage> sendEmbededImage(String s, String imageUrl, IChannel channel) {
    XEmbedBuilder builder = new XEmbedBuilder(Constants.pixelColour);
    builder.withImage(imageUrl);
    if (s.length() > 2000) {
        sendError("Could not send message, Too Large.", s, channel);
        return null;
    }
    if (!Utility.isImageLink(imageUrl)) {
        sendError("Could not send Embed, link is not a valid image URL", imageUrl, channel);
        return null;
    }
    return RequestBuffer.request(() -> {
        if (s == null || s.isEmpty()) {
            return channel.sendMessage(builder.build());
        }
        return channel.sendMessage(s, builder.build());
    });
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder)

Example 43 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class InfoCC method execute.

@Override
public String execute(String args, CommandObject command) {
    CCommandObject customCommand = command.guild.customCommands.getCommand(args);
    if (customCommand == null) {
        return Constants.ERROR_CC_NOT_FOUND;
    }
    StringBuilder builder = new StringBuilder();
    XEmbedBuilder embedBuilder = new XEmbedBuilder(command);
    String title = "> Here is the information for command: **" + customCommand.getName() + "**\n";
    IUser createdBy = command.guild.getUserByID(customCommand.getUserID());
    if (createdBy == null)
        createdBy = command.client.get().fetchUser(customCommand.getUserID());
    if (createdBy == null)
        builder.append("Creator: **Null**\n");
    else
        builder.append("Creator: **@" + createdBy.getName() + "#" + createdBy.getDiscriminator() + "**\n");
    builder.append("Time Run: **" + customCommand.getTimesRun() + "**\n");
    builder.append("Is Locked: **" + customCommand.isLocked() + "**\n");
    builder.append("Is ShitPost: **" + customCommand.isShitPost() + "**");
    embedBuilder.appendField(title, builder.toString(), false);
    RequestHandler.sendEmbedMessage("", embedBuilder, command.channel.get());
    return null;
}
Also used : CCommandObject(com.github.vaerys.objects.CCommandObject) XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser)

Example 44 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class ListCCs method listCommands.

public String listCommands(int page, CommandObject command) {
    ArrayList<String> pages = new ArrayList<>();
    int counter = 0;
    int totalCCs = 0;
    ArrayList<String> list = new ArrayList<>();
    XEmbedBuilder builder = new XEmbedBuilder(command);
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        if (counter > 15) {
            pages.add("```" + Utility.listFormatter(list, true) + "```");
            list.clear();
            counter = 0;
        }
        list.add(command.guild.config.getPrefixCC() + c.getName());
        totalCCs++;
        counter++;
    }
    pages.add("`" + Utility.listFormatter(list, true) + "`");
    try {
        String title = "> Here is Page **" + page + "/" + pages.size() + "** of Custom Commands:";
        builder.appendField(title, pages.get(page - 1), false);
        builder.withFooterText("Total Custom Commands stored on this Server: " + totalCCs);
        RequestHandler.sendEmbedMessage("", builder, command.channel.get());
        return null;
    } catch (IndexOutOfBoundsException e) {
        return "> That Page does not exist.";
    }
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CCommandObject(com.github.vaerys.objects.CCommandObject) ArrayList(java.util.ArrayList)

Example 45 with XEmbedBuilder

use of com.github.vaerys.objects.XEmbedBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class BotStats method execute.

@Override
public String execute(String args, CommandObject command) {
    List<Double> cpuUsage = TimerHandler.cpuUsage;
    long freeMemory = Runtime.getRuntime().freeMemory();
    long totalMemory = Runtime.getRuntime().totalMemory();
    long usedMemory = totalMemory - freeMemory;
    long userCount = command.client.get().getUsers().size();
    double usage = cpuUsage.stream().mapToDouble(value -> value).sum() / cpuUsage.size();
    // and make it look pretty
    NumberFormat nf = NumberFormat.getInstance();
    long ping = command.client.get().getShards().get(0).getResponseTime();
    double mb = 1048576.0;
    XEmbedBuilder builder = new XEmbedBuilder(command);
    builder.withTitle(command.client.bot.username);
    builder.withTimestamp(command.client.bot.get().getCreationDate());
    builder.withFooterText("Creation Date");
    StringHandler handler = new StringHandler();
    handler.append("**Total Servers**: ").append(command.client.get().getGuilds().size());
    handler.append(indent + "**Total Users**: " + userCount);
    handler.append("\n**Total Active Threads**: ").append(Thread.activeCount());
    handler.append("\n**CPU Usage**: ").append(nf.format(usage * 100)).append("%");
    handler.append("\n**Memory Usage**: ");
    nf.setMaximumFractionDigits(1);
    handler.append(nf.format(totalMemory / mb)).append("MB total\t");
    handler.append(nf.format(usedMemory / mb)).append("MB used\t");
    handler.append(nf.format(freeMemory / mb)).append("MB free");
    handler.append("\n**Ping**: ").append(nf.format(ping)).append("ms");
    builder.withDesc(handler.toString());
    builder.withThumbnail(command.client.bot.getAvatarURL());
    builder.send(command.channel);
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) StringHandler(com.github.vaerys.handlers.StringHandler) NumberFormat(java.text.NumberFormat)

Aggregations

XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)51 ArrayList (java.util.ArrayList)15 ChannelSetting (com.github.vaerys.enums.ChannelSetting)10 SAILType (com.github.vaerys.enums.SAILType)10 CommandObject (com.github.vaerys.commands.CommandObject)9 IUser (sx.blah.discord.handle.obj.IUser)9 Utility (com.github.vaerys.main.Utility)8 UserObject (com.github.vaerys.masterobjects.UserObject)8 Collectors (java.util.stream.Collectors)8 Command (com.github.vaerys.templates.Command)7 List (java.util.List)6 Permissions (sx.blah.discord.handle.obj.Permissions)6 RequestHandler (com.github.vaerys.handlers.RequestHandler)5 StringHandler (com.github.vaerys.handlers.StringHandler)5 ProfileObject (com.github.vaerys.objects.ProfileObject)5 IRole (sx.blah.discord.handle.obj.IRole)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)4 GuildToggle (com.github.vaerys.templates.GuildToggle)4 LinkedList (java.util.LinkedList)4