Search in sources :

Example 16 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class GetCompEntries method execute.

@Override
public String execute(String args, CommandObject command) {
    if (command.guild.competition.getEntries().size() == 0) {
        return "> No entries were found.";
    }
    List<CompObject> compObjects = command.guild.competition.getEntries();
    for (int i = 0; i < compObjects.size(); i++) {
        XEmbedBuilder builder = new XEmbedBuilder(command);
        builder.withTitle("Entry " + (i + 1));
        IUser user = command.guild.getUserByID(compObjects.get(i).getUserID());
        if (user != null) {
            builder.withDesc(user.mention());
            builder.withColor(GuildHandler.getUsersColour(user, command.guild.get()));
        }
        if (Utility.isImageLink(compObjects.get(i).getFileUrl())) {
            builder.withThumbnail(compObjects.get(i).getFileUrl());
        } else {
            if (user != null) {
                builder.withDesc(user.mention() + "\n" + compObjects.get(i).getFileUrl());
            } else {
                builder.withDesc(compObjects.get(i).getFileUrl());
            }
        }
        builder.send(command.channel);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Utility.sendStack(e);
        }
    }
    return "";
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) CompObject(com.github.vaerys.objects.CompObject)

Example 17 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class WeightedFinalTally method execute.

@Override
public String execute(String args, CommandObject command) {
    if (!command.guild.config.modulePixels)
        return "> Weighted final tally should only be used if the pixel module is enabled, please use **" + new FinalTally().getUsage(command) + "** instead.";
    Map<Long, Long> entryVotes = new HashMap<>();
    long totalEntries = 0;
    long totalVotes = 0;
    StringBuilder builder = new StringBuilder();
    for (long i = 0; i < command.guild.competition.getEntries().size(); i++) {
        entryVotes.put(i + 1, 0L);
    }
    for (String s : command.guild.competition.getVotes()) {
        String[] splitVotes = s.split(",");
        if (splitVotes.length != 1 && splitVotes.length != 0) {
            for (long i = 1; i < splitVotes.length; i++) {
                try {
                    long vote = Long.parseLong(splitVotes[(int) i]);
                    if (entryVotes.containsKey(vote)) {
                        IUser user = command.guild.getUserByID(Utility.stringLong(splitVotes[0]));
                        if (user != null) {
                            int weight = PixelHandler.getRewardCount(command.guild, user.getLongID());
                            entryVotes.put(vote, entryVotes.get(vote).longValue() + weight + 1);
                            totalVotes += weight + 1;
                        }
                    }
                } catch (NumberFormatException e) {
                // Ignore
                }
                totalEntries++;
            }
        }
    }
    builder.append("**Total Weighted Votes\n**");
    entryVotes.forEach((k, v) -> builder.append("> Entry " + k + ": " + v + " Votes.\n"));
    builder.append("Total votes: " + totalVotes + ".\n");
    builder.append("Total Entries: " + totalEntries + ".");
    return builder.toString();
}
Also used : HashMap(java.util.HashMap) IUser(sx.blah.discord.handle.obj.IUser)

Example 18 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class ListCCs method getUserCommands.

public String getUserCommands(CommandObject command, long userID) {
    IUser user = Globals.getClient().getUserByID(userID);
    int total = 0;
    command.setAuthor(user);
    int max = command.guild.customCommands.maxCCs(command.user, command.guild);
    XEmbedBuilder builder = new XEmbedBuilder(command);
    String title = "> Here are the custom commands for user: **@" + user.getName() + "#" + user.getDiscriminator() + "**.";
    List<String> list = new ArrayList<>();
    for (CCommandObject c : command.guild.customCommands.getCommandList()) {
        if (c.getUserID() == userID) {
            list.add(command.guild.config.getPrefixCC() + c.getName());
            total++;
        }
    }
    builder.withTitle(title);
    String content = Utility.listFormatter(list, true);
    if (content.length() > 2000) {
        String path = Constants.DIRECTORY_TEMP + command.message.longID + ".txt";
        FileHandler.writeToFile(path, content, false);
        File file = new File(path);
        RequestHandler.sendFile(title, file, command.channel.get());
        return null;
    }
    builder.withDescription("```\n" + content + "```");
    builder.withFooterText("Total Custom commands: " + total + "/" + max + ".");
    RequestHandler.sendEmbedMessage("", builder, command.channel.get());
    return null;
}
Also used : XEmbedBuilder(com.github.vaerys.objects.XEmbedBuilder) CCommandObject(com.github.vaerys.objects.CCommandObject) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser) File(java.io.File)

Example 19 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class ResetRuleCode method execute.

@Override
public String execute(String args, CommandObject command) {
    IMessage working = RequestHandler.sendMessage("`Working...`", command.channel).get();
    for (ProfileObject p : command.guild.users.profiles) {
        if (p.getSettings().size() != 0) {
            p.getSettings().remove(UserSetting.READ_RULES);
        }
    }
    for (IUser u : command.guild.getUsers()) {
        GuildHandler.checkUsersRoles(u.getLongID(), command.guild);
    }
    RequestHandler.deleteMessage(working);
    return "Done. The Rule code tag has been removed off all profiles.";
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 20 with IUser

use of sx.blah.discord.handle.obj.IUser in project DiscordSailv2 by Vaerys-Dawn.

the class TagRemoveMentions method execute.

@Override
public String execute(String from, CommandObject command, String args) {
    boolean isRoleMention = false;
    String id;
    if (Pattern.compile("<@&[0-9]*>").matcher(from).find()) {
        id = StringUtils.substringBetween(from, "<@&", ">");
        isRoleMention = true;
    } else {
        id = StringUtils.substringBetween(from, "<@!", ">");
        if (id == null) {
            id = StringUtils.substringBetween(from, "<@", ">");
        }
    }
    if (!isRoleMention) {
        try {
            long userID = Long.parseUnsignedLong(id);
            IUser user = command.guild.getUserByID(userID);
            if (user != null) {
                from = from.replace(user.mention(true), user.getDisplayName(command.guild.get()));
                from = from.replace(user.mention(false), user.getDisplayName(command.guild.get()));
            } else {
                throw new NumberFormatException("You shouldn't see this.");
            }
        } catch (NumberFormatException e) {
            from = from.replaceAll("<@!?" + id + ">", "null");
        }
    } else {
        // remove role mentions
        try {
            long roleID = Long.parseUnsignedLong(id);
            IRole role = command.guild.getRoleByID(roleID);
            if (role != null) {
                from = from.replace("<@&" + id + ">", role.getName());
            } else {
                throw new NumberFormatException("You shouldn't see this.");
            }
        } catch (NumberFormatException e) {
            from = from.replace("<@&" + id + ">", "null");
        }
    }
    return from;
}
Also used : IRole(sx.blah.discord.handle.obj.IRole) IUser(sx.blah.discord.handle.obj.IUser)

Aggregations

IUser (sx.blah.discord.handle.obj.IUser)67 ArrayList (java.util.ArrayList)15 IGuild (sx.blah.discord.handle.obj.IGuild)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)13 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)9 IMessage (sx.blah.discord.handle.obj.IMessage)9 IRole (sx.blah.discord.handle.obj.IRole)8 List (java.util.List)7 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)7 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 HashMap (java.util.HashMap)5 CCommandObject (com.github.vaerys.objects.CCommandObject)4 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)4 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)4 Context (me.shadorc.shadbot.core.command.Context)4 Command (me.shadorc.shadbot.core.command.annotation.Command)4 BotUtils (me.shadorc.shadbot.utils.BotUtils)4 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)4 TextUtils (me.shadorc.shadbot.utils.TextUtils)4