Search in sources :

Example 41 with Member

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

the class SaveCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    if (args.length == 0) {
        MessageUtils.sendUsage(this, channel, sender, args);
        return;
    }
    String name = MessageUtils.getMessage(args, 0);
    if (name.length() > 20) {
        MessageUtils.sendErrorMessage("Name can only be a maximum of 20 characters!", channel);
        return;
    }
    if (!FlareBot.instance().getMusicManager().hasPlayer(channel.getGuild().getId())) {
        MessageUtils.sendErrorMessage("Your playlist is empty!", channel);
        return;
    }
    Queue<Track> playlist = FlareBot.instance().getMusicManager().getPlayer(guild.getGuildId()).getPlaylist();
    Track currentlyPlaying = FlareBot.instance().getMusicManager().getPlayer(guild.getGuildId()).getPlayingTrack();
    channel.sendTyping().complete();
    List<String> tracks = playlist.stream().map(track -> track.getTrack().getIdentifier()).collect(Collectors.toList());
    if (currentlyPlaying != null) {
        tracks.add(currentlyPlaying.getTrack().getIdentifier());
    }
    if (tracks.isEmpty()) {
        MessageUtils.sendErrorMessage("Your playlist is empty!", channel);
        return;
    }
    FlareBot.instance().getManager().savePlaylist(this, channel, sender.getId(), this.getPermissions(channel).hasPermission(member, Permission.SAVE_OVERWRITE), name, tracks);
}
Also used : Track(com.arsenarsen.lavaplayerbridge.player.Track) Member(net.dv8tion.jda.core.entities.Member) TextChannel(net.dv8tion.jda.core.entities.TextChannel) FlareBot(stream.flarebot.flarebot.FlareBot) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) List(java.util.List) Permission(stream.flarebot.flarebot.permissions.Permission) User(net.dv8tion.jda.core.entities.User) Command(stream.flarebot.flarebot.commands.Command) MessageUtils(stream.flarebot.flarebot.util.MessageUtils) Queue(java.util.Queue) CommandType(stream.flarebot.flarebot.commands.CommandType) Track(com.arsenarsen.lavaplayerbridge.player.Track)

Example 42 with Member

use of net.dv8tion.jda.core.entities.Member in project MantaroBot by Mantaro.

the class CommandListener method onCommand.

