use of me.shadorc.shadbot.utils.object.LoadingMessage 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 me.shadorc.shadbot.utils.object.LoadingMessage 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 me.shadorc.shadbot.utils.object.LoadingMessage in project Shadbot by Shadorc.
the class HolidaysCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
Zone zone = Utils.getValueOrNull(Zone.class, context.getArg());
if (zone == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid zone. %s", context.getArg(), FormatUtils.formatOptions(Zone.class)));
}
LoadingMessage loadingMsg = new LoadingMessage("Loading holiday information...", context.getChannel());
loadingMsg.send();
try {
String holidays = StringUtils.remove(TwitterUtils.getLastTweet("Vacances_Zone" + zone), "#");
loadingMsg.edit(Emoji.BEACH + " " + holidays);
} catch (TwitterException err) {
loadingMsg.delete();
Utils.handle("getting holidays information", context, err.getCause());
}
}
use of me.shadorc.shadbot.utils.object.LoadingMessage 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 me.shadorc.shadbot.utils.object.LoadingMessage in project Shadbot by Shadorc.
the class HangmanCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
Difficulty difficulty = Utils.getValueOrNull(Difficulty.class, context.getArg());
if (context.hasArg() && difficulty == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid difficulty. %s", context.getArg(), FormatUtils.formatOptions(Difficulty.class)));
}
if (difficulty == null) {
difficulty = Difficulty.EASY;
}
if (HARD_WORDS.isEmpty() || EASY_WORDS.isEmpty()) {
LoadingMessage loadingMsg = new LoadingMessage("Loading word...", context.getChannel());
loadingMsg.send();
try {
this.load();
} catch (JSONException | IOException err) {
Utils.handle("getting words list", context, err);
}
loadingMsg.delete();
}
HangmanManager hangmanManager = MANAGERS.get(context.getChannel().getLongID());
if (hangmanManager == null) {
hangmanManager = new HangmanManager(this, context.getPrefix(), context.getChannel(), context.getAuthor(), difficulty);
if (MANAGERS.putIfAbsent(context.getChannel().getLongID(), hangmanManager) == null) {
hangmanManager.start();
}
} else {
BotUtils.sendMessage(String.format(Emoji.INFO + " A Hangman game has already been started by **%s**. Please, wait for him to finish.", hangmanManager.getAuthor().getName()), context.getChannel());
}
}
Aggregations