Search in sources :

Example 6 with GuildData

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

the class UtilsCmds method onPostLoad.

@Command
public static void onPostLoad(PostLoadEvent e) {
    OptsCmd.registerOption("birthday:enable", (event, args) -> {
        if (args.length < 2) {
            OptsCmd.onHelp(event);
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        try {
            String channel = args[0];
            String role = args[1];
            boolean isId = channel.matches("^[0-9]*$");
            String channelId = isId ? channel : event.getGuild().getTextChannelsByName(channel, true).get(0).getId();
            String roleId = event.getGuild().getRolesByName(role.replace(channelId, ""), true).get(0).getId();
            guildData.setBirthdayChannel(channelId);
            guildData.setBirthdayRole(roleId);
            dbGuild.save();
            event.getChannel().sendMessage(String.format(EmoteReference.MEGA + "Birthday logging enabled on this server with parameters -> " + "Channel: ``#%s (%s)`` and role: ``%s (%s)``", channel, channelId, role, roleId)).queue();
        } catch (Exception ex) {
            if (ex instanceof IndexOutOfBoundsException) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find a channel or role!\n " + "**Remember, you don't have to mention neither the role or the channel, rather just type its " + "name, order is <channel> <role>, without the leading \"<>\".**").queue();
                return;
            }
            event.getChannel().sendMessage(EmoteReference.ERROR + "You supplied invalid arguments for this command " + EmoteReference.SAD).queue();
            OptsCmd.onHelp(event);
        }
    });
    OptsCmd.registerOption("birthday:disable", (event) -> {
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        guildData.setBirthdayChannel(null);
        guildData.setBirthdayRole(null);
        dbGuild.save();
        event.getChannel().sendMessage(EmoteReference.MEGA + "Birthday logging has been disabled on this server").queue();
    });
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 7 with GuildData

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

the class ImageActionCmd method call.

@Override
protected void call(GuildMessageReceivedEvent event, String content) {
    String random = random(images);
    try {
        if (mentions(event).isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention a user").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        MessageBuilder toSend = new MessageBuilder().append(String.format(format, mentions(event), event.getAuthor().getAsMention()));
        if (!guildData.isNoMentionsAction() && swapNames) {
            toSend = new MessageBuilder().append(String.format(format, event.getAuthor().getAsMention(), mentions(event)));
        }
        if (guildData.isNoMentionsAction() && swapNames) {
            toSend = new MessageBuilder().append(String.format(format, "**" + noMentions(event) + "**", "**" + event.getMember().getEffectiveName() + "**"));
        }
        if (swapNames && guildData.isNoMentionsAction()) {
            toSend = new MessageBuilder().append(String.format(format, "**" + event.getMember().getEffectiveName() + "**", "**" + noMentions(event) + "**"));
        }
        if (isLonely(event)) {
            toSend = new MessageBuilder().append("**").append(lonelyLine).append("**");
        }
        event.getChannel().sendFile(CACHE.getInput(random), imageName, toSend.build()).queue();
    } catch (Exception e) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "I'd like to know what happened, but I couldn't send the image.").queue();
        log.error("Error while performing Action Command ``" + name + "``. The image ``" + random + "`` threw an Exception.", e);
    }
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) MessageBuilder(net.dv8tion.jda.core.MessageBuilder)

Example 8 with GuildData

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

the class MantaroListener method onUserLeave.

private void onUserLeave(GuildMemberLeaveEvent event) {
    try {
        String hour = df.format(new Date(System.currentTimeMillis()));
        DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
        GuildData data = dbg.getData();
        String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
        if (logChannel != null) {
            TextChannel tc = event.getGuild().getTextChannelById(logChannel);
            tc.sendMessage("`[" + hour + "]` " + "📣 `" + event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + "` just left `" + event.getGuild().getName() + "` `(User #" + event.getGuild().getMembers().size() + ")`").queue();
            logTotal++;
        }
        String leaveChannel = MantaroData.db().getGuild(event.getGuild()).getData().getLogJoinLeaveChannel();
        String leaveMessage = MantaroData.db().getGuild(event.getGuild()).getData().getLeaveMessage();
        if (leaveChannel != null && leaveMessage != null) {
            TextChannel tc = event.getGuild().getTextChannelById(leaveChannel);
            if (leaveMessage.contains("$(")) {
                Map<String, String> dynamicMap = new HashMap<>();
                map("event", dynamicMap, event);
                leaveMessage = dynamicResolve(leaveMessage, dynamicMap);
            }
            int c = leaveMessage.indexOf(':');
            if (c != -1) {
                String m = leaveMessage.substring(0, c);
                String v = leaveMessage.substring(c + 1);
                if (m.equals("embed")) {
                    EmbedJSON embed;
                    try {
                        embed = GsonDataManager.gson(false).fromJson('{' + v + '}', EmbedJSON.class);
                    } catch (Exception ignored) {
                        tc.sendMessage(EmoteReference.ERROR2 + "The string ``{" + v + "}`` isn't a valid JSON.").queue();
                        return;
                    }
                    tc.sendMessage(embed.gen(event)).queue();
                    return;
                }
            }
            tc.sendMessage(leaveMessage).queue();
        }
    } catch (Exception e) {
    }
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) EmbedJSON(net.kodehawa.mantarobot.commands.custom.EmbedJSON) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException)

