Search in sources :

Example 1 with MessageChannel

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

the class Tinder method setupSubcommands.

@Override
public void setupSubcommands() throws Exception {
    subcommands.add(new Subcommand("Match yourself with someone in the server!", "matchme", "matchme") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(row -> row.g("user_id").eq(user.getId())).run(connection));
            User potentialMatch = getPotentialMatch(user, guild, matches);
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            String matchMe = "Match me | Tinder";
            builder.setAuthor(matchMe, getShard().url, getShard().bot.getAvatarUrl());
            builder.setThumbnail(potentialMatch.getAvatarUrl());
            StringBuilder description = new StringBuilder();
            description.append("**" + matchMe + "**");
            description.append("\nTheir name: " + UserUtils.getNameWithDiscriminator(potentialMatch.getId()));
            description.append("Swipe right (rightreaction) to connect with this person, or swipe left (left reaction) to pass them " + "by\nType /tinder connect to connect with the people you've swiped right on");
            Message sent = sendEmbed(builder.setDescription(description.toString()), channel, user, ":arrow_left:", ":arrow_right:");
            interactiveReaction(channel, sent, user, 15, messageReaction -> {
                String name = messageReaction.getEmote().getName();
                if (name != null) {
                    if (name.equals("➡")) {
                        r.table("tinder_matches").insert(r.json(gson.toJson(new TinderMatch(user.getId(), potentialMatch.getId(), true)))).run(connection);
                        sendEditedTranslation("You swiped right on {0}! Connect with them using /tinder connect", user, channel, potentialMatch.getName());
                    } else if (name.equals("⬅")) {
                        r.table("tinder_matches").insert(r.json(gson.toJson(new TinderMatch(user.getId(), potentialMatch.getId(), false)))).run(connection);
                        sendEditedTranslation("You swiped right on {0} - Don't worry, you can find better!", user, channel, potentialMatch.getName());
                    } else
                        sendTranslatedMessage("You reacted with an unexpected emoji :thinking:", channel, user);
                }
            });
        }
    });
    subcommands.add(new Subcommand("Connect with the people you've swiped right on", "connect", "connect") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            String yourMatches = "Discord Tinder | Your Matches";
            String swipedRightOnYou = "Swiped right on you";
            EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
            builder.setAuthor(yourMatches, getShard().url, getShard().bot.getAvatarUrl());
            builder.setThumbnail(user.getAvatarUrl());
            StringBuilder description = new StringBuilder();
            description.append("**" + yourMatches + "**");
            ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
            if (matches.size() == 0) {
                description.append("\nYou don't have any connections :frowning:");
            } else {
                for (int i = 0; i < matches.size(); i++) {
                    String swipedRightWithId = matches.get(i).getPerson_id();
                    boolean mutual = swipedRightWith(user.getId(), swipedRightWithId);
                    String yesNo;
                    if (mutual)
                        yesNo = EmojiParser.parseToUnicode(":white_check_mark:");
                    else
                        yesNo = EmojiParser.parseToAliases(":x:");
                    description.append("\n#" + (i + 1) + ": " + UserUtils.getNameWithDiscriminator(swipedRightWithId) + " | " + swipedRightOnYou + ": " + yesNo);
                }
            }
            description.append("\n\nUse /tinder message [number on connection list] to message that person. However, they must have " + "swiped right on you as well to be able to contact them");
            sendEmbed(builder.setDescription(description), channel, user);
        }
    });
    subcommands.add(new Subcommand("Message one of your mutual connections!", "message [number in connection list]", "message") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
                return;
            }
            if (message.getRawContent().split(" ").length == 3) {
                sendTranslatedMessage("You need to include a message to send that person!", channel, user);
                return;
            }
            try {
                int number = Integer.parseInt(args[2]) - 1;
                if (number < 0)
                    sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
                else {
                    ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
                    if (number >= matches.size()) {
                        sendTranslatedMessage("Sorry, but you don't have this many matches!", channel, user);
                        return;
                    }
                    TinderMatch selected = matches.get(number);
                    if (!swipedRightWith(user.getId(), selected.getPerson_id())) {
                        sendTranslatedMessage("That person hasn't swiped right on you!", channel, user);
                        return;
                    }
                    User toMessage = UserUtils.getUserById(selected.getPerson_id());
                    try {
                        toMessage.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage("One of your Tinder " + "matches, **" + UserUtils.getNameWithDiscriminator(user.getId()) + "**, sent you " + "a message!\n\n**" + user.getName() + "**: " + replace(message.getRawContent(), 3)).queue());
                        if (!sentTo.contains(toMessage.getId())) {
                            toMessage.openPrivateChannel().queue(privateChannel -> {
                                privateChannel.sendMessage("To stop receiving messages from this person, remove them from your match " + "list with /tinder remove [number on the /tinder connect list]\n" + "\n" + "To send a message back to this person, type /tinder message [number on your /tinder connect " + "list] [message here] in a server - meet other tinder savvy people on the Ardent guild (where" + " we have a dedicated Tinder channel)! - https://discordapp.com/invite/rfGSxNA").queue();
                                sentTo.add(toMessage.getId());
                            });
                        }
                        sendTranslatedMessage("Ok! I sent that person your message :wink:", channel, user);
                    } catch (Exception e) {
                        sendTranslatedMessage("I was unable to message that person :frowning:", channel, user);
                    }
                }
            } catch (NumberFormatException e) {
                sendTranslatedMessage("Usage: /tinder message [person's number in /tinder connect] [message here]", channel, user);
            }
        }
    });
    subcommands.add(new Subcommand("Remove one of your connections", "remove [number in connection list]", "remove") {

        @Override
        public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
            if (args.length == 2) {
                sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
                return;
            }
            try {
                int number = Integer.parseInt(args[2]) - 1;
                if (number < 0)
                    sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
                else {
                    ArrayList<TinderMatch> matches = queryAsArrayList(TinderMatch.class, r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("swipedRight", true)).run(connection));
                    if (number >= matches.size()) {
                        sendTranslatedMessage("Sorry, but you don't have this many matches!", channel, user);
                        return;
                    }
                    TinderMatch selected = matches.get(number);
                    r.table("tinder_matches").filter(r.hashMap("user_id", user.getId()).with("person_id", selected.getPerson_id())).delete().run(connection);
                    sendTranslatedMessage(":ok_hand: Removed that person from your connection list", channel, user);
                }
            } catch (NumberFormatException e) {
                sendTranslatedMessage("Usage: /tinder remove [person's number in /tinder connect]", channel, user);
            }
        }
    });
}
Also used : MessageUtils(tk.ardentbot.utils.discord.MessageUtils) Command(tk.ardentbot.core.executor.Command) UserUtils(tk.ardentbot.utils.discord.UserUtils) 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) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) Guild(net.dv8tion.jda.core.entities.Guild) EmojiParser(com.vdurmont.emoji.EmojiParser) User(net.dv8tion.jda.core.entities.User) Database.connection(tk.ardentbot.rethink.Database.connection) TinderMatch(tk.ardentbot.rethink.models.TinderMatch) User(net.dv8tion.jda.core.entities.User) Subcommand(tk.ardentbot.core.executor.Subcommand) Message(net.dv8tion.jda.core.entities.Message) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) TinderMatch(tk.ardentbot.rethink.models.TinderMatch)

Example 2 with MessageChannel

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

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

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

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

Guild (net.dv8tion.jda.core.entities.Guild)11 Message (net.dv8tion.jda.core.entities.Message)11 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)11 User (net.dv8tion.jda.core.entities.User)11 Subcommand (tk.ardentbot.core.executor.Subcommand)8 Command (tk.ardentbot.core.executor.Command)7 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)6 Database.connection (tk.ardentbot.rethink.Database.connection)4 Database.r (tk.ardentbot.rethink.Database.r)4 MessageUtils (tk.ardentbot.utils.discord.MessageUtils)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Cursor (com.rethinkdb.net.Cursor)2 SecureRandom (java.security.SecureRandom)2 Map (java.util.Map)2 Shard (tk.ardentbot.main.Shard)2 ShardManager (tk.ardentbot.main.ShardManager)2 MapUtils (tk.ardentbot.utils.MapUtils)2 GuildUtils (tk.ardentbot.utils.discord.GuildUtils)2 UserUtils (tk.ardentbot.utils.discord.UserUtils)2