Search in sources :

Example 1 with User

use of de.c0debase.bot.database.model.User in project c0debaseBot by Biospheere.

the class GuildMemberRoleListener method onGuildMemberRoleAdd.

@Override
public void onGuildMemberRoleAdd(final GuildMemberRoleAddEvent event) {
    final User user = bot.getDatabase().getUserDao().getOrCreateUser(event.getGuild().getId(), event.getUser().getId());
    event.getRoles().forEach(role -> {
        if (role != null && !user.getRoles().contains(role.getId())) {
            user.getRoles().add(role.getId());
        }
        bot.getDatabase().getUserDao().updateUser(user);
    });
}
Also used : User(de.c0debase.bot.database.model.User)

Example 2 with User

use of de.c0debase.bot.database.model.User in project c0debaseBot by Biospheere.

the class GuildMemberRoleListener method onGuildMemberRoleRemove.

@Override
public void onGuildMemberRoleRemove(final GuildMemberRoleRemoveEvent event) {
    final User user = bot.getDatabase().getUserDao().getOrCreateUser(event.getGuild().getId(), event.getUser().getId());
    event.getRoles().forEach(role -> {
        if (role != null) {
            user.getRoles().remove(role.getId());
        }
        bot.getDatabase().getUserDao().updateUser(user);
    });
}
Also used : User(de.c0debase.bot.database.model.User)

Example 3 with User

use of de.c0debase.bot.database.model.User in project c0debaseBot by Biospheere.

the class LevelLeaderboard method buildList.

@Override
public void buildList(EmbedBuilder embedBuilder, int page, boolean descending, Guild guild) {
    final List<User> users = getBot().getDatabase().getLeaderboardDao().getLeaderboard(guild.getId());
    if (descending) {
        Collections.reverse(users);
    }
    for (Map.Entry<Integer, User> entry : getPage(page, users, !descending).entrySet()) {
        User user = entry.getValue();
        int count = entry.getKey();
        final Member member = guild.getMemberById(Long.valueOf(user.getUserID()));
        if (member != null) {
            embedBuilder.appendDescription("`" + count + ")` " + StringUtils.replaceCharacter(member.getEffectiveName()) + "#" + member.getUser().getDiscriminator() + " (Lvl." + user.getLevel() + "/Xp." + user.getXp() + ")\n");
        } else {
            embedBuilder.appendDescription("`" + count + ")` undefined#0000 (Lvl." + user.getLevel() + "/Xp." + user.getXp() + ")\n");
        }
        count++;
    }
}
Also used : User(de.c0debase.bot.database.model.User) Map(java.util.Map) Member(net.dv8tion.jda.api.entities.Member)

Example 4 with User

use of de.c0debase.bot.database.model.User 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 5 with User

use of de.c0debase.bot.database.model.User in project c0debaseBot by Biospheere.

the class LeaderboardImplMongo method getLeaderboard.

@Override
public List<User> getLeaderboard(final String guildId) {
    if (leaderboardCache.containsKey(guildId)) {
        return leaderboardCache.get(guildId);
    }
    final List<User> users = new ArrayList<>();
    final FindIterable<Document> documentIterable = userCollection.find(Filters.eq("guildID", guildId)).sort(Sorts.descending("level", "xp"));
    for (Document document : documentIterable) {
        users.add(Constants.GSON.fromJson(document.toJson(jsonWriterSettings), User.class));
    }
    users.sort((o1, o2) -> {
        if (o1.getLevel() != o2.getLevel()) {
            return Double.compare(o2.getLevel(), o1.getLevel());
        } else {
            return Double.compare((o2.getXp() + o2.getLevel() + (1000 * o2.getLevel() * 1.2)), (o1.getXp() + o1.getLevel() + (1000 * o1.getLevel() * 1.2)));
        }
    });
    leaderboardCache.put(guildId, users);
    return users;
}
Also used : User(de.c0debase.bot.database.model.User) ArrayList(java.util.ArrayList) Document(org.bson.Document)

Aggregations

User (de.c0debase.bot.database.model.User)11 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 ArrayList (java.util.ArrayList)2 Member (net.dv8tion.jda.api.entities.Member)2 Test (org.junit.Test)2 Codebase (de.c0debase.bot.Codebase)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 Invite (net.dv8tion.jda.api.entities.Invite)1 Role (net.dv8tion.jda.api.entities.Role)1 Document (org.bson.Document)1