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());
}
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);
}
}
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());
}
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();
}
}
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();
}
}
Aggregations