Search in sources :

Example 6 with BotException

use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.

the class Setnickname method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        sendTranslatedMessage("Set Nicknames\n" + "Use {0}setnickname @User then type the nickname you want to set\n" + "Example: {0}setnickname @TestUser this is your new nickname!\n" + "\n" + "Only people with `Manage Server` can use this command!".replace("{0}", GuildUtils.getPrefix(guild) + args[0]), channel, user);
    } else {
        List<User> mentionedUsers = message.getMentionedUsers();
        if (mentionedUsers.size() == 1) {
            if (guild.getMember(user).hasPermission(Permission.MANAGE_SERVER)) {
                User mentioned = mentionedUsers.get(0);
                String newNickname = tk.ardentbot.utils.StringUtils.concantenate(2, message.getRawContent().split(" "));
                while (newNickname.startsWith(" ")) newNickname = newNickname.substring(1);
                if (newNickname.length() > 32 && newNickname.length() < 2) {
                    sendTranslatedMessage("The nickname must be between 2 and 32 characters!", channel, user);
                } else {
                    if (newNickname.equalsIgnoreCase("reset"))
                        newNickname = "";
                    String finalNewNickname = newNickname;
                    try {
                        guild.getController().setNickname(guild.getMember(mentioned), newNickname).queue(aVoid -> {
                            try {
                                sendTranslatedMessage("Great success! Changed **{0}**'s nickname to {1}".replace("{0}", mentioned.getName()).replace("{1}", finalNewNickname), channel, user);
                            } catch (Exception e) {
                                new BotException(e);
                            }
                        });
                    } catch (PermissionException e) {
                        sendTranslatedMessage("Please make sure that I have permission to set members' nicknames", channel, user);
                    }
                }
            } else
                sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
        } else
            sendTranslatedMessage("You need to mention someone!", channel, user);
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) User(net.dv8tion.jda.core.entities.User) BotException(tk.ardentbot.core.misc.logging.BotException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 7 with BotException

use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.

the class Clear method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        sendTranslatedMessage("**Clearing Messages**\n" + "/clear 10: removes the last 10 messages\n" + "/clear [2-100] removes the specified amount\n" + "/clear @User [2-100]: removes the specified messages from the user mentioned", channel, user);
    } else {
        if (GuildUtils.hasManageServerPermission(guild.getMember(user))) {
            if (args.length == 2) {
                try {
                    int num = Integer.parseInt(args[1]);
                    if (num > 1 && num <= 100) {
                        TextChannel textChannel = (TextChannel) channel;
                        textChannel.getHistory().retrievePast(num).queue(messages -> {
                            try {
                                textChannel.deleteMessages(messages).queue(aVoid -> {
                                    sendTranslatedMessage("Successfully deleted " + num + " messages", channel, user);
                                });
                            } catch (Exception e) {
                                sendTranslatedMessage("Make sure the requested messages aren't over 2 weeks old and that I have " + "permission " + "to delete messages.", channel, user);
                            }
                        });
                    } else
                        sendTranslatedMessage("You need to specify a number between 1 and 100", channel, user);
                } catch (NumberFormatException ex) {
                    sendTranslatedMessage("That wasn't a number!", channel, user);
                }
            } else {
                List<User> mentionedUsers = message.getMentionedUsers();
                if (mentionedUsers.size() == 1) {
                    User mentioned = mentionedUsers.get(0);
                    try {
                        int num = Integer.parseInt(replace(message.getRawContent(), 2));
                        if (num > 1 && num < 100) {
                            TextChannel textChannel = (TextChannel) channel;
                            ArrayList<Message> messagesToDelete = new ArrayList<>();
                            textChannel.getHistory().retrievePast(100).queue(messages -> {
                                for (Message m : messages) {
                                    if (m.getAuthor().getId().equals(mentioned.getId()) && messagesToDelete.size() < num)
                                        messagesToDelete.add(m);
                                }
                                textChannel.deleteMessages(messagesToDelete).queue(aVoid -> {
                                    try {
                                        sendTranslatedMessage("Deleted " + messagesToDelete.size() + " messages from that user", channel, user);
                                    } catch (Exception e) {
                                        new BotException(e);
                                    }
                                });
                            });
                        } else
                            sendTranslatedMessage("You need to specify a number between 1 and 100", channel, user);
                    } catch (NumberFormatException ex) {
                        sendTranslatedMessage("That's not a number!", channel, user);
                    }
                } else
                    sendTranslatedMessage("You need to mention a user", channel, user);
            }
        } else
            sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
    }
}
Also used : BotException(tk.ardentbot.core.misc.logging.BotException) ArrayList(java.util.ArrayList) BotException(tk.ardentbot.core.misc.logging.BotException)

Example 8 with BotException

use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.

the class OnMessage method onMessage.

