Search in sources :

Example 76 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 77 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 78 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 79 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class CommandPortal method portalInfo.

private void portalInfo(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    String entry = RubiconBot.getMySQL().getGuildValue(parsedCommandInvocation.getGuild(), "portal");
    TextChannel channel = parsedCommandInvocation.getTextChannel();
    if (entry.equals("open")) {
        Guild guild = RubiconBot.getJDA().getGuildById(RubiconBot.getMySQL().getPortalValue(parsedCommandInvocation.getGuild(), "partnerid"));
        SafeMessage.sendMessage(channel, EmbedUtil.info("Connected to " + guild.getName(), "This server is currently connected to `" + guild.getName() + "`!").build(), 8);
    } else if (entry.equals("waiting")) {
        SafeMessage.sendMessage(channel, EmbedUtil.error("Portal is waitng", "The portal is currently waiting to be accepted by the other side").build(), 5);
    } else if (entry.equals("closed")) {
        SafeMessage.sendMessage(channel, EmbedUtil.error("Portal is closed", "The portal is currently closed").build(), 5);
    }
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Example 80 with TextChannel

use of net.dv8tion.jda.core.entities.TextChannel in project Rubicon by Rubicon-Bot.

the class PortalListener method onGuildMessageReceived.

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
    if (!e.getAuthor().isBot()) {
        if (e.getChannel().getId().equals(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "channelid"))) {
            String status = RubiconBot.getMySQL().getGuildValue(e.getGuild(), "portal");
            if (status.contains("open")) {
                TextChannel otherChannel = e.getJDA().getTextChannelById(RubiconBot.getMySQL().getPortalValue(e.getJDA().getGuildById(RubiconBot.getMySQL().getPortalValue(e.getGuild(), "partnerid")), "channelid"));
                try {
                    Webhook webhook = null;
                    for (Webhook hook : otherChannel.getWebhooks().complete()) {
                        if (hook.getName().equals("rubicon-portal-hook")) {
                            webhook = hook;
                            break;
                        }
                    }
                    if (webhook == null) {
                        webhook = otherChannel.createWebhook("rubicon-portal-hook").complete();
                    }
                    WebhookClientBuilder clientBuilder = webhook.newClient();
                    WebhookClient client = clientBuilder.build();
                    WebhookMessageBuilder builder = new WebhookMessageBuilder();
                    builder.setContent(e.getMessage().getContentDisplay().replace("@here", "@ here").replace("@everyone", "@ everyone"));
                    builder.setAvatarUrl(e.getAuthor().getAvatarUrl());
                    builder.setUsername(e.getAuthor().getName());
                    WebhookMessage message = builder.build();
                    client.send(message);
                    client.close();
                /*EmbedBuilder builder = new EmbedBuilder();
                        builder.setAuthor(e.getAuthor().getName(), null, e.getAuthor().getEffectiveAvatarUrl());
                        builder.setDescription(e.getMessage().getContent());
                        otherChannel.sendMessage(builder.build()).queue();*/
                } catch (NullPointerException fuck) {
                    fuck.printStackTrace();
                }
            }
        }
    }
}
Also used : WebhookMessage(net.dv8tion.jda.webhook.WebhookMessage) WebhookClientBuilder(net.dv8tion.jda.webhook.WebhookClientBuilder) TextChannel(net.dv8tion.jda.core.entities.TextChannel) WebhookClient(net.dv8tion.jda.webhook.WebhookClient) WebhookMessageBuilder(net.dv8tion.jda.webhook.WebhookMessageBuilder) Webhook(net.dv8tion.jda.core.entities.Webhook)

Aggregations

TextChannel (net.dv8tion.jda.core.entities.TextChannel)90 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)27 Guild (net.dv8tion.jda.core.entities.Guild)21 User (net.dv8tion.jda.core.entities.User)19 Member (net.dv8tion.jda.core.entities.Member)18 List (java.util.List)17 Message (net.dv8tion.jda.core.entities.Message)17 ArrayList (java.util.ArrayList)14 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)13 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)13 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)13 Collectors (java.util.stream.Collectors)10 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Role (net.dv8tion.jda.core.entities.Role)7 FlareBot (stream.flarebot.flarebot.FlareBot)7 Track (com.arsenarsen.lavaplayerbridge.player.Track)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 MantaroData (net.kodehawa.mantarobot.data.MantaroData)6 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)6 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)6