Search in sources :

Example 1 with PostLoadEvent

use of net.kodehawa.mantarobot.modules.events.PostLoadEvent in project MantaroBot by Mantaro.

the class MusicCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    OptsCmd.registerOption("reactionmenus:toggle", event -> {
        DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
        GuildData data = dbg.getData();
        boolean t = data.isReactionMenus();
        data.setReactionMenus(!t);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "**Set reaction menues to: `" + !t + "`**").queue();
        dbg.save();
    });
    OptsCmd.registerOption("fairqueue:max", (event, args) -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        if (args.length == 0) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a positive integer.").queue();
            return;
        }
        String much = args[0];
        final int fq;
        try {
            fq = Integer.parseInt(much);
        } catch (Exception ex) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "Not a valid number").queue();
            return;
        }
        guildData.setMaxFairQueue(fq);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set max fair queue size to " + fq).queue();
    });
    OptsCmd.registerOption("musicannounce:toggle", event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        boolean t1 = guildData.isMusicAnnounce();
        guildData.setMusicAnnounce(!t1);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set no music announce to " + "**" + !t1 + "**").queue();
        dbGuild.save();
    });
    OptsCmd.registerOption("music:channel", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        String channelName = String.join(" ", args);
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        VoiceChannel channel = null;
        try {
            channel = event.getGuild().getVoiceChannelById(channelName);
        } catch (Exception ignored) {
        }
        if (channel == null) {
            try {
                List<VoiceChannel> voiceChannels = event.getGuild().getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getName().contains(channelName)).collect(Collectors.toList());
                if (voiceChannels.size() == 0) {
                    event.getChannel().sendMessage(EmoteReference.ERROR + "I couldn't found a voice channel matching that" + " name or id").queue();
                    return;
                } else if (voiceChannels.size() == 1) {
                    channel = voiceChannels.get(0);
                    guildData.setMusicChannel(channel.getId());
                    dbGuild.save();
                    event.getChannel().sendMessage(EmoteReference.OK + "Music Channel set to: " + channel.getName()).queue();
                } else {
                    DiscordUtils.selectList(event, voiceChannels, voiceChannel -> String.format("%s (ID: %s)", voiceChannel.getName(), voiceChannel.getId()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Channel:").setDescription(s).build(), voiceChannel -> {
                        guildData.setMusicChannel(voiceChannel.getId());
                        dbGuild.save();
                        event.getChannel().sendMessage(EmoteReference.OK + "Music Channel set to: " + voiceChannel.getName()).queue();
                    });
                }
            } catch (Exception ex) {
                log.warn("Error while setting voice channel", ex);
                event.getChannel().sendMessage("I couldn't set the voice channel " + EmoteReference.SAD + " - try again " + "in a few minutes " + "-> " + ex.getClass().getSimpleName()).queue();
            }
        }
    });
    OptsCmd.registerOption("music:queuelimit", (event, args) -> {
        if (args.length == 0) {
            OptsCmd.onHelp(event);
            return;
        }
        boolean isNumber = args[0].matches("^[0-9]*$");
        if (!isNumber) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "That's not a valid number!").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        try {
            int finalSize = Integer.parseInt(args[0]);
            int applySize = finalSize >= 300 ? 300 : finalSize;
            guildData.setMusicQueueSizeLimit((long) applySize);
            dbGuild.save();
            event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "The queue limit on this server is now " + "**%d** songs.", applySize)).queue();
            return;
        } catch (NumberFormatException ex) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You're trying to set too high of a number (which won't" + " be applied anyway), silly").queue();
        }
    });
    OptsCmd.registerOption("music:clear", (event) -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        guildData.setMusicSongDurationLimit(null);
        guildData.setMusicChannel(null);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "I can play music on all channels now").queue();
    });
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) IntStream(java.util.stream.IntStream) URL(java.net.URL) Utils(net.kodehawa.mantarobot.utils.Utils) GuildMusicManager(net.kodehawa.mantarobot.commands.music.GuildMusicManager) Module(net.kodehawa.mantarobot.modules.Module) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioCmdUtils(net.kodehawa.mantarobot.commands.music.AudioCmdUtils) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) StringUtils.replaceEach(org.apache.commons.lang3.StringUtils.replaceEach) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) TrackScheduler(net.kodehawa.mantarobot.commands.music.TrackScheduler) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) AudioManager(net.dv8tion.jda.core.managers.AudioManager) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) Category(net.kodehawa.mantarobot.modules.commands.base.Category) AudioCmdUtils.embedForQueue(net.kodehawa.mantarobot.commands.music.AudioCmdUtils.embedForQueue) Collectors(java.util.stream.Collectors) TIntHashSet(gnu.trove.set.hash.TIntHashSet) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Repeat(net.kodehawa.mantarobot.commands.music.Repeat) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) TIntIterator(gnu.trove.iterator.TIntIterator) CommandPermission(net.kodehawa.mantarobot.modules.commands.CommandPermission) MantaroData(net.kodehawa.mantarobot.data.MantaroData) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 2 with PostLoadEvent

