Search in sources :

Example 16 with Member

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

the class kick method execute.

@Override
public void execute(CommandEvent event) {
    if (event.getAuthor().isBot()) {
        return;
    }
    Guild guild = event.getGuild();
    Member author = event.getMessage().getMember();
    String[] comd = event.getArgs().split(",");
    String EBR = "";
    String reason = "";
    EmbedBuilder EB = new EmbedBuilder();
    Member mentioned = null;
    if (!author.hasPermission(Permission.KICK_MEMBERS)) {
        event.reply(event.getAuthor().getAsMention() + " você não tem permissão para expulsar ninguém");
        return;
    }
    try {
        mentioned = event.getMessage().getMentionedMembers().get(0);
    } catch (IndexOutOfBoundsException e) {
        event.reply(event.getAuthor().getAsMention() + " você não mencionou ninguém.\nUse: ``gordo expulsar @gordo#0865 , motivo(opcional)``");
        return;
    }
    if (event.getAuthor() == mentioned.getUser() || event.getMessage().getMentionedMembers().get(0).getUser().isBot()) {
        EB.setAuthor("O usuario não foi expulso");
        EB.setTitle(":warning:");
        EB.setDescription("Eu não vou expulsar bots ou a pessoa que invocou o comando.\n \nEntre em contato com um administrador do servidor :face_palm: ");
        EB.setColor(16657966);
        EB.setFooter("Commando executado por: " + event.getAuthor().getName(), event.getAuthor().getAvatarUrl());
        EB.setTimestamp(event.getMessage().getCreationTime());
        event.reply(EB.build());
        return;
    }
    if (!guild.getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
        event.reply("Eu não tenho acesso a expulsar membros do servidor, fale com o adiministrador para me dar um cargo com acesso a **expulsar membros** ativado");
        return;
    }
    if (event.getMessage().getMentionedMembers().isEmpty()) {
        event.reply(author.getEffectiveName() + " Não encontrei esta pessoa, tem certeza que mencionou o nome corretamente?");
        return;
    }
    try {
        reason = (event.getAuthor().getName() + " expulsou o usuario " + mentioned.getEffectiveName() + ", motivo: " + comd[1]);
        EBR = (comd[1]);
    } catch (Exception e) {
        reason = (event.getAuthor().getName() + " expulsou o usuario " + mentioned.getEffectiveName());
        EBR = "Sem motivo";
    }
    try {
        System.out.println("Kick event in:" + event.getGuild().getName() + " , Channel: " + event.getTextChannel().getName() + " , BY: " + event.getAuthor().getName() + " , id: " + event.getAuthor().getId() + " , Banned user: " + mentioned.getEffectiveName());
        EB.setAuthor("O usuario foi expulso");
        EB.setTitle(":white_check_mark:" + mentioned.getEffectiveName());
        EB.setThumbnail(mentioned.getUser().getEffectiveAvatarUrl());
        EB.setColor(16657966);
        EB.setFooter("Commando executado por: " + event.getAuthor().getName(), event.getAuthor().getAvatarUrl());
        EB.setTimestamp(event.getMessage().getCreationTime());
        EB.addField("Id:", mentioned.getUser().getId(), false);
        EB.addField("Motivo", EBR, false);
        EB.setThumbnail(mentioned.getUser().getAvatarUrl());
        event.reply(EB.build());
        guild.getController().kick(mentioned, (event.getAuthor().getAsMention() + reason)).queue();
    } catch (Exception e) {
        EB.setAuthor("O usuario não foi expulso");
        EB.setTitle(":warning:");
        EB.setDescription("um error inesperado aconteceu, contate o criador do bot");
        EB.setColor(16657966);
        EB.setFooter("Commando executado por: " + event.getAuthor().getName(), event.getAuthor().getAvatarUrl());
        EB.setTimestamp(event.getMessage().getCreationTime());
        return;
    }
    return;
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 17 with Member

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

the class ban method execute.

@Override
public void execute(CommandEvent event) {
    Guild guild = event.getGuild();
    Member author = event.getMessage().getMember();
    List<Member> mentioned = event.getMessage().getMentionedMembers();
    String[] comd = event.getArgs().split(",");
    String reason = "";
    String banned = comd[0];
    if (!author.hasPermission(Permission.BAN_MEMBERS)) {
        event.reply("você não tem permissão para banir ninguém, contate o adiministrador do servidor");
        return;
    }
    if (event.getMessage().getMentionedMembers().isEmpty()) {
        event.reply(author.getEffectiveName() + " Não encontrei essa pessoa, tem certeza que mencionou o nome corretamente?");
        return;
    }
    if (guild == null) {
        event.reply("Posso ser gordo porem não sou burro, você precisa executar esse comando no servidor");
        return;
    }
    try {
        reason = comd[1];
    } catch (Exception e) {
        event.reply(event.getAuthor().getAsMention() + " você não colocou um motivo, banimento será realizado sem descrição");
        reason = (event.getAuthor() + " realizou o banimento sem colocar o motivo");
    }
    try {
        event.reply(author.getAsMention() + "** baniu o usuario: **" + mentioned.get(0).getAsMention() + " :white_check_mark:");
        guild.getController().ban(mentioned.get(0), 7, (event.getAuthor().getName() + reason)).queue();
        System.out.println("Ban event in:" + event.getTextChannel().getName() + " , BY: " + event.getAuthor().getName() + " id: " + event.getAuthor().getId() + " , Banned user: " + banned);
    } catch (Exception e) {
        event.reply("um erro aconteceu");
        return;
    }
    return;
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 18 with Member

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

the class Command method isPatron.

/**
 * This checks if the user is a patrons if ours
 * It checks if the user has the patreon role on our support guild
 *
 * @param u  The user to check
 * @param tc the channel to send the message to, if the text channel is null it wont send a message
 * @return true if the user is a patron
 */
protected boolean isPatron(User u, TextChannel tc) {
    // noinspection deprecation
    if (Arrays.asList(Settings.wbkxwkZPaG4ni5lm8laY).contains(u.getId())) {
        return true;
    }
    Guild supportGuild = u.getJDA().asBot().getShardManager().getGuildById("191245668617158656");
    if (supportGuild == null) {
        return false;
    }
    Member m = supportGuild.getMember(u);
    if (m == null) {
        MessageUtils.sendEmbed(tc, EmbedUtils.embedMessage("This command is a premium command and is locked for you because you are " + "not one of our patrons.\n" + "To become a patron and have access to this command please [click this link](https://www.patreon.com/duncte123).\n" + "You will also need to join our support guild [here](https://discord.gg/NKM9Xtk)"));
        return false;
    } else {
        if (!m.getRoles().contains(supportGuild.getRoleById("402497345721466892"))) {
            MessageUtils.sendEmbed(tc, EmbedUtils.embedMessage("This command is a premium command and is locked for you because you are " + "not one of our patrons.\n" + "To become a patron and have access to this command please [click this link](https://www.patreon.com/duncte123)."));
            return false;
        }
        return true;
    }
}
Also used : Guild(net.dv8tion.jda.core.entities.Guild) Member(net.dv8tion.jda.core.entities.Member)

Example 19 with Member

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

the class WolframAlphaCommand method generateEmbed.

/**
 * Generates an embed for the {@link WAQueryResult result of a computation}
 *
 * @param event  The event
 * @param result The result generated
 * @return An {@link MessageEmbed embed} representing this {@link WAQueryResult result}
 */
private MessageEmbed generateEmbed(GuildMessageReceivedEvent event, WAQueryResult result) {
    Member m = event.getMember();
    EmbedBuilder eb = EmbedUtils.defaultEmbed();
    eb.setAuthor(m.getUser().getName(), null, m.getUser().getAvatarUrl());
    eb.setTitle("**Input:** " + a(result.getQuery().getInput()), a(result.getQuery().toWebsiteURL()));
    for (WAPod pod : result.getPods()) {
        String name = a(pod.getTitle());
        StringBuilder embeds = new StringBuilder();
        // Loop over the subpods
        for (WASubpod sp : pod.getSubpods()) {
            // yet another stringbuilder
            StringBuilder e = new StringBuilder();
            // append the title
            e.append(a(sp.getTitle()));
            // loop over the contents
            for (Visitable v : sp.getContents()) {
                String d = "";
                if (v instanceof WAImage) {
                    WAImage i = (WAImage) v;
                    d += "[" + a(i.getTitle()) + "](" + WebUtils.ins.shortenUrl(i.getURL()).execute() + ")";
                } else if (v instanceof WAInfo) {
                    WAInfo i = (WAInfo) v;
                    d += a(i.getText());
                // Ramid when?
                // TODO: Display more...
                } else if (v instanceof WALink) {
                    WALink l = (WALink) v;
                    d += "[" + a(l.getText()) + "](" + WebUtils.ins.shortenUrl(l.getURL()).execute() + ")";
                } else if (v instanceof WAPlainText) {
                    WAPlainText pt = (WAPlainText) v;
                    d += a(pt.getText());
                } else if (v instanceof WASound) {
                    WASound sound = (WASound) v;
                    d += WebUtils.ins.shortenUrl(sound.getURL()).execute();
                }
                e.append(d).append("\n\n");
            }
            embeds.append(a(e.toString().trim())).append("\n\n");
        }
        eb.addField(name, a(embeds.toString().trim()), false);
    }
    return eb.build();
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Visitable(com.wolfram.alpha.visitor.Visitable) Member(net.dv8tion.jda.core.entities.Member)

Example 20 with Member

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

the class FakeTest method medium.

/**
 * Test medium
 * Mock Lists, don't share objects
 */
@Test
public void medium() {
    Member member = new FakeInterface<>(Member.class).create();
    JDA jda = member.getJDA();
    assertNotEquals(jda, member.getJDA());
    assertNotEquals(jda.getGuildById(member.getGuild().getId()), member.getGuild());
    assertEquals(jda.getGuilds(), new ArrayList<>());
}
Also used : JDA(net.dv8tion.jda.core.JDA) Member(net.dv8tion.jda.core.entities.Member) Test(org.junit.Test)

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