Search in sources :

Example 11 with Message

use of net.dv8tion.jda.core.entities.Message 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 12 with Message

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

the class Eval method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (Ardent.developers.contains(user.getId())) {
        if (args.length == 1)
            channel.sendMessage("Use " + args[0] + " (code) to evaluate stuff").queue();
        else {
            String content = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
            final MessageBuilder builder = new MessageBuilder();
            final Map<String, Object> shortcuts = new HashMap<>();
            shortcuts.put("api", message.getJDA());
            shortcuts.put("jda", message.getJDA());
            shortcuts.put("channel", channel);
            shortcuts.put("server", guild);
            shortcuts.put("guild", guild);
            shortcuts.put("connection", Database.connection);
            shortcuts.put("r", Database.r);
            shortcuts.put("message", message);
            shortcuts.put("msg", message);
            shortcuts.put("me", message.getAuthor());
            shortcuts.put("bot", message.getJDA().getSelfUser());
            shortcuts.put("shard", getShard());
            shortcuts.put("shards", ShardManager.getShards());
            final int timeout = 10;
            final Triple<Object, String, String> result = Engine.GROOVY.eval(shortcuts, Collections.emptyList(), Engine.DEFAULT_IMPORTS, timeout, content);
            if (result.getLeft() instanceof RestAction<?>) {
                ((RestAction<?>) result.getLeft()).queue();
            } else if (result.getLeft() != null) {
                builder.appendCodeBlock(result.getLeft().toString(), "");
            }
            if (!result.getMiddle().isEmpty()) {
                builder.append("\n").appendCodeBlock(result.getMiddle(), "");
            }
            if (!result.getRight().isEmpty()) {
                builder.append("\n").appendCodeBlock(result.getRight(), "");
            }
            if (builder.isEmpty()) {
                message.addReaction("✅").queue();
            } else {
                for (final Message m : builder.buildAll(MessageBuilder.SplitPolicy.NEWLINE, MessageBuilder.SplitPolicy.SPACE, MessageBuilder.SplitPolicy.ANYWHERE)) {
                    channel.sendMessage(m).queue();
                }
            }
        }
    }
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Message(net.dv8tion.jda.core.entities.Message) HashMap(java.util.HashMap) RestAction(net.dv8tion.jda.core.requests.RestAction)

Example 13 with Message

use of net.dv8tion.jda.core.entities.Message 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 14 with Message

use of net.dv8tion.jda.core.entities.Message 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)

Example 15 with Message

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

the class Prefix method setupSubcommands.

@Override
public void setupSubcommands() {
    subcommands.add(new Subcommand("View the prefix of your server!", "view", "view") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            sendTranslatedMessage("The prefix for this server is **{0}**.".replace("{0}", GuildUtils.getPrefix(guild)), channel, user);
        }
    });
    subcommands.add(new Subcommand("Change the prefix of your server.", "change", "change") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length > 2) {
                if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
                    String newPrefix = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + "" + args[1] + " ", "").replace(" ", "");
                    if (newPrefix.length() == message.getRawContent().length()) {
                        newPrefix = message.getRawContent().replace("/" + args[0] + " " + args[1] + " ", "");
                    }
                    if (!newPrefix.contains(" ") && !newPrefix.contains("$")) {
                        GuildUtils.updatePrefix(newPrefix, guild);
                        r.db("data").table("guilds").filter(row -> row.g("guild_id").eq(guild.getId())).update(r.hashMap("prefix", newPrefix)).run(connection);
                        sendTranslatedMessage("Successfully updated the prefix,  {0}!".replace("{0}", newPrefix), channel, user);
                    } else
                        sendTranslatedMessage("Your supplied prefix contained invalid characters!", channel, user);
                } else {
                    sendTranslatedMessage("You need ```Manage Server``` permissions.", channel, user);
                }
            } else {
                sendTranslatedMessage("You must include a prefix as your third argument!", channel, user);
            }
        }
    });
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) GuildUtils(tk.ardentbot.utils.discord.GuildUtils) Permission(net.dv8tion.jda.core.Permission) User(net.dv8tion.jda.core.entities.User) Command(tk.ardentbot.core.executor.Command) Database.connection(tk.ardentbot.rethink.Database.connection) Subcommand(tk.ardentbot.core.executor.Subcommand) Database.r(tk.ardentbot.rethink.Database.r) 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) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Message(net.dv8tion.jda.core.entities.Message) Guild(net.dv8tion.jda.core.entities.Guild)

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