Search in sources :

Example 21 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project Shadbot by Shadorc.

the class PollManager method show.

protected void show() {
    int count = 1;
    StringBuilder choicesStr = new StringBuilder();
    for (String choice : choicesMap.keySet()) {
        List<IUser> votersList = choicesMap.get(choice);
        choicesStr.append(String.format("%n\t**%d.** %s", count, choice));
        if (!votersList.isEmpty()) {
            choicesStr.append(String.format(" *(Vote: %d)*", votersList.size()));
            choicesStr.append(String.format("%n\t\t%s", StringUtils.truncate(FormatUtils.format(votersList, IUser::getName, ", "), 30)));
        }
        count++;
    }
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName(String.format("Poll (Created by: %s)", this.getAuthor().getName())).withThumbnail(this.getAuthor().getAvatarURL()).appendDescription(String.format("Vote using: `%s%s <choice>`%n%n__**%s**__%s", this.getPrefix(), this.getCmdName(), question, choicesStr.toString())).withFooterIcon("https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/Clock_simple_white.svg/2000px-Clock_simple_white.svg.png");
    if (this.isTaskDone()) {
        embed.withFooterText("Finished");
    } else {
        embed.withFooterText(String.format("Time left: %s", FormatUtils.formatShortDuration(TimeUnit.SECONDS.toMillis(duration) - TimeUtils.getMillisUntil(startTime))));
    }
    RequestFuture<IMessage> messageRequest = message.send(embed.build());
    if (messageRequest != null) {
        messageRequest.get();
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser)

Example 22 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project Shadbot by Shadorc.

the class LoadingMessage method edit.

public void edit(EmbedObject embed) {
    if (!BotUtils.hasPermissions(channel, Permissions.SEND_MESSAGES, Permissions.EMBED_LINKS)) {
        BotUtils.sendMessage(TextUtils.missingPerm(Permissions.EMBED_LINKS), channel);
        LogUtils.infof("{Guild ID: %d} Shadbot wasn't allowed to send embed link.", channel.getGuild().getLongID());
        return;
    }
    IMessage message = msgRequest == null ? null : msgRequest.get();
    if (message == null) {
        msgRequest = BotUtils.sendMessage(embed, channel);
    } else {
        RequestBuffer.request(() -> {
            message.edit(embed);
        });
    }
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage)

Example 23 with IMessage

use of sx.blah.discord.handle.obj.IMessage 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 24 with IMessage

use of sx.blah.discord.handle.obj.IMessage in project Shadbot by Shadorc.

the class DiceManager method stop.

@Override
public void stop() {
    this.cancelScheduledTask();
    int winningNum = ThreadLocalRandom.current().nextInt(1, 7);
    List<String> list = new ArrayList<>();
    for (int num : numsPlayers.keySet()) {
        IUser user = numsPlayers.get(num);
        int gains = bet;
        if (num == winningNum) {
            gains *= numsPlayers.size() + DiceCmd.MULTIPLIER;
            MoneyStatsManager.log(MoneyEnum.MONEY_GAINED, this.getCmdName(), gains);
        } else {
            gains *= -1;
            MoneyStatsManager.log(MoneyEnum.MONEY_LOST, this.getCmdName(), Math.abs(gains));
        }
        list.add(gains > 0 ? 0 : list.size(), String.format("%s (**%s**)", user.getName(), FormatUtils.formatCoins(gains)));
        Database.getDBUser(this.getGuild(), user).addCoins(gains);
    }
    RequestFuture<IMessage> msgRequest = BotUtils.sendMessage(String.format(Emoji.DICE + " The dice is rolling... **%s** !", winningNum), this.getChannel());
    if (msgRequest != null) {
        msgRequest.get();
    }
    this.results = FormatUtils.format(list, Object::toString, "\n");
    this.show();
    numsPlayers.clear();
    DiceCmd.MANAGERS.remove(this.getChannel().getLongID());
}
Also used : IMessage(sx.blah.discord.handle.obj.IMessage) ArrayList(java.util.ArrayList) IUser(sx.blah.discord.handle.obj.IUser)

Example 25 with IMessage

use of sx.blah.discord.handle.obj.IMessage 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

IMessage (sx.blah.discord.handle.obj.IMessage)46 IUser (sx.blah.discord.handle.obj.IUser)10 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)6 IChannel (sx.blah.discord.handle.obj.IChannel)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 UserObject (com.github.vaerys.masterobjects.UserObject)4 ArrayList (java.util.ArrayList)4 DiscordException (sx.blah.discord.util.DiscordException)4 Announcement (com.cloudcraftgaming.discal.api.object.announcement.Announcement)3 PreEvent (com.cloudcraftgaming.discal.api.object.event.PreEvent)3 CommandObject (com.github.vaerys.commands.CommandObject)3 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)3 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 RateLimitException (sx.blah.discord.util.RateLimitException)3 PreCalendar (com.cloudcraftgaming.discal.api.object.calendar.PreCalendar)2 TrackLikes (com.github.vaerys.objects.TrackLikes)2