private void onCommand(GuildMessageReceivedEvent event) {
    try {
        Member self = event.getGuild().getSelfMember();
        if (!self.getPermissions(event.getChannel()).contains(Permission.MESSAGE_WRITE) && !self.hasPermission(Permission.ADMINISTRATOR))
            return;
        if (commandProcessor.run(event)) {
            commandTotal++;
        } else {
            // Only run experience if no command has been executed, avoids weird race conditions when saving player status.
            try {
                // Only run experience if the user is not rate limited (clears every 30 seconds)
                if (random.nextInt(15) > 7 && !event.getAuthor().isBot() && experienceRatelimiter.process(event.getAuthor())) {
                    if (event.getMember() == null)
                        return;
                    // some nasty race conditions involving player save.
                    if (InteractiveOperations.get(event.getChannel()) != null)
                        return;
                    Player player = MantaroData.db().getPlayer(event.getAuthor());
                    PlayerData data = player.getData();
                    DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
                    GuildData guildData = dbGuild.getData();
                    if (player.isLocked())
                        return;
                    // Set level to 1 if level is zero.
                    if (player.getLevel() == 0)
                        player.setLevel(1);
                    // Set player experience to a random number between 1 and 5.
                    data.setExperience(data.getExperience() + Math.round(random.nextInt(5)));
                    // Apply some black magic.
                    if (data.getExperience() > (player.getLevel() * Math.log10(player.getLevel()) * 1000) + (50 * player.getLevel() / 2)) {
                        player.setLevel(player.getLevel() + 1);
                        // Check if the member is not null, just to be sure it happened in-between.
                        if (player.getLevel() > 1 && event.getGuild().getMemberById(player.getUserId()) != null) {
                            if (guildData.isEnabledLevelUpMessages()) {
                                String levelUpChannel = guildData.getLevelUpChannel();
                                String levelUpMessage = guildData.getLevelUpMessage();
                                // Player has leveled up!
                                if (levelUpMessage != null && levelUpChannel != null) {
                                    processMessage(String.valueOf(player.getLevel()), levelUpMessage, levelUpChannel, event);
                                }
                            }
                        }
                    }
                    // This time, actually remember to save the player so you don't have to restart 102 shards to fix it.
                    player.saveAsync();
                }
            } catch (Exception ignored) {
            }
        }
    } catch (IndexOutOfBoundsException e) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "Your query returned no results or you used the incorrect arguments, seemingly. Just in case, check command help!").queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            event.getChannel().sendMessage(String.format("%sI don't have permission to do this :<, I need the permission: **%s**%s", EmoteReference.ERROR, e.getPermission().getName(), e.getMessage() != null ? String.format(" | Message: %s", e.getMessage()) : "")).queue();
        } else {
            event.getChannel().sendMessage(EmoteReference.ERROR + "I cannot perform this action due to the lack of permission! Is the role I might be trying to assign" + " higher than my role? Do I have the correct permissions/hierarchy to perform this action?").queue();
        }
    } catch (IllegalArgumentException e) {
        // NumberFormatException == IllegalArgumentException
        String id = Snow64.toSnow64(event.getMessage().getIdLong());
        event.getChannel().sendMessage(String.format("%sI think you forgot something on the floor. (Maybe we threw it there? [Error ID: %s]... I hope we didn't)\n" + "- Incorrect type arguments or the message I'm trying to send exceeds 2048 characters, Just in case, check command help!", EmoteReference.ERROR, id)).queue();
        log.warn("Exception caught and alternate message sent. We should look into this, anyway (ID: {})", id, e);
    } catch (ReqlError e) {
        // So much just went wrong...
        e.printStackTrace();
        SentryHelper.captureExceptionContext("Something seems to have broken in the db! Check this out!", e, this.getClass(), "Database");
    } catch (RedisException e) {
        // So much just went wrong but on another side of the db...
        e.printStackTrace();
        SentryHelper.captureExceptionContext("Something seems to have broken in the db! Check this out!", e, this.getClass(), "Redis Database");
    } catch (Exception e) {
        String id = Snow64.toSnow64(event.getMessage().getIdLong());
        Player player = MantaroData.db().getPlayer(event.getAuthor());
        event.getChannel().sendMessage(String.format("%s%s\n(Error ID: `%s`)\n" + "If you want, join our **support guild** (Link on `~>about`), or check out our GitHub page (/Mantaro/MantaroBot). " + "Please tell them to quit exploding me and please don't forget the Error ID when reporting!", EmoteReference.ERROR, boomQuotes[rand.nextInt(boomQuotes.length)], id)).queue();
        if (player.getData().addBadgeIfAbsent(Badge.FIRE))
            player.saveAsync();
        SentryHelper.captureException(String.format("Unexpected Exception on Command: %s | (Error ID: ``%s``)", event.getMessage().getContentRaw(), id), e, this.getClass());
        log.error("Error happened with id: {} (Error ID: {})", event.getMessage().getContentRaw(), id, e);
    }
}
Also used : PermissionException(net.dv8tion.jda.core.exceptions.PermissionException) Player(net.kodehawa.mantarobot.db.entities.Player) GuildData(net.kodehawa.mantarobot.db.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.db.entities.DBGuild) ReqlError(com.rethinkdb.gen.exc.ReqlError) RedisException(org.redisson.client.RedisException) Member(net.dv8tion.jda.core.entities.Member) PlayerData(net.kodehawa.mantarobot.db.entities.helpers.PlayerData) RedisException(org.redisson.client.RedisException) PermissionException(net.dv8tion.jda.core.exceptions.PermissionException)

