Search in sources :

Example 96 with EmbedBuilder

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

the class SuicideGirlsCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    if (!context.getChannel().isNSFW()) {
        BotUtils.sendMessage(TextUtils.mustBeNSFW(context.getPrefix()), context.getChannel());
        return;
    }
    LoadingMessage loadingMsg = new LoadingMessage("Loading image...", context.getChannel());
    loadingMsg.send();
    try {
        Document doc = NetUtils.getDoc("https://www.suicidegirls.com/photos/sg/recent/all/");
        Elements girls = doc.getElementsByTag("article");
        Element girl = girls.get(ThreadLocalRandom.current().nextInt(girls.size()));
        String name = girl.getElementsByTag("a").attr("href").split("/")[2].trim();
        String imageUrl = girl.select("noscript").attr("data-retina");
        String url = girl.getElementsByClass("facebook-share").attr("href");
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("SuicideGirls Image").withAuthorIcon("https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/SuicideGirls_logo.svg/1280px-SuicideGirls_logo.svg.png").withAuthorUrl(url).appendDescription(String.format("Name: **%s**", StringUtils.capitalize(name))).withImage(imageUrl);
        loadingMsg.edit(embed.build());
    } catch (IOException err) {
        loadingMsg.delete();
        Utils.handle("getting SuicideGirls image", context, err);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Element(org.jsoup.nodes.Element) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 97 with EmbedBuilder

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

the class DtcCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    LoadingMessage loadingMsg = new LoadingMessage("Loading quote...", context.getChannel());
    loadingMsg.send();
    try {
        String url = String.format("http://api.danstonchat.com/0.3/view/random?key=%s&format=json", APIKeys.get(APIKey.DTC_API_KEY));
        JSONObject quoteObj = Utils.toList(new JSONArray(NetUtils.getBody(url)), JSONObject.class).stream().filter(obj -> obj.getString("content").length() < 1000).findAny().get();
        String content = quoteObj.getString("content").replace("*", "\\*");
        StringBuilder strBuilder = new StringBuilder();
        for (String line : content.split("\n")) {
            strBuilder.append('\n');
            if (line.contains(" ")) {
                strBuilder.append("**" + line.substring(0, line.indexOf(' ')) + "** " + line.substring(line.indexOf(' ') + 1));
            } else {
                strBuilder.append(line);
            }
        }
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Quote DansTonChat").withAuthorUrl(String.format("https://danstonchat.com/%s.html", quoteObj.getString("id"))).withThumbnail("https://danstonchat.com/themes/danstonchat/images/logo2.png").appendDescription(strBuilder.toString());
        loadingMsg.edit(embed.build());
    } catch (JSONException | IOException err) {
        loadingMsg.delete();
        Utils.handle("getting a quote from DansTonChat.com", context, err);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException)

Example 98 with EmbedBuilder

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

the class JokeCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    LoadingMessage loadingMsg = new LoadingMessage("Loading joke...", context.getChannel());
    loadingMsg.send();
    try {
        String url = String.format("http://www.une-blague.com/blagues-courtes.html?&p=%d", ThreadLocalRandom.current().nextInt(1, 6));
        Document doc = NetUtils.getDoc(url);
        List<String> jokes = doc.getElementsByClass("texte ").stream().map(elmt -> elmt.html()).filter(elmt -> elmt.length() < 1000).collect(Collectors.toList());
        String jokeHtml = jokes.get(ThreadLocalRandom.current().nextInt(jokes.size()));
        String joke = FormatUtils.format(jokeHtml.split("<br>"), line -> Jsoup.parse(line).text().trim(), "\n");
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Blague").withAuthorUrl("http://www.une-blague.com/").appendDescription(joke);
        loadingMsg.edit(embed.build());
    } catch (IOException err) {
        loadingMsg.delete();
        Utils.handle("getting a joke", context, err);
    }
}
Also used : RateLimited(me.shadorc.shadbot.core.command.annotation.RateLimited) HelpBuilder(me.shadorc.shadbot.utils.embed.HelpBuilder) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory) IOException(java.io.IOException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) Collectors(java.util.stream.Collectors) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) List(java.util.List) NetUtils(me.shadorc.shadbot.utils.NetUtils) Context(me.shadorc.shadbot.core.command.Context) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Document(org.jsoup.nodes.Document) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Jsoup(org.jsoup.Jsoup) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) Utils(me.shadorc.shadbot.utils.Utils) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException) Document(org.jsoup.nodes.Document)

