Search in sources :

Example 26 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class GuildInfo method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
    builder.setAuthor("Server Info", guild.getIconUrl(), guild.getIconUrl());
    builder.addField("Number of users", String.valueOf(guild.getMembers().size()), true);
    builder.addField("Online users", String.valueOf(guild.getMembers().stream().filter(m -> m.getOnlineStatus() == OnlineStatus.ONLINE).count()), true);
    builder.addField("Prefix", GuildUtils.getPrefix(guild), true);
    builder.addField("Premium Server", String.valueOf(EntityGuild.get(guild).isPremium()), true);
    builder.addField("Owner", UserUtils.getNameWithDiscriminator(guild.getOwner().getUser().getId()), true);
    builder.addField("Creation Date", guild.getCreationTime().toLocalDate().toString(), true);
    builder.addField("Public channel", guild.getPublicChannel().getAsMention(), true);
    builder.addField("# of Voice Channels", String.valueOf(guild.getVoiceChannels().size()), true);
    builder.addField("# of Text Channels", String.valueOf(guild.getTextChannels().size()), true);
    builder.addField("# of Roles", String.valueOf(guild.getRoles().size()), true);
    builder.addField("Region", guild.getRegion().getName(), true);
    builder.addField("Verification Level", String.valueOf(guild.getVerificationLevel()), true);
    sendEmbed(builder, channel, user);
}
Also used : EntityGuild(tk.ardentbot.utils.rpg.EntityGuild) Guild(net.dv8tion.jda.core.entities.Guild) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) MessageUtils(tk.ardentbot.utils.discord.MessageUtils) User(net.dv8tion.jda.core.entities.User) Command(tk.ardentbot.core.executor.Command) UserUtils(tk.ardentbot.utils.discord.UserUtils) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) OnlineStatus(net.dv8tion.jda.core.OnlineStatus) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Example 27 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class Bet method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("Bet a specified amount of money", "start", "start") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                sendTranslatedMessage("You need to specify a bet amount", channel, user);
                return;
            }
            try {
                double amountToBet = Double.parseDouble(args[2]);
                Profile profile = Profile.get(user);
                if (amountToBet <= 0 || profile.getMoney() < amountToBet) {
                    sendTranslatedMessage("Invalid amount - either it was more than what you have or less than $0", channel, user);
                    return;
                }
                sendEditedTranslation("Are you sure you want to bet **{0}**? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(amountToBet));
                interactiveOperation(channel, message, (returnedMessage) -> {
                    if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
                        sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
                        interactiveOperation(channel, message, (numberInput) -> {
                            try {
                                int num = Integer.parseInt(numberInput.getContent());
                                if (num > 0 && num <= 2) {
                                    int generated = new SecureRandom().nextInt(2) + 1;
                                    if (num == generated || new Random().nextInt(20) == 5) {
                                        profile.addMoney(profile.afterCredit(amountToBet));
                                        sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(amountToBet)), channel, user);
                                    } else {
                                        sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(amountToBet) + " :frowning: " + "The correct answer " + "was " + generated, channel, user);
                                        profile.removeMoney(amountToBet);
                                    }
                                } else
                                    sendTranslatedMessage("You specified an invalid number", channel, user);
                            } catch (Exception ex) {
                                sendTranslatedMessage("You specified an invalid number", channel, user);
                            }
                        });
                    } else {
                        sendTranslatedMessage("Ok, cancelled your bet", channel, user);
                    }
                });
            } catch (NumberFormatException e) {
                sendTranslatedMessage("That's not a number!", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("Bet all your money", "all", "all") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            Profile profile = Profile.get(user);
            if (profile.getMoney() < 0) {
                sendTranslatedMessage("You can't bet if you're in debt!", channel, user);
                return;
            }
            sendEditedTranslation("Are you sure you want to bet all? Type **yes** if so, or **no** to cancel", user, channel, RPGUtils.formatMoney(profile.getMoney()));
            interactiveOperation(channel, message, (returnedMessage) -> {
                if (returnedMessage.getContent().equalsIgnoreCase("yes")) {
                    sendTranslatedMessage("Type 1 or 2 below - choose wisely!", channel, user);
                    interactiveOperation(channel, message, (numberInput) -> {
                        try {
                            int num = Integer.parseInt(numberInput.getContent());
                            if (num > 0 && num <= 2) {
                                int generated = new SecureRandom().nextInt(2) + 1;
                                if (num == generated || new Random().nextInt(20) == 5) {
                                    profile.addMoney(profile.afterCredit(profile.getMoney()));
                                    sendTranslatedMessage("Congrats! You won " + RPGUtils.formatMoney(profile.afterCredit(profile.getMoney())), channel, user);
                                } else {
                                    sendTranslatedMessage("Sorry, you lost " + RPGUtils.formatMoney(profile.getMoney()) + " :frowning: The correct answer " + "was " + generated, channel, user);
                                    profile.setZero();
                                }
                            } else
                                sendTranslatedMessage("You specified an invalid number", channel, user);
                        } catch (Exception ex) {
                            sendTranslatedMessage("You specified an invalid number", channel, user);
                        }
                    });
                } else {
                    sendTranslatedMessage("Ok, cancelled your bet", channel, user);
                }
            });
        }
    });
}
Also used : SecureRandom(java.security.SecureRandom) Guild(net.dv8tion.jda.core.entities.Guild) User(net.dv8tion.jda.core.entities.User) RPGUtils(tk.ardentbot.utils.rpg.RPGUtils) Command(tk.ardentbot.core.executor.Command) Subcommand(tk.ardentbot.core.executor.Subcommand) Random(java.util.Random) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) SecureRandom(java.security.SecureRandom) Guild(net.dv8tion.jda.core.entities.Guild) Profile(tk.ardentbot.utils.rpg.profiles.Profile) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) SecureRandom(java.security.SecureRandom) Random(java.util.Random)

