Search in sources :

Example 6 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class Leave method onUserLeave.

@SubscribeEvent
public void onUserLeave(GuildMemberLeaveEvent event) throws SQLException {
    userLeaveEvents.add(Instant.now());
    Guild guild = event.getGuild();
    Member left = event.getMember();
    Triplet<String, String, String> automessageSettings = Automessage.getMessagesAndChannel(guild);
    String channelId = automessageSettings.getA();
    String leave = automessageSettings.getC();
    if (channelId != null && leave != null) {
        TextChannel channel = guild.getTextChannelById(channelId);
        if (channel != null) {
            try {
                leave = leave.replace("{user}", left.getUser().getName()).replace("{servername}", guild.getName()).replace("{amtusers}", String.valueOf(guild.getMembers().size()));
                channel.sendMessage(leave).queue();
            } catch (PermissionException ex) {
            }
        }
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Example 7 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class StuckVoiceConnection method run.

@Override
public void run() {
    for (Shard shard : getShards()) {
        for (Guild guild : shard.jda.getGuilds()) {
            GuildMusicManager guildMusicManager = Music.getGuildAudioPlayer(guild, null, shard);
            AudioPlayer player = guildMusicManager.player;
            if (!player.isPaused() && guild.getAudioManager().getConnectedChannel() != null && guild.getAudioManager().getConnectedChannel().getMembers().size() > 1) {
                AudioTrack playingTrack = player.getPlayingTrack();
                if (playingTrack != null) {
                    long position = playingTrack.getPosition();
                    if (position == 0 || (position > 0 && !guild.getAudioManager().isConnected())) {
                        String textChannelId = voiceChannelsAtZeroDuration.get(guild.getId());
                        if (textChannelId == null) {
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            TextChannel channel = ardentMusicManager.getChannel();
                            voiceChannelsAtZeroDuration.put(guild.getId(), channel.getId());
                        } else {
                            TextChannel channel = guild.getTextChannelById(textChannelId);
                            ArdentMusicManager ardentMusicManager = guildMusicManager.scheduler.manager;
                            if (ardentMusicManager != null) {
                                List<ArdentTrack> queue = ardentMusicManager.getQueueAsList();
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                                GuildMusicManager manager = Music.getGuildAudioPlayer(guild, channel, shard);
                                for (ArdentTrack track : queue) {
                                    manager.scheduler.manager.addToQueue(new ArdentTrack(track.getAuthor(), track.getAddedFrom(), track.getTrack().makeClone()));
                                }
                            } else
                                shard.musicManagers.remove(Long.parseLong(guild.getId()));
                            if (channel == null)
                                channel = guild.getPublicChannel();
                            try {
                                channel.sendMessage("I detected that my audio connection was stuck and reset my player. #BlameDiscord").queue();
                            } catch (Exception e) {
                                new BotException(e);
                            }
                        }
                    }
                } else {
                    voiceChannelsAtZeroDuration.remove(guild.getId());
                }
            }
        }
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Guild(net.dv8tion.jda.core.entities.Guild) BotException(tk.ardentbot.core.misc.logging.BotException) TextChannel(net.dv8tion.jda.core.entities.TextChannel) BotException(tk.ardentbot.core.misc.logging.BotException) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) Shard(tk.ardentbot.main.Shard)

Example 8 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class TriviaChecker method check.

static void check(MessageReceivedEvent event) throws Exception {
    if (event.isFromType(ChannelType.TEXT)) {
        User user = event.getAuthor();
        Guild guild = event.getGuild();
        Shard shard = GuildUtils.getShard(guild);
        TextChannel channel = event.getTextChannel();
        for (Iterator<TriviaGame> iterator = Trivia.gamesInSession.iterator(); iterator.hasNext(); ) {
            TriviaGame triviaGame = iterator.next();
            if (triviaGame.getGuildId().equalsIgnoreCase(guild.getId()) && triviaGame.getTextChannelId().equalsIgnoreCase(channel.getId())) {
                if (!triviaGame.isAnsweredCurrentQuestion()) {
                    if (triviaGame.isSolo() && !triviaGame.getCreator().equalsIgnoreCase(user.getId()))
                        return;
                    String content = event.getMessage().getContent();
                    if (triviaGame.getCurrentTriviaQuestion() != null) {
                        final boolean[] correct = { false };
                        triviaGame.getCurrentTriviaQuestion().getAnswers().forEach(a -> {
                            if (a.equalsIgnoreCase(content))
                                correct[0] = true;
                        });
                        if (correct[0]) {
                            triviaGame.addPoint(user);
                            shard.help.sendEditedTranslation("{0} got it right!", user, channel, user.getAsMention());
                            if (triviaGame.getRound() != triviaGame.getTotalRounds()) {
                                Trivia.dispatchRound(guild, channel, guild.getMemberById(triviaGame.getCreator()).getUser(), triviaGame, triviaGame.getEx());
                            } else
                                triviaGame.finish(shard, shard.help);
                        }
                    }
                }
            }
        }
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) User(net.dv8tion.jda.core.entities.User) TriviaGame(tk.ardentbot.utils.rpg.TriviaGame) Guild(net.dv8tion.jda.core.entities.Guild) Shard(tk.ardentbot.main.Shard)

Example 9 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Ardent by adamint.

the class GuildUtils method getChannelNames.

public static ArrayList<String> getChannelNames(ArrayList<String> ids, Guild guild) {
    ArrayList<String> names = new ArrayList<>();
    ids.forEach(id -> {
        TextChannel channel = guild.getTextChannelById(id);
        if (channel != null)
            names.add(channel.getName());
    });
    return names;
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) ArrayList(java.util.ArrayList)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)9 Guild (net.dv8tion.jda.core.entities.Guild)6 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2 User (net.dv8tion.jda.core.entities.User)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)2 Shard (tk.ardentbot.main.Shard)2 CollectionUtils (br.com.brjdevs.java.utils.collections.CollectionUtils)1 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 AudioTrackInfo (com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo)1 Color (java.awt.Color)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1