From 62130b8506cc9a050d2949d08b083523c1c295b8 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sun, 29 Apr 2018 18:42:34 +0200 Subject: [PATCH] Some improvement --- src/main/java/net/Broken/Commands/Help.java | 43 ++++++++++--------- .../Broken/Tools/DayListener/DayListener.java | 4 +- src/main/resources/templates/header.html | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/Broken/Commands/Help.java b/src/main/java/net/Broken/Commands/Help.java index f4b14f9..c842d8c 100644 --- a/src/main/java/net/Broken/Commands/Help.java +++ b/src/main/java/net/Broken/Commands/Help.java @@ -37,8 +37,10 @@ public class Help implements Commande { //System.out.println(argsString); if (MainBot.commandes.containsKey(argsString)) { + + Commande cmdObj = MainBot.commandes.get(argsString); - if(!cmdObj.isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR)) + if(!cmdObj.isAdminCmd() || isAdmin(event)) { logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName()); MessageEmbed messageEmbed; @@ -119,25 +121,8 @@ public class Help implements Commande { nsfwTable.setHeader("NSFW Only\u00A0", "PU"); List noPu = new ArrayList<>(); - boolean isAdmin; - if(event.isFromType(ChannelType.PRIVATE)){ - isAdmin = false; - List guilds = event.getAuthor().getMutualGuilds(); - for(Guild iterator : guilds){ - if(iterator.getMember(event.getAuthor()).hasPermission(Permission.ADMINISTRATOR)){ - isAdmin = true; - break; - } - - } - - } - else - isAdmin = event.getMember().hasPermission(Permission.ADMINISTRATOR); - - for (Map.Entry e : MainBot.commandes.entrySet()) { - if(!e.getValue().isAdminCmd() || isAdmin){ + if(!e.getValue().isAdminCmd() || isAdmin(event)){ if(e.getValue().isPrivateUsable()) table.addRow(e.getKey(), "XX"); else if(e.getValue().isNSFW()) @@ -163,7 +148,7 @@ public class Help implements Commande { String role; - if(isAdmin) + if(isAdmin(event)) role = "Admin"; else role = "Non Admin"; @@ -196,4 +181,22 @@ public class Help implements Commande { public boolean isNSFW() { return false; } + + + public boolean isAdmin(MessageReceivedEvent event){ + + if(event.isFromType(ChannelType.PRIVATE)){ + List guilds = event.getAuthor().getMutualGuilds(); + for(Guild iterator : guilds){ + if(iterator.getMember(event.getAuthor()).hasPermission(Permission.ADMINISTRATOR)){ + return true; + } + + } + + } + else + return event.getMember().hasPermission(Permission.ADMINISTRATOR); + return false; + } } diff --git a/src/main/java/net/Broken/Tools/DayListener/DayListener.java b/src/main/java/net/Broken/Tools/DayListener/DayListener.java index 2c6162e..ca39ce7 100644 --- a/src/main/java/net/Broken/Tools/DayListener/DayListener.java +++ b/src/main/java/net/Broken/Tools/DayListener/DayListener.java @@ -65,8 +65,8 @@ public class DayListener extends Thread { @Override public void run() { while(true) - { calendar = Calendar.getInstance(); - logger.debug(calendar.get(GregorianCalendar.DAY_OF_MONTH)+"/"+previousDay); + { + calendar = Calendar.getInstance(); if(calendar.get(GregorianCalendar.DAY_OF_MONTH) != previousDay) { LogManager.getLogger().info("New day triggered!"); diff --git a/src/main/resources/templates/header.html b/src/main/resources/templates/header.html index 8044dd5..ce7aae9 100644 --- a/src/main/resources/templates/header.html +++ b/src/main/resources/templates/header.html @@ -132,7 +132,7 @@