Search in sources :

Example 1 with Invite

use of net.dv8tion.jda.api.entities.Invite 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)

Aggregations

Codebase (de.c0debase.bot.Codebase)1 User (de.c0debase.bot.database.model.User)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 Invite (net.dv8tion.jda.api.entities.Invite)1