Search in sources :

Example 91 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.

the class OverwatchCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    List<String> splitArgs = StringUtils.split(context.getArg());
    if (!Utils.isInRange(splitArgs.size(), 1, 3)) {
        throw new MissingArgumentException();
    }
    LoadingMessage loadingMsg = new LoadingMessage("Loading Overwatch profile...", context.getChannel());
    try {
        OverwatchPlayer player;
        String username = null;
        Platform platform = null;
        if (splitArgs.size() == 1) {
            username = splitArgs.get(0);
            loadingMsg.send();
            player = new OverwatchPlayer(username);
        } else {
            platform = this.getPlatform(splitArgs.get(0));
            username = splitArgs.get(1);
            loadingMsg.send();
            player = new OverwatchPlayer(username, platform);
        }
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Overwatch Stats").withAuthorIcon("http://vignette4.wikia.nocookie.net/overwatch/images/b/bd/Overwatch_line_art_logo_symbol-only.png").withAuthorUrl(player.getProfileURL()).withThumbnail(player.getIconUrl()).appendDescription(String.format("Stats for user **%s**", player.getName())).appendField("Level", Integer.toString(player.getLevel()), true).appendField("Competitive rank", Integer.toString(player.getRank()), true).appendField("Wins", Integer.toString(player.getWins()), true).appendField("Game time", player.getTimePlayed(), true).appendField("Top hero (Time played)", this.getTopThreeHeroes(player.getList(TopHeroesStats.TIME_PLAYED)), true).appendField("Top hero (Eliminations per life)", this.getTopThreeHeroes(player.getList(TopHeroesStats.ELIMINATIONS_PER_LIFE)), true);
        loadingMsg.edit(embed.build());
    } catch (OverwatchException err) {
        loadingMsg.edit(Emoji.MAGNIFYING_GLASS + " " + err.getMessage());
    } catch (IOException err) {
        loadingMsg.delete();
        Utils.handle("getting information from Overwatch profile", context, err);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Platform(net.shadorc.overwatch4j.enums.Platform) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException) OverwatchException(net.shadorc.overwatch4j.exception.OverwatchException) OverwatchPlayer(net.shadorc.overwatch4j.OverwatchPlayer)

Example 92 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.

the class BaguetteCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    EmbedBuilder embed = new EmbedBuilder().withColor(Config.BOT_COLOR).withImage("http://i.telegraph.co.uk/multimedia/archive/02600/CECPY7_2600591b.jpg");
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder)

Example 93 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.

the class HelpCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (context.hasArg()) {
        AbstractCommand cmd = CommandManager.getCommand(context.getArg());
        if (cmd == null) {
            return;
        }
        BotUtils.sendMessage(cmd.getHelp(context.getPrefix()), context.getChannel());
        CommandStatsManager.log(CommandEnum.COMMAND_HELPED, cmd);
        return;
    }
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Shadbot Help").appendDescription(String.format("Any issues, questions or suggestions ? Join the [support server.](%s)" + "%nGet more information by using `%s%s <command>`.", Config.SUPPORT_SERVER, context.getPrefix(), this.getName()));
    for (CommandCategory category : CommandCategory.values()) {
        if (category.equals(CommandCategory.HIDDEN)) {
            continue;
        }
        String commands = CommandManager.getCommands().values().stream().distinct().filter(cmd -> cmd.getCategory().equals(category) && !cmd.getPermission().isSuperior(context.getAuthorPermission()) && (context.getGuild() == null || BotUtils.isCommandAllowed(context.getGuild(), cmd))).map(cmd -> String.format("`%s%s`", context.getPrefix(), cmd.getName())).collect(Collectors.joining(" "));
        embed.appendField(String.format("%s Commands", category.toString()), commands, false);
    }
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : RateLimited(me.shadorc.shadbot.core.command.annotation.RateLimited) HelpBuilder(me.shadorc.shadbot.utils.embed.HelpBuilder) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory) CommandManager(me.shadorc.shadbot.core.command.CommandManager) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Collectors(java.util.stream.Collectors) BotUtils(me.shadorc.shadbot.utils.BotUtils) CommandStatsManager(me.shadorc.shadbot.data.stats.CommandStatsManager) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Context(me.shadorc.shadbot.core.command.Context) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) CommandEnum(me.shadorc.shadbot.data.stats.CommandStatsManager.CommandEnum) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) Config(me.shadorc.shadbot.Config) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory)

Example 94 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.

