Add rank page for test

This commit is contained in:
Sebastien 2018-12-31 16:26:18 +01:00
parent ecd5ed31a3
commit 84d626dad6
5 changed files with 152 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package net.Broken.Commands.Over18; package net.Broken.Commands.Over18;
import net.Broken.Commande; import net.Broken.Commande;
import net.Broken.Tools.Command.NoDev;
import net.Broken.Tools.Command.NumberedCommande; import net.Broken.Tools.Command.NumberedCommande;
import net.Broken.Tools.EmbedMessageUtils; import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.FindContentOnWebPage; import net.Broken.Tools.FindContentOnWebPage;
@ -16,6 +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
public class Madame extends NumberedCommande { public class Madame extends NumberedCommande {
Logger logger = LogManager.getLogger(); Logger logger = LogManager.getLogger();
MessageReceivedEvent event; MessageReceivedEvent event;

View File

@ -2,6 +2,7 @@ package net.Broken.Tools.UserManager.Stats;
public class GuildStats{ public class GuildStats{
public String userName; public String userName;
public String avatarUrl;
public long voiceTime; public long voiceTime;
public long voiceXp; public long voiceXp;
@ -18,8 +19,9 @@ public class GuildStats{
public GuildStats() { public GuildStats() {
} }
public GuildStats(String userName, long voiceTime, long messageCount, long apiCount) { public GuildStats(String userName, String avatarUrl, long voiceTime, long messageCount, long apiCount) {
this.userName = userName; this.userName = userName;
this.avatarUrl = avatarUrl;
this.voiceTime = voiceTime; this.voiceTime = voiceTime;
this.messageCount = messageCount; this.messageCount = messageCount;
this.apiCount = apiCount; this.apiCount = apiCount;

View File

@ -166,7 +166,8 @@ public class UserStatsUtils {
List<UserStats> allStats = userStatsRepository.findByGuildId(guildId); List<UserStats> allStats = userStatsRepository.findByGuildId(guildId);
List<GuildStats> ranked = new ArrayList<>(); List<GuildStats> ranked = new ArrayList<>();
for(UserStats stats : allStats){ for(UserStats stats : allStats){
GuildStats temp = new GuildStats(stats.getUser().getName(), stats.getVocalTime(), stats.getMessageCount(), stats.getApiCommandCount()); String avatar = MainBot.jda.getUserById(stats.getUser().getJdaId()).getAvatarUrl();
GuildStats temp = new GuildStats(stats.getUser().getName(), avatar, stats.getVocalTime(), stats.getMessageCount(), stats.getApiCommandCount());
if(stats.getUser().getId().equals(userEntity.getId())){ if(stats.getUser().getId().equals(userEntity.getId())){
selfGuildStats = temp; selfGuildStats = temp;
} }

View File

@ -5,6 +5,8 @@ import net.Broken.DB.Repository.UserRepository;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.Tools.SettingsUtils; import net.Broken.Tools.SettingsUtils;
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException; import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
import net.Broken.Tools.UserManager.Stats.GuildStatsPack;
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
import net.Broken.Tools.UserManager.UserUtils; import net.Broken.Tools.UserManager.UserUtils;
import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.User;
@ -16,8 +18,14 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -66,11 +74,7 @@ public class GeneralWebView {
model.addAttribute("noMutualGuilds", true); model.addAttribute("noMutualGuilds", true);
else else
model.addAttribute("noMutualGuilds", false); model.addAttribute("noMutualGuilds", false);
Guild guild = MainBot.jda.getGuildById(guildId); addGuildAndRedirect(model, guildId);
if(guild != null)
model.addAttribute("guild_name", guild.getName());
else
model.addAttribute("guild_name", "");
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId)); model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
model.addAttribute("isLogged", true); model.addAttribute("isLogged", true);
model.addAttribute("inviteLink", "https://discordapp.com/oauth2/authorize?client_id=" + MainBot.jda.getSelfUser().getId() + "&scope=bot&permissions=8"); model.addAttribute("inviteLink", "https://discordapp.com/oauth2/authorize?client_id=" + MainBot.jda.getSelfUser().getId() + "&scope=bot&permissions=8");
@ -122,12 +126,8 @@ public class GeneralWebView {
public String settings(Model model, @CookieValue(value = "guild", defaultValue = "") String guildId, @CookieValue(value = "token", defaultValue = "") String token){ public String settings(Model model, @CookieValue(value = "guild", defaultValue = "") String guildId, @CookieValue(value = "token", defaultValue = "") String token){
SettingsUtils settingsUtils = SettingsUtils.getInstance(); SettingsUtils settingsUtils = SettingsUtils.getInstance();
if(settingsUtils.checkPermission(token, guildId)){ if(settingsUtils.checkPermission(token, guildId)){
addGuildAndRedirect(model, guildId);
Guild guild = MainBot.jda.getGuildById(guildId); Guild guild = MainBot.jda.getGuildById(guildId);
if(guild != null)
model.addAttribute("guild_name", guild.getName());
else
model.addAttribute("guild_name", "");
model.addAttribute("redirect_url", System.getenv("OAUTH_URL"));
model.addAttribute("settings", SettingsUtils.getInstance().extractSettings(guild)); model.addAttribute("settings", SettingsUtils.getInstance().extractSettings(guild));
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId)); model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
@ -152,12 +152,36 @@ public class GeneralWebView {
@RequestMapping("/500") @RequestMapping("/rank")
public String errorTest(Model model){ public String login(Model model, @CookieValue(value = "token") String token, @CookieValue(value = "guild", defaultValue = "") String cookieGuildId, @RequestParam(value = "guild", defaultValue = "") String praramGuildId){
return "error/500"; model.addAttribute("redirect_url", System.getenv("OAUTH_URL"));
try {
UserEntity userEntity = userUtils.getUserWithApiToken(userRepository, token);
addGuildAndRedirect(model, cookieGuildId);
GuildStatsPack stack = UserStatsUtils.getINSTANCE().getStatPack(userEntity, cookieGuildId);
model.addAttribute("stack", stack);
return CheckPage.getPageIfReady("rank");
} catch (UnknownTokenException e) {
return "login"; // TODO Public rank
}
} }
private Model addGuildAndRedirect(Model model, String guildId){
Guild guild = MainBot.jda.getGuildById(guildId);
if(guild != null)
model.addAttribute("guild_name", guild.getName());
else
model.addAttribute("guild_name", "");
model.addAttribute("redirect_url", System.getenv("OAUTH_URL"));
return model;
}
} }

View File

@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<title>Claptrap Bot</title>
<link rel="icon"
type="image/x-icon"
href="/favicon.png"/>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link rel="manifest" href="/manifest.json"/>
<meta name="theme-color" content="#263238"/>
<style>
tr{
border-color: #fbcf40;
}
h4 span{
color: #fbcf40;
font-size: 15px;
font-weight: normal;
}
</style>
</head>
<body class="blue-grey lighten-5">
<!--/*@thymesVar id="guild_name" type="java.lang.String"*/-->
<!--/*@thymesVar id="redirect_url" type="java.lang.String"*/-->
<!--/*@thymesVar id="isAdmin" type="java.lang.Boolean"*/-->
<header>
<div th:replace="header :: header ('rank',${guild_name}, ${isAdmin})">...</div>
</header>
<main>
<!--/*@thymesVar id="stack" type="net.Broken.Tools.UserManager.Stats.GuildStatsPack"*/-->
<div class="row">
<div class="card-panel col m6 offset-m3 s10 offset-s1 grey darken-4 white-text">
<div class="row" style="margin-bottom: 0">
<div class="col s12 center" style="margin-top: 10px">
<img class="circle" th:src="${stack.selfStats.avatarUrl}" style="border-color: green; border-style: solid;"/>
</div>
<div class="col s12 center">
<h4 style="font-weight: bold; margin: 0;" th:text="${stack.selfStats.userName}"></h4>
</div>
</div>
<div class="row">
<div class="col s6 center">
<table class="centered">
<thead>
<tr>
<th>Rank</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<h4 style="font-weight: bold; margin: 0"><span th:text="${stack.rank}" th:remove="tag"></span> <span th:text="${' / ' + stack.ranking.size()}">/ 50</span></h4>
</td>
</tr>
</tbody>
</table>
</div>
<div class="col s6 center">
<table class="centered">
<thead>
<tr>
<th>Experience</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<h4 style="font-weight: bold; margin: 0"><span th:text="${stack.selfStats.total}" th:remove="tag"></span> <span>Xp</span></h4>
</td>
</tr>
</tbody>
</table> </div>
</div>
</div>
</div>
</main>
<footer class="page-footer" style="padding: 0">
<div th:replace="footer :: footer">...</div>
</footer>
<!-- Scripts-->
<script th:src="@{/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{/js/materialize.js}"></script>
<script th:src="@{/js/navabar.js}"></script>
<script th:src="@{/js/js.cookie.js}"></script>
<!--<script th:src="@{/js/rank.js}"></script>-->
<script th:src="@{/js/fontawesome.js}"></script>
<script th:src="@{/js/workerRegister.js}"></script>
</body>
</html>