Change flush method

This commit is contained in:
Sebastien 2018-12-04 17:16:41 +02:00
parent be84a0a1ad
commit ef01ed691e

View File

@ -29,16 +29,12 @@ public class Flush implements Commande{
{ {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){
try { try {
int limit = Integer.parseInt(args[0]); int limit = Integer.parseInt(args[0]) + 1;
MessageChannel chanel = event.getChannel(); MessageChannel chanel = event.getChannel();
MessageHistory history = chanel.getHistoryAround(chanel.getLatestMessageIdLong(), 100).complete();
List<Message> retrieved = history.getRetrievedHistory(); chanel.getIterableHistory().takeAsync(limit).thenAccept(chanel::purgeMessages);
if(limit > retrieved.size())
limit = retrieved.size()-1;
for(int i = 0; i<limit+1; i++){
logger.debug(retrieved.get(i).getContentRaw());
retrieved.get(i).delete().queue();
}
}catch (NumberFormatException e){ }catch (NumberFormatException e){
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("L'argument n'est pas valide!")).queue(); event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("L'argument n'est pas valide!")).queue();
} }