Format
This commit is contained in:
parent
12230218df
commit
9517a0a318
@ -9,6 +9,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|||||||
public interface Commande {
|
public interface Commande {
|
||||||
/**
|
/**
|
||||||
* Main action of command
|
* Main action of command
|
||||||
|
*
|
||||||
* @param args Command args.
|
* @param args Command args.
|
||||||
* @param event Command MessageReceivedEvent
|
* @param event Command MessageReceivedEvent
|
||||||
*/
|
*/
|
||||||
@ -16,24 +17,28 @@ public interface Commande {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the command is usable whit private message
|
* Determines if the command is usable whit private message
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean isPrivateUsable();
|
boolean isPrivateUsable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the command is usable only by admin user
|
* Determines if the command is usable only by admin user
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean isAdminCmd();
|
boolean isAdminCmd();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the command is usable only by bot level admin user
|
* Determines if the command is usable only by bot level admin user
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean isBotAdminCmd();
|
boolean isBotAdminCmd();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the command is only usable on NSFW channels
|
* Determines if the command is only usable on NSFW channels
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
boolean isNSFW();
|
boolean isNSFW();
|
||||||
|
@ -20,8 +20,7 @@ public class Cat implements Commande {
|
|||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
|
||||||
if(!event.isFromType(ChannelType.PRIVATE))
|
if (!event.isFromType(ChannelType.PRIVATE)) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
URL urlC = new URL("http://aws.random.cat/meow");
|
URL urlC = new URL("http://aws.random.cat/meow");
|
||||||
URLConnection yc = urlC.openConnection();
|
URLConnection yc = urlC.openConnection();
|
||||||
@ -40,8 +39,7 @@ public class Cat implements Commande {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
event.getPrivateChannel().sendMessage("\n:warning: **__This command cannot be used there !__** :warning:").queue();
|
event.getPrivateChannel().sendMessage("\n:warning: **__This command cannot be used there !__** :warning:").queue();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package net.Broken.Commands;
|
|||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageHistory;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -30,8 +29,7 @@ public class ChannelsReview implements Commande {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
logger.warn("Can't parse date : " + e.getMessage());
|
logger.warn("Can't parse date : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
SendBack(event);
|
SendBack(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,25 +3,15 @@ package net.Broken.Commands;
|
|||||||
import groovy.lang.Binding;
|
import groovy.lang.Binding;
|
||||||
import groovy.lang.GroovyShell;
|
import groovy.lang.GroovyShell;
|
||||||
import net.Broken.Commande;
|
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.DB.Repository.UserRepository;
|
||||||
import net.Broken.SpringContext;
|
import net.Broken.SpringContext;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
|
||||||
import net.Broken.Tools.MessageTimeOut;
|
|
||||||
import net.Broken.Tools.PrivateMessage;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Code implements Commande {
|
public class Code implements Commande {
|
||||||
|
|
||||||
@ -57,8 +47,7 @@ public class Code implements Commande {
|
|||||||
for (Object obj : array) {
|
for (Object obj : array) {
|
||||||
if (stringResult.length() < 1800) {
|
if (stringResult.length() < 1800) {
|
||||||
stringResult.append(obj.toString()).append("\n\n");
|
stringResult.append(obj.toString()).append("\n\n");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
stringResult.append("\n...");
|
stringResult.append("\n...");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,11 @@ package net.Broken.Commands;
|
|||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||||
import net.dv8tion.jda.api.entities.MessageHistory;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to flush X last message on channel.
|
* Command to flush X last message on channel.
|
||||||
*/
|
*/
|
||||||
@ -24,9 +20,7 @@ public class Flush implements Commande{
|
|||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Missing argument!")).queue();
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Missing argument!")).queue();
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
|
if (event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
|
||||||
try {
|
try {
|
||||||
int limit = Integer.parseInt(args[0]) + 1;
|
int limit = Integer.parseInt(args[0]) + 1;
|
||||||
@ -38,14 +32,11 @@ public class Flush implements Commande{
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Argument unknown!")).queue();
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("Argument unknown!")).queue();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("You are not a supreme being, you cannot do that !")).queue();
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getFlushError("You are not a supreme being, you cannot do that !")).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,17 +31,14 @@ public class Help implements Commande {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
if(args.length>=1)
|
if (args.length >= 1) {
|
||||||
{
|
|
||||||
String argsString = args[0];
|
String argsString = args[0];
|
||||||
//System.out.println(argsString);
|
//System.out.println(argsString);
|
||||||
if (MainBot.commandes.containsKey(argsString))
|
if (MainBot.commandes.containsKey(argsString)) {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
Commande cmdObj = MainBot.commandes.get(argsString);
|
Commande cmdObj = MainBot.commandes.get(argsString);
|
||||||
if(!cmdObj.isAdminCmd() || isAdmin(event))
|
if (!cmdObj.isAdminCmd() || isAdmin(event)) {
|
||||||
{
|
|
||||||
logger.debug("Help for " + argsString + " by " + event.getAuthor().getName());
|
logger.debug("Help for " + argsString + " by " + event.getAuthor().getName());
|
||||||
MessageEmbed messageEmbed;
|
MessageEmbed messageEmbed;
|
||||||
try {
|
try {
|
||||||
@ -60,9 +57,7 @@ public class Help implements Commande {
|
|||||||
} else {
|
} else {
|
||||||
PrivateMessage.send(event.getAuthor(), messageEmbed, logger);
|
PrivateMessage.send(event.getAuthor(), messageEmbed, logger);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.info("Help wanted for admin command, Denied!");
|
logger.info("Help wanted for admin command, Denied!");
|
||||||
if (!event.isFromType(ChannelType.PRIVATE)) {
|
if (!event.isFromType(ChannelType.PRIVATE)) {
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
||||||
@ -78,10 +73,7 @@ public class Help implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!event.isFromType(ChannelType.PRIVATE)) {
|
if (!event.isFromType(ChannelType.PRIVATE)) {
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnknowCommand()).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnknowCommand()).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -94,9 +86,7 @@ public class Help implements Commande {
|
|||||||
}
|
}
|
||||||
logger.debug("Unknown command!");
|
logger.debug("Unknown command!");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TableRenderer table = new TableRenderer();
|
TableRenderer table = new TableRenderer();
|
||||||
table.setHeader("Command", "PU");
|
table.setHeader("Command", "PU");
|
||||||
|
|
||||||
@ -187,8 +177,7 @@ public class Help implements Commande {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
return event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ public class Invite implements Commande{
|
|||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
if (event.getChannelType().isGuild()) {
|
if (event.getChannelType().isGuild()) {
|
||||||
event.getTextChannel().sendMessage("You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8").complete();
|
event.getTextChannel().sendMessage("You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8").complete();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
PrivateMessage.send(event.getAuthor(), "You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8", LogManager.getLogger());
|
PrivateMessage.send(event.getAuthor(), "You can invite me whit this link:\nhttps://discordapp.com/oauth2/authorize?client_id=" + event.getJDA().getSelfUser().getId() + "&scope=bot&permissions=8", LogManager.getLogger());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import net.dv8tion.jda.api.managers.GuildManager;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -21,13 +20,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Move implements Commande {
|
public class Move implements Commande {
|
||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
private String HELP="`//move <@user> <@Role>`\n:arrow_right:\t*Move a user to a specified role.*";
|
|
||||||
public List<Role> saveRoleUser;
|
public List<Role> saveRoleUser;
|
||||||
public Member user;
|
public Member user;
|
||||||
public Guild serveur;
|
public Guild serveur;
|
||||||
public GuildManager serveurManager;
|
public GuildManager serveurManager;
|
||||||
/** Perform a move (Reset is role and add target(s) role(s)
|
Logger logger = LogManager.getLogger();
|
||||||
|
private String HELP = "`//move <@user> <@Role>`\n:arrow_right:\t*Move a user to a specified role.*";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a move (Reset is role and add target(s) role(s)
|
||||||
*
|
*
|
||||||
* @param user User to move
|
* @param user User to move
|
||||||
* @param cible Complete list of new role
|
* @param cible Complete list of new role
|
||||||
@ -36,14 +37,12 @@ public class Move implements Commande {
|
|||||||
* @param serveurManager GuildManager
|
* @param serveurManager GuildManager
|
||||||
* @return success
|
* @return success
|
||||||
*/
|
*/
|
||||||
public boolean exc(Member user, List<Role> cible , boolean reset, Guild serveur, GuildManager serveurManager) throws HierarchyException
|
public boolean exc(Member user, List<Role> cible, boolean reset, Guild serveur, GuildManager serveurManager) throws HierarchyException {
|
||||||
{
|
|
||||||
MainBot.roleFlag = true;
|
MainBot.roleFlag = true;
|
||||||
boolean erreur = false;
|
boolean erreur = false;
|
||||||
List<Role> allRoll = serveur.getRoles();
|
List<Role> allRoll = serveur.getRoles();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//On recupere les roles de l'utilisateur
|
//On recupere les roles de l'utilisateur
|
||||||
|
|
||||||
List<Role> roleUserList = user.getRoles();
|
List<Role> roleUserList = user.getRoles();
|
||||||
@ -69,23 +68,20 @@ public class Move implements Commande {
|
|||||||
return erreur;
|
return erreur;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Command handler
|
/**
|
||||||
|
* Command handler
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
public void action(String[] args, MessageReceivedEvent event)
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
{
|
if (!event.isFromType(ChannelType.PRIVATE)) {
|
||||||
if(!event.isFromType(ChannelType.PRIVATE))
|
if (args.length >= 2) {
|
||||||
{
|
|
||||||
if(args.length>=2)
|
|
||||||
{
|
|
||||||
serveur = event.getGuild();
|
serveur = event.getGuild();
|
||||||
List<User> userL = event.getMessage().getMentionedUsers();
|
List<User> userL = event.getMessage().getMentionedUsers();
|
||||||
List<Role> roleL = event.getMessage().getMentionedRoles();
|
List<Role> roleL = event.getMessage().getMentionedRoles();
|
||||||
|
|
||||||
if(userL.size()<1 ||roleL.size()<1)
|
if (userL.size() < 1 || roleL.size() < 1) {
|
||||||
{
|
|
||||||
logger.warn("Wrong mention.");
|
logger.warn("Wrong mention.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Error, please check if the user and/or the role are existing.")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Error, please check if the user and/or the role are existing.")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -93,9 +89,7 @@ public class Move implements Commande {
|
|||||||
add(event.getMessage());
|
add(event.getMessage());
|
||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
user = serveur.getMember(userL.get(0));
|
user = serveur.getMember(userL.get(0));
|
||||||
serveur = event.getGuild();
|
serveur = event.getGuild();
|
||||||
logger.info("Attempting role assignement for " + user.getEffectiveName() + " to " + roleL + " by " + event.getAuthor().getName());
|
logger.info("Attempting role assignement for " + user.getEffectiveName() + " to " + roleL + " by " + event.getAuthor().getName());
|
||||||
@ -104,26 +98,21 @@ public class Move implements Commande {
|
|||||||
logger.debug("User found");
|
logger.debug("User found");
|
||||||
try {
|
try {
|
||||||
boolean erreur = this.exc(user, roleL, true, serveur, serveur.getManager());
|
boolean erreur = this.exc(user, roleL, true, serveur, serveur.getManager());
|
||||||
if(erreur)
|
if (erreur) {
|
||||||
{
|
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Check the targeted role. ")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Check the targeted role. ")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
add(rest);
|
add(rest);
|
||||||
add(event.getMessage());
|
add(event.getMessage());
|
||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
StringBuilder roleStr = new StringBuilder("");
|
StringBuilder roleStr = new StringBuilder("");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for( Role role : roleL)
|
for (Role role : roleL) {
|
||||||
{
|
|
||||||
if (!first) {
|
if (!first) {
|
||||||
roleStr.append(", ");
|
roleStr.append(", ");
|
||||||
|
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
first = false;
|
first = false;
|
||||||
roleStr.append("__");
|
roleStr.append("__");
|
||||||
roleStr.append(role.getName());
|
roleStr.append(role.getName());
|
||||||
@ -149,12 +138,9 @@ public class Move implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Missing argument.");
|
logger.warn("Missing argument.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Missing argument.")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Missing argument.")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -163,17 +149,10 @@ public class Move implements Commande {
|
|||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate());
|
event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
package net.Broken.Commands;
|
package net.Broken.Commands;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.MainBot;
|
|
||||||
import net.Broken.Tools.MessageTimeOut;
|
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class Ordre66 implements Commande {
|
public class Ordre66 implements Commande {
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ public class Boobs extends NumberedCommande {
|
|||||||
public Boobs() {
|
public Boobs() {
|
||||||
super(LogManager.getLogger(), "http://lesaintdesseins.fr/", "-2/", "featured-img", "img");
|
super(LogManager.getLogger(), "http://lesaintdesseins.fr/", "-2/", "featured-img", "img");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Boobs";
|
return "Boobs";
|
||||||
|
@ -15,9 +15,9 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
@NoDev
|
@NoDev
|
||||||
public class Madame extends NumberedCommande {
|
public class Madame extends NumberedCommande {
|
||||||
|
public String HELP = "Yo really? Just type Madame to see some :cat:";
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
MessageReceivedEvent event;
|
MessageReceivedEvent event;
|
||||||
public String HELP = "Yo really? Just type Madame to see some :cat:";
|
|
||||||
|
|
||||||
public Madame() {
|
public Madame() {
|
||||||
super(LogManager.getLogger(), "https://www.bonjourmadame.fr/page/", "/");
|
super(LogManager.getLogger(), "https://www.bonjourmadame.fr/page/", "/");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.Broken.Commands.Over18;
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
import net.Broken.Tools.Redirection;
|
import net.Broken.Tools.Redirection;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
@ -55,8 +54,6 @@ public class Suicide implements Commande{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,10 +3,8 @@ package net.Broken.Commands;
|
|||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.requests.RestAction;
|
import net.dv8tion.jda.api.requests.RestAction;
|
||||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
|
||||||
|
|
||||||
|
|
||||||
public class ReportUsers implements Commande {
|
public class ReportUsers implements Commande {
|
||||||
|
@ -1,27 +1,17 @@
|
|||||||
package net.Broken.Commands;
|
package net.Broken.Commands;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
|
||||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.SpringContext;
|
import net.Broken.SpringContext;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.MessageTimeOut;
|
|
||||||
import net.Broken.Tools.SettingsUtils;
|
|
||||||
import net.Broken.audio.AudioM;
|
|
||||||
import net.Broken.audio.NotConnectedException;
|
|
||||||
import net.Broken.audio.NullMusicManager;
|
|
||||||
import net.Broken.audio.Youtube.YoutubeTools;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Settings implements Commande {
|
public class Settings implements Commande {
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import net.dv8tion.jda.api.exceptions.RateLimitedException;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -30,13 +29,11 @@ public class Spam implements Commande {
|
|||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event)
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
{
|
|
||||||
/****************************
|
/****************************
|
||||||
* Verif argument *
|
* Verif argument *
|
||||||
****************************/
|
****************************/
|
||||||
if(args.length>=1)
|
if (args.length >= 1) {
|
||||||
{
|
|
||||||
|
|
||||||
String commande = args[0];
|
String commande = args[0];
|
||||||
/****************************
|
/****************************
|
||||||
@ -66,7 +63,6 @@ public class Spam implements Commande {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -104,8 +100,7 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* verif argument *
|
* verif argument *
|
||||||
****************************/
|
****************************/
|
||||||
if (args.length >= 1)
|
if (args.length >= 1) {
|
||||||
{
|
|
||||||
/****************************
|
/****************************
|
||||||
* On recupere l'utilisateur et le role cible
|
* On recupere l'utilisateur et le role cible
|
||||||
****************************/
|
****************************/
|
||||||
@ -115,8 +110,7 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* verif utilisteur trouver *
|
* verif utilisteur trouver *
|
||||||
****************************/
|
****************************/
|
||||||
if(userL.size()<1)
|
if (userL.size() < 1) {
|
||||||
{
|
|
||||||
logger.error("User unknown.");
|
logger.error("User unknown.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: User not found. ", "pardon")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: User not found. ", "pardon")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -124,8 +118,7 @@ public class Spam implements Commande {
|
|||||||
add(event.getMessage());
|
add(event.getMessage());
|
||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Member user = userL.get(0);
|
Member user = userL.get(0);
|
||||||
logger.info("Attempt to forgive " + user.getEffectiveName() + " by " + event.getMember().getEffectiveName());
|
logger.info("Attempt to forgive " + user.getEffectiveName() + " by " + event.getMember().getEffectiveName());
|
||||||
/****************************
|
/****************************
|
||||||
@ -155,9 +148,7 @@ public class Spam implements Commande {
|
|||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Missing argument.");
|
logger.warn("Missing argument.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "pardon")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "pardon")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -174,8 +165,7 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* verif argument *
|
* verif argument *
|
||||||
****************************/
|
****************************/
|
||||||
if (args.length >= 3)
|
if (args.length >= 3) {
|
||||||
{
|
|
||||||
/****************************
|
/****************************
|
||||||
* On recupere l'utilisateur et le role cible
|
* On recupere l'utilisateur et le role cible
|
||||||
****************************/
|
****************************/
|
||||||
@ -185,12 +175,10 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* verif utilisteur trouver *
|
* verif utilisteur trouver *
|
||||||
****************************/
|
****************************/
|
||||||
if(userL.size()<1)
|
if (userL.size() < 1) {
|
||||||
{
|
|
||||||
logger.warn("Wrong mention (Spam).");
|
logger.warn("Wrong mention (Spam).");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Wrong mention. ", "extermine")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Wrong mention. ", "extermine")).complete();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
|
|
||||||
|
|
||||||
Guild serveur = event.getGuild();
|
Guild serveur = event.getGuild();
|
||||||
@ -204,14 +192,10 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* virif pas deja en spammer *
|
* virif pas deja en spammer *
|
||||||
****************************/
|
****************************/
|
||||||
if(MainBot.spamUtils.containsKey(user))
|
if (MainBot.spamUtils.containsKey(user)) {
|
||||||
{
|
if (!MainBot.spamUtils.get(user).isOnSpam()) {
|
||||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
|
||||||
{
|
|
||||||
this.goSpam(user, multiStr, serveur, event);
|
this.goSpam(user, multiStr, serveur, event);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("User already in spam.");
|
logger.warn("User already in spam.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("User already in spam.", "extermine")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("User already in spam.", "extermine")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -222,18 +206,14 @@ public class Spam implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
this.goSpam(user, multiStr, serveur, event);
|
this.goSpam(user, multiStr, serveur, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Missing argument.");
|
logger.warn("Missing argument.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "extermine")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "extermine")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -245,10 +225,8 @@ public class Spam implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reset(MessageReceivedEvent event, String[] args) throws RateLimitedException {
|
public void reset(MessageReceivedEvent event, String[] args) throws RateLimitedException {
|
||||||
if(event!=null)
|
if (event != null) {
|
||||||
{
|
if (args.length >= 2) {
|
||||||
if(args.length>=2)
|
|
||||||
{
|
|
||||||
|
|
||||||
Guild serveur = event.getGuild();
|
Guild serveur = event.getGuild();
|
||||||
/****************************
|
/****************************
|
||||||
@ -260,8 +238,7 @@ public class Spam implements Commande {
|
|||||||
/****************************
|
/****************************
|
||||||
* verif utilisteur trouver *
|
* verif utilisteur trouver *
|
||||||
****************************/
|
****************************/
|
||||||
if(userL.size()<1)
|
if (userL.size() < 1) {
|
||||||
{
|
|
||||||
logger.warn("User not found.");
|
logger.warn("User not found.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("User not found.", "reset")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("User not found.", "reset")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -270,8 +247,7 @@ public class Spam implements Commande {
|
|||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Member user = userL.get(0);
|
Member user = userL.get(0);
|
||||||
logger.info("Attempt spam reset of " + user.getEffectiveName() + " by " + event.getMember().getEffectiveName());
|
logger.info("Attempt spam reset of " + user.getEffectiveName() + " by " + event.getMember().getEffectiveName());
|
||||||
|
|
||||||
@ -292,9 +268,7 @@ public class Spam implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Missing argument.");
|
logger.warn("Missing argument.");
|
||||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "reset")).complete();
|
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Missing argument!", "reset")).complete();
|
||||||
List<Message> messages = new ArrayList<Message>() {{
|
List<Message> messages = new ArrayList<Message>() {{
|
||||||
@ -303,14 +277,10 @@ public class Spam implements Commande {
|
|||||||
}};
|
}};
|
||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (args[0].equals("all")) {
|
||||||
{
|
|
||||||
if (args[0].equals("all"))
|
|
||||||
{
|
|
||||||
logger.info("Multiplicator reseted automaticly.");
|
logger.info("Multiplicator reseted automaticly.");
|
||||||
for (Member unUser: MainBot.spamUtils.keySet())
|
for (Member unUser : MainBot.spamUtils.keySet()) {
|
||||||
{
|
|
||||||
|
|
||||||
MainBot.message_compteur.remove(unUser); //TODO resolve garbage collector error ????
|
MainBot.message_compteur.remove(unUser); //TODO resolve garbage collector error ????
|
||||||
}
|
}
|
||||||
@ -318,28 +288,18 @@ public class Spam implements Commande {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void goSpam(Member user, String multiStr, Guild serveur, MessageReceivedEvent event) {
|
||||||
|
if (Objects.equals(multiStr, "/")) {
|
||||||
public void goSpam(Member user, String multiStr, Guild serveur, MessageReceivedEvent event)
|
|
||||||
{
|
|
||||||
if(Objects.equals(multiStr, "/"))
|
|
||||||
{
|
|
||||||
new AntiSpam().extermine(user, serveur, serveur.getManager(), true, event);
|
new AntiSpam().extermine(user, serveur, serveur.getManager(), true, event);
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int multi = Integer.parseInt(multiStr);
|
int multi = Integer.parseInt(multiStr);
|
||||||
if(MainBot.spamUtils.containsKey(user))
|
if (MainBot.spamUtils.containsKey(user)) {
|
||||||
{
|
|
||||||
MainBot.spamUtils.get(user).setMultip(multi);
|
MainBot.spamUtils.get(user).setMultip(multi);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
MainBot.spamUtils.put(user, new UserSpamUtils(user, new ArrayList<>()));
|
MainBot.spamUtils.put(user, new UserSpamUtils(user, new ArrayList<>()));
|
||||||
MainBot.spamUtils.get(user).setMultip(multi);
|
MainBot.spamUtils.get(user).setMultip(multi);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import net.dv8tion.jda.api.EmbedBuilder;
|
|||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -25,17 +24,15 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* Spam Info Command
|
* Spam Info Command
|
||||||
*/
|
*/
|
||||||
public class SpamInfo implements Commande {
|
public class SpamInfo implements Commande {
|
||||||
private HashMap<Member,MessageUpdater> threadHashMap = new HashMap<>();
|
|
||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
|
private HashMap<Member, MessageUpdater> threadHashMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
Member user;
|
Member user;
|
||||||
if (event.getMessage().getMentionedUsers().size() == 0) {
|
if (event.getMessage().getMentionedUsers().size() == 0) {
|
||||||
user = event.getMember();
|
user = event.getMember();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
user = event.getMessage().getMentionedMembers().get(0);
|
user = event.getMessage().getMentionedMembers().get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,16 +43,14 @@ public class SpamInfo implements Commande{
|
|||||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `1`\n\t- In spam: `No`")).complete();
|
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `1`\n\t- In spam: `No`")).complete();
|
||||||
else
|
else
|
||||||
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `1`\n\t- In spam: `No`"), logger);
|
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `1`\n\t- In spam: `No`"), logger);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
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))
|
||||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + "\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `No`")).complete();
|
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + "\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `No`")).complete();
|
||||||
else
|
else
|
||||||
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `No`"), logger);
|
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `No`"), logger);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
if (!event.isFromType(ChannelType.PRIVATE))
|
if (!event.isFromType(ChannelType.PRIVATE))
|
||||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `Yes`\n\t- Time remaining: `" + formatSecond(util.getTimeLeft()) + "`")).complete();
|
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicator: `" + util.getMultip() + "`\n\t- In spam: `Yes`\n\t- Time remaining: `" + formatSecond(util.getTimeLeft()) + "`")).complete();
|
||||||
else
|
else
|
||||||
@ -69,17 +64,13 @@ public class SpamInfo implements Commande{
|
|||||||
MessageUpdater newThread = new MessageUpdater(message, event.getMessage(), 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, event.getMessage(), 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, event.getMessage(), 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();
|
||||||
@ -87,8 +78,6 @@ public class SpamInfo implements Commande{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -192,9 +181,6 @@ public class SpamInfo implements Commande{
|
|||||||
new MessageTimeOut(messages, 15).start();
|
new MessageTimeOut(messages, 15).start();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
package net.Broken.Commands;
|
package net.Broken.Commands;
|
||||||
|
|
||||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.MessageTimeOut;
|
import net.Broken.Tools.MessageTimeOut;
|
||||||
import net.Broken.audio.Youtube.SearchResult;
|
import net.Broken.audio.Youtube.SearchResult;
|
||||||
import net.Broken.audio.Youtube.YoutubeSearchRework;
|
import net.Broken.audio.Youtube.YoutubeSearchRework;
|
||||||
import net.Broken.audio.Youtube.YoutubeTools;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class YtSearch implements Commande {
|
public class YtSearch implements Commande {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package net.Broken.DB.Entity;
|
package net.Broken.DB.Entity;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.Entity;
|
||||||
import java.util.ArrayList;
|
import javax.persistence.GeneratedValue;
|
||||||
import java.util.List;
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class GuildPreferenceEntity {
|
public class GuildPreferenceEntity {
|
||||||
|
@ -27,7 +27,8 @@ public class PendingPwdResetEntity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PendingPwdResetEntity() {}
|
public PendingPwdResetEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public UserEntity getUserEntity() {
|
public UserEntity getUserEntity() {
|
||||||
|
@ -34,7 +34,6 @@ public class PendingUserEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ package net.Broken.DB.Entity;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.sound.midi.Track;
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -71,8 +68,7 @@ public class PlaylistEntity {
|
|||||||
this.tracks = tracks;
|
this.tracks = tracks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTracks(TrackEntity... tracks )
|
public void addTracks(TrackEntity... tracks) {
|
||||||
{
|
|
||||||
if (this.tracks == null)
|
if (this.tracks == null)
|
||||||
this.tracks = new ArrayList<>();
|
this.tracks = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ public class UserStats {
|
|||||||
@ColumnDefault("0")
|
@ColumnDefault("0")
|
||||||
private Long apiCommandCount = 0L;
|
private Long apiCommandCount = 0L;
|
||||||
|
|
||||||
public UserStats(){}
|
public UserStats() {
|
||||||
|
}
|
||||||
|
|
||||||
public UserStats(String guildId, UserEntity user) {
|
public UserStats(String guildId, UserEntity user) {
|
||||||
this.guildId = guildId;
|
this.guildId = guildId;
|
||||||
|
@ -11,6 +11,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface UserRepository extends CrudRepository<UserEntity, Integer> {
|
public interface UserRepository extends CrudRepository<UserEntity, Integer> {
|
||||||
List<UserEntity> findByName(String name);
|
List<UserEntity> findByName(String name);
|
||||||
|
|
||||||
List<UserEntity> findByJdaId(String jdaId);
|
List<UserEntity> findByJdaId(String jdaId);
|
||||||
|
|
||||||
List<UserEntity> findByApiToken(String apiToken);
|
List<UserEntity> findByApiToken(String apiToken);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface UserStatsRepository extends CrudRepository<UserStats, Long> {
|
public interface UserStatsRepository extends CrudRepository<UserStats, Long> {
|
||||||
List<UserStats> findByUser(UserEntity userEntity);
|
List<UserStats> findByUser(UserEntity userEntity);
|
||||||
|
|
||||||
List<UserStats> findByGuildId(String guildId);
|
List<UserStats> findByGuildId(String guildId);
|
||||||
|
|
||||||
List<UserStats> findByUserAndGuildId(UserEntity user, String guildId);
|
List<UserStats> findByUserAndGuildId(UserEntity user, String guildId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import net.Broken.Tools.DayListener.DayListener;
|
|||||||
import net.Broken.Tools.DayListener.Listeners.DailyMadame;
|
import net.Broken.Tools.DayListener.Listeners.DailyMadame;
|
||||||
import net.Broken.Tools.DayListener.Listeners.ResetSpam;
|
import net.Broken.Tools.DayListener.Listeners.ResetSpam;
|
||||||
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
import net.Broken.Tools.UserManager.Stats.UserStatsUtils;
|
||||||
import net.dv8tion.jda.api.AccountType;
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.OnlineStatus;
|
import net.dv8tion.jda.api.OnlineStatus;
|
||||||
|
@ -10,7 +10,6 @@ import net.dv8tion.jda.api.Permission;
|
|||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.boot.ExitCodeGenerator;
|
import org.springframework.boot.ExitCodeGenerator;
|
||||||
@ -43,8 +42,6 @@ public class MainBot {
|
|||||||
public static String url = "claptrapbot.com";
|
public static String url = "claptrapbot.com";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static int messageTimeOut = 10;
|
public static int messageTimeOut = 10;
|
||||||
public static int gifMessageTimeOut = 30;
|
public static int gifMessageTimeOut = 30;
|
||||||
|
|
||||||
@ -85,10 +82,10 @@ public class MainBot {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform test (admin, NSFW and private usable or not) and execute command or not
|
* Perform test (admin, NSFW and private usable or not) and execute command or not
|
||||||
|
*
|
||||||
* @param cmd Container whit all command info
|
* @param cmd Container whit all command info
|
||||||
*/
|
*/
|
||||||
public static void handleCommand(CommandParser.CommandContainer cmd, UserEntity user)
|
public static void handleCommand(CommandParser.CommandContainer cmd, UserEntity user) {
|
||||||
{
|
|
||||||
|
|
||||||
if (!ready) {
|
if (!ready) {
|
||||||
return;
|
return;
|
||||||
@ -100,47 +97,36 @@ public class MainBot {
|
|||||||
boolean isBotAdmin = user != null && user.isBotAdmin();
|
boolean isBotAdmin = user != null && user.isBotAdmin();
|
||||||
if (cmd.event.isFromType(ChannelType.PRIVATE)) {
|
if (cmd.event.isFromType(ChannelType.PRIVATE)) {
|
||||||
isAdmin = false;
|
isAdmin = false;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
isAdmin = cmd.event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
isAdmin = cmd.event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||||
|
|
||||||
if ((!cmdObj.isAdminCmd() || isAdmin) && (!cmdObj.isBotAdminCmd() || isBotAdmin)) {
|
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);
|
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||||
}
|
} else if (!cmd.event.isFromType(ChannelType.PRIVATE)) {
|
||||||
else if (!cmd.event.isFromType(ChannelType.PRIVATE))
|
|
||||||
{
|
|
||||||
if (!cmdObj.isNSFW() || cmd.event.getTextChannel().isNSFW()) {
|
if (!cmdObj.isNSFW() || cmd.event.getTextChannel().isNSFW()) {
|
||||||
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
cmd.event.getMessage().delete().queue();
|
cmd.event.getMessage().delete().queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
|
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (cmd.event.isFromType(ChannelType.PRIVATE)) {
|
if (cmd.event.isFromType(ChannelType.PRIVATE)) {
|
||||||
PrivateMessage.send(cmd.event.getAuthor(), EmbedMessageUtils.getUnautorized(), logger);
|
PrivateMessage.send(cmd.event.getAuthor(), EmbedMessageUtils.getUnautorized(), logger);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
logger.debug("Unknown command : " + cmd.commande);
|
logger.debug("Unknown command : " + cmd.commande);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import java.util.Set;
|
|||||||
public class ApiCommandLoader {
|
public class ApiCommandLoader {
|
||||||
public static HashMap<String, CommandInterface> apiCommands = new HashMap<>();
|
public static HashMap<String, CommandInterface> apiCommands = new HashMap<>();
|
||||||
private static Logger logger = LogManager.getLogger();
|
private static Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
logger.info("Loading Api Command...");
|
logger.info("Loading Api Command...");
|
||||||
// Reflections reflections = new Reflections("net.Broken.RestApi.Command");
|
// Reflections reflections = new Reflections("net.Broken.RestApi.Command");
|
||||||
|
@ -13,6 +13,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
public interface CommandInterface {
|
public interface CommandInterface {
|
||||||
/**
|
/**
|
||||||
* Main action
|
* Main action
|
||||||
|
*
|
||||||
* @param musicCommande Current guild music command
|
* @param musicCommande Current guild music command
|
||||||
* @param data Received data
|
* @param data Received data
|
||||||
* @param user User who submit RestApi command
|
* @param user User who submit RestApi command
|
||||||
|
@ -22,7 +22,8 @@ public class Connect implements CommandInterface{
|
|||||||
VoiceChannel voiceChannel = null;
|
VoiceChannel voiceChannel = null;
|
||||||
try {
|
try {
|
||||||
voiceChannel = guild.getVoiceChannelById(data.chanelId);
|
voiceChannel = guild.getVoiceChannelById(data.chanelId);
|
||||||
}catch (NumberFormatException ignored){}
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
if (voiceChannel == null) {
|
if (voiceChannel == null) {
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Channel Not found"), HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Channel Not found"), HttpStatus.BAD_REQUEST);
|
||||||
|
@ -18,8 +18,7 @@ public class Dell implements CommandInterface {
|
|||||||
if (data.url != null) {
|
if (data.url != null) {
|
||||||
if (AudioM.getInstance(guild).getGuildMusicManager().scheduler.remove(data.url)) {
|
if (AudioM.getInstance(guild).getGuildMusicManager().scheduler.remove(data.url)) {
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "URL not found"), HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "URL not found"), HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Missing URL"), HttpStatus.NOT_ACCEPTABLE);
|
return new ResponseEntity<>(new CommandResponseData(data.command, "Missing URL"), HttpStatus.NOT_ACCEPTABLE);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.Broken.RestApi.Data;
|
package net.Broken.RestApi.Data;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for JSON Parsing
|
* Data for JSON Parsing
|
||||||
*/
|
*/
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package net.Broken.RestApi.Data;
|
package net.Broken.RestApi.Data;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackState;
|
|
||||||
/**
|
/**
|
||||||
* Data for JSON Parsing
|
* Data for JSON Parsing
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +13,7 @@ public class PlaylistResponseData {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaylistResponseData(String message, String error) {
|
public PlaylistResponseData(String message, String error) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.error = error;
|
this.error = error;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package net.Broken.RestApi.Data;
|
package net.Broken.RestApi.Data;
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for JSON Parsing
|
* Data for JSON Parsing
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,7 @@ public class Value {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value(String name, String id, boolean selected) {
|
public Value(String name, String id, boolean selected) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -2,6 +2,7 @@ package net.Broken.RestApi.Data;
|
|||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||||
import net.Broken.audio.UserAudioTrack;
|
import net.Broken.audio.UserAudioTrack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for JSON Parsing
|
* Data for JSON Parsing
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package net.Broken.RestApi;
|
package net.Broken.RestApi;
|
||||||
|
|
||||||
import net.Broken.DB.Entity.PlaylistEntity;
|
|
||||||
import net.Broken.DB.Entity.TrackEntity;
|
|
||||||
import net.Broken.DB.Entity.UserEntity;
|
|
||||||
import net.Broken.DB.Repository.PlaylistRepository;
|
import net.Broken.DB.Repository.PlaylistRepository;
|
||||||
import net.Broken.DB.Repository.TrackRepository;
|
import net.Broken.DB.Repository.TrackRepository;
|
||||||
import net.Broken.DB.Repository.UserRepository;
|
import net.Broken.DB.Repository.UserRepository;
|
||||||
@ -10,14 +7,10 @@ import net.Broken.MainBot;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/")
|
@RequestMapping("/api/")
|
||||||
public class GeneralApiController {
|
public class GeneralApiController {
|
||||||
@ -42,9 +35,7 @@ public class GeneralApiController {
|
|||||||
public ResponseEntity<String> isReady() {
|
public ResponseEntity<String> isReady() {
|
||||||
if (MainBot.ready) {
|
if (MainBot.ready) {
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,4 @@ public class PlaylistAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
package net.Broken.RestApi;
|
package net.Broken.RestApi;
|
||||||
|
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
|
||||||
import net.Broken.DB.Entity.UserEntity;
|
import net.Broken.DB.Entity.UserEntity;
|
||||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
|
||||||
import net.Broken.DB.Repository.UserRepository;
|
import net.Broken.DB.Repository.UserRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.RestApi.Data.Settings.GetSettingsData;
|
import net.Broken.RestApi.Data.Settings.GetSettingsData;
|
||||||
import net.Broken.RestApi.Data.Settings.ListPostSetting;
|
import net.Broken.RestApi.Data.Settings.ListPostSetting;
|
||||||
import net.Broken.RestApi.Data.Settings.PostSetSettings;
|
|
||||||
import net.Broken.RestApi.Data.Settings.Value;
|
|
||||||
import net.Broken.Tools.SettingsUtils;
|
import net.Broken.Tools.SettingsUtils;
|
||||||
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
||||||
import net.Broken.Tools.UserManager.UserUtils;
|
import net.Broken.Tools.UserManager.UserUtils;
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -25,16 +16,14 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.RegEx;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class SettingAPIController {
|
public class SettingAPIController {
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
final
|
final
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SettingAPIController(UserRepository userRepository) {
|
public SettingAPIController(UserRepository userRepository) {
|
||||||
@ -48,8 +37,7 @@ public class SettingAPIController {
|
|||||||
if (settingUtils.checkPermission(token, guild)) {
|
if (settingUtils.checkPermission(token, guild)) {
|
||||||
Guild jdaGuild = MainBot.jda.getGuildById(guild);
|
Guild jdaGuild = MainBot.jda.getGuildById(guild);
|
||||||
return new ResponseEntity<>(settingUtils.extractSettings(jdaGuild), HttpStatus.OK);
|
return new ResponseEntity<>(settingUtils.extractSettings(jdaGuild), HttpStatus.OK);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,13 +63,11 @@ public class SettingAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
logger.warn("Try to change setting, UNAUTHORIZED. TOKEN: " + token + " GUILD: " + guild);
|
logger.warn("Try to change setting, UNAUTHORIZED. TOKEN: " + token + " GUILD: " + guild);
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import net.Broken.DB.Entity.UserEntity;
|
|||||||
import net.Broken.DB.Repository.PendingUserRepository;
|
import net.Broken.DB.Repository.PendingUserRepository;
|
||||||
import net.Broken.DB.Repository.UserRepository;
|
import net.Broken.DB.Repository.UserRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.RestApi.Data.CommandResponseData;
|
|
||||||
import net.Broken.RestApi.Data.UserManager.*;
|
import net.Broken.RestApi.Data.UserManager.*;
|
||||||
import net.Broken.Tools.UserManager.Exceptions.*;
|
import net.Broken.Tools.UserManager.Exceptions.*;
|
||||||
import net.Broken.Tools.UserManager.Oauth;
|
import net.Broken.Tools.UserManager.Oauth;
|
||||||
@ -15,7 +14,6 @@ import net.Broken.Tools.UserManager.UserUtils;
|
|||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import org.apache.http.HttpResponse;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -34,15 +32,12 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/userManagement")
|
@RequestMapping("/api/userManagement")
|
||||||
public class UserManagerAPIController {
|
public class UserManagerAPIController {
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
final
|
final
|
||||||
PendingUserRepository pendingUserRepository;
|
PendingUserRepository pendingUserRepository;
|
||||||
|
|
||||||
final
|
final
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
UserUtils userUtils = UserUtils.getInstance();
|
UserUtils userUtils = UserUtils.getInstance();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -68,8 +63,7 @@ public class UserManagerAPIController {
|
|||||||
} catch (UserAlreadyRegistered userAlreadyRegistered) {
|
} catch (UserAlreadyRegistered userAlreadyRegistered) {
|
||||||
return new ResponseEntity<>(new CheckResposeData(false, data.name, "User already registered in database!", ""), HttpStatus.NOT_ACCEPTABLE);
|
return new ResponseEntity<>(new CheckResposeData(false, data.name, "User already registered in database!", ""), HttpStatus.NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return new ResponseEntity<>(new CheckResposeData(false, "", "Missing parameter(s)", ""), HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(new CheckResposeData(false, "", "Missing parameter(s)", ""), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,8 +123,6 @@ public class UserManagerAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/oauthLogin", method = RequestMethod.POST)
|
@RequestMapping(value = "/oauthLogin", method = RequestMethod.POST)
|
||||||
public ResponseEntity<UserConnectionData> oauthLogin(@RequestParam(value = "token") String discordToken) {
|
public ResponseEntity<UserConnectionData> oauthLogin(@RequestParam(value = "token") String discordToken) {
|
||||||
logger.debug(discordToken);
|
logger.debug(discordToken);
|
||||||
@ -139,7 +131,6 @@ public class UserManagerAPIController {
|
|||||||
return new ResponseEntity<>(new UserConnectionData(true, user.getName(), user.getApiToken(), ""), HttpStatus.OK);
|
return new ResponseEntity<>(new UserConnectionData(true, user.getName(), user.getApiToken(), ""), HttpStatus.OK);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -167,7 +158,6 @@ public class UserManagerAPIController {
|
|||||||
return new ResponseEntity<>(UserStatsUtils.getINSTANCE().getStatPack(user, guildID), HttpStatus.OK);
|
return new ResponseEntity<>(UserStatsUtils.getINSTANCE().getStatPack(user, guildID), HttpStatus.OK);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (UnknownTokenException e) {
|
} catch (UnknownTokenException e) {
|
||||||
logger.info("Token check fail");
|
logger.info("Token check fail");
|
||||||
return new ResponseEntity(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity(HttpStatus.UNAUTHORIZED);
|
||||||
@ -175,7 +165,4 @@ public class UserManagerAPIController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ import java.util.List;
|
|||||||
* Command that return a random picture of cat.
|
* Command that return a random picture of cat.
|
||||||
*/
|
*/
|
||||||
public class Cat implements SlashCommand {
|
public class Cat implements SlashCommand {
|
||||||
private Logger logger = LogManager.getLogger();;
|
private Logger logger = LogManager.getLogger();
|
||||||
|
;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(SlashCommandEvent event) {
|
public void action(SlashCommandEvent event) {
|
||||||
try {
|
try {
|
||||||
|
@ -63,8 +63,7 @@ public class Music implements SlashCommand {
|
|||||||
}
|
}
|
||||||
if (event.getOption("playlist-limit") == null) {
|
if (event.getOption("playlist-limit") == null) {
|
||||||
audio.add(event, url.getAsString(), 30, next);
|
audio.add(event, url.getAsString(), 30, next);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
long limit = event.getOption("playlist-limit").getAsLong();
|
long limit = event.getOption("playlist-limit").getAsLong();
|
||||||
audio.add(event, url.getAsString(), (int) limit, next);
|
audio.add(event, url.getAsString(), (int) limit, next);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
import net.Broken.MainBot;
|
|
||||||
import net.Broken.Commands.Move;
|
import net.Broken.Commands.Move;
|
||||||
|
import net.Broken.MainBot;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
||||||
@ -9,8 +9,6 @@ import net.dv8tion.jda.api.managers.GuildManager;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -22,14 +20,16 @@ import static java.lang.Thread.sleep;
|
|||||||
*/
|
*/
|
||||||
public class AntiSpam {
|
public class AntiSpam {
|
||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
public Move move = new Move();
|
public Move move = new Move();
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public AntiSpam() {
|
public AntiSpam() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send user to Spam role
|
* Send user to Spam role
|
||||||
|
*
|
||||||
* @param user User to punish
|
* @param user User to punish
|
||||||
* @param guild Guild
|
* @param guild Guild
|
||||||
* @param guildManager GuildManager
|
* @param guildManager GuildManager
|
||||||
@ -44,30 +44,24 @@ public class AntiSpam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// On créer un nouvelle case dans le tableau des statuts si il n'y est pas
|
// On créer un nouvelle case dans le tableau des statuts si il n'y est pas
|
||||||
if(!MainBot.spamUtils.containsKey(user))
|
if (!MainBot.spamUtils.containsKey(user)) {
|
||||||
{
|
|
||||||
List<Message> messages = new ArrayList<>();
|
List<Message> messages = new ArrayList<>();
|
||||||
messages.addAll(MainBot.historique.get(user));
|
messages.addAll(MainBot.historique.get(user));
|
||||||
MainBot.spamUtils.put(user, new UserSpamUtils(user, messages));
|
MainBot.spamUtils.put(user, new UserSpamUtils(user, messages));
|
||||||
}
|
}
|
||||||
// On verrifie que l'uttilisateur n'est pas deja en spam
|
// On verrifie que l'uttilisateur n'est pas deja en spam
|
||||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
if (!MainBot.spamUtils.get(user).isOnSpam()) {
|
||||||
{
|
|
||||||
//l'utilisateur n'est pas deja en spam
|
//l'utilisateur n'est pas deja en spam
|
||||||
if(MainBot.spamUtils.get(user).getMultip() != 0)
|
if (MainBot.spamUtils.get(user).getMultip() != 0) {
|
||||||
{
|
if (MainBot.spamUtils.get(user).getMultip() < 45 && incrMulti) {
|
||||||
if(MainBot.spamUtils.get(user).getMultip()<45 && incrMulti)
|
|
||||||
{
|
|
||||||
MainBot.spamUtils.get(user).setMultip(MainBot.spamUtils.get(user).getMultip() * 2);
|
MainBot.spamUtils.get(user).setMultip(MainBot.spamUtils.get(user).getMultip() * 2);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
MainBot.spamUtils.get(user).setMultip(1);
|
MainBot.spamUtils.get(user).setMultip(1);
|
||||||
|
|
||||||
logger.info("Starting protocol 66 on " + user.getEffectiveName() + " with a multiplicator of " + MainBot.spamUtils.get(user));
|
logger.info("Starting protocol 66 on " + user.getEffectiveName() + " with a multiplicator of " + MainBot.spamUtils.get(user));
|
||||||
|
|
||||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
if (!MainBot.spamUtils.get(user).isOnSpam()) {
|
||||||
{
|
|
||||||
MainBot.spamUtils.get(user).setOnSpam(true);
|
MainBot.spamUtils.get(user).setOnSpam(true);
|
||||||
List<Role> spm = guild.getRolesByName("Spammer", false);
|
List<Role> spm = guild.getRolesByName("Spammer", false);
|
||||||
if (spm.size() != 0) {
|
if (spm.size() != 0) {
|
||||||
@ -85,8 +79,7 @@ public class AntiSpam {
|
|||||||
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
new MessageTimeOut(messages, MainBot.messageTimeOut).start();
|
||||||
MainBot.spamUtils.get(user).setOnSpam(false);
|
MainBot.spamUtils.get(user).setOnSpam(false);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nSpam role not found, you need to create it!"));
|
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nSpam role not found, you need to create it!"));
|
||||||
event.getTextChannel().sendMessage(msg).complete();
|
event.getTextChannel().sendMessage(msg).complete();
|
||||||
}
|
}
|
||||||
@ -96,8 +89,6 @@ public class AntiSpam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,8 +105,7 @@ public class AntiSpam {
|
|||||||
public int timeLeft;
|
public int timeLeft;
|
||||||
|
|
||||||
|
|
||||||
public Minuteur(int multip, Member user, List<Role> saveRoleUser, Guild serveur, GuildManager serveurManager, MessageReceivedEvent event )
|
public Minuteur(int multip, Member user, List<Role> saveRoleUser, Guild serveur, GuildManager serveurManager, MessageReceivedEvent event) {
|
||||||
{
|
|
||||||
this.multip = multip;
|
this.multip = multip;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.saveRoleUser = saveRoleUser;
|
this.saveRoleUser = saveRoleUser;
|
||||||
@ -130,15 +120,13 @@ public class AntiSpam {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.info("[" + user.getEffectiveName() + "] Start for " + multip + "min");
|
logger.info("[" + user.getEffectiveName() + "] Start for " + multip + "min");
|
||||||
while (MainBot.spamUtils.get(user).isOnSpam())
|
while (MainBot.spamUtils.get(user).isOnSpam()) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if(timeLeft<=0)
|
if (timeLeft <= 0) {
|
||||||
{
|
|
||||||
MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
|
MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
|
||||||
}
|
}
|
||||||
timeLeft--;
|
timeLeft--;
|
||||||
@ -167,7 +155,4 @@ public class AntiSpam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,10 @@ import net.dv8tion.jda.api.requests.RestAction;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static net.Broken.MainBot.jda;
|
import static net.Broken.MainBot.jda;
|
||||||
|
|
||||||
@ -20,6 +23,10 @@ public class AutoVoiceChannel {
|
|||||||
private final String guildID;
|
private final String guildID;
|
||||||
private final HashMap<Integer, String> createdChannels = new HashMap<>();
|
private final HashMap<Integer, String> createdChannels = new HashMap<>();
|
||||||
|
|
||||||
|
public AutoVoiceChannel(Guild guild) {
|
||||||
|
this.guildID = guild.getId();
|
||||||
|
}
|
||||||
|
|
||||||
public static AutoVoiceChannel getInstance(Guild guild) {
|
public static AutoVoiceChannel getInstance(Guild guild) {
|
||||||
if (INSTANCE_MAP.get(guild.getId()) == null) {
|
if (INSTANCE_MAP.get(guild.getId()) == null) {
|
||||||
INSTANCE_MAP.put(guild.getId(), new AutoVoiceChannel(guild));
|
INSTANCE_MAP.put(guild.getId(), new AutoVoiceChannel(guild));
|
||||||
@ -27,10 +34,6 @@ public class AutoVoiceChannel {
|
|||||||
return INSTANCE_MAP.get(guild.getId());
|
return INSTANCE_MAP.get(guild.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoVoiceChannel(Guild guild) {
|
|
||||||
this.guildID = guild.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void join(VoiceChannel voiceChannel) {
|
public void join(VoiceChannel voiceChannel) {
|
||||||
Guild guild = jda.getGuildById(guildID);
|
Guild guild = jda.getGuildById(guildID);
|
||||||
if (guild == null)
|
if (guild == null)
|
||||||
|
@ -16,12 +16,12 @@ public class CommandParser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse raw received string.
|
* Parse raw received string.
|
||||||
|
*
|
||||||
* @param brt Raw command string.
|
* @param brt Raw command string.
|
||||||
* @param e Event
|
* @param e Event
|
||||||
* @return Readable container that contain all useful data
|
* @return Readable container that contain all useful data
|
||||||
*/
|
*/
|
||||||
public CommandContainer parse(String brt, MessageReceivedEvent e)
|
public CommandContainer parse(String brt, MessageReceivedEvent e) {
|
||||||
{
|
|
||||||
ArrayList<String> split = new ArrayList<String>();
|
ArrayList<String> split = new ArrayList<String>();
|
||||||
String brut = brt;
|
String brut = brt;
|
||||||
String sansTete = brut.replaceFirst("//", "");
|
String sansTete = brut.replaceFirst("//", "");
|
||||||
@ -40,7 +40,6 @@ public class CommandParser {
|
|||||||
args[i] = args[i].replace('$', ' ');
|
args[i] = args[i].replace('$', ' ');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Author: " + e.getAuthor().getName() + ", Command: " + commande + ", args: " + Arrays.toString(args));
|
logger.info("Author: " + e.getAuthor().getName() + ", Command: " + commande + ", args: " + Arrays.toString(args));
|
||||||
|
|
||||||
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e);
|
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e);
|
||||||
@ -58,8 +57,7 @@ public class CommandParser {
|
|||||||
public final String[] args;
|
public final String[] args;
|
||||||
public final MessageReceivedEvent event;
|
public final MessageReceivedEvent event;
|
||||||
|
|
||||||
public CommandContainer(String brut, String sansTete, String[] splitSansTete, String commande, String[] args, MessageReceivedEvent e)
|
public CommandContainer(String brut, String sansTete, String[] splitSansTete, String commande, String[] args, MessageReceivedEvent e) {
|
||||||
{
|
|
||||||
this.brut = brut;
|
this.brut = brut;
|
||||||
this.sansTete = sansTete;
|
this.sansTete = sansTete;
|
||||||
this.splitSansTete = splitSansTete;
|
this.splitSansTete = splitSansTete;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package net.Broken.Tools.Command;
|
package net.Broken.Tools.Command;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
import net.Broken.Tools.LimitChecker;
|
import net.Broken.Tools.LimitChecker;
|
||||||
@ -11,7 +12,6 @@ import java.io.IOException;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +19,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
*/
|
*/
|
||||||
@Ignore
|
@Ignore
|
||||||
public abstract class NumberedCommande implements Commande {
|
public abstract class NumberedCommande implements Commande {
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
protected int minNumber = 1;
|
protected int minNumber = 1;
|
||||||
protected int maxNumber = -1;
|
protected int maxNumber = -1;
|
||||||
protected String baseURL;
|
protected String baseURL;
|
||||||
@ -27,9 +26,11 @@ public abstract class NumberedCommande implements Commande{
|
|||||||
protected String htmlType;
|
protected String htmlType;
|
||||||
protected String urlSuffix;
|
protected String urlSuffix;
|
||||||
protected LinkedBlockingQueue<Integer> randomQueue = new LinkedBlockingQueue<>();
|
protected LinkedBlockingQueue<Integer> randomQueue = new LinkedBlockingQueue<>();
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
|
*
|
||||||
* @param logger Logger used for logs
|
* @param logger Logger used for logs
|
||||||
* @param baseURL WebSite base url
|
* @param baseURL WebSite base url
|
||||||
* @param divClass DivClass to search to extract image
|
* @param divClass DivClass to search to extract image
|
||||||
@ -57,16 +58,12 @@ public abstract class NumberedCommande implements Commande{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
try
|
try {
|
||||||
{
|
if (args.length == 0) {
|
||||||
if(args.length == 0)
|
|
||||||
{
|
|
||||||
String result = poll();
|
String result = poll();
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + result).queue();
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + result).queue();
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "update":
|
case "update":
|
||||||
logger.info("update commande from " + event.getMessage().getAuthor().getName());
|
logger.info("update commande from " + event.getMessage().getAuthor().getName());
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package net.Broken.Tools.Command;
|
package net.Broken.Tools.Command;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.SlashCommand;
|
import net.Broken.SlashCommand;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.jboss.jandex.Main;
|
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.reflections.util.ClasspathHelper;
|
import org.reflections.util.ClasspathHelper;
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
@ -48,7 +46,8 @@ public class SlashCommandLoader {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
MainBot.slashCommands.put(name, command.getDeclaredConstructor().newInstance());
|
MainBot.slashCommands.put(name, command.getDeclaredConstructor().newInstance());
|
||||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||||
|
NoSuchMethodException e) {
|
||||||
logger.error("Failed to load " + name + "!");
|
logger.error("Failed to load " + name + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.Broken.Tools.DayListener;
|
package net.Broken.Tools.DayListener;
|
||||||
import net.Broken.Commands.Spam;
|
|
||||||
import net.dv8tion.jda.api.exceptions.RateLimitedException;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -12,15 +11,14 @@ import java.util.GregorianCalendar;
|
|||||||
* Day change listener
|
* Day change listener
|
||||||
*/
|
*/
|
||||||
public class DayListener extends Thread {
|
public class DayListener extends Thread {
|
||||||
|
private static DayListener INSTANCE = new DayListener();
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
private Calendar calendar;
|
private Calendar calendar;
|
||||||
private int previousDay;
|
private int previousDay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of listeners to need to be triggered
|
* List of listeners to need to be triggered
|
||||||
*/
|
*/
|
||||||
private ArrayList<NewDayListener> listeners = new ArrayList<>();
|
private ArrayList<NewDayListener> listeners = new ArrayList<>();
|
||||||
private static DayListener INSTANCE = new DayListener();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,15 +32,16 @@ public class DayListener extends Thread {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton
|
* Singleton
|
||||||
|
*
|
||||||
* @return Unique DayListener instance.
|
* @return Unique DayListener instance.
|
||||||
*/
|
*/
|
||||||
public static DayListener getInstance()
|
public static DayListener getInstance() {
|
||||||
{
|
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Listener who will be triggered
|
* Add Listener who will be triggered
|
||||||
|
*
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
public void addListener(NewDayListener listener) {
|
public void addListener(NewDayListener listener) {
|
||||||
@ -69,11 +68,9 @@ public class DayListener extends Thread {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(true)
|
while (true) {
|
||||||
{
|
|
||||||
calendar = Calendar.getInstance();
|
calendar = Calendar.getInstance();
|
||||||
if(calendar.get(GregorianCalendar.DAY_OF_MONTH) != previousDay)
|
if (calendar.get(GregorianCalendar.DAY_OF_MONTH) != previousDay) {
|
||||||
{
|
|
||||||
LogManager.getLogger().info("New day triggered!");
|
LogManager.getLogger().info("New day triggered!");
|
||||||
trigger();
|
trigger();
|
||||||
previousDay = calendar.get(GregorianCalendar.DAY_OF_MONTH);
|
previousDay = calendar.get(GregorianCalendar.DAY_OF_MONTH);
|
||||||
|
@ -7,7 +7,6 @@ import net.Broken.MainBot;
|
|||||||
import net.Broken.SpringContext;
|
import net.Broken.SpringContext;
|
||||||
import net.Broken.Tools.DayListener.NewDayListener;
|
import net.Broken.Tools.DayListener.NewDayListener;
|
||||||
import net.Broken.Tools.FindContentOnWebPage;
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
import net.Broken.Tools.Redirection;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -15,11 +14,9 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,13 +25,13 @@ import java.util.List;
|
|||||||
public class DailyMadame implements NewDayListener {
|
public class DailyMadame implements NewDayListener {
|
||||||
|
|
||||||
private GuildPreferenceRepository guildPreferenceRepository;
|
private GuildPreferenceRepository guildPreferenceRepository;
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public DailyMadame() {
|
public DailyMadame() {
|
||||||
ApplicationContext context = SpringContext.getAppContext();
|
ApplicationContext context = SpringContext.getAppContext();
|
||||||
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewDay() {
|
public void onNewDay() {
|
||||||
|
|
||||||
@ -58,15 +55,12 @@ public class DailyMadame implements NewDayListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (Guild guild : guilds) {
|
for (Guild guild : guilds) {
|
||||||
TextChannel chanel = null;
|
TextChannel chanel = null;
|
||||||
logger.debug(guild.getName());
|
logger.debug(guild.getName());
|
||||||
List<GuildPreferenceEntity> guildPref = guildPreferenceRepository.findByGuildId(guild.getId());
|
List<GuildPreferenceEntity> guildPref = guildPreferenceRepository.findByGuildId(guild.getId());
|
||||||
if (guildPref.size() > 0 && guildPref.get(0).isDailyMadame()) {
|
if (guildPref.size() > 0 && guildPref.get(0).isDailyMadame()) {
|
||||||
for(TextChannel iterator : guild.getTextChannels())
|
for (TextChannel iterator : guild.getTextChannels()) {
|
||||||
{
|
|
||||||
if (iterator.isNSFW() && iterator.canTalk()) {
|
if (iterator.isNSFW() && iterator.canTalk()) {
|
||||||
chanel = iterator;
|
chanel = iterator;
|
||||||
logger.debug("break: " + chanel.getName());
|
logger.debug("break: " + chanel.getName());
|
||||||
@ -78,8 +72,7 @@ public class DailyMadame implements NewDayListener{
|
|||||||
chanel.sendMessage("Madame of the day :kissing_heart: \n" + imgUrl).queue();
|
chanel.sendMessage("Madame of the day :kissing_heart: \n" + imgUrl).queue();
|
||||||
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!");
|
logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import net.Broken.Commands.Spam;
|
|||||||
import net.Broken.Tools.DayListener.NewDayListener;
|
import net.Broken.Tools.DayListener.NewDayListener;
|
||||||
import net.dv8tion.jda.api.exceptions.RateLimitedException;
|
import net.dv8tion.jda.api.exceptions.RateLimitedException;
|
||||||
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Daily spam reset
|
* Daily spam reset
|
||||||
*/
|
*/
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.audio.Youtube.SearchResult;
|
import net.Broken.audio.Youtube.SearchResult;
|
||||||
import net.Broken.audio.Youtube.YoutubeTools;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
@ -11,8 +9,6 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -135,6 +131,4 @@ public class EmbedMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ import java.net.URLConnection;
|
|||||||
public class FindContentOnWebPage {
|
public class FindContentOnWebPage {
|
||||||
/**
|
/**
|
||||||
* Find picture URL on webPage
|
* Find picture URL on webPage
|
||||||
|
*
|
||||||
* @param url Web Page URL
|
* @param url Web Page URL
|
||||||
* @param divClass Div class where the picture is
|
* @param divClass Div class where the picture is
|
||||||
* @param htmlType HTML tag of image (img)
|
* @param htmlType HTML tag of image (img)
|
||||||
@ -32,6 +33,7 @@ public class FindContentOnWebPage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get source code of web page
|
* Get source code of web page
|
||||||
|
*
|
||||||
* @param url Web page URL
|
* @param url Web page URL
|
||||||
* @return Web page source as String
|
* @return Web page source as String
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
@ -3,9 +3,7 @@ package net.Broken.Tools;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,6 +15,7 @@ public class LimitChecker {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check max page url for web site like baseURL.com/number-2/
|
* Check max page url for web site like baseURL.com/number-2/
|
||||||
|
*
|
||||||
* @param baseURL Base url without numbers
|
* @param baseURL Base url without numbers
|
||||||
* @param minNumber Start number
|
* @param minNumber Start number
|
||||||
* @return max Number
|
* @return max Number
|
||||||
@ -28,8 +27,7 @@ public class LimitChecker {
|
|||||||
boolean redirected = false;
|
boolean redirected = false;
|
||||||
Redirection redirection = new Redirection();
|
Redirection redirection = new Redirection();
|
||||||
|
|
||||||
while(!redirected )
|
while (!redirected) {
|
||||||
{
|
|
||||||
String origin = baseURL + number + suffix;
|
String origin = baseURL + number + suffix;
|
||||||
String newUrl = redirection.get(origin);
|
String newUrl = redirection.get(origin);
|
||||||
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
||||||
@ -41,8 +39,7 @@ public class LimitChecker {
|
|||||||
number -= 400;
|
number -= 400;
|
||||||
redirected = false;
|
redirected = false;
|
||||||
logger.debug("First pass: " + number);
|
logger.debug("First pass: " + number);
|
||||||
while(!redirected )
|
while (!redirected) {
|
||||||
{
|
|
||||||
String origin = baseURL + number + suffix;
|
String origin = baseURL + number + suffix;
|
||||||
String newUrl = redirection.get(origin);
|
String newUrl = redirection.get(origin);
|
||||||
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
||||||
@ -54,8 +51,7 @@ public class LimitChecker {
|
|||||||
number -= 90;
|
number -= 90;
|
||||||
redirected = false;
|
redirected = false;
|
||||||
logger.debug("Second pass: " + number);
|
logger.debug("Second pass: " + number);
|
||||||
while(!redirected )
|
while (!redirected) {
|
||||||
{
|
|
||||||
String origin = baseURL + number + suffix;
|
String origin = baseURL + number + suffix;
|
||||||
String newUrl = redirection.get(origin);
|
String newUrl = redirection.get(origin);
|
||||||
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
||||||
@ -67,8 +63,7 @@ public class LimitChecker {
|
|||||||
number -= 9;
|
number -= 9;
|
||||||
redirected = false;
|
redirected = false;
|
||||||
logger.debug("Third pass: " + number);
|
logger.debug("Third pass: " + number);
|
||||||
while(!redirected )
|
while (!redirected) {
|
||||||
{
|
|
||||||
String origin = baseURL + number + suffix;
|
String origin = baseURL + number + suffix;
|
||||||
String newUrl = redirection.get(origin);
|
String newUrl = redirection.get(origin);
|
||||||
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
logger.trace("Origin URL: " + origin + " Result: " + newUrl);
|
||||||
|
@ -5,7 +5,6 @@ import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -38,8 +37,7 @@ public class MessageTimeOut extends Thread{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("Time out! Deleting message!");
|
logger.debug("Time out! Deleting message!");
|
||||||
for(Message aMessage: messages)
|
for (Message aMessage : messages) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
aMessage.delete().queue();
|
aMessage.delete().queue();
|
||||||
} catch (ErrorResponseException e) {
|
} catch (ErrorResponseException e) {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
@ -20,7 +18,8 @@ public class Moderateur {
|
|||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public Moderateur() {}
|
public Moderateur() {
|
||||||
|
}
|
||||||
|
|
||||||
// Cette méthode récupère le dernier message est le rajoute à "historique"
|
// Cette méthode récupère le dernier message est le rajoute à "historique"
|
||||||
// SI (spam) retourne 1 (si l'user spam)
|
// SI (spam) retourne 1 (si l'user spam)
|
||||||
@ -28,6 +27,7 @@ public class Moderateur {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get last message and add it on history. After analyse for spam detection
|
* Get last message and add it on history. After analyse for spam detection
|
||||||
|
*
|
||||||
* @param user User
|
* @param user User
|
||||||
* @param guild Guild
|
* @param guild Guild
|
||||||
* @param guildManager Guild manager
|
* @param guildManager Guild manager
|
||||||
@ -77,8 +77,7 @@ public class Moderateur {
|
|||||||
if (equalCont >= nbMessage) {
|
if (equalCont >= nbMessage) {
|
||||||
spam = 1;
|
spam = 1;
|
||||||
logger.info("Spam detected for " + user.getEffectiveName() + "with 3 identical messages : ");
|
logger.info("Spam detected for " + user.getEffectiveName() + "with 3 identical messages : ");
|
||||||
for(Message aMessage : thisUserHistory)
|
for (Message aMessage : thisUserHistory) {
|
||||||
{
|
|
||||||
logger.info("\t - " + aMessage.getContentRaw());
|
logger.info("\t - " + aMessage.getContentRaw());
|
||||||
}
|
}
|
||||||
MainBot.historique.put(user, new ArrayList<Message>());
|
MainBot.historique.put(user, new ArrayList<Message>());
|
||||||
@ -99,8 +98,6 @@ public class Moderateur {
|
|||||||
**********************************/
|
**********************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/********************************************
|
/********************************************
|
||||||
* Comptage du nombre de message *
|
* Comptage du nombre de message *
|
||||||
********************************************/
|
********************************************/
|
||||||
@ -115,8 +112,7 @@ public class Moderateur {
|
|||||||
spam = 1;
|
spam = 1;
|
||||||
logger.info("Spam detected for " + user.getEffectiveName() + "with 5 messages in 5 secondes: ");
|
logger.info("Spam detected for " + user.getEffectiveName() + "with 5 messages in 5 secondes: ");
|
||||||
ArrayList<Message> histo = MainBot.historique.get(user);
|
ArrayList<Message> histo = MainBot.historique.get(user);
|
||||||
for (Message aMessage:histo )
|
for (Message aMessage : histo) {
|
||||||
{
|
|
||||||
// logger.debug("\t*"+aMessage.getContent());
|
// logger.debug("\t*"+aMessage.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public class PrivateMessage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto open private channel and send message
|
* Auto open private channel and send message
|
||||||
|
*
|
||||||
* @param user User to send message
|
* @param user User to send message
|
||||||
* @param message Message to send
|
* @param message Message to send
|
||||||
* @param logger Logger
|
* @param logger Logger
|
||||||
@ -24,6 +25,7 @@ public class PrivateMessage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto open private channel and send message
|
* Auto open private channel and send message
|
||||||
|
*
|
||||||
* @param user User to send message
|
* @param user User to send message
|
||||||
* @param message Message to send
|
* @param message Message to send
|
||||||
* @param logger Logger
|
* @param logger Logger
|
||||||
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirection URL Util
|
* Redirection URL Util
|
||||||
@ -16,6 +15,7 @@ public class Redirection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Redirected URL
|
* Return Redirected URL
|
||||||
|
*
|
||||||
* @param urlString Source URL
|
* @param urlString Source URL
|
||||||
* @return Redirected URL
|
* @return Redirected URL
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@ -39,5 +39,4 @@ public class Redirection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,18 @@ package net.Broken.Tools;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ResourceLoader {
|
public class ResourceLoader {
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file contents as string for resource folder
|
* Get file contents as string for resource folder
|
||||||
|
*
|
||||||
* @param fileName Requested file
|
* @param fileName Requested file
|
||||||
* @return File contents as string
|
* @return File contents as string
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
|
@ -17,22 +17,14 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SettingsUtils {
|
public class SettingsUtils {
|
||||||
|
|
||||||
private static SettingsUtils INSTANCE;
|
private static SettingsUtils INSTANCE;
|
||||||
private final Logger logger = LogManager.getLogger();
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static SettingsUtils getInstance() {
|
|
||||||
return (INSTANCE == null) ? new SettingsUtils() : INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final GuildPreferenceRepository guildPreferenceRepository;
|
private final GuildPreferenceRepository guildPreferenceRepository;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
|
||||||
private SettingsUtils() {
|
private SettingsUtils() {
|
||||||
ApplicationContext context = SpringContext.getAppContext();
|
ApplicationContext context = SpringContext.getAppContext();
|
||||||
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||||
@ -41,6 +33,10 @@ public class SettingsUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SettingsUtils getInstance() {
|
||||||
|
return (INSTANCE == null) ? new SettingsUtils() : INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract all settings for displaying on webpage
|
* Extract all settings for displaying on webpage
|
||||||
*
|
*
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utils to render table in block code
|
* Utils to render table in block code
|
||||||
*/
|
*/
|
||||||
@ -25,6 +25,7 @@ public class TableRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Table header(s)
|
* Set Table header(s)
|
||||||
|
*
|
||||||
* @param header Header(s) as String
|
* @param header Header(s) as String
|
||||||
*/
|
*/
|
||||||
public void setHeader(Object... header) {
|
public void setHeader(Object... header) {
|
||||||
@ -35,6 +36,7 @@ public class TableRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add row to table
|
* Add row to table
|
||||||
|
*
|
||||||
* @param content Content(s) as string
|
* @param content Content(s) as string
|
||||||
*/
|
*/
|
||||||
public void addRow(Object... content) {
|
public void addRow(Object... content) {
|
||||||
@ -46,6 +48,7 @@ public class TableRenderer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Change default empty string
|
* Change default empty string
|
||||||
|
*
|
||||||
* @param str
|
* @param str
|
||||||
*/
|
*/
|
||||||
public void setEmptyString(String str) {
|
public void setEmptyString(String str) {
|
||||||
|
@ -3,14 +3,11 @@ package net.Broken.Tools;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class TimeConvertor {
|
public class TimeConvertor {
|
||||||
static Logger logger = LogManager.getLogger();
|
static Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static ArrayList<String> sToTime(long sec) {
|
public static ArrayList<String> sToTime(long sec) {
|
||||||
final int MINUTES_IN_AN_HOUR = 60;
|
final int MINUTES_IN_AN_HOUR = 60;
|
||||||
final int SECONDS_IN_A_MINUTE = 60;
|
final int SECONDS_IN_A_MINUTE = 60;
|
||||||
|
@ -9,7 +9,6 @@ import org.apache.http.entity.StringEntity;
|
|||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -20,19 +19,16 @@ import java.util.List;
|
|||||||
public class TrueRandom {
|
public class TrueRandom {
|
||||||
|
|
||||||
private static TrueRandom INSTANCE = new TrueRandom();
|
private static TrueRandom INSTANCE = new TrueRandom();
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
private String url = "https://api.random.org/json-rpc/2/invoke";
|
||||||
|
private String apiKey = System.getenv("RANDOM_API_KEY");
|
||||||
|
private TrueRandom() {
|
||||||
|
}
|
||||||
|
|
||||||
public static TrueRandom getINSTANCE() {
|
public static TrueRandom getINSTANCE() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
private String url = "https://api.random.org/json-rpc/2/invoke";
|
|
||||||
private String apiKey = System.getenv("RANDOM_API_KEY");
|
|
||||||
|
|
||||||
private TrueRandom() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Integer> getNumbers(int min, int max) throws IOException {
|
public ArrayList<Integer> getNumbers(int min, int max) throws IOException {
|
||||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||||
|
|
||||||
@ -52,7 +48,6 @@ public class TrueRandom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
InputStream responseIS = response.getEntity().getContent();
|
InputStream responseIS = response.getEntity().getContent();
|
||||||
String content = IOUtils.toString(responseIS, "UTF-8");
|
String content = IOUtils.toString(responseIS, "UTF-8");
|
||||||
logger.trace(content);
|
logger.trace(content);
|
||||||
|
@ -18,13 +18,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Oauth {
|
public class Oauth {
|
||||||
private static Oauth INSTANCE = new Oauth();
|
private static Oauth INSTANCE = new Oauth();
|
||||||
public static Oauth getInstance(){ return INSTANCE; }
|
|
||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
private String baseUrl = "https://discordapp.com/api";
|
private String baseUrl = "https://discordapp.com/api";
|
||||||
private String mePath = "/users/@me";
|
private String mePath = "/users/@me";
|
||||||
|
|
||||||
|
public static Oauth getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
private JSONObject getUserId(String token) {
|
private JSONObject getUserId(String token) {
|
||||||
StringBuffer content = new StringBuffer();
|
StringBuffer content = new StringBuffer();
|
||||||
|
@ -15,13 +15,12 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PasswordResetUtils {
|
public class PasswordResetUtils {
|
||||||
|
private static PasswordResetUtils INSTANCE = new PasswordResetUtils();
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
private PendingPwdResetRepository pendingPwdResetRepository;
|
private PendingPwdResetRepository pendingPwdResetRepository;
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
private static PasswordResetUtils INSTANCE = new PasswordResetUtils();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private default constructor
|
* Private default constructor
|
||||||
*/
|
*/
|
||||||
@ -35,6 +34,7 @@ public class PasswordResetUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton
|
* Singleton
|
||||||
|
*
|
||||||
* @return Unique PasswordResetUtils instance
|
* @return Unique PasswordResetUtils instance
|
||||||
*/
|
*/
|
||||||
public static PasswordResetUtils getInstance() {
|
public static PasswordResetUtils getInstance() {
|
||||||
|
@ -23,17 +23,18 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class UserUtils {
|
public class UserUtils {
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
private static UserUtils INSTANCE = new UserUtils();
|
private static UserUtils INSTANCE = new UserUtils();
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private default constructor
|
* Private default constructor
|
||||||
*/
|
*/
|
||||||
private UserUtils(){}
|
private UserUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton
|
* Singleton
|
||||||
|
*
|
||||||
* @return Unique UserUtils instance
|
* @return Unique UserUtils instance
|
||||||
*/
|
*/
|
||||||
public static UserUtils getInstance() {
|
public static UserUtils getInstance() {
|
||||||
@ -43,6 +44,7 @@ public class UserUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if user exist on Guild, if exist, generate and send checkTocken, create entry on PendingUser DB
|
* Check if user exist on Guild, if exist, generate and send checkTocken, create entry on PendingUser DB
|
||||||
|
*
|
||||||
* @param pendingUserRepository Pending user DB interface
|
* @param pendingUserRepository Pending user DB interface
|
||||||
* @param userRepository User DB interface
|
* @param userRepository User DB interface
|
||||||
* @param passwordEncoder Password encoder
|
* @param passwordEncoder Password encoder
|
||||||
@ -73,7 +75,6 @@ public class UserUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Check if exist in pading user Table
|
//Check if exist in pading user Table
|
||||||
List<PendingUserEntity> pendingUsers = pendingUserRepository.findByJdaId(user.getId());
|
List<PendingUserEntity> pendingUsers = pendingUserRepository.findByJdaId(user.getId());
|
||||||
if (pendingUsers.size() != 0) {
|
if (pendingUsers.size() != 0) {
|
||||||
@ -89,7 +90,6 @@ public class UserUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("Generating check Token...");
|
logger.info("Generating check Token...");
|
||||||
if (token.equals("")) {
|
if (token.equals("")) {
|
||||||
token = generateCheckToken();
|
token = generateCheckToken();
|
||||||
@ -118,6 +118,7 @@ public class UserUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirm user account
|
* Confirm user account
|
||||||
|
*
|
||||||
* @param pendingUserRepository Pending user DB interface
|
* @param pendingUserRepository Pending user DB interface
|
||||||
* @param id UserPendingEntity PK to cofirm
|
* @param id UserPendingEntity PK to cofirm
|
||||||
* @param checkToken received token
|
* @param checkToken received token
|
||||||
@ -130,13 +131,11 @@ public class UserUtils {
|
|||||||
if (pendingUser != null) {
|
if (pendingUser != null) {
|
||||||
if (pendingUser.getCheckToken().equals(checkToken)) {
|
if (pendingUser.getCheckToken().equals(checkToken)) {
|
||||||
logger.info("Check Token match!");
|
logger.info("Check Token match!");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
logger.warn("Check token not match!");
|
logger.warn("Check token not match!");
|
||||||
throw new TokenNotMatch();
|
throw new TokenNotMatch();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
logger.warn("Id not Found!");
|
logger.warn("Id not Found!");
|
||||||
throw new UserNotFoundException();
|
throw new UserNotFoundException();
|
||||||
}
|
}
|
||||||
@ -145,6 +144,7 @@ public class UserUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get user Entity
|
* Get user Entity
|
||||||
|
*
|
||||||
* @param userRepository User DB interface
|
* @param userRepository User DB interface
|
||||||
* @param passwordEncoder Password encoder
|
* @param passwordEncoder Password encoder
|
||||||
* @param userInfoData Received data
|
* @param userInfoData Received data
|
||||||
@ -157,15 +157,12 @@ public class UserUtils {
|
|||||||
if (users.size() < 1) {
|
if (users.size() < 1) {
|
||||||
logger.warn("Login with unknown username: " + userInfoData.name);
|
logger.warn("Login with unknown username: " + userInfoData.name);
|
||||||
throw new UserNotFoundException();
|
throw new UserNotFoundException();
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
UserEntity user = users.get(0);
|
UserEntity user = users.get(0);
|
||||||
if (passwordEncoder.matches(userInfoData.password, user.getPassword())) {
|
if (passwordEncoder.matches(userInfoData.password, user.getPassword())) {
|
||||||
logger.info("Login successful for " + user.getName());
|
logger.info("Login successful for " + user.getName());
|
||||||
return user;
|
return user;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Login fail for " + user.getName() + ", wrong password!");
|
logger.warn("Login fail for " + user.getName() + ", wrong password!");
|
||||||
throw new PasswordNotMatchException();
|
throw new PasswordNotMatchException();
|
||||||
}
|
}
|
||||||
@ -174,6 +171,7 @@ public class UserUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* return token's UserEntity
|
* return token's UserEntity
|
||||||
|
*
|
||||||
* @param userRepository User DB interface
|
* @param userRepository User DB interface
|
||||||
* @param token Received token
|
* @param token Received token
|
||||||
* @return User Entity
|
* @return User Entity
|
||||||
@ -183,14 +181,14 @@ public class UserUtils {
|
|||||||
List<UserEntity> users = userRepository.findByApiToken(token);
|
List<UserEntity> users = userRepository.findByApiToken(token);
|
||||||
if (users.size() > 0) {
|
if (users.size() > 0) {
|
||||||
return users.get(0);
|
return users.get(0);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
throw new UnknownTokenException();
|
throw new UnknownTokenException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate API Token
|
* Generate API Token
|
||||||
|
*
|
||||||
* @return UUID String TODO Find something more secure
|
* @return UUID String TODO Find something more secure
|
||||||
*/
|
*/
|
||||||
public String generateApiToken() {
|
public String generateApiToken() {
|
||||||
@ -199,6 +197,7 @@ public class UserUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate short check token
|
* Generate short check token
|
||||||
|
*
|
||||||
* @return check token as string
|
* @return check token as string
|
||||||
*/
|
*/
|
||||||
public String generateCheckToken() {
|
public String generateCheckToken() {
|
||||||
|
@ -15,20 +15,22 @@ public class UserSpamUtils {
|
|||||||
private boolean onSpam = false;
|
private boolean onSpam = false;
|
||||||
private List<Message> messages;
|
private List<Message> messages;
|
||||||
|
|
||||||
public int getTimeLeft(){
|
|
||||||
return minuteur.timeLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMultip()
|
|
||||||
{
|
|
||||||
return multip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserSpamUtils(Member user, List<Message> messages) {
|
public UserSpamUtils(Member user, List<Message> messages) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.messages = messages;
|
this.messages = messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTimeLeft() {
|
||||||
|
return minuteur.timeLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMultip() {
|
||||||
|
return multip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMultip(int multip) {
|
||||||
|
this.multip = multip;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMinuteur(AntiSpam.Minuteur minuteur) {
|
public void setMinuteur(AntiSpam.Minuteur minuteur) {
|
||||||
this.minuteur = minuteur;
|
this.minuteur = minuteur;
|
||||||
@ -38,10 +40,6 @@ public class UserSpamUtils {
|
|||||||
minuteur.start();
|
minuteur.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMultip(int multip) {
|
|
||||||
this.multip = multip;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOnSpam() {
|
public boolean isOnSpam() {
|
||||||
return onSpam;
|
return onSpam;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ import net.dv8tion.jda.api.entities.Message;
|
|||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -27,6 +26,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AudioM {
|
public class AudioM {
|
||||||
|
|
||||||
|
private static HashMap<Guild, AudioM> INSTANCES = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* Music manager for this guild
|
* Music manager for this guild
|
||||||
*/
|
*/
|
||||||
@ -53,7 +53,12 @@ public class AudioM {
|
|||||||
private Guild guild;
|
private Guild guild;
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
private static HashMap<Guild, AudioM> INSTANCES = new HashMap<>();
|
private AudioM(Guild guild) {
|
||||||
|
this.playerManager = new DefaultAudioPlayerManager();
|
||||||
|
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||||
|
AudioSourceManagers.registerLocalSource(playerManager);
|
||||||
|
this.guild = guild;
|
||||||
|
}
|
||||||
|
|
||||||
public static AudioM getInstance(Guild guild) {
|
public static AudioM getInstance(Guild guild) {
|
||||||
if (!INSTANCES.containsKey(guild)) {
|
if (!INSTANCES.containsKey(guild)) {
|
||||||
@ -63,14 +68,6 @@ public class AudioM {
|
|||||||
return INSTANCES.get(guild);
|
return INSTANCES.get(guild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private AudioM(Guild guild) {
|
|
||||||
this.playerManager = new DefaultAudioPlayerManager();
|
|
||||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
|
||||||
AudioSourceManagers.registerLocalSource(playerManager);
|
|
||||||
this.guild = guild;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load audio track from url, connect to chanel if not connected
|
* Load audio track from url, connect to chanel if not connected
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.Broken.audio;
|
package net.Broken.audio;
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
|
import com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame;
|
||||||
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ public class GuildMusicManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a player and a track scheduler.
|
* Creates a player and a track scheduler.
|
||||||
|
*
|
||||||
* @param manager Audio player manager to use for creating the player.
|
* @param manager Audio player manager to use for creating the player.
|
||||||
*/
|
*/
|
||||||
public GuildMusicManager(AudioPlayerManager manager, Guild guild) {
|
public GuildMusicManager(AudioPlayerManager manager, Guild guild) {
|
||||||
|
@ -27,23 +27,14 @@ import java.util.List;
|
|||||||
|
|
||||||
public class PlaylistManager {
|
public class PlaylistManager {
|
||||||
|
|
||||||
private final ResponseEntity<PlaylistResponseData> TOKEN_ERROR = new ResponseEntity<>(new PlaylistResponseData("Unknown Token!\nPlease Re-connect.", "token"), HttpStatus.UNAUTHORIZED);
|
|
||||||
|
|
||||||
private final ResponseEntity<PlaylistResponseData> PLAYLIST_NOT_FOUND = new ResponseEntity<>(new PlaylistResponseData("Playlist not found", "playlist"), HttpStatus.NOT_FOUND);
|
|
||||||
|
|
||||||
private final ResponseEntity<PlaylistResponseData> TRACK_NOT_FOUND = new ResponseEntity<>(new PlaylistResponseData("Can't find media!", "track"), HttpStatus.NOT_FOUND);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private PlaylistRepository playlistRepository;
|
|
||||||
|
|
||||||
private TrackRepository trackRepository;
|
|
||||||
|
|
||||||
private UserRepository userRepository;
|
|
||||||
|
|
||||||
Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
private static PlaylistManager INSTANCE = new PlaylistManager();
|
private static PlaylistManager INSTANCE = new PlaylistManager();
|
||||||
|
private final ResponseEntity<PlaylistResponseData> TOKEN_ERROR = new ResponseEntity<>(new PlaylistResponseData("Unknown Token!\nPlease Re-connect.", "token"), HttpStatus.UNAUTHORIZED);
|
||||||
|
private final ResponseEntity<PlaylistResponseData> PLAYLIST_NOT_FOUND = new ResponseEntity<>(new PlaylistResponseData("Playlist not found", "playlist"), HttpStatus.NOT_FOUND);
|
||||||
|
private final ResponseEntity<PlaylistResponseData> TRACK_NOT_FOUND = new ResponseEntity<>(new PlaylistResponseData("Can't find media!", "track"), HttpStatus.NOT_FOUND);
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
|
private PlaylistRepository playlistRepository;
|
||||||
|
private TrackRepository trackRepository;
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
private PlaylistManager() {
|
private PlaylistManager() {
|
||||||
ApplicationContext context = SpringContext.getAppContext();
|
ApplicationContext context = SpringContext.getAppContext();
|
||||||
@ -71,9 +62,7 @@ public class PlaylistManager {
|
|||||||
|
|
||||||
if (webLoadUtils.userAudioTrack == null) {
|
if (webLoadUtils.userAudioTrack == null) {
|
||||||
return TRACK_NOT_FOUND;
|
return TRACK_NOT_FOUND;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
TrackEntity trackEntity = new TrackEntity(webLoadUtils.userAudioTrack.getAudioTrack().getInfo(), data.pos, playlist);
|
TrackEntity trackEntity = new TrackEntity(webLoadUtils.userAudioTrack.getAudioTrack().getInfo(), data.pos, playlist);
|
||||||
|
|
||||||
playlist = insert(playlist, trackEntity);
|
playlist = insert(playlist, trackEntity);
|
||||||
@ -81,7 +70,6 @@ public class PlaylistManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (UnknownTokenException e) {
|
} catch (UnknownTokenException e) {
|
||||||
logger.warn("Unknown token: " + token);
|
logger.warn("Unknown token: " + token);
|
||||||
return TOKEN_ERROR;
|
return TOKEN_ERROR;
|
||||||
@ -99,13 +87,11 @@ public class PlaylistManager {
|
|||||||
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TrackEntity toDelete = trackRepository.findById(data.id);
|
TrackEntity toDelete = trackRepository.findById(data.id);
|
||||||
|
|
||||||
playlist = remove(playlist, toDelete);
|
playlist = remove(playlist, toDelete);
|
||||||
|
|
||||||
if(playlist == null)
|
if (playlist == null) {
|
||||||
{
|
|
||||||
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
||||||
return TRACK_NOT_FOUND;
|
return TRACK_NOT_FOUND;
|
||||||
}
|
}
|
||||||
@ -128,15 +114,13 @@ public class PlaylistManager {
|
|||||||
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TrackEntity toMove = trackRepository.findById(data.id);
|
TrackEntity toMove = trackRepository.findById(data.id);
|
||||||
|
|
||||||
TrackEntity save = new TrackEntity(toMove);
|
TrackEntity save = new TrackEntity(toMove);
|
||||||
|
|
||||||
playlist = remove(playlist, toMove);
|
playlist = remove(playlist, toMove);
|
||||||
|
|
||||||
if(playlist == null)
|
if (playlist == null) {
|
||||||
{
|
|
||||||
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
||||||
return TRACK_NOT_FOUND;
|
return TRACK_NOT_FOUND;
|
||||||
}
|
}
|
||||||
@ -146,7 +130,6 @@ public class PlaylistManager {
|
|||||||
playlist = insert(playlist, save);
|
playlist = insert(playlist, save);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlist), HttpStatus.OK);
|
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlist), HttpStatus.OK);
|
||||||
|
|
||||||
} catch (UnknownTokenException e) {
|
} catch (UnknownTokenException e) {
|
||||||
@ -186,8 +169,7 @@ public class PlaylistManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!increase)
|
if (!increase) {
|
||||||
{
|
|
||||||
trackEntity.setPos(tracks.size());
|
trackEntity.setPos(tracks.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,12 +205,12 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoFlow() {
|
||||||
|
return autoFlow;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAutoFlow(boolean autoFlow) {
|
public void setAutoFlow(boolean autoFlow) {
|
||||||
this.autoFlow = autoFlow;
|
this.autoFlow = autoFlow;
|
||||||
needAutoPlay();
|
needAutoPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAutoFlow() {
|
|
||||||
return autoFlow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,13 @@ import org.springframework.http.ResponseEntity;
|
|||||||
* Interface between WebApi and Music bot for submitting track
|
* Interface between WebApi and Music bot for submitting track
|
||||||
*/
|
*/
|
||||||
public class WebLoadUtils {
|
public class WebLoadUtils {
|
||||||
|
public UserAudioTrack userAudioTrack;
|
||||||
private ResponseEntity<CommandResponseData> response;
|
private ResponseEntity<CommandResponseData> response;
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
public UserAudioTrack userAudioTrack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit a track or playlist to Music bot
|
* Submit a track or playlist to Music bot
|
||||||
|
*
|
||||||
* @param data Received data from API
|
* @param data Received data from API
|
||||||
* @param user User who submit the track
|
* @param user User who submit the track
|
||||||
* @param guild
|
* @param guild
|
||||||
@ -49,13 +50,11 @@ public class WebLoadUtils {
|
|||||||
@Override
|
@Override
|
||||||
public void playlistLoaded(AudioPlaylist playlist) {
|
public void playlistLoaded(AudioPlaylist playlist) {
|
||||||
|
|
||||||
if(submit)
|
if (submit) {
|
||||||
{
|
|
||||||
logger.info("Playlist detected from web! Limit: " + data.playlistLimit);
|
logger.info("Playlist detected from web! Limit: " + data.playlistLimit);
|
||||||
audioM.playListLoader(playlist, data.playlistLimit, user, data.onHead);
|
audioM.playListLoader(playlist, data.playlistLimit, user, data.onHead);
|
||||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
||||||
}else
|
} else {
|
||||||
{
|
|
||||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Adding a list on saved playlist is currently not supported"), HttpStatus.NOT_ACCEPTABLE);
|
response = new ResponseEntity<>(new CommandResponseData("ADD", "Adding a list on saved playlist is currently not supported"), HttpStatus.NOT_ACCEPTABLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -86,6 +85,7 @@ public class WebLoadUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for the end of submit process and return ResponseEntity
|
* Wait for the end of submit process and return ResponseEntity
|
||||||
|
*
|
||||||
* @return HTTP Response
|
* @return HTTP Response
|
||||||
*/
|
*/
|
||||||
public ResponseEntity<CommandResponseData> getResponse() {
|
public ResponseEntity<CommandResponseData> getResponse() {
|
||||||
|
@ -2,7 +2,6 @@ package net.Broken.audio.Youtube;
|
|||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
|
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
|
||||||
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeSearchProvider;
|
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeSearchProvider;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioItem;
|
|
||||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||||
import com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist;
|
import com.sedmelluq.discord.lavaplayer.track.BasicAudioPlaylist;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -21,9 +20,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class YoutubeSearchRework {
|
public class YoutubeSearchRework {
|
||||||
|
|
||||||
private Logger logger = LogManager.getLogger();
|
|
||||||
|
|
||||||
private static YoutubeSearchRework INSTANCE;
|
private static YoutubeSearchRework INSTANCE;
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static YoutubeSearchRework getInstance() {
|
public static YoutubeSearchRework getInstance() {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
|
@ -3,8 +3,8 @@ package net.Broken.audio.Youtube;
|
|||||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.gson.GsonFactory;
|
import com.google.api.client.json.gson.GsonFactory;
|
||||||
import com.google.api.services.youtube.YouTube;
|
import com.google.api.services.youtube.YouTube;
|
||||||
import com.google.api.services.youtube.model.*;
|
|
||||||
import com.google.api.services.youtube.model.SearchResult;
|
import com.google.api.services.youtube.model.SearchResult;
|
||||||
|
import com.google.api.services.youtube.model.*;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -13,15 +13,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.hibernate.engine.jdbc.Size.LobMultiplier.M;
|
|
||||||
|
|
||||||
public class YoutubeTools {
|
public class YoutubeTools {
|
||||||
|
|
||||||
|
private static YoutubeTools INSTANCE;
|
||||||
private Logger logger = LogManager.getLogger();
|
private Logger logger = LogManager.getLogger();
|
||||||
private String apiKey = System.getenv("GOOGLE_API_KEY");
|
private String apiKey = System.getenv("GOOGLE_API_KEY");
|
||||||
|
|
||||||
private static YoutubeTools INSTANCE;
|
|
||||||
|
|
||||||
private YoutubeTools() {
|
private YoutubeTools() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -49,8 +46,6 @@ public class YoutubeTools {
|
|||||||
YouTube youtube = getYoutubeService();
|
YouTube youtube = getYoutubeService();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
YouTube.Search.List searchListRelatedVideosRequest = youtube.search().list(Collections.singletonList("snippet"));
|
YouTube.Search.List searchListRelatedVideosRequest = youtube.search().list(Collections.singletonList("snippet"));
|
||||||
searchListRelatedVideosRequest.setRelatedToVideoId(videoId);
|
searchListRelatedVideosRequest.setRelatedToVideoId(videoId);
|
||||||
searchListRelatedVideosRequest.setType(Collections.singletonList("video"));
|
searchListRelatedVideosRequest.setType(Collections.singletonList("video"));
|
||||||
@ -110,8 +105,7 @@ public class YoutubeTools {
|
|||||||
|
|
||||||
}
|
}
|
||||||
return finalResult;
|
return finalResult;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
for (SearchResult item : response.getItems()) {
|
for (SearchResult item : response.getItems()) {
|
||||||
idString.append(item.getId().getVideoId()).append(",");
|
idString.append(item.getId().getVideoId()).append(",");
|
||||||
}
|
}
|
||||||
@ -132,13 +126,6 @@ public class YoutubeTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -155,8 +142,7 @@ public class YoutubeTools {
|
|||||||
String matched = time.substring(0, time.indexOf("H") + 1);
|
String matched = time.substring(0, time.indexOf("H") + 1);
|
||||||
time = time.replace(matched, "");
|
time = time.replace(matched, "");
|
||||||
hours = Integer.parseInt(matched.replace("H", ""));
|
hours = Integer.parseInt(matched.replace("H", ""));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
hours = 0;
|
hours = 0;
|
||||||
logger.trace(time);
|
logger.trace(time);
|
||||||
|
|
||||||
@ -165,8 +151,7 @@ public class YoutubeTools {
|
|||||||
String matched = time.substring(0, time.indexOf("M") + 1);
|
String matched = time.substring(0, time.indexOf("M") + 1);
|
||||||
time = time.replace(matched, "");
|
time = time.replace(matched, "");
|
||||||
minutes = Integer.parseInt(matched.replace("M", ""));
|
minutes = Integer.parseInt(matched.replace("M", ""));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
minutes = 0;
|
minutes = 0;
|
||||||
logger.trace(time);
|
logger.trace(time);
|
||||||
if (time.contains("S")) {
|
if (time.contains("S")) {
|
||||||
@ -174,8 +159,7 @@ public class YoutubeTools {
|
|||||||
String matched = time.substring(0, time.indexOf("S") + 1);
|
String matched = time.substring(0, time.indexOf("S") + 1);
|
||||||
time = time.replace(matched, "");
|
time = time.replace(matched, "");
|
||||||
seconds = Integer.parseInt(matched.replace("S", ""));
|
seconds = Integer.parseInt(matched.replace("S", ""));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
seconds = 0;
|
seconds = 0;
|
||||||
logger.trace(time);
|
logger.trace(time);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -46,11 +45,31 @@ public class GeneralWebView {
|
|||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Model addGuildAndRedirect(Model model, String token, String guildId, User user) {
|
||||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
List<Guild> mutualGuilds = user.getMutualGuilds();
|
||||||
public class ForbiddenException extends RuntimeException {
|
Integer lastCount = MainBot.mutualGuildCount.get(user.getId());
|
||||||
|
if (lastCount == null || lastCount != mutualGuilds.size()) {
|
||||||
|
LogManager.getLogger().debug("Guild miss match, re-cache users...");
|
||||||
|
CacheTools.loadAllGuildMembers();
|
||||||
|
mutualGuilds = user.getMutualGuilds();
|
||||||
|
MainBot.mutualGuildCount.put(user.getId(), mutualGuilds.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||||
|
if (guild != null) {
|
||||||
|
model.addAttribute("guild_name", guild.getName());
|
||||||
|
model.addAttribute("guild_id", guild.getId());
|
||||||
|
model.addAttribute("guild_icon", guild.getIconUrl() == null ? "https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png" : guild.getIconUrl());
|
||||||
|
model.addAttribute("mutual_guilds", mutualGuilds);
|
||||||
|
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
|
||||||
|
} else {
|
||||||
|
model.addAttribute("guild_name", "");
|
||||||
|
model.addAttribute("guild_icon", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute("redirect_url", System.getenv("OAUTH_URL"));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public String music(Model model, HttpServletResponse response, HttpServletRequest request, @CookieValue(value = "guild", defaultValue = "1") String guildId, @CookieValue(value = "token", defaultValue = "") String token) {
|
public String music(Model model, HttpServletResponse response, HttpServletRequest request, @CookieValue(value = "guild", defaultValue = "1") String guildId, @CookieValue(value = "token", defaultValue = "") String token) {
|
||||||
@ -180,31 +199,8 @@ public class GeneralWebView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||||
public static Model addGuildAndRedirect(Model model, String token, String guildId, User user) {
|
public class ForbiddenException extends RuntimeException {
|
||||||
List<Guild> mutualGuilds = user.getMutualGuilds();
|
|
||||||
Integer lastCount = MainBot.mutualGuildCount.get(user.getId());
|
|
||||||
if (lastCount == null || lastCount != mutualGuilds.size()) {
|
|
||||||
LogManager.getLogger().debug("Guild miss match, re-cache users...");
|
|
||||||
CacheTools.loadAllGuildMembers();
|
|
||||||
mutualGuilds = user.getMutualGuilds();
|
|
||||||
MainBot.mutualGuildCount.put(user.getId(), mutualGuilds.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
Guild guild = MainBot.jda.getGuildById(guildId);
|
|
||||||
if (guild != null) {
|
|
||||||
model.addAttribute("guild_name", guild.getName());
|
|
||||||
model.addAttribute("guild_id", guild.getId());
|
|
||||||
model.addAttribute("guild_icon", guild.getIconUrl() == null ? "https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png" : guild.getIconUrl());
|
|
||||||
model.addAttribute("mutual_guilds", mutualGuilds);
|
|
||||||
model.addAttribute("isAdmin", SettingsUtils.getInstance().checkPermission(token, guildId));
|
|
||||||
} else {
|
|
||||||
model.addAttribute("guild_name", "");
|
|
||||||
model.addAttribute("guild_icon", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("redirect_url", System.getenv("OAUTH_URL"));
|
|
||||||
return model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ public class MusicWebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/music")
|
@RequestMapping("/music")
|
||||||
public String music(Model model, HttpServletResponse response, HttpServletRequest request, @CookieValue(value = "guild", defaultValue = "1") String guildId, @CookieValue(value = "token", defaultValue = "") String token) {
|
public String music(Model model, HttpServletResponse response, HttpServletRequest request, @CookieValue(value = "guild", defaultValue = "1") String guildId, @CookieValue(value = "token", defaultValue = "") String token) {
|
||||||
if (token.equals("")) {
|
if (token.equals("")) {
|
||||||
@ -75,6 +74,5 @@ public class MusicWebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class MvcApplication implements WebMvcConfigurer {
|
|||||||
.resourceChain(true)
|
.resourceChain(true)
|
||||||
.addResolver(versionResourceResolver);
|
.addResolver(versionResourceResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
|
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
|
||||||
return new ResourceUrlEncodingFilter();
|
return new ResourceUrlEncodingFilter();
|
||||||
|
@ -29,11 +29,9 @@ public class MyErrorController implements ErrorController {
|
|||||||
|
|
||||||
if (statusCode == HttpStatus.NOT_FOUND.value()) {
|
if (statusCode == HttpStatus.NOT_FOUND.value()) {
|
||||||
return "error/404";
|
return "error/404";
|
||||||
}
|
} else if (statusCode == HttpStatus.FORBIDDEN.value()) {
|
||||||
else if(statusCode == HttpStatus.FORBIDDEN.value()){
|
|
||||||
return "error/403";
|
return "error/403";
|
||||||
}
|
} else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
|
||||||
else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()){
|
|
||||||
return "error/500";
|
return "error/500";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user