the class RelicStatusCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    List<Relic> relics = PremiumManager.getRelicsForUser(context.getAuthor().getLongID());
    if (relics.isEmpty()) {
        BotUtils.sendMessage(String.format(Emoji.INFO + " You are not a donator. If you like Shadbot, you can help me keep it alive" + " by making a donation on **%s**.%nAll donations are important and really help me %s", Config.PATREON_URL, Emoji.HEARTS), context.getChannel());
        return;
    }
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Contributor status").withThumbnail("https://orig00.deviantart.net/24e1/f/2015/241/8/7/relic_fragment_by_yukimemories-d97l8c8.png");
    for (Relic relic : relics) {
        StringBuilder contentBld = new StringBuilder();
        contentBld.append(String.format("**ID:** %s", relic.getRelicID()));
        if (relic.getType().equals(RelicType.GUILD)) {
            contentBld.append(String.format("%n**Guild ID:** %d", relic.getGuildID()));
        }
        contentBld.append(String.format("%n**Duration:** %d days", relic.getDuration()));
        if (!relic.isExpired()) {
            long daysLeft = relic.getDuration() - TimeUnit.MILLISECONDS.toDays(TimeUtils.getMillisUntil(relic.getActivationTime()));
            contentBld.append(String.format("%n**Expires in:** %d days", daysLeft));
        }
        StringBuilder titleBld = new StringBuilder();
        if (relic.getType().equals(RelicType.GUILD)) {
            titleBld.append("Legendary ");
        }
        titleBld.append(String.format("Relic (%s)", relic.isExpired() ? "Expired" : "Activated"));
        embed.appendField(titleBld.toString(), contentBld.toString(), false);
    }
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : Relic(me.shadorc.shadbot.data.premium.Relic) EmbedBuilder(sx.blah.discord.util.EmbedBuilder)

Example 95 with EmbedBuilder

use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.

the class Rule34Cmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    if (!context.getChannel().isNSFW()) {
        BotUtils.sendMessage(TextUtils.mustBeNSFW(context.getPrefix()), context.getChannel());
        return;
    }
    if (!context.hasArg()) {
        throw new MissingArgumentException();
    }
    LoadingMessage loadingMsg = new LoadingMessage("Loading image...", context.getChannel());
    loadingMsg.send();
    try {
        String url = String.format("https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags=%s", NetUtils.encode(context.getArg().replace(" ", "_")));
        JSONObject mainObj = XML.toJSONObject(NetUtils.getBody(url));
        JSONObject postsObj = mainObj.getJSONObject("posts");
        if (postsObj.getInt("count") == 0) {
            loadingMsg.edit(TextUtils.noResult(context.getArg()));
            return;
        }
        JSONObject postObj;
        if (postsObj.get("post") instanceof JSONArray) {
            JSONArray postsArray = postsObj.getJSONArray("post");
            postObj = postsArray.getJSONObject(ThreadLocalRandom.current().nextInt(postsArray.length()));
        } else {
            postObj = postsObj.getJSONObject("post");
        }
        List<String> tags = StringUtils.split(postObj.getString("tags"), " ");
        if (postObj.getBoolean("has_children") || tags.stream().anyMatch(tag -> tag.contains("loli") || tag.contains("shota"))) {
            loadingMsg.edit(Emoji.WARNING + " Sorry, I don't display images containing children or tagged with `loli` or `shota`.");
            return;
        }
        String formattedtags = StringUtils.truncate(FormatUtils.format(tags, tag -> String.format("`%s`", tag.toString()), " "), MAX_TAGS_LENGTH);
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Rule34 (Search: " + context.getArg() + ")").withAuthorUrl(postObj.getString("file_url")).withThumbnail("http://rule34.paheal.net/themes/rule34v2/rule34_logo_top.png").appendField("Resolution", String.format("%dx%s", postObj.getInt("width"), postObj.getInt("height")), false).appendField("Tags", formattedtags, false).withImage(postObj.getString("file_url")).withFooterText("If there is no preview, click on the title to see the media (probably a video)");
        String source = postObj.get("source").toString();
        if (!source.isEmpty()) {
            embed.withDescription(String.format("%n[**Source**](%s)", source));
        }
        loadingMsg.edit(embed.build());
    } catch (JSONException | IOException err) {
        loadingMsg.delete();
        Utils.handle("getting an image from Rule34", context, err);
    }
}
Also used : HelpBuilder(me.shadorc.shadbot.utils.embed.HelpBuilder) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory) BotUtils(me.shadorc.shadbot.utils.BotUtils) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) StringUtils(me.shadorc.shadbot.utils.StringUtils) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) XML(org.json.XML) TextUtils(me.shadorc.shadbot.utils.TextUtils) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Utils(me.shadorc.shadbot.utils.Utils) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) RateLimited(me.shadorc.shadbot.core.command.annotation.RateLimited) IOException(java.io.IOException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) List(java.util.List) NetUtils(me.shadorc.shadbot.utils.NetUtils) Context(me.shadorc.shadbot.core.command.Context) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Emoji(me.shadorc.shadbot.utils.object.Emoji) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) JSONArray(org.json.JSONArray) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) JSONObject(org.json.JSONObject) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException)

Aggregations

EmbedBuilder (sx.blah.discord.util.EmbedBuilder)103 IOException (java.io.IOException)19 Random (java.util.Random)17 IUser (sx.blah.discord.handle.obj.IUser)14 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)13 LoadingMessage (me.shadorc.shadbot.utils.object.LoadingMessage)13 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)12 JSONObject (org.json.JSONObject)11 IMessage (sx.blah.discord.handle.obj.IMessage)10 List (java.util.List)9 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)9 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)9 JSONException (org.json.JSONException)9 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)8 Utils (me.shadorc.shadbot.utils.Utils)8 IChannel (sx.blah.discord.handle.obj.IChannel)8 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)7 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)7 File (java.io.File)6 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)6