Adding flush and change admin detection

This commit is contained in:
Unknown 2017-10-04 09:54:25 +02:00
parent 9fd52e65ad
commit ff6733cb52
5 changed files with 90 additions and 7 deletions

View File

@ -0,0 +1,72 @@
package net.Broken.Commandes;
import net.Broken.Commande;
import net.Broken.Outils.EmbedMessageUtils;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.MessageHistory;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
public class Flush implements Commande{
Logger logger = LogManager.getLogger();
@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return true;
}
@Override
public void action(String[] args, MessageReceivedEvent event) {
if(args.length<1){
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Argument manquant!")).queue();
}
else
{
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){
try {
int limit = Integer.parseInt(args[0]);
MessageChannel chanel = event.getChannel();
MessageHistory history = chanel.getHistoryAround(chanel.getLatestMessageIdLong(), 100).complete();
logger.debug(history.getRetrievedHistory().size());
List<Message> retrieved = history.getRetrievedHistory();
if(limit > retrieved.size())
limit = retrieved.size()-1;
for(int i = 0; i<limit+1; i++){
logger.debug(retrieved.get(i).getContent());
retrieved.get(i).delete().queue();
}
}catch (NumberFormatException e){
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("L'argument n'est pas valide!")).queue();
}
}
else
{
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Vous n'avez pas l'autorisation de faire ça!")).queue();
}
}
}
@Override
public String help(String[] args) {
return "`//flush <nbr>`\n:arrow_right:\t*Efface les n derniers messages (Max = 100)*";
}
@Override
public void executed(boolean success, MessageReceivedEvent event) {
}
@Override
public boolean isPrivateUsable() {
return false;
}
}

View File

@ -3,6 +3,7 @@ package net.Broken.Commandes;
import net.Broken.Commande;
import net.Broken.MainBot;
import net.Broken.Outils.EmbedMessageUtils;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.HierarchyException;
@ -109,7 +110,7 @@ public class Move implements Commande {
Role roleCible = roleL.get(0);
serveur=event.getGuild();
logger.info("Tentative de déplacement de "+user.getEffectiveName()+" vers "+roleCible.getName()+" par l'utilisateur "+event.getAuthor().getName());
if(event.getMember().getRoles().contains(serveur.getRolesByName("Big_Daddy",false).get(0)))
if(event.getMember().hasPermission(Permission.ADMINISTRATOR))
{
logger.info("Autorisation suffisante, deplacement autorisé");
@ -134,7 +135,7 @@ public class Move implements Commande {
else
{
logger.info("Autorisation insuffisante, deplacement refusé");
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Vous n'avez pas l'autorisation de faire ca!")).queue();
event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Vous n'avez pas l'autorisation de faire ça!")).queue();
}
}

View File

@ -5,6 +5,7 @@ import net.Broken.MainBot;
import net.Broken.Outils.AntiSpam;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.UserSpamUtils;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
@ -120,7 +121,7 @@ public class Spam implements Commande {
* c'est un big dady *
****************************/
if (event.getMember().getRoles().get(0)==serveur.getRolesByName("Big_Daddy",false).get(0)) {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){
logger.info("Autorisation suffisante, pardon autorisé");
/****************************
@ -185,7 +186,7 @@ public class Spam implements Commande {
* c'est un big dady *
****************************/
if(event.getMember().getRoles().get(0)==serveur.getRolesByName("Big_Daddy",false).get(0))
if(event.getMember().hasPermission(Permission.ADMINISTRATOR))
{
logger.info("Autorisation suffisante, extermination autorisé");
String multiStr =args[2];
@ -260,7 +261,7 @@ public class Spam implements Commande {
* c'est un big dady *
****************************/
if ( event.getMember().getRoles().get(0) == serveur.getRolesByName("Big_Daddy", false).get(0)) {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){
logger.info("Autorisation suffisante, pardon autorisé");
/****************************
* verif utilisteur trouver *
@ -273,7 +274,7 @@ public class Spam implements Commande {
}
} else {
logger.warn("Autorisation insuffisante, reset refusé");
event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ca!")).queue();
event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).queue();
}
}

View File

@ -104,6 +104,8 @@ public class MainBot {
commandes.put("help",new Help());
commandes.put("move", new Move());
commandes.put("spam", new Spam());
commandes.put("spaminfo",new SpamInfo());
commandes.put("flush",new Flush());
if(!dev){
commandes.put("ass",new Ass());
@ -116,7 +118,7 @@ public class MainBot {
commandes.put("madame",new Madame());
commandes.put("cat",new Cat());
}
commandes.put("spaminfo",new SpamInfo());
//On recupere le l'id serveur

View File

@ -50,4 +50,11 @@ public class EmbedMessageUtils {
public static MessageEmbed getSpamInfo(String message) {
return new EmbedBuilder().setTitle(":hourglass: Spam Info :hourglass:").setDescription(message).setColor(Color.green).setFooter("'//help spaminfo' pour plus d'info ", null).build();
}
public static MessageEmbed getFlushError(String message) {
return new EmbedBuilder().setTitle(":warning: Flush Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help flush' pour plus d'info ", null).build();
}
}