Search in sources :

Example 6 with GuildSQL

use of fun.rubicon.sql.GuildSQL in project Rubicon by Rubicon-Bot.

the class CommandManager method onMessageReceived.

@Override
public void onMessageReceived(MessageReceivedEvent event) {
    if (event.getAuthor().isBot())
        return;
    if (event.isFromType(ChannelType.PRIVATE))
        return;
    GuildSQL guildSQL = GuildSQL.fromGuild(event.getGuild());
    if (guildSQL.enabledBlacklist())
        if (guildSQL.isBlacklisted(event.getTextChannel()))
            return;
        else if (guildSQL.enabledWhitelist())
            if (!guildSQL.isWhitelisted(event.getTextChannel()))
                return;
    MusicManager.handleTrackChoose(event);
    super.onMessageReceived(event);
    ParsedCommandInvocation commandInvocation = parse(event.getMessage());
    // Send typing because it's useless
    if (commandInvocation != null && !event.getAuthor().isBot() && !event.getAuthor().isFake() && !event.isWebhookMessage()) {
        if (GlobalBlacklist.isOnBlacklist(event.getAuthor())) {
            event.getTextChannel().sendMessage(EmbedUtil.message(EmbedUtil.error("Blacklisted", "You are on the RubiconBot blacklist! ;)"))).queue(msg -> msg.delete().queueAfter(20, TimeUnit.SECONDS));
            return;
        }
        call(commandInvocation);
    }
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL)

Example 7 with GuildSQL

use of fun.rubicon.sql.GuildSQL in project Rubicon by Rubicon-Bot.

the class CommandBlacklist 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!blacklist add <#Channel>`").build(), 7);
        return;
    }
    TextChannel channel = message.getMentionedChannels().get(0);
    if (!sql.isBlacklisted(channel)) {
        SafeMessage.sendMessage(textChannel, EmbedUtil.info("Not blacklisted", "This channel is not blacklisted").build());
        return;
    }
    String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "blacklist");
    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, "blacklist", newEntry);
    SafeMessage.sendMessage(textChannel, EmbedUtil.success("Successfully removed channel from blacklist", "Successfully removed channel `" + channel.getName() + "` from blacklist!").build(), 5);
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL) TextChannel(net.dv8tion.jda.core.entities.TextChannel)

Example 8 with GuildSQL

use of fun.rubicon.sql.GuildSQL in project Rubicon by Rubicon-Bot.

the class CommandBlacklist method handleTextChannelDeletion.

public static void handleTextChannelDeletion(TextChannelDeleteEvent event) {
    GuildSQL sql = GuildSQL.fromGuild(event.getGuild());
    if (sql.isBlacklisted(event.getChannel())) {
        String oldEntry = RubiconBot.getMySQL().getGuildValue(event.getGuild(), "blacklist");
        String newEntry = oldEntry.replace(event.getChannel().getId(), "");
        if (newEntry.contains(","))
            newEntry = new StringBuilder(newEntry).replace(newEntry.lastIndexOf(","), newEntry.lastIndexOf(",") + 1, "").toString();
        RubiconBot.getMySQL().updateGuildValue(event.getGuild(), "blacklist", newEntry);
    }
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL)

Example 9 with GuildSQL

use of fun.rubicon.sql.GuildSQL in project Rubicon by Rubicon-Bot.

the class CommandWhitelist method handleTextChannelDeletion.

public static void handleTextChannelDeletion(TextChannelDeleteEvent event) {
    GuildSQL sql = GuildSQL.fromGuild(event.getGuild());
    if (sql.isBlacklisted(event.getChannel())) {
        String oldEntry = RubiconBot.getMySQL().getGuildValue(event.getGuild(), "whitelist");
        String newEntry = oldEntry.replace(event.getChannel().getId(), "");
        if (newEntry.contains(","))
            newEntry = new StringBuilder(newEntry).replace(newEntry.lastIndexOf(","), newEntry.lastIndexOf(",") + 1, "").toString();
        RubiconBot.getMySQL().updateGuildValue(event.getGuild(), "whitelist", newEntry);
    }
}
Also used : GuildSQL(fun.rubicon.sql.GuildSQL)

Aggregations

GuildSQL (fun.rubicon.sql.GuildSQL)9 TextChannel (net.dv8tion.jda.core.entities.TextChannel)6 SafeMessage (fun.rubicon.util.SafeMessage)2 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)2 Guild (net.dv8tion.jda.core.entities.Guild)2 Member (net.dv8tion.jda.core.entities.Member)2 Message (net.dv8tion.jda.core.entities.Message)2