Example 28 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class ShardInfo method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    StringBuilder builder = new StringBuilder();
    for (Shard shard : ShardManager.getShards()) {
        builder.append(shard.jda.getShardInfo()).append(" | STATUS: ").append(shard.jda.getStatus()).append(" | " + "U: ").append(shard.jda.getUsers().size()).append(" | G: ").append(shard.jda.getGuilds().size()).append(" | MC: ").append(shard.jda.getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getMembers().contains(voiceChannel.getGuild().getSelfMember())).count()).append(" | LE: " + (System.currentTimeMillis() - shard.getLAST_EVENT()));
        if (shard.jda.getShardInfo() != null && shard.jda.getShardInfo().equals(guild.getJDA().getShardInfo())) {
            builder.append(" <- CURRENT");
        }
        builder.append("\n");
    }
    channel.sendMessage(String.format("```prolog\n%s```", builder.toString())).queue();
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) ShardManager(tk.ardentbot.main.ShardManager) User(net.dv8tion.jda.core.entities.User) Command(tk.ardentbot.core.executor.Command) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Shard(tk.ardentbot.main.Shard) Message(net.dv8tion.jda.core.entities.Message) Shard(tk.ardentbot.main.Shard)

Example 29 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class Stats method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("See what commands are being used", "commands", "commands") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            StringBuilder commandBars = new StringBuilder();
            Map<String, Long> commandsUsed = getCommandData(ShardManager.getShards());
            final int[] counter = { 0 };
            final int[] totalCommandsReceived = { 0 };
            commandsUsed.forEach((key, value) -> {
                if (counter[0] < 7)
                    totalCommandsReceived[0] += value;
                counter[0]++;
            });
            counter[0] = 0;
            commandsUsed.forEach((key, value) -> {
                if (counter[0] < 7) {
                    int percent = (int) (value * 100 / totalCommandsReceived[0]);
                    String bar = bar(percent);
                    if (bar != null) {
                        commandBars.append(bar + " " + percent + "% **" + key + "**\n");
                    }
                }
                counter[0]++;
            });
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Command Statistics", getShard().url, getShard().bot.getAvatarUrl());
            builder.setColor(Color.GREEN);
            builder.setDescription("Command Usage\n" + commandBars.toString());
            sendEmbed(builder, channel, user);
        }
    });
    subcommands.add(new Subcommand("See how many server's I'm joining and leaving", "guilds") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor("Guild Statistics", getShard().url, getShard().bot.getAvatarUrl());
            builder.setColor(Color.GREEN);
            int lPH = 0;
            int lPD = 0;
            int lPS = 0;
            long epochSecond = Instant.now().getEpochSecond();
            long hBar = epochSecond - (60 * 60);
            long dBar = epochSecond - (60 * 60 * 24);
            long sBar = 0;
            for (Instant i : Leave.botLeaveEvents) {
                if (i.getEpochSecond() >= hBar)
                    lPH++;
                if (i.getEpochSecond() >= dBar)
                    lPD++;
                // Always true
                if (i.getEpochSecond() >= sBar)
                    lPS++;
            }
            int jPH = 0;
            int jPD = 0;
            int jPS = 0;
            for (Instant i : Join.botJoinEvents) {
                if (i.getEpochSecond() >= hBar)
                    jPH++;
                if (i.getEpochSecond() >= dBar)
                    jPD++;
                // Always true
                if (i.getEpochSecond() >= sBar)
                    jPS++;
            }
            builder.addField("Hourly", generateGuild(jPH, lPH), false);
            builder.addField("Daily", generateGuild(jPD, lPD), false);
            builder.addField("This Session", generateGuild(jPS, lPS), false);
            builder.addField("Guilds", String.valueOf(InternalStats.collect().getGuilds()), false);
            sendEmbed(builder, channel, user);
        }
    });
}
Also used : ShardManager(tk.ardentbot.main.ShardManager) MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Join(tk.ardentbot.core.events.Join) Command(tk.ardentbot.core.executor.Command) Leave(tk.ardentbot.core.events.Leave) Subcommand(tk.ardentbot.core.executor.Subcommand) HashMap(java.util.HashMap) Instant(java.time.Instant) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Shard(tk.ardentbot.main.Shard) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) Guild(net.dv8tion.jda.core.entities.Guild) User(net.dv8tion.jda.core.entities.User) MapUtils(tk.ardentbot.utils.MapUtils) Map(java.util.Map) InternalStats(tk.ardentbot.utils.discord.InternalStats) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) Instant(java.time.Instant) Guild(net.dv8tion.jda.core.entities.Guild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with Message

use of net.dv8tion.jda.core.entities.Message in project Ardent by adamint.

the class MusicConfig method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    Cursor<HashMap> settings = r.db("data").table("music_settings").filter(row -> row.g("guild_id").eq(guild.getId())).run(connection);
    if (settings.hasNext()) {
        MusicSettingsModel musicSettingsModel = asPojo(settings.next(), MusicSettingsModel.class);
        sendTranslatedMessage("**music Settings**\n" + "Delete music play messages: " + musicSettingsModel.isRemove_addition_messages(), channel, user);
    } else
        sendTranslatedMessage("Your guild has no set music settings! Type **/manage** to find your portal" + " link", channel, user);
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) Cursor(com.rethinkdb.net.Cursor) User(net.dv8tion.jda.core.entities.User) Command(tk.ardentbot.core.executor.Command) MusicSettingsModel(tk.ardentbot.rethink.models.MusicSettingsModel) Database.connection(tk.ardentbot.rethink.Database.connection) Database.r(tk.ardentbot.rethink.Database.r) HashMap(java.util.HashMap) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) HashMap(java.util.HashMap) MusicSettingsModel(tk.ardentbot.rethink.models.MusicSettingsModel)

Aggregations

Message (net.dv8tion.jda.core.entities.Message)30 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)14 Guild (net.dv8tion.jda.core.entities.Guild)13 User (net.dv8tion.jda.core.entities.User)12 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)11 Subcommand (tk.ardentbot.core.executor.Subcommand)8 Command (tk.ardentbot.core.executor.Command)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Database.connection (tk.ardentbot.rethink.Database.connection)4 Database.r (tk.ardentbot.rethink.Database.r)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Consumer (java.util.function.Consumer)3 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)3 MessageUtils (tk.ardentbot.utils.discord.MessageUtils)3 Cursor (com.rethinkdb.net.Cursor)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)2 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)2