Search in sources :

Example 36 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandBlacklist method executeAdd.

private void executeAdd(String[] args, Member member, Guild guild, TextChannel textChannel, Message message) {
    GuildSQL guildSQL = GuildSQL.fromGuild(guild);
    if (message.getMentionedChannels().isEmpty()) {
        SafeMessage.sendMessage(textChannel, EmbedUtil.error("Unknown usage", "Please use `rc!whitelist add <#Channel>`").build(), 7);
        return;
    }
    TextChannel channel = message.getMentionedChannels().get(0);
    if (guildSQL.isBlacklisted(channel)) {
        SafeMessage.sendMessage(textChannel, EmbedUtil.info("Already blacklisted", "This channel is already whitelisted").build());
        return;
    }
    String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "blacklist");
    String newEntry;
    if (oldEntry.equals(""))
        newEntry = channel.getId();
    else
        newEntry = oldEntry + "," + channel.getId();
    RubiconBot.getMySQL().updateGuildValue(guild, "blacklist", newEntry);
    SafeMessage.sendMessage(textChannel, EmbedUtil.success("Successfully blacklisted channel", "Successfully whitelisted channel `" + channel.getName() + "` !").build(), 5);
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL) TextChannel(net.dv8tion.jda.core.entities.TextChannel)

Example 37 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandBlacklist method executeList.

private void executeList(String[] args, Member member, Guild guild, TextChannel textChannel) {
    GuildSQL guildSQL = GuildSQL.fromGuild(guild);
    if (guildSQL.enabledBlacklist()) {
        List<String> channelIDs = Arrays.asList(RubiconBot.getMySQL().getGuildValue(guild, "blacklist").split(","));
        StringBuilder channels = new StringBuilder();
        channelIDs.forEach(id -> {
            try {
                TextChannel channel = guild.getTextChannelById(id);
                channels.append(channel.getName()).append(", ");
            } catch (NullPointerException ignored) {
                String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "blacklist");
                String newEntry = oldEntry.replace(id, "");
                if (newEntry.contains(","))
                    newEntry = new StringBuilder(newEntry).replace(newEntry.lastIndexOf(","), newEntry.lastIndexOf(",") + 1, "").toString();
                RubiconBot.getMySQL().updateGuildValue(guild, "blacklist", newEntry);
                if (channelIDs.size() == 0) {
                    SafeMessage.sendMessage(textChannel, EmbedUtil.info("Blacklisted Channels", "Blacklist mode: `" + String.valueOf(guildSQL.enabledBlacklist()).replace("true", "enabled").replace("false", "disabled") + "`").build());
                    return;
                }
            }
        });
        channels.replace(channels.lastIndexOf(","), channels.lastIndexOf(",") + 1, "");
        SafeMessage.sendMessage(textChannel, EmbedUtil.info("Blacklisted Channels", "Blacklist mode: `" + String.valueOf(guildSQL.enabledBlacklist()).replace("true", "enabled").replace("false", "disabled") + "`\nChannels: `" + channels.toString() + "`").build());
    } else
        SafeMessage.sendMessage(textChannel, EmbedUtil.info("Blacklisted Channels", "Blacklist mode: `" + String.valueOf(guildSQL.enabledBlacklist()).replace("true", "enabled").replace("false", "disabled") + "`").build());
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL) TextChannel(net.dv8tion.jda.core.entities.TextChannel)