use of net.kodehawa.mantarobot.modules.events.PostLoadEvent in project MantaroBot by Mantaro.

the class ModerationCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    OptsCmd.registerOption("modlog:blacklist", 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();
    });
    OptsCmd.registerOption("modlog:whitelist", event -> {
        List<User> mentioned = event.getMessage().getMentionedUsers();
        if (mentioned.isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "**You need to specify the users to locally un-blacklist 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();
    });
    OptsCmd.registerOption("linkprotection:toggle", 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();
    });
    OptsCmd.registerOption("slowmode:toggle", event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        boolean toggler = guildData.isSlowMode();
        guildData.setSlowMode(!toggler);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set slowmode chat to " + "`" + !toggler + "`").queue();
        dbGuild.save();
    });
    OptsCmd.registerOption("antispam:toggle", event -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        boolean toggler = guildData.isAntiSpam();
        guildData.setAntiSpam(!toggler);
        event.getChannel().sendMessage(EmoteReference.CORRECT + "Set anti-spam chat mode to " + "`" + !toggler + "`").queue();
        dbGuild.save();
    });
    OptsCmd.registerOption("linkprotection:channel:allow", (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];
        List<TextChannel> textChannels = event.getGuild().getTextChannels().stream().filter(textChannel -> textChannel.getName().contains(channelName)).collect(Collectors.toList());
        if (textChannels.isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "There were no channels matching your search.").queue();
        }
        if (textChannels.size() <= 1) {
            guildData.getLinkProtectionAllowedChannels().add(textChannels.get(0).getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.CORRECT + textChannels.get(0).getAsMention() + " can now be used to post discord invites.").queue();
            return;
        }
        DiscordUtils.selectList(event, textChannels, textChannel -> String.format("%s (ID: %s)", textChannel.getName(), textChannel.getId()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Channel:").setDescription(s).build(), textChannel -> {
            guildData.getLinkProtectionAllowedChannels().add(textChannel.getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.OK + textChannel.getAsMention() + " can now be used to send discord invites.").queue();
        });
    });
    OptsCmd.registerOption("linkprotection:channel:disallow", (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];
        List<TextChannel> textChannels = event.getGuild().getTextChannels().stream().filter(textChannel -> textChannel.getName().contains(channelName)).collect(Collectors.toList());
        if (textChannels.isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "There were no channels matching your search.").queue();
        }
        if (textChannels.size() <= 1) {
            guildData.getLinkProtectionAllowedChannels().remove(textChannels.get(0).getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.CORRECT + textChannels.get(0).getAsMention() + " cannot longer be used to post discord invites.").queue();
            return;
        }
        DiscordUtils.selectList(event, textChannels, textChannel -> String.format("%s (ID: %s)", textChannel.getName(), textChannel.getId()), s -> OptsCmd.getOpts().baseEmbed(event, "Select the Channel:").setDescription(s).build(), textChannel -> {
            guildData.getLinkProtectionAllowedChannels().remove(textChannel.getId());
            dbGuild.save();
            event.getChannel().sendMessage(EmoteReference.OK + textChannel.getAsMention() + " cannot longer be used to send discord invites.").queue();
        });
    });
}
Also used : SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) StringUtils(net.kodehawa.mantarobot.utils.StringUtils) Utils(net.kodehawa.mantarobot.utils.Utils) Module(net.kodehawa.mantarobot.modules.Module) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioCmdUtils(net.kodehawa.mantarobot.commands.music.AudioCmdUtils) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) Map(java.util.Map) ManagedDatabase(net.kodehawa.mantarobot.data.db.ManagedDatabase) CommandRegistry(net.kodehawa.mantarobot.modules.CommandRegistry) Command(net.kodehawa.mantarobot.modules.Command) TextChannelGround(net.kodehawa.mantarobot.commands.currency.TextChannelGround) PostLoadEvent(net.kodehawa.mantarobot.modules.events.PostLoadEvent) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) Category(net.kodehawa.mantarobot.modules.commands.base.Category) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) CommandPermission(net.kodehawa.mantarobot.modules.commands.CommandPermission) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) Queue(java.util.Queue) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Aggregations

List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Permission (net.dv8tion.jda.core.Permission)2 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)2 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)2 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)2 MantaroBot (net.kodehawa.mantarobot.MantaroBot)2 TextChannelGround (net.kodehawa.mantarobot.commands.currency.TextChannelGround)2 AudioCmdUtils (net.kodehawa.mantarobot.commands.music.AudioCmdUtils)2 MantaroData (net.kodehawa.mantarobot.data.MantaroData)2 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)2 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)2 Command (net.kodehawa.mantarobot.modules.Command)2 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)2 Module (net.kodehawa.mantarobot.modules.Module)2 CommandPermission (net.kodehawa.mantarobot.modules.commands.CommandPermission)2 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)2 Category (net.kodehawa.mantarobot.modules.commands.base.Category)2 PostLoadEvent (net.kodehawa.mantarobot.modules.events.PostLoadEvent)2