Example 99 with EmbedBuilder

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

the class DiceManager method show.

private void show() {
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Dice Game").withThumbnail("http://findicons.com/files/icons/2118/nuvola/128/package_games_board.png").withDescription(String.format("**Use `%s%s <num>` to join the game.**%n**Bet:** %s", this.getPrefix(), this.getCmdName(), FormatUtils.formatCoins(bet))).appendField("Player", numsPlayers.values().stream().map(IUser::getName).collect(Collectors.joining("\n")), true).appendField("Number", numsPlayers.keySet().stream().map(Object::toString).collect(Collectors.joining("\n")), true).appendField("Results", results, false).withFooterText(String.format("You have %d seconds to make your bets.", GAME_DURATION));
    RequestFuture<IMessage> msgRequest = message.send(embed.build());
    if (msgRequest != null) {
        msgRequest.get();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IMessage(sx.blah.discord.handle.obj.IMessage)

Example 100 with EmbedBuilder

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

the class HangmanManager method show.

private void show() {
    List<String> missesList = charsTested.stream().filter(letter -> !word.contains(letter)).collect(Collectors.toList());
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorIcon(this.getAuthor().getAvatarURL()).withAuthorName("Hangman Game").withThumbnail("https://lh5.ggpht.com/nIoJylIWCj1gKv9dxtd4CFE2aeXvG7MbvP0BNFTtTFusYlxozJRQmHizsIDxydaa7DHT=w300").withDescription("Type letters or enter a word if you think you've guessed it.").appendField("Word", this.getRepresentation(word), false).appendField("Misses", FormatUtils.format(missesList, chr -> chr.toString().toUpperCase(), ", "), false);
    if (this.isTaskDone()) {
        embed.withFooterText("Finished.");
    } else {
        embed.withFooterText(String.format("Use %scancel to cancel this game (Automatically cancelled in %d min in case of inactivity)", this.getPrefix(), IDLE_MIN));
    }
    if (failsCount > 0) {
        embed.withImage(IMG_LIST.get(Math.min(IMG_LIST.size(), failsCount) - 1));
    }
    RequestFuture<IMessage> msgRequest = message.send(embed.build());
    if (msgRequest != null) {
        msgRequest.get();
    }
}
Also used : MoneyEnum(me.shadorc.shadbot.data.stats.MoneyStatsManager.MoneyEnum) BotUtils(me.shadorc.shadbot.utils.BotUtils) ArrayList(java.util.ArrayList) StringUtils(me.shadorc.shadbot.utils.StringUtils) IMessage(sx.blah.discord.handle.obj.IMessage) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) AbstractGameManager(me.shadorc.shadbot.core.game.AbstractGameManager) UpdateableMessage(me.shadorc.shadbot.utils.object.UpdateableMessage) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) Collectors(java.util.stream.Collectors) MessageListener(me.shadorc.shadbot.message.MessageListener) TimeUnit(java.util.concurrent.TimeUnit) MoneyStatsManager(me.shadorc.shadbot.data.stats.MoneyStatsManager) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) RequestFuture(sx.blah.discord.util.RequestBuffer.RequestFuture) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Database(me.shadorc.shadbot.data.db.Database) IChannel(sx.blah.discord.handle.obj.IChannel) Difficulty(me.shadorc.shadbot.command.game.hangman.HangmanCmd.Difficulty) RateLimiter(me.shadorc.shadbot.ratelimiter.RateLimiter) Emoji(me.shadorc.shadbot.utils.object.Emoji) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) MessageManager(me.shadorc.shadbot.message.MessageManager) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IMessage(sx.blah.discord.handle.obj.IMessage)

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