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