Search in sources :

Example 1 with Poll

use of net.kodehawa.mantarobot.commands.interaction.polls.Poll in project MantaroBot by Mantaro.

the class GeneralOptions method onRegistry.

@Subscribe
public void onRegistry(OptionRegistryEvent e) {
    registerOption("lobby:reset", "Lobby reset", "Fixes stuck game/poll/operations session.", event -> {
        GameLobby.LOBBYS.remove(event.getChannel());
        Poll.getRunningPolls().remove(event.getChannel().getId());
        Future<Void> stuck = InteractiveOperations.get(event.getChannel());
        if (stuck != null)
            stuck.cancel(true);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Reset the lobby correctly.").queue();
    });
    registerOption("modlog:blacklist", "Modlog blacklist", "Prevents an user from appearing in modlogs.\n" + "You need the user mention.\n" + "Example: ~>opts modlog blacklist @user", "Prevents an user from appearing in modlogs", event -> {
        List<User> mentioned = event.getMessage().getMentionedUsers();
        if (mentioned.isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally blacklist from mod logs.**").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        List<String> toBlackList = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
        String blacklisted = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
        guildData.getModlogBlacklistedPeople().addAll(toBlackList);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally blacklisted users from mod-log: **" + blacklisted + "**").queue();
    });
    registerOption("modlog:whitelist", "Modlog whitelist", "Allows an user from appearing in modlogs.\n" + "You need the user mention.\n" + "Example: ~>opts modlog whitelist @user", "Allows an user from appearing in modlogs (everyone by default)", event -> {
        List<User> mentioned = event.getMessage().getMentionedUsers();
        if (mentioned.isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally whitelist from mod logs.**").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        List<String> toUnBlacklist = mentioned.stream().map(ISnowflake::getId).collect(Collectors.toList());
        String unBlacklisted = mentioned.stream().map(user -> user.getName() + "#" + user.getDiscriminator()).collect(Collectors.joining(","));
        guildData.getModlogBlacklistedPeople().removeAll(toUnBlacklist);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Locally un-blacklisted users from mod-log: **" + unBlacklisted + "**").queue();
    });
    registerOption("linkprotection:toggle", "Link-protection toggle", "Toggles anti-link protection.", event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        boolean toggler = guildData.isLinkProtection();
        guildData.setLinkProtection(!toggler);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set link protection to " + "`" + !toggler + "`").queue();
        dbGuild.save();
    });
    registerOption("linkprotection:channel:allow", "Link-protection channel allow", "Allows the posting of invites on a channel.\n" + "You need the channel name.\n" + "Example: ~>opts linkprotection channel allow promote-here", "Allows the posting of invites on a channel.", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        String channelName = args[0];
        Consumer<TextChannel> consumer = tc -> {
            guildData.getLinkProtectionAllowedChannels().add(tc.getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.OK + tc.getAsMention() + " can now be used to send discord invites.").queue();
        };
        TextChannel channel = Utils.findChannelSelect(event, channelName, consumer);
        if (channel != null) {
            consumer.accept(channel);
        }
    });
    registerOption("linkprotection:channel:disallow", "Link-protection channel disallow", "Disallows the posting of invites on a channel.\n" + "You need the channel name.\n" + "Example: ~>opts linkprotection channel disallow general", "Disallows the posting of invites on a channel (every channel by default)", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        String channelName = args[0];
        Consumer<TextChannel> consumer = tc -> {
            guildData.getLinkProtectionAllowedChannels().remove(tc.getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.OK + tc.getAsMention() + " cannot longer be used to send discord invites.").queue();
        };
        TextChannel channel = Utils.findChannelSelect(event, channelName, consumer);
        if (channel != null) {
            consumer.accept(channel);
        }
    });
    registerOption("linkprotection:user:allow", "Link-protection user whitelist", "Allows an user to post invites.\n" + "You need to mention the user.", "Allows an user to post invites.", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        if (event.getMessage().getMentionedUsers().isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention the user to whitelist from posting invites!").queue();
            return;
        }
        User toWhiteList = event.getMessage().getMentionedUsers().get(0);
        guildData.getLinkProtectionAllowedUsers().add(toWhiteList.getId());
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully whitelisted " + toWhiteList.getName() + "#" + toWhiteList.getDiscriminator() + " from posting discord invites.").queue();
    });
    registerOption("linkprotection:user:disallow", "Link-protection user blacklist", "Disallows an user to post invites.\n" + "You need to mention the user. (This is the default behaviour)", "Allows an user to post invites (This is the default behaviour)", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        if (event.getMessage().getMentionedUsers().isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention the user to blacklist from posting invites!").queue();
            return;
        }
        User toBlackList = event.getMessage().getMentionedUsers().get(0);
        if (!guildData.getLinkProtectionAllowedUsers().contains(toBlackList.getId())) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "This user isn't in the invite posting whitelist!").queue();
            return;
        }
        guildData.getLinkProtectionAllowedUsers().remove(toBlackList.getId());
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully blacklisted " + toBlackList.getName() + "#" + toBlackList.getDiscriminator() + " from posting discord invites.").queue();
    });
    registerOption("imageboard:tags:blacklist:add", "Blacklist imageboard tags", "Blacklists the specified imageboard tag from being looked up.", "Blacklist imageboard tags", (event, args) -> {
        if (args.length == 0) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify at least a tag to blacklist!").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        for (String tag : args) {
            guildData.getBlackListedImageTags().add(tag.toLowerCase());
        }
        dbGuild.saveAsync();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully blacklisted " + String.join(" ,", args) + " from image search.").queue();
    });
    registerOption("imageboard:tags:blacklist:remove", "Un-blacklist imageboard tags", "Un-blacklist the specified imageboard tag from being looked up.", "Un-blacklist imageboard tags", (event, args) -> {
        if (args.length == 0) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify at least a tag to un-blacklist!").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        for (String tag : args) {
            guildData.getBlackListedImageTags().remove(tag.toLowerCase());
        }
        dbGuild.saveAsync();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Successfully un-blacklisted " + String.join(" ,", args) + " from image search.").queue();
    });
}
Also used : Poll(net.kodehawa.mantarobot.commands.interaction.polls.Poll) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Option(net.kodehawa.mantarobot.options.annotations.Option) Utils(net.kodehawa.mantarobot.utils.Utils) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) OptsCmd(net.kodehawa.mantarobot.commands.OptsCmd) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Future(java.util.concurrent.Future) User(net.dv8tion.jda.core.entities.User) ISnowflake(net.dv8tion.jda.core.entities.ISnowflake) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Subscribe(com.google.common.eventbus.Subscribe) OptionRegistryEvent(net.kodehawa.mantarobot.options.event.OptionRegistryEvent) OptionHandler(net.kodehawa.mantarobot.options.core.OptionHandler) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) User(net.dv8tion.jda.core.entities.User) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 ISnowflake (net.dv8tion.jda.core.entities.ISnowflake)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 User (net.dv8tion.jda.core.entities.User)1 OptsCmd (net.kodehawa.mantarobot.commands.OptsCmd)1 GameLobby (net.kodehawa.mantarobot.commands.game.core.GameLobby)1 Poll (net.kodehawa.mantarobot.commands.interaction.polls.Poll)1 InteractiveOperations (net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations)1 MantaroData (net.kodehawa.mantarobot.data.MantaroData)1 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)1 GuildData (net.kodehawa.mantarobot.db.entities.helpers.GuildData)1 Option (net.kodehawa.mantarobot.options.annotations.Option)1 OptionHandler (net.kodehawa.mantarobot.options.core.OptionHandler)1 OptionRegistryEvent (net.kodehawa.mantarobot.options.event.OptionRegistryEvent)1 Utils (net.kodehawa.mantarobot.utils.Utils)1