Merge branch 'master' into develop
This commit is contained in:
commit
bc708fdc70
@ -16,29 +16,42 @@ 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);
|
||||||
|
int charCtl = 0;
|
||||||
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 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (charCtl != 0)
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user