Search in sources :

Example 6 with Guild

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

the class InternalStats method collect.

public static InternalStats collect() {
    long messagesReceived = 0;
    long commandsReceived = 0;
    long loadedCommands = 0;
    long guilds = 0;
    long users = 0;
    long roleCount = 0;
    long textChannelCount = 0;
    long voiceChannelCount = 0;
    long musicPlayers = 0;
    for (Shard shard : getShards()) {
        CommandFactory factory = shard.factory;
        messagesReceived += factory.getMessagesReceived();
        commandsReceived += factory.getCommandsReceived();
        if (loadedCommands == 0)
            loadedCommands = factory.getLoadedCommandsAmount();
        guilds += shard.jda.getGuilds().size();
        users += shard.jda.getUsers().size();
        for (Guild guild : shard.jda.getGuilds()) {
            roleCount += guild.getRoles().size();
            textChannelCount += guild.getTextChannels().size();
            voiceChannelCount += guild.getVoiceChannels().size();
            if (guild.getAudioManager().isConnected())
                musicPlayers++;
        }
    }
    return new InternalStats(messagesReceived, commandsReceived, loadedCommands, guilds, users, roleCount, textChannelCount, voiceChannelCount, musicPlayers);
}
Also used : Shard(tk.ardentbot.main.Shard) CommandFactory(tk.ardentbot.core.executor.CommandFactory) Guild(net.dv8tion.jda.core.entities.Guild)

Example 7 with Guild

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

the class TriviaGame method finish.

public void finish(Shard shard, Command command) throws Exception {
    totalRounds = 9001;
    final int bonus = 250;
    final int perQuestion = 50;
    Trivia.gamesInSession.remove(this);
    Trivia.gamesSettingUp.remove(guildId);
    Guild guild = shard.jda.getGuildById(guildId);
    TextChannel channel = guild.getTextChannelById(textChannelId);
    channel.sendMessage(displayScores(shard, command).build()).queue();
    channel.sendMessage("Thanks for playing! You'll receive **$50** for every correct answer").queue();
    Map<String, Integer> sorted = MapUtils.sortByValue(scores);
    Iterator<Map.Entry<String, Integer>> iterator = sorted.entrySet().iterator();
    int current = 0;
    while (iterator.hasNext()) {
        Map.Entry<String, Integer> entry = iterator.next();
        User user = guild.getMemberById(entry.getKey()).getUser();
        Profile profile = Profile.get(user);
        profile.addMoney(perQuestion * entry.getValue());
        if (current == 0 && !isSolo() && scores.size() > 1) {
            profile.addMoney(bonus);
            channel.sendMessage(user.getAsMention() + ", you won a **$250** bonus for being so smart!").queue();
        }
        current++;
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) User(net.dv8tion.jda.core.entities.User) Guild(net.dv8tion.jda.core.entities.Guild) HashMap(java.util.HashMap) Map(java.util.Map) Profile(tk.ardentbot.utils.rpg.profiles.Profile)

Example 8 with Guild

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

the class AdBlock method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("View the Adblock settings for this server", "settings", "settings") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
            if (settings == null) {
                settings = new AntiAdvertisingSettings(guild.getId(), true, false);
                r.table("anti_advertising_settings").insert(r.json(gson.toJson(settings))).run(connection);
            }
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            String adblockSettings = "Adblock Settings";
            builder.setAuthor(adblockSettings, guild.getIconUrl(), guild.getIconUrl());
            StringBuilder description = new StringBuilder();
            description.append("**" + adblockSettings + "**");
            description.append("\nAllow users to post server invites: *" + settings.isAllow_discord_server_links() + "*");
            description.append("\nBan users after they advertise twice: *" + settings.isBan_after_two_infractions() + "*");
            sendEmbed(builder.setDescription(description), channel, user);
        }
    });
    subcommands.add(new Subcommand("Allow or block users from sending server invites", "serverinvites [true/false]", "serverinvites") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            try {
                AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
                boolean allow = Boolean.parseBoolean(args[2]);
                if (allow) {
                    if (settings == null)
                        r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), true, false)))).run(connection);
                    else
                        r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("allow_discord_server_links", true)).run(connection);
                    sendTranslatedMessage("People can now post Discord server invite links", channel, user);
                } else {
                    if (settings == null)
                        r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), false, false)))).run(connection);
                    else
                        r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("allow_discord_server_links", false)).run(connection);
                    sendTranslatedMessage("People now **cannot** post Discord server invite links", channel, user);
                }
            } catch (Exception ex) {
                sendTranslatedMessage("You need to specify true or false!", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("Ban users who advertise more than twice", "banafter2ads [true/false]", "banafter2ads") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            try {
                AntiAdvertisingSettings settings = asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
                boolean yes = Boolean.parseBoolean(args[2]);
                if (yes) {
                    if (settings == null)
                        r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), false, true)))).run(connection);
                    else
                        r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("ban_after_two_infractions", true)).run(connection);
                    sendTranslatedMessage("I will now ban users if they advertise more than twice", channel, user);
                } else {
                    if (settings == null)
                        r.table("anti_advertising_settings").insert(r.json(gson.toJson(new AntiAdvertisingSettings(guild.getId(), true, false)))).run(connection);
                    else
                        r.table("anti_advertising_settings").get(guild.getId()).update(r.hashMap("ban_after_two_infractions", false)).run(connection);
                    sendTranslatedMessage("I won't ban members after 2 advertising infractions", channel, user);
                }
            } catch (Exception ex) {
                sendTranslatedMessage("You need to specify true or false!", channel, user);
            }
        }
    });
}
Also used : AntiAdvertisingSettings(tk.ardentbot.rethink.models.AntiAdvertisingSettings) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) Guild(net.dv8tion.jda.core.entities.Guild)

