From 00f0c04f379b09758eab302ccaa42a436d6f18c3 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Oct 2017 10:45:45 +0200 Subject: [PATCH] Adding auto Dellete of spaminfo message --- src/net/Broken/Commandes/SpamInfo.java | 61 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/net/Broken/Commandes/SpamInfo.java b/src/net/Broken/Commandes/SpamInfo.java index 8396ae3..62e04fc 100644 --- a/src/net/Broken/Commandes/SpamInfo.java +++ b/src/net/Broken/Commandes/SpamInfo.java @@ -45,7 +45,7 @@ public class SpamInfo implements Commande{ Message message = null; if(!MainBot.spamUtils.containsKey(user)){ if(!event.isFromType(ChannelType.PRIVATE)) - event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).queue(); + message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).complete(); else PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger); } @@ -53,7 +53,7 @@ public class SpamInfo implements Commande{ UserSpamUtils util = MainBot.spamUtils.get(user); if(!util.isOnSpam()){ if(!event.isFromType(ChannelType.PRIVATE)) - event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).queue(); + message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); else PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger); } @@ -68,21 +68,21 @@ public class SpamInfo implements Commande{ if(threadHashMap.containsKey(user)){ MessageUpdater startedThread = threadHashMap.get(user); if(!message.getChannelType().equals(startedThread.message.getChannelType())){ - MessageUpdater newThread = new MessageUpdater(message,MainBot.spamUtils.get(user),user); + MessageUpdater newThread = new MessageUpdater(message,event.getMessage(),MainBot.spamUtils.get(user),user); threadHashMap.put(user,newThread); newThread.start(); } else { threadHashMap.get(user).stop = true; - MessageUpdater newThread = new MessageUpdater(message,MainBot.spamUtils.get(user),user); + MessageUpdater newThread = new MessageUpdater(message,event.getMessage(),MainBot.spamUtils.get(user),user); threadHashMap.replace(user, newThread); newThread.start(); } } else { - MessageUpdater newThread = new MessageUpdater(message,MainBot.spamUtils.get(user),user); + MessageUpdater newThread = new MessageUpdater(message,event.getMessage(),MainBot.spamUtils.get(user),user); threadHashMap.put(user, newThread); newThread.start(); } @@ -138,39 +138,58 @@ public class SpamInfo implements Commande{ private class MessageUpdater extends Thread{ public Message message; + public Message command; public UserSpamUtils util; public boolean stop; private int oldValue; private User user; - public MessageUpdater(Message message, UserSpamUtils util,User user) { + public MessageUpdater(Message message,Message command, UserSpamUtils util,User user) { this.message = message; this.util = util; this.user = user; + this.command = command; + } @Override public void run() { logger.debug("Start "+user.getName()+" theard!"); - oldValue = util.getTimeLeft(); - while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){ - try { - Thread.sleep(500); - if(util.getTimeLeft()%5 == 0 && oldValue - util.getTimeLeft() >= 5){ - message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); - oldValue = util.getTimeLeft(); - } + if(util != null){ + oldValue = util.getTimeLeft(); + while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){ + try { + Thread.sleep(500); + if(util.getTimeLeft()%5 == 0 && oldValue - util.getTimeLeft() >= 5){ + message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete(); + oldValue = util.getTimeLeft(); + } - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + logger.debug("Kill "+user.getName()+" theard!"); + if(stop) + message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete(); + else + message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); + } - logger.debug("Kill "+user.getName()+" theard!"); - if(stop) - message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete(); - else - message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete(); + logger.debug("Timer for message deletion of "+user.getName()+" stated..."); threadHashMap.remove(user); + try { + Thread.sleep(15000); + logger.debug("Delete "+user.getName()+" messages"); + message.delete().queue(); + command.delete().queue(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + + + } } }