Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.6 kB
25
Indexable
Never
public class UserEvents extends ListenerAdapter {

    HashMap<Member, String> map = new HashMap<Member, String>();
    public String WelcomeChannel = "another category";

    @Override
    public void onGuildMemberJoin(GuildMemberJoinEvent e) {
        TextChannel c = e.getGuild().getTextChannelById(WelcomeChannel);
        EmbedBuilder b = new EmbedBuilder();
        b.setTitle("yestye");
        b.setImage(e.getMember().getUser().getDefaultAvatarUrl());
        c.sendMessage(b.build()).queue();
        //c.sendMessage("Bem vindo " + e.getMember().getAsMention()).queue();
    }

    @Override
    public void onGuildVoiceJoin(GuildVoiceJoinEvent e) {
        Guild g = e.getGuild();
        Category c = e.getGuild().getCategoryById("another category");
        Category f = e.getGuild().getCategoryById("other category");
        System.out.println("Entrou no canal" + e.getChannelJoined().getId());
        if (e.getChannelJoined().getId().equals("channel here")) {
            if (!map.containsKey(e.getMember())) {
                int number = (int) (Math.random() * 5000);
                c.createVoiceChannel("DUO - " + number)
                        .setUserlimit(2)
                        .queue(canal -> {
                            map.put(e.getMember(), canal.getId());
                            g.moveVoiceMember(e.getMember(), canal).queue();
                        });
            }
        }
        if(e.getChannelJoined().getMembers().size() == e.getChannelJoined().getUserLimit()) {
            e.getChannelJoined().getManager().setParent(f).queue();
        }
    }

    @Override
    public void onGuildVoiceLeave(GuildVoiceLeaveEvent e) {
        Category f = e.getGuild().getCategoryById("category here");
        if (map.containsKey(e.getMember())) {
            for (VoiceChannel voice : e.getGuild().getVoiceChannels()) {
                if (voice.getId().equals(e.getChannelLeft().getId()) && e.getChannelLeft().getMembers().isEmpty()) {
                    map.remove(e.getMember());
                    e.getChannelLeft().delete().queue();
                }
                if (!e.getChannelLeft().getMembers().isEmpty()) {
                    map.remove(e.getMember());
                    List<Member> l = new LinkedList<>(e.getChannelLeft().getMembers());
                    Random r = new Random();
                    map.put(l.get(r.nextInt(l.size())), e.getChannelLeft().getId());
                }
            }
        }
        if(e.getChannelLeft().getMembers().size() != e.getChannelLeft().getUserLimit()) {
            e.getChannelLeft().getManager().setParent(f).queue();
        }
    }
}