Added args to send back only before a date in channelsreview
This commit is contained in:
parent
bc708fdc70
commit
cd4a64f864
@ -10,7 +10,11 @@ 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 org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -19,6 +23,57 @@ public class ChannelsReview implements Commande {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
DateFormat format = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
|
event.getTextChannel().sendMessage("Number of channels found in total : " + event.getGuild().getTextChannels().size()).queue();
|
||||||
|
if(args.length>=1){
|
||||||
|
try {
|
||||||
|
SendBackBefore(format.parse(args[0]), event, format );
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.warn("Can't parse date : " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SendBack(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SendBackBefore(Date beforeDate,MessageReceivedEvent event,DateFormat format ){
|
||||||
|
HashMap<String, String> result = new HashMap<>();
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy").withLocale(Locale.ENGLISH);
|
||||||
|
int charCtl = 0;
|
||||||
|
for (TextChannel textChannel : event.getGuild().getTextChannels()) {
|
||||||
|
if (textChannel.hasLatestMessage()) {
|
||||||
|
String lastMessageId = textChannel.getLatestMessageId();
|
||||||
|
try {
|
||||||
|
Message lastMessage = textChannel.retrieveMessageById(lastMessageId).complete();
|
||||||
|
if(beforeDate.compareTo(format.parse(lastMessage.getTimeCreated().format(formatter)))>0){
|
||||||
|
logger.debug("Last message in channel " + textChannel.toString() + " is " + lastMessageId);
|
||||||
|
String date = lastMessage.getTimeCreated().format(formatter);
|
||||||
|
charCtl += textChannel.getName().length() + date.length();
|
||||||
|
result.put(textChannel.getName(), date);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException | ParseException e) {
|
||||||
|
logger.warn("Can't find message with id: " + lastMessageId);
|
||||||
|
result.put(textChannel.getName(), "ERROR");
|
||||||
|
charCtl += textChannel.getName().length() + 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
result.put(textChannel.getName(), "No message or access denied.");
|
||||||
|
charCtl += textChannel.getName().length() + 30;
|
||||||
|
}
|
||||||
|
if (charCtl > 3000) {
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).complete();
|
||||||
|
result = new HashMap<>();
|
||||||
|
charCtl = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (charCtl != 0)
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getLastMessageFromTextChannel(result)).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendBack(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;
|
int charCtl = 0;
|
||||||
@ -38,8 +93,6 @@ public class ChannelsReview implements Commande {
|
|||||||
charCtl += textChannel.getName().length() + 5;
|
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;
|
charCtl += textChannel.getName().length() + 30;
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
This command allow you to see which text channel is used by
|
This command allow you to see which text channel is used by
|
||||||
returning the date from the last message sent in every text channel.
|
returning the date from the last message sent in every text channel.
|
||||||
|
|
||||||
|
You can add a date in the format "day.month.year" to return channels
|
||||||
|
that don't have new message since this date.
|
@ -1,3 +1,6 @@
|
|||||||
Cette commande permet de verifier quels channels textes ne sont
|
Cette commande permet de verifier quels channels textes ne sont
|
||||||
pas utilisés en remontant la date du dernier message envoyé
|
pas utilisés en remontant la date du dernier message envoyé
|
||||||
dans tout les channels.
|
dans tout les channels.
|
||||||
|
|
||||||
|
Vous pouvez ajouter une date au format "jour.mois.année" pour remonter les channels
|
||||||
|
qui n'ont pas eu de message depuis avant cette date.
|
Loading…
Reference in New Issue
Block a user