Example 43 with Member

use of net.dv8tion.jda.core.entities.Member in project MantaroBot by Mantaro.

the class CurrencyCmds method inventory.

@Subscribe
public void inventory(CommandRegistry cr) {
    cr.register("inventory", new SimpleCommand(Category.CURRENCY) {

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Map<String, Optional<String>> t = StringUtils.parse(args);
            content = Utils.replaceArguments(t, content, "brief", "calculate");
            Member member = Utils.findMember(event, event.getMember(), content);
            if (member == null)
                return;
            Player player = MantaroData.db().getPlayer(member);
            if (t.containsKey("brief")) {
                event.getChannel().sendMessage(String.format("**%s's inventory:** %s", member.getEffectiveName(), ItemStack.toString(player.getInventory().asList()))).queue();
                return;
            }
            if (t.containsKey("calculate")) {
                long all = player.getInventory().asList().stream().filter(item -> item.getItem().isSellable()).mapToLong(value -> (long) (value.getItem().getValue() * value.getAmount() * 0.9d)).sum();
                event.getChannel().sendMessage(String.format("%sYou will get **%d credits** if you sell all of your items!", EmoteReference.DIAMOND, all)).queue();
                return;
            }
            EmbedBuilder builder = baseEmbed(event, member.getEffectiveName() + "'s Inventory", member.getUser().getEffectiveAvatarUrl());
            List<ItemStack> list = player.getInventory().asList();
            List<MessageEmbed.Field> fields = new LinkedList<>();
            if (list.isEmpty())
                builder.setDescription("There is only dust here.");
            else
                player.getInventory().asList().forEach(stack -> {
                    long buyValue = stack.getItem().isBuyable() ? stack.getItem().getValue() : 0;
                    long sellValue = stack.getItem().isSellable() ? (long) (stack.getItem().getValue() * 0.9) : 0;
                    fields.add(new MessageEmbed.Field(stack.getItem().getEmoji() + " " + stack.getItem().getName() + " x " + stack.getAmount(), String.format("**Price**: \uD83D\uDCE5 %d \uD83D\uDCE4 %d\n%s", buyValue, sellValue, stack.getItem().getDesc()), false));
                });
            List<List<MessageEmbed.Field>> splitFields = DiscordUtils.divideFields(18, fields);
            boolean hasReactionPerms = event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION);
            if (hasReactionPerms) {
                DiscordUtils.list(event, 45, false, builder, splitFields);
            } else {
                DiscordUtils.listText(event, 45, false, builder, splitFields);
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Inventory command").setDescription("**Shows your current inventory.**\n" + "You can use `~>inventory -brief` to get a mobile friendly version.\n" + "Use `~>inventory -calculate` to see how much you'd get if you sell every sellable item on your inventory!").build();
        }
    });
    cr.registerAlias("inventory", "inv");
}
Also used : Items(net.kodehawa.mantarobot.commands.currency.item.Items) Badge(net.kodehawa.mantarobot.commands.currency.profile.Badge) Module(net.kodehawa.mantarobot.core.modules.Module) java.util(java.util) Command(net.kodehawa.mantarobot.core.modules.commands.base.Command) Member(net.dv8tion.jda.core.entities.Member) Utils(net.kodehawa.mantarobot.utils.Utils) RateLimiter(net.kodehawa.mantarobot.utils.commands.RateLimiter) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) RethinkDB.r(com.rethinkdb.RethinkDB.r) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Cursor(com.rethinkdb.net.Cursor) Permission(net.dv8tion.jda.core.Permission) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) Utils.handleDefaultRatelimit(net.kodehawa.mantarobot.utils.Utils.handleDefaultRatelimit) OptArgs(com.rethinkdb.model.OptArgs) Inventory(net.kodehawa.mantarobot.db.entities.helpers.Inventory) StringUtils(br.com.brjdevs.java.utils.texts.StringUtils) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) ItemStack(net.kodehawa.mantarobot.commands.currency.item.ItemStack) Connection(com.rethinkdb.net.Connection) Player(net.kodehawa.mantarobot.db.entities.Player) SubCommand(net.kodehawa.mantarobot.core.modules.commands.SubCommand) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) Collectors(java.util.stream.Collectors) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) TreeCommand(net.kodehawa.mantarobot.core.modules.commands.TreeCommand) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) User(net.dv8tion.jda.core.entities.User) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) Item(net.kodehawa.mantarobot.commands.currency.item.Item) Player(net.kodehawa.mantarobot.db.entities.Player) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) List(java.util.List) Member(net.dv8tion.jda.core.entities.Member) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 44 with Member