Example 9 with Guild

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

the class ServerInfo method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("Set server info for new useres", "set", "set") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            String serverInfo = getServerInfo(guild);
            if (serverInfo == null) {
                if (guild.getMember(user).hasPermission(Permission.MANAGE_CHANNEL)) {
                    if (args.length > 2) {
                        String parsed = replace(message.getContent(), 2);
                        setInfo(guild, parsed);
                        sendTranslatedMessage("Successfully set the server info message! Invoke it by doing /server info", channel, user);
                    } else {
                        sendTranslatedMessage("You need to include some text in the info!", channel, user);
                    }
                } else
                    sendTranslatedMessage("You need the Manage Server permission to use this!", channel, user);
            } else {
                sendTranslatedMessage("Server info has already been added! Remove it before you can change it.", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("Remove the set server info", "remove", "remove") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            String serverInfo = getServerInfo(guild);
            if (serverInfo != null) {
                if (guild.getMember(user).hasPermission(Permission.MANAGE_CHANNEL)) {
                    setInfo(guild, null);
                    sendTranslatedMessage("Successfully removed server info.", channel, user);
                } else
                    sendTranslatedMessage("You need the Manage Server permission to use this!", channel, user);
            } else {
                sendTranslatedMessage("Your server doesn't have a setup info message.", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("View the server info settings", "view", "view") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            String serverInfo = getServerInfo(guild);
            if (serverInfo == null) {
                sendTranslatedMessage("Your server doesn't have a setup info message.", channel, user);
            } else {
                sendTranslatedMessage("**" + guild.getName() + "**:\n" + serverInfo, channel, user);
            }
        }
    });
}
Also used : User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) Guild(net.dv8tion.jda.core.entities.Guild) SQLException(java.sql.SQLException)

Example 10 with Guild

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

the class Help method setupSubcommands.

@Override
public void setupSubcommands() {
    all = new Subcommand("See the traditional help screen", "all", "all") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            EmbedBuilder helpEmbed = MessageUtils.getDefaultEmbed(user);
            helpEmbed.setAuthor("Ardent Help", "https://ardentbot.tk/guild", getShard().bot.getAvatarUrl());
            helpEmbed.setThumbnail("https://a.dryicons.com/images/icon_sets/polygon_icons/png/256x256/computer" + ".png");
            StringBuilder description = new StringBuilder();
            description.append("Command Categories\n");
            for (Category category : Category.values()) {
                description.append(" > **" + category.name().toLowerCase() + "**\n");
            }
            description.append("\nType /help [category] to view a specific category\n\nIf you need help, join our support guild: " + "https://ardentbot.tk/guild");
            helpEmbed.setDescription(description.toString());
            sendEmbed(helpEmbed, channel, user);
        }
    };
    subcommands.add(all);
    for (Category category : Category.values()) {
        subcommands.add(new Subcommand("how tf did you see this", Category.getName(category), Category.getName(category)) {

            @Override
            public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
                EmbedBuilder embedBuilder = MessageUtils.getDefaultEmbed(user);
                embedBuilder.setAuthor("Commands in Category ".replace("{0}", WordUtils.capitalize(category.name().toLowerCase())), "https://ardentbot.tk/guild", getShard().bot.getAvatarUrl());
                ArrayList<BaseCommand> commandsInCategory = Help.this.getCommandsInCategory(category);
                StringBuilder description = new StringBuilder();
                for (BaseCommand baseCommand : commandsInCategory) {
                    description.append(" > **" + baseCommand.getName() + "**: " + baseCommand.getDescription() + "\n");
                }
                embedBuilder.setDescription(description.toString());
                sendEmbed(embedBuilder, channel, user);
            }
        });
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Category(tk.ardentbot.core.executor.Category) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) BaseCommand(tk.ardentbot.core.executor.BaseCommand) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel)

Aggregations

Guild (net.dv8tion.jda.core.entities.Guild)27 User (net.dv8tion.jda.core.entities.User)14 Message (net.dv8tion.jda.core.entities.Message)13 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)11 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)10 Shard (tk.ardentbot.main.Shard)9 Subcommand (tk.ardentbot.core.executor.Subcommand)8 TextChannel (net.dv8tion.jda.core.entities.TextChannel)7 Command (tk.ardentbot.core.executor.Command)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)5 Database.connection (tk.ardentbot.rethink.Database.connection)4 Database.r (tk.ardentbot.rethink.Database.r)4 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)3 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)3 Map (java.util.Map)3 Member (net.dv8tion.jda.core.entities.Member)3 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)3 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)3