implement BotAdmin privilege
This commit is contained in:
parent
b05401777c
commit
f4b99c0061
@ -2,7 +2,9 @@ package net.Broken;
|
||||
|
||||
import net.Broken.Commands.Move;
|
||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.Tools.AntiSpam;
|
||||
import net.Broken.Tools.Command.CommandParser;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
@ -38,6 +40,7 @@ public class BotListener extends ListenerAdapter {
|
||||
private Moderateur modo = new Moderateur();
|
||||
|
||||
private GuildPreferenceRepository guildPreferenceRepository;
|
||||
private UserRepository userRepository;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
@ -45,6 +48,7 @@ public class BotListener extends ListenerAdapter {
|
||||
|
||||
ApplicationContext context = SpringContext.getAppContext();
|
||||
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||
userRepository = (UserRepository) context.getBean("userRepository");
|
||||
|
||||
}
|
||||
|
||||
@ -157,7 +161,9 @@ public class BotListener extends ListenerAdapter {
|
||||
if (event.getMessage().getContentRaw().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
//On a detecter que c'etait une commande
|
||||
//System.out.println(event.getMessage().getContent());
|
||||
MainBot.handleCommand(new CommandParser().parse(event.getMessage().getContentRaw(), event));
|
||||
List<UserEntity> users = userRepository.findByJdaId(event.getAuthor().getId());
|
||||
UserEntity user = users.size() == 0 ? null : users.get(0);
|
||||
MainBot.handleCommand(new CommandParser().parse(event.getMessage().getContentRaw(), event), user);
|
||||
|
||||
}
|
||||
else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
|
||||
|
@ -26,6 +26,12 @@ public interface Commande {
|
||||
*/
|
||||
boolean isAdminCmd();
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
* @return boolean
|
||||
*/
|
||||
boolean isBotAdminCmd();
|
||||
|
||||
/**
|
||||
* Determines if the command is only usable on NSFW channels
|
||||
* @return boolean
|
||||
|
@ -56,6 +56,16 @@ public class Cat implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -3,14 +3,41 @@ package net.Broken.Commands;
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyShell;
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.SpringContext;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
import net.Broken.Tools.MessageTimeOut;
|
||||
import net.Broken.Tools.PrivateMessage;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
|
||||
public class Code implements Commande {
|
||||
|
||||
private UserRepository userRepository;
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
public Code (){
|
||||
ApplicationContext context = SpringContext.getAppContext();
|
||||
userRepository = (UserRepository) context.getBean("userRepository");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(String arg : args){
|
||||
stringBuilder.append(arg);
|
||||
@ -61,6 +88,16 @@ public class Code implements Commande {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -31,6 +31,16 @@ public class DayTrigger implements Commande{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -59,6 +59,16 @@ public class Flush implements Commande{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -160,6 +160,16 @@ public class Help implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -26,6 +26,16 @@ public class Invite implements Commande{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -31,6 +31,16 @@ public class ListRoles implements Commande {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -190,6 +190,16 @@ public class Move implements Commande {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -165,6 +165,16 @@ public class Music implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -30,6 +30,16 @@ public class Ass extends NumberedCommande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -28,6 +28,16 @@ public class Boobs extends NumberedCommande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -38,6 +38,16 @@ public class Madame extends NumberedCommande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -28,6 +28,16 @@ public class Pipe extends NumberedCommande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -40,6 +40,16 @@ public class SM implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -69,6 +69,16 @@ public class Suicide implements Commande{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
|
@ -37,6 +37,16 @@ public class Ping implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -23,6 +23,16 @@ public class Rank implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -56,6 +56,16 @@ public class Settings implements Commande {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -81,6 +81,16 @@ public class Spam implements Commande {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -101,6 +101,16 @@ public class SpamInfo implements Commande{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -58,6 +58,16 @@ public class YtSearch implements Commande {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the command is usable only by bot level admin user
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isBotAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
|
@ -25,6 +25,8 @@ public class UserEntity {
|
||||
|
||||
private String apiToken;
|
||||
|
||||
private boolean isBotAdmin = false;
|
||||
|
||||
@JsonIgnore
|
||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
|
||||
private List<UserStats> userStats;
|
||||
@ -124,4 +126,12 @@ public class UserEntity {
|
||||
public void setUserStats(List<UserStats> userStats) {
|
||||
this.userStats = userStats;
|
||||
}
|
||||
|
||||
public boolean isBotAdmin() {
|
||||
return isBotAdmin;
|
||||
}
|
||||
|
||||
public void setBotAdmin(boolean botAdmin) {
|
||||
isBotAdmin = botAdmin;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Broken;
|
||||
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.Tools.Command.CommandParser;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
import net.Broken.Tools.MessageTimeOut;
|
||||
@ -85,7 +86,7 @@ public class MainBot {
|
||||
* Perform test (admin, NSFW and private usable or not) and execute command or not
|
||||
* @param cmd Container whit all command info
|
||||
*/
|
||||
public static void handleCommand(CommandParser.CommandContainer cmd)
|
||||
public static void handleCommand(CommandParser.CommandContainer cmd, UserEntity user)
|
||||
{
|
||||
|
||||
if(!ready)
|
||||
@ -98,39 +99,42 @@ public class MainBot {
|
||||
{
|
||||
Commande cmdObj = commandes.get(cmd.commande);
|
||||
boolean isAdmin;
|
||||
boolean isBotAdmin = user != null && user.isBotAdmin();
|
||||
if(cmd.event.isFromType(ChannelType.PRIVATE)){
|
||||
isAdmin = false;
|
||||
}
|
||||
else
|
||||
isAdmin = cmd.event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||
|
||||
if(!cmdObj.isAdminCmd() || isAdmin){
|
||||
if((!cmdObj.isAdminCmd() || isAdmin) && (!cmdObj.isBotAdminCmd() || isBotAdmin)){
|
||||
|
||||
if(cmd.event.isFromType(ChannelType.PRIVATE) && commandes.get(cmd.commande).isPrivateUsable())
|
||||
{
|
||||
if(cmd.event.isFromType(ChannelType.PRIVATE) && commandes.get(cmd.commande).isPrivateUsable())
|
||||
{
|
||||
|
||||
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||
}
|
||||
else if (!cmd.event.isFromType(ChannelType.PRIVATE))
|
||||
{
|
||||
if(!cmdObj.isNSFW() || cmd.event.getTextChannel().isNSFW()){
|
||||
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||
}
|
||||
else{
|
||||
cmd.event.getMessage().delete().queue();
|
||||
}
|
||||
else if (!cmd.event.isFromType(ChannelType.PRIVATE))
|
||||
{
|
||||
if(!cmdObj.isNSFW() || cmd.event.getTextChannel().isNSFW()){
|
||||
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||
}
|
||||
else{
|
||||
cmd.event.getMessage().delete().queue();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
|
||||
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
|
||||
}
|
||||
else{
|
||||
if(cmd.event.isFromType(ChannelType.PRIVATE)){
|
||||
PrivateMessage.send(cmd.event.getAuthor(),EmbedMessageUtils.getUnautorized(), logger);
|
||||
}
|
||||
else{
|
||||
Message msg = cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
||||
new MessageTimeOut(gifMessageTimeOut, msg, cmd.event.getMessage()).start();
|
||||
cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user