Search in sources :

Example 96 with EmbedBuilder

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());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Guild(net.dv8tion.jda.core.entities.Guild) HashMap(java.util.HashMap) Map(java.util.Map)

Example 97 with EmbedBuilder

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();
        }
    });
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WeatherData(net.kodehawa.mantarobot.commands.utils.WeatherData) Subscribe(com.google.common.eventbus.Subscribe)

Example 98 with EmbedBuilder

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();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 99 with EmbedBuilder

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();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 100 with EmbedBuilder

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;
}
Also used : ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.core.ReactionOperation) MessageReactionAddEvent(net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Utils(net.kodehawa.mantarobot.utils.Utils) HashMap(java.util.HashMap) Message(net.dv8tion.jda.core.entities.Message) Lobby(net.kodehawa.mantarobot.commands.interaction.Lobby) ArrayList(java.util.ArrayList) MantaroBot(net.kodehawa.mantarobot.MantaroBot) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Future(java.util.concurrent.Future) Permission(net.dv8tion.jda.core.Permission) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Stream(java.util.stream.Stream) User(net.dv8tion.jda.core.entities.User) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.core.ReactionOperation) Operation(net.kodehawa.mantarobot.core.listeners.operations.core.Operation) MessageReactionAddEvent(net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList)

Aggregations

EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)128 Message (net.dv8tion.jda.core.entities.Message)26 List (java.util.List)24 ArrayList (java.util.ArrayList)22 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)22 User (net.dv8tion.jda.core.entities.User)20 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)20 Collectors (java.util.stream.Collectors)19 MantaroData (net.kodehawa.mantarobot.data.MantaroData)19 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)17 Utils (net.kodehawa.mantarobot.utils.Utils)17 TimeUnit (java.util.concurrent.TimeUnit)16 Permission (net.dv8tion.jda.core.Permission)15 Subscribe (com.google.common.eventbus.Subscribe)13 Color (java.awt.Color)13 Guild (net.dv8tion.jda.core.entities.Guild)12 TextChannel (net.dv8tion.jda.core.entities.TextChannel)12 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)12 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)12 java.awt (java.awt)11