Search in sources :

Example 41 with Guild

use of net.dv8tion.jda.core.entities.Guild in project FlareBot by FlareBot.

the class PlayerListener method onTrackStart.

@Override
public void onTrackStart(AudioPlayer aplayer, AudioTrack atrack) {
    FlareBotManager.instance().getLastActive().remove(Long.parseLong(player.getGuildId()));
    GuildWrapper wrapper = FlareBotManager.instance().getGuild(player.getGuildId());
    if (wrapper.getMusicAnnounceChannelId() != null) {
        TextChannel c = Getters.getChannelById(wrapper.getMusicAnnounceChannelId());
        if (c != null) {
            if (c.getGuild().getSelfMember().hasPermission(c, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_READ, Permission.MESSAGE_WRITE)) {
                Track track = player.getPlayingTrack();
                Queue<Track> playlist = player.getPlaylist();
                c.sendMessage(MessageUtils.getEmbed().addField("Now Playing", SongCommand.getLink(track), false).addField("Duration", FormatUtils.formatDuration(track.getTrack().getDuration()), false).addField("Requested by", String.format("<@!%s>", track.getMeta().get("requester")), false).addField("Next up", playlist.isEmpty() ? "Nothing" : SongCommand.getLink(playlist.peek()), false).setImage("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg").build()).queue();
            } else {
                wrapper.setMusicAnnounceChannelId(null);
            }
        } else {
            wrapper.setMusicAnnounceChannelId(null);
        }
    }
    if (wrapper.isSongnickEnabled()) {
        Guild c = wrapper.getGuild();
        if (c == null || !GuildUtils.canChangeNick(player.getGuildId())) {
            if (!GuildUtils.canChangeNick(player.getGuildId())) {
                wrapper.setSongnick(false);
                MessageUtils.sendPM(wrapper.getGuild().getOwner().getUser(), "FlareBot can't change it's nickname so SongNick has been disabled!");
            }
        } else {
            Track track = player.getPlayingTrack();
            String str = null;
            if (track != null) {
                str = track.getTrack().getInfo().title;
                if (str.length() > 32)
                    str = str.substring(0, 32);
                str = str.substring(0, str.lastIndexOf(' ') + 1);
            }
            // Even I couldn't make this a one-liner
            c.getController().setNickname(c.getSelfMember(), str).queue();
        }
    }
}
Also used : GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild) Track(com.arsenarsen.lavaplayerbridge.player.Track) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack)

Example 42 with Guild

use of net.dv8tion.jda.core.entities.Guild in project TheLighterBot by PhotonBursted.

the class FileController method retrieveDefaultCategories.

private void retrieveDefaultCategories() throws SQLException {
    retrieveData("SELECT dc.*\n" + "FROM \"Servers\" AS s\n" + "  LEFT JOIN \"DefaultCategories\" AS dc ON dc.server_id = s.discord_id\n" + "WHERE dc.server_id IS NOT NULL", result -> {
        try {
            Guild g = l.getBot().getGuildById(result.getLong("server_id"));
            long entityId = result.getLong("category_id");
            Category c = l.getBot().getCategoryById(entityId);
            if (g != null && c != null) {
                l.getChannelController().getCategories().put(g, c);
            }
        } catch (SQLException ex) {
            log.error("Something went wrong retrieving the default categories", ex);
        }
    });
}
Also used : Category(net.dv8tion.jda.core.entities.Category) Guild(net.dv8tion.jda.core.entities.Guild)

Example 43 with Guild

use of net.dv8tion.jda.core.entities.Guild in project TheLighterBot by PhotonBursted.

the class FileController method retrieveBlacklist.

private void retrieveBlacklist() throws SQLException {
    retrieveData("SELECT bl.*\n" + "FROM \"Servers\" AS s\n" + "  LEFT JOIN \"Blacklists\" AS bl ON bl.server_id = s.discord_id\n" + "WHERE bl.server_id IS NOT NULL", result -> {
        try {
            Guild g = l.getBot().getGuildById(result.getLong("server_id"));
            long entityId = result.getLong("entity_id");
            String entityType = result.getString("entity_type");
            switch(entityType) {
                case "role":
                    BannableRole role = new BannableRole(entityId);
                    if (role.get() != null)
                        l.getAccesslistController().blacklist(g, role);
                    break;
                case "user":
                    BannableUser user = new BannableUser(entityId);
                    if (user.get() != null)
                        l.getAccesslistController().blacklist(g, user);
                    break;
                default:
            }
        } catch (SQLException ex) {
            log.error("Something went wrong retrieving the blacklist", ex);
        }
    });
}
Also used : BannableUser(st.photonbur.Discord.Bot.lightbotv3.entity.bannable.BannableUser) Guild(net.dv8tion.jda.core.entities.Guild) BannableRole(st.photonbur.Discord.Bot.lightbotv3.entity.bannable.BannableRole)

Aggregations

Guild (net.dv8tion.jda.core.entities.Guild)43 User (net.dv8tion.jda.core.entities.User)16 Message (net.dv8tion.jda.core.entities.Message)13 TextChannel (net.dv8tion.jda.core.entities.TextChannel)12 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)11 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)11 Shard (tk.ardentbot.main.Shard)9 List (java.util.List)8 Subcommand (tk.ardentbot.core.executor.Subcommand)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 Member (net.dv8tion.jda.core.entities.Member)7 MantaroData (net.kodehawa.mantarobot.data.MantaroData)7 Command (tk.ardentbot.core.executor.Command)7 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)6 HashMap (java.util.HashMap)5 Permission (net.dv8tion.jda.core.Permission)5 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)5 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)5