Example 38 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandBlacklist method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    String[] args = parsedCommandInvocation.getArgs();
    Member member = parsedCommandInvocation.getMember();
    Guild guild = parsedCommandInvocation.getGuild();
    TextChannel channel = parsedCommandInvocation.getTextChannel();
    Message message = parsedCommandInvocation.getMessage();
    if (args.length == 0)
        return createHelpMessage();
    GuildSQL guildSQL = GuildSQL.fromGuild(guild);
    if (guildSQL.enabledWhitelist()) {
        return new MessageBuilder().setEmbed(EmbedUtil.error("Already using whitelist", "You can't use black- and whitelist on the same server").build()).build();
    }
    switch(args[0]) {
        case "list":
            executeList(args, member, guild, channel);
            break;
        case "add":
        case "blacklist":
            executeAdd(args, member, guild, channel, message);
            break;
        case "remove":
        case "whitelist":
            executeRemove(args, member, guild, channel, message);
            break;
        default:
            SafeMessage.sendMessage(channel, createHelpMessage(), 5);
            break;
    }
    return null;
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL) TextChannel(net.dv8tion.jda.core.entities.TextChannel) SafeMessage(fun.rubicon.util.SafeMessage) Message(net.dv8tion.jda.core.entities.Message) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 39 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandSearch method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message message = parsedCommandInvocation.getMessage();
    String[] args = parsedCommandInvocation.getArgs();
    TextChannel channel = message.getTextChannel();
    Guild guild = message.getGuild();
    if (args.length == 0) {
        return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "search <query>").build()).build();
    }
    StringBuilder query = new StringBuilder();
    for (String arg : args) {
        query.append(arg);
    }
    StringBuilder textchannels = new StringBuilder();
    StringBuilder voicechannels = new StringBuilder();
    StringBuilder members = new StringBuilder();
    StringBuilder roles = new StringBuilder();
    Message mymsg = channel.sendMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting textchannels ...").build()).complete();
    guild.getTextChannels().forEach(i -> {
        if (i.getName().toLowerCase().contains(query.toString().toLowerCase()))
            textchannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
    });
    mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting voicechannels ...").build()).queue();
    guild.getVoiceChannels().forEach(i -> {
        if (i.getName().toLowerCase().contains(query.toString().toLowerCase()))
            voicechannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
    });
    mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting users ...").build()).queue();
    guild.getMembers().forEach(i -> {
        if (i.getUser().getName().toLowerCase().contains(query.toString().toLowerCase()) || i.getEffectiveName().toLowerCase().contains(query.toString().toLowerCase()))
            members.append(i.getUser().getName() + "(`" + i.getUser().getId() + "`)").append("\n");
    });
    mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting roles ...").build()).queue();
    guild.getRoles().forEach(i -> {
        if (i.getName().toLowerCase().contains(query.toString().toLowerCase()))
            roles.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
    });
    mymsg.delete().queue();
    try {
        EmbedBuilder results = new EmbedBuilder().setColor(Color.green).addField("**Textchannels**", textchannels.toString(), false).addField("**Voicechannles**", voicechannels.toString(), false).addField("**Members**", members.toString(), false).addField("**Roles**", roles.toString(), false);
        return new MessageBuilder().setEmbed(results.build()).build();
    } catch (IllegalArgumentException ex) {
        return new MessageBuilder().setEmbed(EmbedUtil.error("Error!", "Too many results!").build()).build();
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Message(net.dv8tion.jda.core.entities.Message) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Guild(net.dv8tion.jda.core.entities.Guild)

Example 40 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandWhitelist method executeRemove.

private void executeRemove(String[] args, Member member, Guild guild, TextChannel textChannel, Message message) {
    GuildSQL sql = GuildSQL.fromGuild(guild);
    if (message.getMentionedChannels().isEmpty()) {
        SafeMessage.sendMessage(textChannel, EmbedUtil.error("Unknown usage", "Please use `rc!whitelist add <#Channel>`").build(), 7);
        return;
    }
    TextChannel channel = message.getMentionedChannels().get(0);
    if (!sql.isWhitelisted(channel)) {
        SafeMessage.sendMessage(textChannel, EmbedUtil.info("Not whitelisted", "This channel is not whitelisted").build());
        return;
    }
    String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "whitelist");
    String newEntry;
    if (oldEntry.equals(channel.getId()))
        newEntry = "";
    else
        newEntry = oldEntry.replace(channel.getId(), "");
    if (newEntry.contains(","))
        newEntry = new StringBuilder(newEntry).replace(newEntry.lastIndexOf(","), newEntry.lastIndexOf(",") + 1, "").toString();
    RubiconBot.getMySQL().updateGuildValue(guild, "whitelist", newEntry);
    SafeMessage.sendMessage(textChannel, EmbedUtil.success("Successfully removed channel from whitelist", "Successfully removed channel `" + channel.getName() + "` from whitelist!").build(), 5);
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL) TextChannel(net.dv8tion.jda.core.entities.TextChannel)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)91 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)22 User (net.dv8tion.jda.core.entities.User)20 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)11 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6