Example 9 with GuildData

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

the class AudioRequester method loadSingle.

private void loadSingle(AudioTrack audioTrack, boolean silent) {
    AudioTrackInfo trackInfo = audioTrack.getInfo();
    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
    GuildData guildData = dbGuild.getData();
    String title = trackInfo.title;
    long length = trackInfo.length;
    long queueLimit = !Optional.ofNullable(dbGuild.getData().getMusicQueueSizeLimit()).isPresent() ? MAX_QUEUE_LENGTH : dbGuild.getData().getMusicQueueSizeLimit();
    int fqSize = guildData.getMaxFairQueue();
    if (getMusicManager().getTrackScheduler().getQueue().size() > queueLimit && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
        if (!silent)
            event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Surpassed queue song limit!", title)).queue(message -> message.delete().queueAfter(30, TimeUnit.SECONDS));
        if (musicManager.getTrackScheduler().isStopped())
            event.getGuild().getAudioManager().closeAudioConnection();
        return;
    }
    if (audioTrack.getInfo().length > MAX_SONG_LENGTH && !MantaroData.db().getUser(event.getMember()).isPremium() && !dbGuild.isPremium()) {
        event.getChannel().sendMessage(String.format(":warning: Could not queue %s: Track is longer than 21 minutes! (%s)", title, AudioUtils.getLength(length))).queue();
        if (musicManager.getTrackScheduler().isStopped())
            //do you?
            event.getGuild().getAudioManager().closeAudioConnection();
        return;
    }
    //Comparing if the URLs are the same to be 100% sure they're just not spamming the same url over and over again.
    if (musicManager.getTrackScheduler().getQueue().stream().filter(track -> track.getInfo().uri.equals(audioTrack.getInfo().uri)).count() > fqSize) {
        event.getChannel().sendMessage(EmoteReference.ERROR + String.format("**Surpassed fair queue level of %d (Too many songs which are exactly equal)**", fqSize + 1)).queue();
        return;
    }
    musicManager.getTrackScheduler().queue(new AudioTrackContext(event.getAuthor(), event.getChannel(), audioTrack.getSourceManager() instanceof YoutubeAudioSourceManager ? "https://www.youtube.com/watch?v=" + audioTrack.getIdentifier() : trackUrl, audioTrack));
    if (!silent) {
        event.getChannel().sendMessage(String.format("📣 Added to queue -> **%s** **!(%s)**", title, AudioUtils.getLength(length))).queue();
    }
}
Also used : FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) Color(java.awt.Color) Utils(net.kodehawa.mantarobot.utils.Utils) IntConsumer(java.util.function.IntConsumer) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) ReactionOperations(net.kodehawa.mantarobot.core.listeners.operations.ReactionOperations) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Optional(java.util.Optional) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) YoutubeAudioSourceManager(com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)

Example 10 with GuildData

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

the class CommandRegistry method process.

public boolean process(GuildMessageReceivedEvent event, String cmdname, String content) {
    Command cmd = commands.get(cmdname);
    Config conf = MantaroData.config().get();
    DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
    GuildData data = dbg.getData();
    if (cmd == null)
        return false;
    if (data.getDisabledCommands().contains(cmdname)) {
        return false;
    }
    if (data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()) != null && data.getChannelSpecificDisabledCommands().get(event.getChannel().getId()).contains(cmdname)) {
        return false;
    }
    if (data.getDisabledUsers().contains(event.getAuthor().getId())) {
        return false;
    }
    if (MantaroData.db().getGuild(event.getGuild()).getData().getDisabledChannels().contains(event.getChannel().getId()) && cmd.category() != Category.MODERATION) {
        return false;
    }
    if (MantaroData.config().get().isPremiumBot() && cmd.category() == Category.CURRENCY) {
        return false;
    }
    if (data.getDisabledCategories().contains(cmd.category())) {
        return false;
    }
    //If we are in the patreon bot, deny all requests from unknown guilds.
    if (conf.isPremiumBot() && !conf.isOwner(event.getAuthor()) && !dbg.isPremium()) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like you're trying to use the Patreon bot when this guild is **not** marked as premium. " + "**If you think this is an error please contact Kodehawa#3457 or poke me on #donators in the support guild**").queue();
        return false;
    }
    if (!cmd.permission().test(event.getMember())) {
        event.getChannel().sendMessage(EmoteReference.STOP + "You have no permissions to trigger this command").queue();
        return false;
    }
    cmd.run(event, cmdname, content);
    return true;
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) AliasCommand(net.kodehawa.mantarobot.modules.commands.AliasCommand) Command(net.kodehawa.mantarobot.modules.commands.base.Command) Config(net.kodehawa.mantarobot.data.Config)

Aggregations

DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)17 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)17 Command (net.kodehawa.mantarobot.modules.Command)8 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)8 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6 TimeUnit (java.util.concurrent.TimeUnit)5 Collectors (java.util.stream.Collectors)5 Permission (net.dv8tion.jda.core.Permission)5 Slf4j (lombok.extern.slf4j.Slf4j)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)4 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)4 MantaroBot (net.kodehawa.mantarobot.MantaroBot)4 Utils (net.kodehawa.mantarobot.utils.Utils)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2