Search in sources :

Example 16 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class Tempchannel method onTempchannelLeave.

@Override
public void onTempchannelLeave(final VoiceChannel voiceChannel, final Member member) {
    if (voiceChannel.equals(voiceChannel.getGuild().getAfkChannel())) {
        return;
    }
    if (voiceChannel.getMembers().isEmpty()) {
        textChannel.delete().queue();
        textChannel = null;
    } else if (textChannel.getPermissionOverride(member) != null) {
        textChannel.getPermissionOverride(member).delete().queue();
        if (member.getUser().isBot()) {
            return;
        }
        final EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setColor(member.getColor());
        embedBuilder.setDescription(":arrow_left: " + member.getAsMention() + " hat uns verlassen");
        textChannel.sendMessage(embedBuilder.build()).queue();
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

Example 17 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class Tempchannel method onTempchannelJoin.

@Override
public void onTempchannelJoin(final VoiceChannel voiceChannel, final Member member) {
    if (voiceChannel.equals(voiceChannel.getGuild().getAfkChannel())) {
        return;
    }
    if (textChannel == null) {
        final Guild guild = voiceChannel.getGuild();
        voiceChannel.getParent().createTextChannel("temp-" + voiceChannel.getName().toLowerCase()).addPermissionOverride(guild.getSelfMember(), MEMBER_PERMISSIONS, null).addPermissionOverride(member, MEMBER_PERMISSIONS, null).addPermissionOverride(guild.getPublicRole(), null, MEMBER_PERMISSIONS).queue(channel -> setTextChannel((TextChannel) channel));
    } else {
        if (textChannel.getPermissionOverride(member) != null) {
            textChannel.getPermissionOverride(member).getManager().grant(MEMBER_PERMISSIONS).queue();
        } else {
            textChannel.createPermissionOverride(member).setAllow(MEMBER_PERMISSIONS).queue();
        }
        if (member.getUser().isBot()) {
            return;
        }
        final EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setColor(member.getColor());
        embedBuilder.setDescription(":arrow_right: " + member.getAsMention() + " ist beigetreten");
        textChannel.sendMessage(embedBuilder.build()).queue();
    }
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Guild(net.dv8tion.jda.api.entities.Guild)

Example 18 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class InviteTracker method start.

/**
 * See which invite has been used by a new member of a guild
 */
public void start() {
    Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> bot.getJDA().getGuilds().get(0).retrieveInvites().queue(inviteList -> inviteList.forEach(invite -> {
        if (inviteHashMap.containsKey(invite.getCode()) && invite.getUses() > inviteHashMap.get(invite.getCode()).getUses()) {
            final User user = bot.getDatabase().getUserDao().getOrCreateUser(invite.getGuild().getId(), invite.getInviter().getId());
            EmbedBuilder embedBuilder = new EmbedBuilder();
            embedBuilder.setDescription(invite.getInviter().getAsMention() + " vielen Dank das du jemand neues auf c0debase gebracht hast [" + invite.getCode() + "]");
            bot.getJDA().getTextChannelById(System.getenv("BOTCHANNEL")).sendMessage(embedBuilder.build()).queue();
            if (user.addXP(100)) {
                EmbedBuilder levelUpEmbed = new EmbedBuilder();
                levelUpEmbed.setDescription(invite.getInviter().getAsMention() + " ist nun Level " + user.getLevel());
                bot.getJDA().getTextChannelById(System.getenv("BOTCHANNEL")).sendMessage(levelUpEmbed.build()).queue();
            }
            bot.getDatabase().getUserDao().updateUser(user);
        }
        inviteHashMap.put(invite.getCode(), invite);
    })), 5, 5, TimeUnit.SECONDS);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) User(de.c0debase.bot.database.model.User) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Codebase(de.c0debase.bot.Codebase) Invite(net.dv8tion.jda.api.entities.Invite) Executors(java.util.concurrent.Executors) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) User(de.c0debase.bot.database.model.User)

Example 19 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class SinceCommand method execute.

@Override
public void execute(final String[] args, final Message message) {
    final Member member = message.getMentionedMembers().size() == 0 ? message.getMember() : message.getMentionedMembers().get(0);
    final EmbedBuilder embedBuilder = getEmbed(message.getGuild(), message.getAuthor());
    if (args.length > 0 && message.getMentionedMembers().isEmpty() && StringUtils.isInteger(args[0]) && message.getGuild().isLoaded()) {
        final Integer since = Integer.valueOf(args[0]);
        if (since < 0) {
            final Member oldestMember = DiscordUtils.getOldestMember(message.getGuild());
            embedBuilder.setDescription("!since [0-" + ((oldestMember == null) ? "?]" : ChronoUnit.DAYS.between(oldestMember.getTimeJoined(), LocalDateTime.now().atOffset(ZoneOffset.UTC)) + "]"));
        } else {
            final Integer memberCount = getMemberCoundByDays(since, message.getGuild());
            final float percentage = ((float) memberCount / (float) message.getGuild().getMemberCount()) * 100;
            embedBuilder.setDescription("Es gibt " + memberCount + " Mitglieder welche seit mehr als " + since + " Tagen auf diesem Server sind.\n Das sind " + DECIMAL_FORMAT.format(percentage) + "%");
        }
    } else {
        embedBuilder.setDescription(member.getAsMention() + " ist seit " + ChronoUnit.DAYS.between(member.getTimeJoined(), LocalDateTime.now().atOffset(ZoneOffset.UTC)) + " Tagen auf " + message.getGuild().getName());
    }
    message.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member)

Example 20 with EmbedBuilder

use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.

the class CoinCommand method execute.

@Override
public void execute(final String[] args, final Message message) {
    final Member member = DiscordUtils.getAddressedMember(message);
    final EmbedBuilder embedBuilder = getEmbed(message.getGuild(), member.getUser());
    embedBuilder.setDescription(member.getAsMention() + " hat " + String.format("%.2f", bot.getDatabase().getUserDao().getOrCreateUser(member.getGuild().getId(), member.getUser().getId()).getCoins()) + " Coins");
    message.getTextChannel().sendMessage(embedBuilder.build()).queue();
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)47 Member (net.dv8tion.jda.api.entities.Member)8 TimeUnit (java.util.concurrent.TimeUnit)7 Collectors (java.util.stream.Collectors)7 Message (net.dv8tion.jda.api.entities.Message)7 Context (net.kodehawa.mantarobot.core.modules.commands.base.Context)7 MantaroData (net.kodehawa.mantarobot.data.MantaroData)7 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)7 Color (java.awt.Color)6 MessageBuilder (net.dv8tion.jda.api.MessageBuilder)6 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)6 Utils (net.kodehawa.mantarobot.utils.Utils)6 Subscribe (com.google.common.eventbus.Subscribe)5 List (java.util.List)5 Role (net.dv8tion.jda.api.entities.Role)5 CommandCategory (net.kodehawa.mantarobot.core.modules.commands.base.CommandCategory)5 HelpContent (net.kodehawa.mantarobot.core.modules.commands.help.HelpContent)5 I18nContext (net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)5 LinkedList (java.util.LinkedList)4 Permission (net.dv8tion.jda.api.Permission)4