🚑 Fix Char > 6000 for ChannelsReview
This commit is contained in:
parent
8c57423d4d
commit
4a0a47a397
@ -16,30 +16,43 @@ 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) {
|
||||||
HashMap<String, String> result = new HashMap<>();
|
HashMap<String, String> result = new HashMap<>();
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy").withLocale(Locale.ENGLISH);
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy").withLocale(Locale.ENGLISH);
|
||||||
for( TextChannel textChannel: event.getGuild().getTextChannels()){
|
int charCtl = 0;
|
||||||
if(textChannel.hasLatestMessage()){
|
for (TextChannel textChannel : event.getGuild().getTextChannels()) {
|
||||||
|
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 channel " + textChannel.toString() + " is " + lastMessageId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
||||||
String date = lastMessage.getTimeCreated().format(formatter);
|
String date = lastMessage.getTimeCreated().format(formatter);
|
||||||
|
charCtl += textChannel.getName().length() + date.length();
|
||||||
result.put(textChannel.getName(), 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);
|
||||||
result.put(textChannel.getName(), "ERROR");
|
result.put(textChannel.getName(), "ERROR");
|
||||||
|
charCtl += textChannel.getName().length() + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
} else {
|
||||||
result.put(textChannel.getName(), "No message or access denied.");
|
result.put(textChannel.getName(), "No message or access denied.");
|
||||||
|
charCtl += textChannel.getName().length() + 30;
|
||||||
|
}
|
||||||
|
if (charCtl > 3000) {
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
||||||
|
event.getTextChannel().sendTyping().queue();
|
||||||
|
result = new HashMap<>();
|
||||||
|
charCtl = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
if (charCtl != 0)
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user