use of sx.blah.discord.util.EmbedBuilder in project BoltBot by DiscordBolt.
the class ImagePost method toEmbed.
@Override
public EmbedObject toEmbed() {
EmbedBuilder embed = new EmbedBuilder();
embed.withColor(EMBED_COLOR);
// Embed Title
embed.withAuthorName(EmbedUtil.limitString(EmbedUtil.AUTHOR_NAME_MAX_LENGTH, getTitle()));
embed.withAuthorUrl("https://www.reddit.com/r/" + getSubreddit() + "/comments/" + getId());
// Image
embed.withImage(getUrl());
// Post info
embed.appendField(":pencil2: Author", EmbedUtil.limitString(EmbedUtil.FIELD_VALUE_MAX_LENGTH, getAuthor()), true);
embed.appendField(":arrow_up: Upvotes", String.format("%,d", getScore()), true);
if (getGilded() > 0)
embed.appendField(":star: Gold", "x" + getGilded(), false);
return embed.build();
}
use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.
the class UserInfoCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
List<IUser> mentions = context.getMessage().getMentions();
IUser user = mentions.isEmpty() ? context.getAuthor() : mentions.get(0);
String creationDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(user.getCreationDate()).format(dateFormatter), FormatUtils.formatLongDuration(user.getCreationDate()));
String joinDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(context.getGuild().getJoinTimeForUser(user)).format(dateFormatter), FormatUtils.formatLongDuration(context.getGuild().getJoinTimeForUser(user)));
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName(String.format("Info about user \"%s\"%s", user.getName(), user.isBot() ? " (Bot)" : "")).withThumbnail(user.getAvatarURL()).appendField("Display name", user.getDisplayName(context.getGuild()), true).appendField("User ID", Long.toString(user.getLongID()), true).appendField("Creation date", creationDate, true).appendField("Join date", joinDate, true).appendField("Roles", FormatUtils.format(user.getRolesForGuild(context.getGuild()), IRole::getName, "\n"), true).appendField("Status", StringUtils.capitalize(user.getPresence().getStatus().toString()), true).appendField("Playing text", user.getPresence().getText().orElse(null), true);
BotUtils.sendMessage(embed.build(), context.getChannel());
}
use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.
the class WeatherCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
LoadingMessage loadingMsg = new LoadingMessage("Loading weather information...", context.getChannel());
loadingMsg.send();
try {
OpenWeatherMap owm = new OpenWeatherMap(Units.METRIC, APIKeys.get(APIKey.OPENWEATHERMAP_API_KEY));
CurrentWeather weather = owm.currentWeatherByCityName(context.getArg());
if (!weather.isValid()) {
loadingMsg.edit(TextUtils.noResult(context.getArg()));
return;
}
String clouds = StringUtils.capitalize(weather.getWeatherInstance(0).getWeatherDescription());
float windSpeed = weather.getWindInstance().getWindSpeed() * 3.6f;
String windDesc = this.getWindDesc(windSpeed);
String rain = weather.hasRainInstance() ? String.format("%.1f mm/h", weather.getRainInstance().getRain3h()) : "None";
float humidity = weather.getMainInstance().getHumidity();
float temperature = weather.getMainInstance().getTemperature();
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Weather for: " + weather.getCityName()).withThumbnail("https://image.flaticon.com/icons/svg/494/494472.svg").withAuthorUrl("http://openweathermap.org/city/" + weather.getCityCode()).appendDescription("Last updated " + dateFormatter.format(weather.getDateTime())).appendField(Emoji.CLOUD + " Clouds", clouds, true).appendField(Emoji.WIND + " Wind", String.format("%s%n%.1f km/h", windDesc, windSpeed), true).appendField(Emoji.RAIN + " Rain", rain, true).appendField(Emoji.DROPLET + " Humidity", String.format("%.1f%%", humidity), true).appendField(Emoji.THERMOMETER + " Temperature", String.format("%.1f°C", temperature), true);
loadingMsg.edit(embed.build());
} catch (IOException err) {
loadingMsg.delete();
Utils.handle("getting weather information", context, err);
}
}
use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.
the class WikiCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
try {
// Wiki api doc https://en.wikipedia.org/w/api.php?action=help&modules=query%2Bextracts
JSONObject mainObj = new JSONObject(NetUtils.getBody("https://en.wikipedia.org/w/api.php?" + "format=json" + "&action=query" + "&titles=" + NetUtils.encode(context.getArg()) + "&redirects=true" + "&prop=extracts" + "&explaintext=true" + "&exintro=true" + "&exsentences=5"));
JSONObject pagesObj = mainObj.getJSONObject("query").getJSONObject("pages");
String pageId = pagesObj.names().getString(0);
JSONObject resultObj = pagesObj.getJSONObject(pageId);
if ("-1".equals(pageId) || resultObj.getString("extract").isEmpty()) {
BotUtils.sendMessage(TextUtils.noResult(context.getArg()), context.getChannel());
return;
}
String extract = StringUtils.truncate(resultObj.getString("extract"), EmbedBuilder.DESCRIPTION_CONTENT_LIMIT);
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName(String.format("Wikipedia: %s", resultObj.getString("title"))).withAuthorIcon("https://upload.wikimedia.org/wikipedia/commons/thumb/4/4e/Mohapedia.png/842px-Mohapedia.png").withAuthorUrl(String.format("https://en.wikipedia.org/wiki/%s", resultObj.getString("title").replace(" ", "_"))).appendDescription(extract);
BotUtils.sendMessage(embed.build(), context.getChannel());
} catch (JSONException | IOException err) {
Utils.handle("getting Wikipedia information", context, err);
}
}
use of sx.blah.discord.util.EmbedBuilder 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();
}
}
Aggregations