✏️ Reformat result of command 'channelsReview'
This commit is contained in:
parent
e906b70670
commit
7c363f2fed
@ -8,35 +8,38 @@ import net.dv8tion.jda.api.entities.TextChannel;
|
|||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
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.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
||||||
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class ChannelsReview implements Commande {
|
public class ChannelsReview implements Commande {
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
StringBuilder messageToSend= new StringBuilder();
|
HashMap<String, String> result = new HashMap<>();
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy").withLocale(Locale.ENGLISH);
|
||||||
for( TextChannel textChannel: event.getGuild().getTextChannels()){
|
for( TextChannel textChannel: event.getGuild().getTextChannels()){
|
||||||
if(textChannel.hasLatestMessage()){
|
if(textChannel.hasLatestMessage()){
|
||||||
String lastMessageId = textChannel.getLatestMessageId();
|
String lastMessageId = textChannel.getLatestMessageId();
|
||||||
logger.debug("Last message in chanel " + textChannel.toString() + " is " + lastMessageId );
|
logger.debug("Last message in chanel " + textChannel.toString() + " is " + lastMessageId );
|
||||||
try {
|
try {
|
||||||
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
||||||
String date = lastMessage.getTimeCreated().toLocalDate().format(formatter);
|
String date = lastMessage.getTimeCreated().format(formatter);
|
||||||
messageToSend.append("\nChannel : ").append(textChannel.getName()).append(" Date :").append(date);
|
result.put(textChannel.getName(), date);
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.warn("Can't find message with id: " + lastMessageId);
|
logger.warn("Can't find message with id: " + lastMessageId);
|
||||||
messageToSend.append("\nChannel : ERROR");
|
result.put(textChannel.getName(), "ERROR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
messageToSend.append("\nChannel : ").append(textChannel.getName()).append(" was never used.");
|
result.put(textChannel.getName(), "No message or access denied.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(messageToSend.toString())).queue();
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,6 +13,8 @@ import java.io.FileNotFoundException;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre build Message Embed
|
* Pre build Message Embed
|
||||||
@ -108,8 +110,12 @@ public class EmbedMessageUtils {
|
|||||||
return new EmbedBuilder().setTitle("Bot Command ("+role+")").setDescription(message).setFooter("Use '//help <command>' for more info",MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).setColor(Color.green).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build();
|
return new EmbedBuilder().setTitle("Bot Command ("+role+")").setDescription(message).setFooter("Use '//help <command>' 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) {
|
public static MessageEmbed getLastMessageFromTextChannel(HashMap<String, String> message) {
|
||||||
EmbedBuilder temp = new EmbedBuilder().setTitle("Channel uses checker").setDescription(message).setColor(Color.green);
|
EmbedBuilder temp = new EmbedBuilder().setTitle("Channel uses checker").setDescription("Last message date for channels:").setColor(Color.green);
|
||||||
|
for(Map.Entry<String, String> entry : message.entrySet()) {
|
||||||
|
temp.addField(entry.getKey(),entry.getValue(), false);
|
||||||
|
}
|
||||||
|
|
||||||
return buildStandar(temp);
|
return buildStandar(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user