Search in sources :

Example 1 with DBGuild

use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.

the class PollLobby method startPoll.

public void startPoll() {
    try {
        if (!isCompilant) {
            getChannel().sendMessage(EmoteReference.WARNING + "This poll cannot build. " + "**Remember that the maximum amount of options are 9, the minimum is 2 and that the maximum timeout is 10m and the minimum timeout is 30s.**\n" + "Options are separated with a comma, for example `1,2,3`. For spaced stuff use commas at the start and end of the sentence.").queue();
            getRunningPolls().remove(getChannel());
            return;
        }
        if (isPollAlreadyRunning(getChannel())) {
            getChannel().sendMessage(EmoteReference.WARNING + "There seems to be another poll running here...").queue();
            return;
        }
        if (!event.getGuild().getSelfMember().hasPermission(getChannel(), Permission.MESSAGE_ADD_REACTION)) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like I cannot add reactions here...").queue();
            getRunningPolls().remove(getChannel());
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData data = dbGuild.getData();
        AtomicInteger at = new AtomicInteger();
        data.setRanPolls(data.getRanPolls() + 1L);
        dbGuild.save();
        String toShow = Stream.of(options).map(opt -> String.format("#%01d.- %s", at.incrementAndGet(), opt)).collect(Collectors.joining("\n"));
        EmbedBuilder builder = new EmbedBuilder().setAuthor(String.format("Poll #%1d created by %s", data.getRanPolls(), event.getAuthor().getName()), null, event.getAuthor().getAvatarUrl()).setDescription("**Poll started. React to the number to vote.**\n*" + name + "*").addField("Options", "```md\n" + toShow + "```", false).setColor(event.getMember().getColor()).setThumbnail("https://cdn.pixabay.com/photo/2012/04/14/16/26/question-34499_960_720.png").setFooter("You have " + Utils.getDurationMinutes(timeout) + " minutes to vote.", event.getAuthor().getAvatarUrl());
        getChannel().sendMessage(builder.build()).queue(message -> ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {

            @Override
            public boolean run(MessageReactionAddEvent e) {
                int i = e.getReactionEmote().getName().charAt(0) - '0';
                if (i < 1 || i > options.length)
                    return false;
                return false;
            }

            @Override
            public void onExpire() {
                EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Poll results").setDescription("**Showing results for the poll started by " + event.getAuthor().getName() + "** with name: *" + name + "*").setFooter("Thanks for your vote", null);
                AtomicInteger react = new AtomicInteger(0);
                AtomicInteger counter = new AtomicInteger(0);
                String votes = new ArrayList<>(getChannel().getMessageById(message.getIdLong()).complete().getReactions()).stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> "+Registered " + (r.getCount() - 1) + " votes for option " + options[counter.getAndIncrement()]).collect(Collectors.joining("\n"));
                embedBuilder.addField("Results", "```diff\n" + votes + "```", false);
                event.getChannel().sendMessage(embedBuilder.build()).queue();
            }
        }, reactions(options.length)));
    } catch (Exception e) {
        getChannel().sendMessage(EmoteReference.ERROR + "An unknown error has occurred while setting up a poll. Maybe try again?").queue();
    }
}
Also used : MessageReactionAddEvent(net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Utils(net.kodehawa.mantarobot.utils.Utils) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Lobby(net.kodehawa.mantarobot.commands.interaction.Lobby) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Stream(java.util.stream.Stream) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) Map(java.util.Map) ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperation) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Assert(org.junit.Assert) ReactionOperation(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperation) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageReactionAddEvent(net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList)

Example 2 with DBGuild

use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.

the class ModLog method logUnban.

public static void logUnban(Member author, String target, String reason) {
    DBGuild guildDB = MantaroData.db().getGuild(author.getGuild());
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
    embedBuilder.addField("Member ID", target, true);
    embedBuilder.addField("Reason", reason, false);
    embedBuilder.setAuthor("Unban", null, author.getUser().getEffectiveAvatarUrl());
    if (guildDB.getData().getGuildLogChannel() != null) {
        MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild)

Example 3 with DBGuild

use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.

the class ModLog method log.

public static void log(Member author, User target, String reason, ModAction action, long caseN, String... time) {
    DBGuild guildDB = MantaroData.db().getGuild(author.getGuild());
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
    embedBuilder.addField("Member", target.getName(), true);
    embedBuilder.addField("Reason", reason, false);
    embedBuilder.setThumbnail(target.getEffectiveAvatarUrl());
    switch(action) {
        case BAN:
            embedBuilder.setAuthor("Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
            break;
        case TEMP_BAN:
            embedBuilder.setAuthor("Temp Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
            embedBuilder.addField("Time", time[0], true);
            break;
        case KICK:
            embedBuilder.setAuthor("Kick | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
            break;
        case MUTE:
            embedBuilder.setAuthor("Mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
            break;
        case UNMUTE:
            embedBuilder.setAuthor("Un-mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
            break;
    }
    if (guildDB.getData().getGuildLogChannel() != null) {
        MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild)

Example 4 with DBGuild

use of net.kodehawa.mantarobot.data.entities.DBGuild 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 5 with DBGuild

use of net.kodehawa.mantarobot.data.entities.DBGuild in project MantaroBot by Mantaro.

the class ImageCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    nRating.put("safe", "s");
    nRating.put("questionable", "q");
    nRating.put("explicit", "e");
    registerOption("nsfw:toggle", (event) -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        if (guildData.getGuildUnsafeChannels().contains(event.getChannel().getId())) {
            guildData.getGuildUnsafeChannels().remove(event.getChannel().getId());
            event.getChannel().sendMessage(EmoteReference.CORRECT + "NSFW in this channel has been disabled").queue();
            dbGuild.saveAsync();
            return;
        }
        guildData.getGuildUnsafeChannels().add(event.getChannel().getId());
        dbGuild.saveAsync();
        event.getChannel().sendMessage(EmoteReference.CORRECT + "NSFW in this channel has been enabled.").queue();
    });
}
Also used : 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

DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)23 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)18 Command (net.kodehawa.mantarobot.modules.Command)10 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)10 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)8 MantaroData (net.kodehawa.mantarobot.data.MantaroData)8 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)8 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)7 Utils (net.kodehawa.mantarobot.utils.Utils)7 TimeUnit (java.util.concurrent.TimeUnit)6 Collectors (java.util.stream.Collectors)6 Slf4j (lombok.extern.slf4j.Slf4j)6 MantaroBot (net.kodehawa.mantarobot.MantaroBot)6 Permission (net.dv8tion.jda.core.Permission)5 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)5 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)5 CommandRegistry (net.kodehawa.mantarobot.modules.CommandRegistry)5 Module (net.kodehawa.mantarobot.modules.Module)5 CommandPermission (net.kodehawa.mantarobot.modules.commands.CommandPermission)5 Category (net.kodehawa.mantarobot.modules.commands.base.Category)5