Adding auto Dellete of spaminfo message
This commit is contained in:
parent
ff6733cb52
commit
00f0c04f37
@ -45,7 +45,7 @@ public class SpamInfo implements Commande{
|
|||||||
Message message = null;
|
Message message = null;
|
||||||
if(!MainBot.spamUtils.containsKey(user)){
|
if(!MainBot.spamUtils.containsKey(user)){
|
||||||
if(!event.isFromType(ChannelType.PRIVATE))
|
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
|
else
|
||||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger);
|
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);
|
UserSpamUtils util = MainBot.spamUtils.get(user);
|
||||||
if(!util.isOnSpam()){
|
if(!util.isOnSpam()){
|
||||||
if(!event.isFromType(ChannelType.PRIVATE))
|
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
|
else
|
||||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger);
|
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)){
|
if(threadHashMap.containsKey(user)){
|
||||||
MessageUpdater startedThread = threadHashMap.get(user);
|
MessageUpdater startedThread = threadHashMap.get(user);
|
||||||
if(!message.getChannelType().equals(startedThread.message.getChannelType())){
|
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);
|
threadHashMap.put(user,newThread);
|
||||||
newThread.start();
|
newThread.start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
threadHashMap.get(user).stop = true;
|
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);
|
threadHashMap.replace(user, newThread);
|
||||||
newThread.start();
|
newThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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);
|
threadHashMap.put(user, newThread);
|
||||||
newThread.start();
|
newThread.start();
|
||||||
}
|
}
|
||||||
@ -138,20 +138,24 @@ public class SpamInfo implements Commande{
|
|||||||
|
|
||||||
private class MessageUpdater extends Thread{
|
private class MessageUpdater extends Thread{
|
||||||
public Message message;
|
public Message message;
|
||||||
|
public Message command;
|
||||||
public UserSpamUtils util;
|
public UserSpamUtils util;
|
||||||
public boolean stop;
|
public boolean stop;
|
||||||
private int oldValue;
|
private int oldValue;
|
||||||
private User user;
|
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.message = message;
|
||||||
this.util = util;
|
this.util = util;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.command = command;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.debug("Start "+user.getName()+" theard!");
|
logger.debug("Start "+user.getName()+" theard!");
|
||||||
|
if(util != null){
|
||||||
oldValue = util.getTimeLeft();
|
oldValue = util.getTimeLeft();
|
||||||
while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){
|
while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){
|
||||||
try {
|
try {
|
||||||
@ -170,7 +174,22 @@ public class SpamInfo implements Commande{
|
|||||||
message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete();
|
message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete();
|
||||||
else
|
else
|
||||||
message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete();
|
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);
|
threadHashMap.remove(user);
|
||||||
|
try {
|
||||||
|
Thread.sleep(15000);
|
||||||
|
logger.debug("Delete "+user.getName()+" messages");
|
||||||
|
message.delete().queue();
|
||||||
|
command.delete().queue();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user