use of net.dv8tion.jda.core.entities.Member in project c0debaseBot by Biospheere.

the class CheckCommand method execute.

@Override
public void execute(String[] args, Message msg) {
    if (msg.getMember().hasPermission(Permission.ADMINISTRATOR) || msg.getMember().hasPermission(Permission.BAN_MEMBERS)) {
        if (args.length < 1) {
            return;
        }
        String id = args[0];
        if (msg.getGuild().getMemberById(id) != null) {
            Member member = msg.getGuild().getMemberById(id);
            EmbedBuilder embedBuilder = getEmbed(msg.getGuild(), member.getUser());
            embedBuilder.addField("Erstelldatum: ", member.getUser().getCreationTime().format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm")), true);
            embedBuilder.addField("Standart Avatar: ", String.valueOf(member.getUser().getAvatarUrl() == null), true);
            embedBuilder.addField("Beitritt: ", member.getJoinDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm")), true);
            msg.getTextChannel().sendMessage(embedBuilder.build()).queue();
        }
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Member(net.dv8tion.jda.core.entities.Member)

Example 45 with Member

use of net.dv8tion.jda.core.entities.Member in project Frost by woojiahao.

the class UserID method checkInput.

@Override
public boolean checkInput(DiscordSet set, String input) {
    if (!super.checkInput(set, input))
        return false;
    if (set.getGuild().getMemberById(input) == null) {
        set.getFrom().sendMessage("Unable to find member of ID: " + input).queue();
        return false;
    }
    Member invoker = set.getGuild().getMember(set.getUser());
    Member target = set.getGuild().getMemberById(input);
    if (invoker.isOwner()) {
        return true;
    } else if (target.isOwner()) {
        set.getFrom().sendMessage("Nice try kiddo, you are still to young to do that").queue();
        return false;
    }
    if (invoker.getRoles().get(0).getPosition() < target.getRoles().get(0).getPosition()) {
        set.getFrom().sendMessage("You think I will allow you to do that?").queue();
        return false;
    }
    return true;
}
Also used : Member(net.dv8tion.jda.core.entities.Member)

Aggregations

Member (net.dv8tion.jda.core.entities.Member)69 Message (net.dv8tion.jda.core.entities.Message)23 Guild (net.dv8tion.jda.core.entities.Guild)22 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)19 User (net.dv8tion.jda.core.entities.User)19 TextChannel (net.dv8tion.jda.core.entities.TextChannel)18 MessageBuilder (net.dv8tion.jda.core.MessageBuilder)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)10 Permission (net.dv8tion.jda.core.Permission)9 MessageUtils (stream.flarebot.flarebot.util.MessageUtils)9 Role (net.dv8tion.jda.core.entities.Role)8 CommandType (stream.flarebot.flarebot.commands.CommandType)8 Collectors (java.util.stream.Collectors)7 FlareBot (stream.flarebot.flarebot.FlareBot)6 Permission (stream.flarebot.flarebot.permissions.Permission)6 Track (com.arsenarsen.lavaplayerbridge.player.Track)5 GuildPlayer (fredboat.audio.player.GuildPlayer)5 AudioTrackContext (fredboat.audio.queue.AudioTrackContext)5