use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class TriviaGame method displayScores.
public EmbedBuilder displayScores(Shard shard, Command command) throws Exception {
Map<String, Integer> sorted = MapUtils.sortByValue(scores);
Guild guild = shard.jda.getGuildById(guildId);
EmbedBuilder builder = MessageUtils.getDefaultEmbed(guild.getSelfMember().getUser());
String currentScores = "Current Scores";
if (solo)
builder.setAuthor(currentScores + " | Solo Game", shard.url, guild.getIconUrl());
else
builder.setAuthor(currentScores + " | Everyone can play", shard.url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
description.append("**" + currentScores + "**");
Iterator<Map.Entry<String, Integer>> iterator = sorted.entrySet().iterator();
int currentPlace = 1;
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = iterator.next();
description.append("\n#" + currentPlace + ": **" + shard.jda.getUserById(entry.getKey()).getName() + "** " + entry.getValue() + " points");
currentPlace++;
}
if (currentPlace == 1) {
description.append("\nNo one has gotten a question right so far!");
}
description.append("\n\nCurrent Round: " + round);
return builder.setDescription(description.toString());
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class UtilsCmds method weather.
@Subscribe
public void weather(CommandRegistry registry) {
registry.register("weather", new SimpleCommand(Category.UTILS) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
onError(event);
return;
}
EmbedBuilder embed = new EmbedBuilder();
try {
long start = System.currentTimeMillis();
WeatherData data = GsonDataManager.GSON_PRETTY.fromJson(Utils.wgetResty(String.format("http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s", URLEncoder.encode(content, "UTF-8"), MantaroData.config().get().weatherAppId), event), WeatherData.class);
String countryCode = data.getSys().country;
String status = data.getWeather().get(0).main;
Double temp = data.getMain().getTemp();
double pressure = data.getMain().getPressure();
int humidity = data.getMain().getHumidity();
Double ws = data.getWind().speed;
int cloudiness = data.getClouds().all;
Double finalTemperatureCelsius = temp - 273.15;
Double finalTemperatureFahrenheit = temp * 9 / 5 - 459.67;
Double finalWindSpeedMetric = ws * 3.6;
Double finalWindSpeedImperial = ws / 0.447046;
long end = System.currentTimeMillis() - start;
embed.setColor(Color.CYAN).setTitle(":flag_" + countryCode.toLowerCase() + ":" + " Forecast information for " + content, null).setDescription(status + " (" + cloudiness + "% clouds)").addField(":thermometer: Temperature", String.format("%d°C | %d°F", finalTemperatureCelsius.intValue(), finalTemperatureFahrenheit.intValue()), true).addField(":droplet: Humidity", humidity + "%", true).addBlankField(true).addField(":wind_blowing_face: Wind Speed", String.format("%dkm/h | %dmph", finalWindSpeedMetric.intValue(), finalWindSpeedImperial.intValue()), true).addField("Pressure", pressure + "hPA", true).addBlankField(true).setFooter("Information provided by OpenWeatherMap (Process time: " + end + "ms)", null);
event.getChannel().sendMessage(embed.build()).queue();
} catch (NullPointerException npe) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Error while fetching results. (Not found?)").queue();
log.warn("Exception caught while trying to fetch weather data, maybe the API changed something?", e);
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Weather command").setDescription("This command retrieves information from OpenWeatherMap. Used to check **forecast information.**").addField("Usage", "`~>weather <city>,<countrycode>` - **Retrieves the forecast information for the given location.**", false).addField("Parameters", "`city` - **Your city name, e.g. New York, **\n" + "`countrycode` - **(OPTIONAL) The abbreviation for your country, for example US (USA) or MX (Mexico).**", false).addField("Example", "`~>weather New York, US`", false).build();
}
});
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class EmbedJSON method gen.
public MessageEmbed gen(Member member) {
EmbedBuilder embedBuilder = new EmbedBuilder();
if (title != null)
embedBuilder.setTitle(title, titleUrl);
if (description != null)
embedBuilder.setDescription(description);
if (author != null)
embedBuilder.setAuthor(author, authorUrl, authorImg);
if (footer != null)
embedBuilder.setFooter(footer, footerImg);
if (image != null)
embedBuilder.setImage(image);
if (thumbnail != null)
embedBuilder.setThumbnail(thumbnail);
if (color != null) {
Color col = null;
try {
col = (Color) Color.class.getField(color).get(null);
} catch (Exception ignored) {
String colorLower = color.toLowerCase();
if (colorLower.equals("member")) {
if (member != null)
col = member.getColor();
} else if (colorLower.matches("#?(0x)?[0123456789abcdef]{1,6}")) {
try {
col = Color.decode(colorLower.startsWith("0x") ? colorLower : "0x" + colorLower);
} catch (Exception ignored2) {
}
}
}
if (col != null)
embedBuilder.setColor(col);
}
fields.forEach(f -> {
if (f == null) {
embedBuilder.addBlankField(false);
} else if (f.value == null) {
embedBuilder.addBlankField(f.inline);
} else {
embedBuilder.addField(f.name == null ? "" : f.name, f.value, f.inline);
}
});
return embedBuilder.build();
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class ImageboardUtils method imageEmbed.
private static void imageEmbed(String url, String width, String height, String tags, Rating rating, String imageboard, TextChannel channel) {
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Found image", url, null).setImage(url).setDescription("Rating: **" + rating.getLongName() + "**, Imageboard: **" + imageboard + "**").addField("Width", width, true).addField("Height", height, true).addField("Tags", "`" + (tags == null ? "None" : tags) + "`", false).setFooter("If the image doesn't load, click the title." + (imageboard.equals("rule34") ? " If you don't like the content on this command, you can use ~>yandere" : ""), null);
channel.sendMessage(builder.build()).queue();
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class Poll method createPoll.
private Future<Void> createPoll(Message message) {
runningPoll = ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {
@Override
public int add(MessageReactionAddEvent e) {
int i = e.getReactionEmote().getName().charAt(0) - '\u0030';
if (i < 1 || i > options.length)
return Operation.IGNORED;
// always return false anyway lul
return Operation.IGNORED;
}
@Override
public void onExpire() {
if (getChannel() == null)
return;
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Poll results").setDescription("**Showing results for the poll started by " + MantaroBot.getInstance().getUserById(owner).getName() + "** with name: *" + name + "*").setFooter("Thanks for your vote", null);
AtomicInteger react = new AtomicInteger(0);
AtomicInteger counter = new AtomicInteger(0);
String votes = new ArrayList<>(getChannel().getMessageById(message.getIdLong()).complete().getReactions()).stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> "+Registered " + (r.getCount() - 1) + " votes for option " + options[counter.getAndIncrement()]).collect(Collectors.joining("\n"));
embedBuilder.addField("Results", "```diff\n" + votes + "```", false);
getChannel().sendMessage(embedBuilder.build()).queue();
getRunningPolls().remove(getChannel().getId());
}
@Override
public void onCancel() {
getChannel().sendMessage(EmoteReference.CORRECT + "Cancelled poll").queue();
onExpire();
}
}, reactions(options.length));
return runningPoll;
}
Aggregations