Search in sources :

Example 16 with GuildData

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

the class TrackScheduler method announce.

private void announce() {
    try {
        DBGuild dbGuild = MantaroData.db().getGuild(guildId);
        GuildData guildData = dbGuild.getData();
        if (guildData.isMusicAnnounce()) {
            AudioTrackContext atc = getCurrentTrack();
            if (atc == null)
                return;
            TextChannel req = atc.getRequestedChannel();
            if (req == null)
                return;
            VoiceChannel vc = req.getGuild().getSelfMember().getVoiceState().getChannel();
            AudioTrackInfo trackInfo = getCurrentTrack().getInfo();
            String title = trackInfo.title;
            long trackLength = trackInfo.length;
            if (req.canTalk()) {
                getCurrentTrack().getRequestedChannel().sendMessage(String.format("📣 Now playing in **%s**: %s (%s)%s", vc.getName(), title, AudioUtils.getLength(trackLength), getCurrentTrack().getDJ() != null ? " requested by **" + getCurrentTrack().getDJ().getName() + "**" : "")).queue(message -> message.delete().queueAfter(90, TimeUnit.SECONDS));
            }
        }
    } catch (Exception ignored) {
    }
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) TextChannel(net.dv8tion.jda.core.entities.TextChannel) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) AudioTrackInfo(com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 17 with GuildData

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

the class MantaroListener method onUserJoin.

private void onUserJoin(GuildMemberJoinEvent event) {
    try {
        String role = MantaroData.db().getGuild(event.getGuild()).getData().getGuildAutoRole();
        DBGuild dbg = MantaroData.db().getGuild(event.getGuild());
        GuildData data = dbg.getData();
        String hour = df.format(new Date(System.currentTimeMillis()));
        if (role != null) {
            try {
                event.getGuild().getController().addRolesToMember(event.getMember(), event.getGuild().getRoleById(role)).queue(s -> log.debug("Successfully added a new role to " + event.getMember()));
            } catch (PermissionException e) {
                MantaroData.db().getGuild(event.getGuild()).getData().setGuildAutoRole(null);
                MantaroData.db().getGuild(event.getGuild()).save();
                event.getGuild().getOwner().getUser().openPrivateChannel().queue(messageChannel -> messageChannel.sendMessage("Removed autorole since I don't have the permissions to assign that role").queue());
            }
        }
        String logChannel = MantaroData.db().getGuild(event.getGuild()).getData().getGuildLogChannel();
        if (logChannel != null) {
            TextChannel tc = event.getGuild().getTextChannelById(logChannel);
            tc.sendMessage(String.format("`[%s]` 📣 `%s#%s` just joined `%s` `(User #%d | ID:%s)`", hour, event.getMember().getEffectiveName(), event.getMember().getUser().getDiscriminator(), event.getGuild().getName(), event.getGuild().getMembers().size(), event.getGuild().getId())).queue();
            logTotal++;
        }
        String joinChannel = MantaroData.db().getGuild(event.getGuild()).getData().getLogJoinLeaveChannel();
        String joinMessage = MantaroData.db().getGuild(event.getGuild()).getData().getJoinMessage();
        if (joinChannel != null && joinMessage != null) {
            TextChannel tc = event.getGuild().getTextChannelById(joinChannel);
            if (joinMessage.contains("$(")) {
                Map<String, String> dynamicMap = new HashMap<>();
                map("event", dynamicMap, event);
                joinMessage = dynamicResolve(joinMessage, dynamicMap);
            }
            int c = joinMessage.indexOf(':');
            if (c != -1) {
                String m = joinMessage.substring(0, c);
                String v = joinMessage.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(joinMessage).queue();
        }
    } catch (Exception e) {
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) UserData(net.kodehawa.mantarobot.data.entities.helpers.UserData) StatusChangeEvent(net.dv8tion.jda.core.events.StatusChangeEvent) java.util(java.util) GuildMessageDeleteEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageDeleteEvent) Async(br.com.brjdevs.java.utils.async.Async) GuildMemberJoinEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent) SimpleDateFormat(java.text.SimpleDateFormat) MantaroBot(net.kodehawa.mantarobot.MantaroBot) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) GuildLeaveEvent(net.dv8tion.jda.core.events.guild.GuildLeaveEvent) Permission(net.dv8tion.jda.core.Permission) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) DisconnectEvent(net.dv8tion.jda.core.events.DisconnectEvent) JDA(net.dv8tion.jda.core.JDA) GuildMessageUpdateEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageUpdateEvent) EventListener(net.dv8tion.jda.core.hooks.EventListener) DateFormat(java.text.DateFormat) CommandListener(net.kodehawa.mantarobot.core.listeners.command.CommandListener) GuildStatsManager(net.kodehawa.mantarobot.commands.info.GuildStatsManager) net.dv8tion.jda.core.entities(net.dv8tion.jda.core.entities) RateLimiter(net.kodehawa.mantarobot.commands.currency.RateLimiter) Mapifier.map(net.kodehawa.mantarobot.commands.custom.Mapifier.map) GsonDataManager(net.kodehawa.mantarobot.utils.data.GsonDataManager) GuildJoinEvent(net.dv8tion.jda.core.events.guild.GuildJoinEvent) Collectors(java.util.stream.Collectors) CacheLoader(com.google.common.cache.CacheLoader) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) ModLog(net.kodehawa.mantarobot.commands.moderation.ModLog) Mapifier.dynamicResolve(net.kodehawa.mantarobot.commands.custom.Mapifier.dynamicResolve) ExceptionEvent(net.dv8tion.jda.core.events.ExceptionEvent) GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) EmbedJSON(net.kodehawa.mantarobot.commands.custom.EmbedJSON) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Event(net.dv8tion.jda.core.events.Event) ShardMonitorEvent(net.kodehawa.mantarobot.core.ShardMonitorEvent) GuildUnbanEvent(net.dv8tion.jda.core.events.guild.GuildUnbanEvent) LoggedEvent(net.kodehawa.mantarobot.commands.info.GuildStatsManager.LoggedEvent) Pattern(java.util.regex.Pattern) GuildBanEvent(net.dv8tion.jda.core.events.guild.GuildBanEvent) GuildMemberLeaveEvent(net.dv8tion.jda.core.events.guild.member.GuildMemberLeaveEvent) 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)

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