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);
});
}
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);
});
}
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++;
}
}
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);
}
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;
}
Aggregations