Add //rank command

This commit is contained in:
Sebastien 2019-01-16 19:49:05 +01:00
parent f9f1da2d50
commit e10a8d652d
3 changed files with 77 additions and 1 deletions

View File

@ -17,7 +17,7 @@ import java.io.IOException;
/** /**
* Madame command that return random picture from dites.bonjourmadame.fr * Madame command that return random picture from dites.bonjourmadame.fr
*/ */
//@NoDev @NoDev
public class Madame extends NumberedCommande { public class Madame extends NumberedCommande {
Logger logger = LogManager.getLogger(); Logger logger = LogManager.getLogger();
MessageReceivedEvent event; MessageReceivedEvent event;

View File

@ -0,0 +1,30 @@
package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
public class Rank implements Commande {
@Override
public void action(String[] args, MessageReceivedEvent event) {
UserStatsUtils userStats = UserStatsUtils.getINSTANCE();
MessageEmbed msg = userStats.getRankMessage(event.getMember());
event.getTextChannel().sendMessage(msg).queue();
}
@Override
public boolean isPrivateUsable() {
return false;
}
@Override
public boolean isAdminCmd() {
return false;
}
@Override
public boolean isNSFW() {
return false;
}
}

View File

@ -6,16 +6,20 @@ import net.Broken.DB.Repository.UserRepository;
import net.Broken.DB.Repository.UserStatsRepository; import net.Broken.DB.Repository.UserStatsRepository;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.SpringContext; import net.Broken.SpringContext;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException; import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
import net.Broken.Tools.UserManager.UserUtils; import net.Broken.Tools.UserManager.UserUtils;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.User;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@ -204,6 +208,48 @@ public class UserStatsUtils {
} }
public MessageEmbed getRankMessage(Member member){
UserStats userStats = getGuildUserStats(member);
GuildStatsPack pack = getStatPack(userStats.getUser(), member.getGuild().getId());
StringBuilder stringBuilder = new StringBuilder();
int i = 1;
for(GuildStats stats : pack.ranking){
if( i >= 6){
break;
}
stringBuilder.append(i).append(". ").append(stats.userName).append(" with ").append(stats.total).append(" points!").append("\n");
i++;
}
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.yellow);
embedBuilder.setTitle(member.getGuild().getName() + " Ranking");
embedBuilder.addField("Top 5:", stringBuilder.toString(), false);
String rank;
switch (pack.selfStats.rank){
case 1:
rank = "1st";
break;
case 2:
rank = "2nd";
break;
case 3:
rank = "3rd";
break;
default:
rank = pack.selfStats.rank + "th";
break;
}
embedBuilder.addField("Your stats:", rank + " with " + pack.selfStats.total + " points", false);
embedBuilder.addField("More stats:", "https://" + MainBot.url+"/rank", false);
return EmbedMessageUtils.buildStandar(embedBuilder);
}
public static class VoicePresenceCounter extends Thread{ public static class VoicePresenceCounter extends Thread{
private Member member; private Member member;
public VoicePresenceCounter(Member member){ public VoicePresenceCounter(Member member){