@SubscribeEvent
public void onMessage(MessageReceivedEvent event) {
    if (!Ardent.started)
        return;
    if (event.getAuthor().isBot())
        return;
    try {
        switch(event.getChannel().getType()) {
            case TEXT:
                TriviaChecker.check(event);
                Guild guild = event.getGuild();
                Shard shard = GuildUtils.getShard(guild);
                shard.factory.incrementMessagesReceived();
                if (event.getGuild() == null)
                    // This one will never be executed. But just in case to avoid NPE.
                    return;
                AntiAdvertisingSettings antiAdvertisingSettings = BaseCommand.asPojo(r.table("anti_advertising_settings").get(guild.getId()).run(connection), AntiAdvertisingSettings.class);
                if (antiAdvertisingSettings != null && !antiAdvertisingSettings.isAllow_discord_server_links()) {
                    if (!event.getMember().hasPermission(Permission.MANAGE_SERVER)) {
                        if (event.getMessage().getRawContent().contains("discordapp.com/invite") || event.getMessage().getRawContent().contains("discord.gg")) {
                            event.getMessage().delete().queue();
                            ArrayList<AdvertisingInfraction> infractions = BaseCommand.queryAsArrayList(AdvertisingInfraction.class, r.table("advertising_infractions").filter(row -> row.g("guild_id").eq(guild.getId()).and(row.g("user_id").eq(event.getAuthor().getId()))).run(connection));
                            if (infractions.size() > 2 && antiAdvertisingSettings.isBan_after_two_infractions()) {
                                guild.getController().ban(event.getAuthor(), 1).queue();
                                shard.help.sendEditedTranslation("Banned {0} for advertising.", event.getAuthor(), event.getChannel(), UserUtils.getNameWithDiscriminator(event.getAuthor().getId()));
                                event.getAuthor().openPrivateChannel().queue(privateChannel -> {
                                    privateChannel.sendMessage("You were banned from " + guild.getName() + " for advertising.").queue();
                                });
                                r.table("advertising_infractions").filter(row -> row.g("guild_id").eq(guild.getId()).and(row.g("user_id").eq(event.getAuthor().getId()))).delete().run(connection);
                            } else {
                                r.table("advertising_infractions").insert(r.json(BaseCommand.getStaticGson().toJson(new AdvertisingInfraction(event.getAuthor().getId(), guild.getId())))).run(connection);
                                shard.help.sendEditedTranslation("{0}, you can't advertise Discord servers here!", event.getAuthor(), event.getChannel(), event.getAuthor().getAsMention());
                            }
                            return;
                        }
                    }
                }
                if (guild.getId().equalsIgnoreCase("260841592070340609")) {
                    UserUtils.addMoney(event.getAuthor(), 0.10);
                }
                Member ardentMember = event.getGuild().getMember(event.getJDA().getSelfUser());
                Member userMember = event.getMember();
                if (ardentMember == null || userMember == null || userMember.hasPermission(Permission.MANAGE_SERVER) || !ardentMember.hasPermission(Permission.MESSAGE_MANAGE)) {
                    shard.factory.pass(event, GuildUtils.getPrefix(guild));
                    // The event will be handled and musn't be resumed here.
                    return;
                }
                if (!shard.botMuteData.isMuted(event.getMember())) {
                    shard.factory.pass(event, GuildUtils.getPrefix(guild));
                    // The event will be handled and musn't be resumed here.
                    return;
                }
                event.getMessage().delete().queue();
                String reply = "Sorry, but you're muted in {0} until {1}".replace("{0}", event.getGuild().getName()).replace("{1}", Date.from(Instant.ofEpochSecond(shard.botMuteData.getUnmuteTime(event.getMember()) / 1000)).toLocaleString());
                event.getAuthor().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(reply).queue());
                break;
            case PRIVATE:
                event.getChannel().sendMessage("Please use Ardent commands inside of a guild!").queue();
                shard0.factory.incrementMessagesReceived();
                break;
        }
    } catch (Exception ex) {
        new BotException(ex);
    }
}
Also used : AntiAdvertisingSettings(tk.ardentbot.rethink.models.AntiAdvertisingSettings) BotException(tk.ardentbot.core.misc.logging.BotException) AdvertisingInfraction(tk.ardentbot.rethink.models.AdvertisingInfraction) Guild(net.dv8tion.jda.core.entities.Guild) Shard(tk.ardentbot.main.Shard) Member(net.dv8tion.jda.core.entities.Member) BotException(tk.ardentbot.core.misc.logging.BotException) SubscribeEvent(net.dv8tion.jda.core.hooks.SubscribeEvent)

Example 9 with BotException

use of tk.ardentbot.core.misc.logging.BotException in project Ardent by adamint.

the class Asses method addAsses.

private void addAsses(String site) {
    try {
        Document assList = Jsoup.parse(new URL(site), 10000);
        Elements links = assList.getElementsByTag("img");
        links.forEach(img -> {
            String url = img.attr("src");
            if (url.contains(".jpeg"))
                asses.add(url);
        });
    } catch (IOException e) {
        new BotException(e);
    }
}
Also used : BotException(tk.ardentbot.core.misc.logging.BotException) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URL(java.net.URL)

Example 10 with BotException

use of tk.ardentbot.core.misc.logging.BotException 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)

Aggregations

BotException (tk.ardentbot.core.misc.logging.BotException)24 Shard (tk.ardentbot.main.Shard)10 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)8 List (java.util.List)6 net.dv8tion.jda.core.entities (net.dv8tion.jda.core.entities)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Command (tk.ardentbot.core.executor.Command)5 Database.connection (tk.ardentbot.rethink.Database.connection)5 Database.r (tk.ardentbot.rethink.Database.r)5 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 Permission (net.dv8tion.jda.core.Permission)4 Subcommand (tk.ardentbot.core.executor.Subcommand)4 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)3 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)3 Guild (net.dv8tion.jda.core.entities.Guild)3 GuildUtils (tk.ardentbot.utils.discord.GuildUtils)3 UserUtils (tk.ardentbot.utils.discord.UserUtils)3 Cursor (com.rethinkdb.net.Cursor)2 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)2