Search in sources :

Example 51 with EmbedBuilder

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

the class ServerInfoCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    IGuild guild = context.getGuild();
    DBGuild dbGuild = Database.getDBGuild(guild);
    StringBuilder settingsStr = new StringBuilder();
    if (!dbGuild.getPrefix().equals(Config.DEFAULT_PREFIX)) {
        settingsStr.append(String.format("**Prefix:** %s", context.getPrefix()));
    }
    if (dbGuild.getDefaultVol() != Config.DEFAULT_VOLUME) {
        settingsStr.append(String.format("%n**Default volume:** %d%%", dbGuild.getDefaultVol()));
    }
    if (!dbGuild.getAllowedChannels().isEmpty()) {
        List<IChannel> channels = dbGuild.getAllowedChannels().stream().map(guild::getChannelByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Allowed channels:**%n\t%s", FormatUtils.format(channels, IChannel::getName, "\n\t")));
    }
    if (!dbGuild.getBlacklistedCmd().isEmpty()) {
        settingsStr.append(String.format("%n**Blacklisted commands:**%n\t%s", FormatUtils.format(dbGuild.getBlacklistedCmd(), Object::toString, "\n\t")));
    }
    if (!dbGuild.getAutoRoles().isEmpty()) {
        List<IRole> roles = dbGuild.getAutoRoles().stream().map(guild::getRoleByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Auto-roles:**%n\t%s", FormatUtils.format(roles, IRole::mention, "\n\t")));
    }
    String creationDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(guild.getCreationDate()).format(dateFormatter), FormatUtils.formatLongDuration(guild.getCreationDate()));
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName(String.format("Info about \"%s\"", guild.getName())).withThumbnail(guild.getIconURL()).appendField("Owner", guild.getOwner().getName(), true).appendField("Server ID", Long.toString(guild.getLongID()), true).appendField("Creation date", creationDate, true).appendField("Region", guild.getRegion().getName(), true).appendField("Channels", String.format("**Voice:** %d", guild.getVoiceChannels().size()) + String.format("%n**Text:** %d", guild.getChannels().size()), true).appendField("Members", Integer.toString(guild.getTotalMemberCount()), true).appendField("Settings", settingsStr.toString(), true);
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DBGuild(me.shadorc.shadbot.data.db.DBGuild) IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 52 with EmbedBuilder

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

the class ThisDayCmd method execute.

@Override
public void execute(Context context) {
    LoadingMessage loadingMsg = new LoadingMessage("Loading information...", context.getChannel());
    loadingMsg.send();
    try {
        Document doc = NetUtils.getDoc(HOME_URL);
        String date = doc.getElementsByClass("date-large").first().attr("datetime");
        Elements eventsElmt = doc.getElementsByClass("event-list event-list--with-advert").first().getElementsByClass("event-list__item");
        String events = eventsElmt.stream().map(elmt -> Jsoup.parse(elmt.html().replaceAll("<b>|</b>", "**")).text()).collect(Collectors.joining("\n\n"));
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName(String.format("On This Day (%s)", date)).withAuthorUrl(HOME_URL).withThumbnail("http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/calendar-icon.png").appendDescription(StringUtils.truncate(events, EmbedBuilder.DESCRIPTION_CONTENT_LIMIT));
        loadingMsg.edit(embed.build());
    } catch (IOException err) {
        loadingMsg.delete();
        Utils.handle("getting events", 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) Collectors(java.util.stream.Collectors) StringUtils(me.shadorc.shadbot.utils.StringUtils) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) NetUtils(me.shadorc.shadbot.utils.NetUtils) Context(me.shadorc.shadbot.core.command.Context) Document(org.jsoup.nodes.Document) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) 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) Elements(org.jsoup.select.Elements)

Example 53 with EmbedBuilder

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

the class LottoCmd method show.

private void show(Context context) {
    List<LottoPlayer> players = LottoManager.getPlayers();
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Lotto").withThumbnail("https://cdn.onlineunitedstatescasinos.com/wp-content/uploads/2016/04/Lottery-icon.png").withDescription(String.format("The next draw will take place in **%s**%nTo participate, type: `%s%s %d-%d`", FormatUtils.formatCustomDate(LottoCmd.getDelay()), context.getPrefix(), this.getName(), MIN_NUM, MAX_NUM)).appendField("Number of participants", Integer.toString(players.size()), false).appendField("Prize pool", FormatUtils.formatCoins(LottoManager.getPool()), false);
    LottoPlayer player = players.stream().filter(lottoPlayer -> lottoPlayer.getUserID() == context.getAuthor().getLongID()).findAny().orElse(null);
    if (player != null) {
        embed.withFooterIcon("https://images.emojiterra.com/twitter/512px/1f39f.png");
        embed.withFooterText(String.format("%s, you bet on number %d.", context.getAuthorName(), player.getNum()));
    }
    LottoHistoric historic = LottoManager.getHistoric();
    if (historic != null) {
        String people;
        switch(historic.getWinnersCount()) {
            case 0:
                people = "nobody";
                break;
            case 1:
                people = "one person";
                break;
            default:
                people = historic.getWinnersCount() + " people";
                break;
        }
        embed.appendField("Historic", String.format("Last week, the prize pool contained **%s**, the winning number was **%d** and **%s won**.", FormatUtils.formatCoins(historic.getPool()), historic.getNum(), people), false);
    }
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) LottoPlayer(me.shadorc.shadbot.data.lotto.LottoPlayer) LottoHistoric(me.shadorc.shadbot.data.lotto.LottoHistoric)

Example 54 with EmbedBuilder

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

the class BlackjackManager method show.

private void show() {
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Blackjack").withThumbnail("https://pbs.twimg.com/profile_images/1874281601/BlackjackIcon_400x400.png").appendDescription(String.format("**Use `%s%s <bet>` to join the game.**" + "%n%nType `hit` to take another card, `stand` to pass or `double down` to double down.", this.getPrefix(), this.getCmdName())).appendField("Dealer's hand", BlackjackUtils.formatCards(this.isTaskDone() ? dealerCards : dealerCards.subList(0, 1)), true);
    if (this.isTaskDone()) {
        embed.withFooterText("Finished");
    } else {
        long remainingTime = GAME_DURATION - TimeUnit.MILLISECONDS.toSeconds(TimeUtils.getMillisUntil(startTime));
        embed.withFooterText(String.format("This game will end automatically in %d seconds.", remainingTime));
    }
    players.stream().forEach(player -> embed.appendField(String.format("%s's hand%s%s", player.getUser().getName(), player.isStanding() ? " (Stand)" : "", player.isDoubleDown() ? " (Double down)" : ""), BlackjackUtils.formatCards(player.getCards()), true));
    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 55 with EmbedBuilder

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

the class RouletteManager method show.

public void show() {
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Roulette Game").withThumbnail("http://icongal.com/gallery/image/278586/roulette_baccarat_casino.png").withDescription(String.format("**Use `%s%s <bet> <place>` to join the game.**" + "%n%n**Place** is a `number between 1 and 36`, %s", this.getPrefix(), this.getCmdName(), FormatUtils.format(Place.values(), value -> String.format("`%s`", value.toString().toLowerCase()), ", "))).appendField("Player (Bet)", FormatUtils.format(playersPlace.keySet().stream(), user -> String.format("**%s** (%s)", user.getName(), FormatUtils.formatCoins(playersPlace.get(user).getFirst())), "\n"), true).appendField("Place", playersPlace.values().stream().map(Pair::getSecond).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) Pair(me.shadorc.shadbot.utils.object.Pair)

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