diff --git a/src/main/java/net/Broken/Commands/ChannelsReview.java b/src/main/java/net/Broken/Commands/ChannelsReview.java new file mode 100644 index 0000000..6307a35 --- /dev/null +++ b/src/main/java/net/Broken/Commands/ChannelsReview.java @@ -0,0 +1,66 @@ +package net.Broken.Commands; + +import net.Broken.Commande; +import net.Broken.Tools.EmbedMessageUtils; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.MessageHistory; +import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.time.format.DateTimeFormatter; + +public class ChannelsReview implements Commande { + Logger logger = LogManager.getLogger(); + @Override + public void action(String[] args, MessageReceivedEvent event) { + StringBuilder messageToSend= new StringBuilder(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy"); + for( TextChannel textChannel: event.getGuild().getTextChannels()){ + if(textChannel.hasLatestMessage()){ + String lastMessageId = textChannel.getLatestMessageId(); + logger.debug("Last message in chanel " + textChannel.toString() + " is " + lastMessageId ); + try { + Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete(); + String date = lastMessage.getTimeCreated().toLocalDate().format(formatter); + messageToSend.append("\nChannel : ").append(textChannel.getName()).append(" Date :").append(date); + }catch (RuntimeException e){ + logger.warn("Can't find message with id: " + lastMessageId); + messageToSend.append("\nChannel : ERROR"); + } + + + } + else{ + messageToSend.append("\nChannel : ").append(textChannel.getName()).append(" was never used."); + } + } + event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(messageToSend.toString())).queue(); + } + + @Override + public boolean isPrivateUsable() { + return false; + } + + @Override + public boolean isAdminCmd() { + return true; + } + + /** + * Determines if the command is usable only by bot level admin user + * + * @return boolean + */ + @Override + public boolean isBotAdminCmd() { + return false; + } + + @Override + public boolean isNSFW() { + return false; + } +} diff --git a/src/main/java/net/Broken/Init.java b/src/main/java/net/Broken/Init.java index 0b45904..1636848 100644 --- a/src/main/java/net/Broken/Init.java +++ b/src/main/java/net/Broken/Init.java @@ -112,11 +112,11 @@ public class Init { List users = (List) userRepository.findAll(); UserStatsUtils userStatsUtils = UserStatsUtils.getINSTANCE(); logger.debug("Stats..."); - for (UserEntity userEntity : users) { - logger.debug("..." + userEntity.getName()); - userStatsUtils.getUserStats(userEntity); - - } +// for (UserEntity userEntity : users) { +// logger.debug("..." + userEntity.getName()); +// userStatsUtils.getUserStats(userEntity); +// +// } } diff --git a/src/main/java/net/Broken/Tools/EmbedMessageUtils.java b/src/main/java/net/Broken/Tools/EmbedMessageUtils.java index 23a504a..0a90dad 100644 --- a/src/main/java/net/Broken/Tools/EmbedMessageUtils.java +++ b/src/main/java/net/Broken/Tools/EmbedMessageUtils.java @@ -108,6 +108,11 @@ public class EmbedMessageUtils { return new EmbedBuilder().setTitle("Bot Command ("+role+")").setDescription(message).setFooter("Use '//help ' for more info",MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).setColor(Color.green).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build(); } + public static MessageEmbed getLastMessageFromTextChannel(String message) { + EmbedBuilder temp = new EmbedBuilder().setTitle("Channel uses checker").setDescription(message).setColor(Color.green); + return buildStandar(temp); + } + public static MessageEmbed searchResult(SearchResult result){ EmbedBuilder builder = new EmbedBuilder() .setColor(Color.CYAN) diff --git a/src/main/resources/Help/ChannelsReview/en/main.md b/src/main/resources/Help/ChannelsReview/en/main.md new file mode 100644 index 0000000..45ec863 --- /dev/null +++ b/src/main/resources/Help/ChannelsReview/en/main.md @@ -0,0 +1,2 @@ +This command allow you to see which text channel is used by +returning the date from the last message sent in every text channel. \ No newline at end of file diff --git a/src/main/resources/Help/ChannelsReview/fr/main.md b/src/main/resources/Help/ChannelsReview/fr/main.md new file mode 100644 index 0000000..e06d5e9 --- /dev/null +++ b/src/main/resources/Help/ChannelsReview/fr/main.md @@ -0,0 +1,3 @@ +Cette commande permet de verifier quels channels textes ne sont +pas utilisés en remontant la date du dernier message envoyé +dans tout les channels. \ No newline at end of file