Merge branch 'devel'
This commit is contained in:
commit
929a06ccc1
@ -34,6 +34,15 @@ dependencies {
|
||||
compile("com.sedmelluq:lavaplayer:1.2.45")
|
||||
compile 'net.dv8tion:JDA:3.3.1_303'
|
||||
compile group: 'org.json', name: 'json', version: '20160810'
|
||||
// JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
|
||||
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
|
||||
exclude group:"org.springframework.boot", module: "spring-boot-starter-logging"
|
||||
}
|
||||
// Use MySQL Connector-J
|
||||
compile 'mysql:mysql-connector-java'
|
||||
compile 'org.reflections:reflections:0.9.11'
|
||||
|
||||
|
||||
testCompile('org.springframework.boot:spring-boot-starter-test')
|
||||
testCompile('com.jayway.jsonpath:json-path')
|
||||
compile("org.springframework.boot:spring-boot-starter-thymeleaf") {
|
||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
#Sun Jan 07 23:09:03 CET 2018
|
||||
#Wed Jan 10 09:57:49 CET 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.Broken;
|
||||
|
||||
import net.Broken.Commandes.Move;
|
||||
import net.Broken.Commandes.Music;
|
||||
import net.Broken.Commands.Move;
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.Outils.AntiSpam;
|
||||
import net.Broken.Outils.Moderateur;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
|
||||
import net.Broken.Commande;
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Outils.EmbedMessageUtils;
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
@ -9,7 +9,6 @@ import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -84,7 +83,7 @@ public class Help implements Commande {
|
||||
}
|
||||
|
||||
if(!event.isFromType(ChannelType.PRIVATE)){
|
||||
Message rest = event.getTextChannel().sendMessage(new EmbedBuilder().setTitle("Commandes envoyées par message privé").setColor(Color.green).build()).complete();
|
||||
Message rest = event.getTextChannel().sendMessage(new EmbedBuilder().setTitle("Command envoyées par message privé").setColor(Color.green).build()).complete();
|
||||
List<Message> messages = new ArrayList<Message>(){{
|
||||
add(rest);
|
||||
add(event.getMessage());
|
||||
@ -92,7 +91,7 @@ public class Help implements Commande {
|
||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||
}
|
||||
|
||||
PrivateMessage.send(event.getAuthor(),new EmbedBuilder().setTitle("Commandes du bot").setDescription(txt.toString()).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(event.getJDA().getSelfUser().getAvatarUrl()).build(),logger);
|
||||
PrivateMessage.send(event.getAuthor(),new EmbedBuilder().setTitle("Command du bot").setDescription(txt.toString()).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(event.getJDA().getSelfUser().getAvatarUrl()).build(),logger);
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
@ -15,7 +15,6 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
@ -19,8 +19,8 @@ import java.util.List;
|
||||
public class Music implements Commande {
|
||||
public AudioM audio;
|
||||
Logger logger = LogManager.getLogger();
|
||||
public Music(Guild guild) {
|
||||
audio = new AudioM(guild);
|
||||
public Music() {
|
||||
audio = new AudioM(MainBot.jda.getGuilds().get(0));
|
||||
}
|
||||
|
||||
@Override
|
@ -1,6 +1,6 @@
|
||||
package net.Broken.Commandes.Over18;
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commandes.NumberedCommande;
|
||||
import net.Broken.Outils.Command.NumberedCommande;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
package net.Broken.Commandes.Over18;
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commandes.NumberedCommande;
|
||||
import net.Broken.Outils.Command.NumberedCommande;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes.Over18;
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Outils.Redirection;
|
@ -1,6 +1,6 @@
|
||||
package net.Broken.Commandes.Over18;
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commandes.NumberedCommande;
|
||||
import net.Broken.Outils.Command.NumberedCommande;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes.Over18;
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Outils.Redirection;
|
||||
@ -6,8 +6,6 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by seb65 on 10/11/2016.
|
||||
*/
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
@ -8,8 +8,6 @@ import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -17,10 +15,10 @@ import java.util.List;
|
||||
/**
|
||||
* Created by seb65 on 19/10/2016.
|
||||
*/
|
||||
public class PingCommande implements Commande {
|
||||
public class Ping implements Commande {
|
||||
|
||||
|
||||
private String HELP = "`//ping` \n :arrow_right:\t*Le bot vous répondra Pong!*";
|
||||
private String HELP = "`//ping` \n :arrow_right:\t*Renvoi le ping du bot*";
|
||||
@Override
|
||||
public boolean called(String[] args, MessageReceivedEvent event) {
|
||||
return true;
|
||||
@ -28,11 +26,12 @@ public class PingCommande implements Commande {
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
long receivedTime = Timestamp.valueOf(LocalDateTime.ofInstant(event.getMessage().getCreationTime().toInstant(), ZoneId.systemDefault())).getTime();
|
||||
long ping = event.getJDA().getPing();
|
||||
// long receivedTime = Timestamp.valueOf(LocalDateTime.ofInstant(event.getMessage().getCreationTime().toInstant(), ZoneId.systemDefault())).getTime();
|
||||
if(event.isFromType(ChannelType.PRIVATE))
|
||||
event.getPrivateChannel().sendMessage(":arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
|
||||
event.getPrivateChannel().sendMessage(":arrow_right: Pong! `" + ping+ "ms`").queue();
|
||||
else {
|
||||
Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").complete();
|
||||
Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `" + ping + "ms`").complete();
|
||||
List<Message> messages = new ArrayList<Message>(){{
|
||||
add(rest);
|
||||
add(event.getMessage());
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
@ -8,7 +8,6 @@ import net.Broken.Outils.PrivateMessage;
|
||||
import net.Broken.Outils.UserSpamUtils;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
@ -1,7 +1,6 @@
|
||||
package net.Broken;
|
||||
|
||||
import net.Broken.Commandes.*;
|
||||
import net.Broken.Commandes.Over18.*;
|
||||
import net.Broken.Outils.Command.CommandLoader;
|
||||
import net.Broken.Outils.DayListener;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
@ -11,7 +10,6 @@ import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
import net.dv8tion.jda.core.managers.GuildManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -40,6 +38,7 @@ public class Init {
|
||||
logger.info("Connection au serveur...");
|
||||
//connection au bot
|
||||
jda = new JDABuilder(AccountType.BOT).addEventListener(new BotListener()).setToken(token).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
||||
MainBot.jda = jda;
|
||||
jda.setAutoReconnect(true);
|
||||
jda.addEventListener();
|
||||
|
||||
@ -48,25 +47,7 @@ public class Init {
|
||||
*************************************/
|
||||
jda.getPresence().setGame(Game.of("Statut: Loading..."));
|
||||
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
||||
MainBot.commandes.put("ping", new PingCommande());
|
||||
MainBot.commandes.put("help", new Help());
|
||||
MainBot.commandes.put("move", new Move());
|
||||
MainBot.commandes.put("spam", new Spam());
|
||||
MainBot.commandes.put("spaminfo", new SpamInfo());
|
||||
MainBot.commandes.put("flush", new Flush());
|
||||
MainBot.commandes.put("music", new Music(jda.getGuilds().get(0)));
|
||||
|
||||
if (!dev) {
|
||||
MainBot.commandes.put("ass", new Ass());
|
||||
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
||||
MainBot.commandes.put("boobs", new Boobs());
|
||||
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
||||
MainBot.commandes.put("pipe", new Pipe());
|
||||
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
||||
MainBot.commandes.put("sm", new SM());
|
||||
MainBot.commandes.put("madame", new Madame());
|
||||
MainBot.commandes.put("cat", new Cat());
|
||||
}
|
||||
CommandLoader.load();
|
||||
|
||||
|
||||
//On recupere le l'id serveur
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.Broken;
|
||||
|
||||
import net.Broken.Outils.CommandParser;
|
||||
import net.Broken.Outils.Command.CommandParser;
|
||||
import net.Broken.Outils.EmbedMessageUtils;
|
||||
import net.Broken.Outils.UserSpamUtils;
|
||||
import net.Broken.RestApi.ApiCommandLoader;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
@ -32,6 +33,9 @@ public class MainBot {
|
||||
public static HashMap<User, Integer> message_compteur =new HashMap<>();
|
||||
public static boolean roleFlag = false;
|
||||
public static HashMap<User, UserSpamUtils> spamUtils = new HashMap<>();
|
||||
public static JDA jda;
|
||||
|
||||
|
||||
|
||||
public static int messageTimeOut = 10;
|
||||
|
||||
@ -61,7 +65,7 @@ public class MainBot {
|
||||
i++;
|
||||
}
|
||||
|
||||
JDA jda = Init.initBot(token, dev);
|
||||
jda = Init.initBot(token, dev);
|
||||
ConfigurableApplicationContext ctx = SpringApplication.run(MainBot.class, args);
|
||||
if(jda == null) {
|
||||
System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) () -> {
|
||||
@ -70,6 +74,11 @@ public class MainBot {
|
||||
}));
|
||||
}
|
||||
|
||||
ApiCommandLoader.load();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
package net.Broken.Outils;
|
||||
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.Commandes.Move;
|
||||
import net.Broken.Commands.Move;
|
||||
import net.Broken.Outils.EmbedMessageUtils;
|
||||
import net.Broken.Outils.MessageTimeOut;
|
||||
import net.Broken.Outils.UserSpamUtils;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.exceptions.HierarchyException;
|
||||
|
35
src/main/java/net/Broken/Outils/Command/CommandLoader.java
Normal file
35
src/main/java/net/Broken/Outils/Command/CommandLoader.java
Normal file
@ -0,0 +1,35 @@
|
||||
package net.Broken.Outils.Command;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandLoader {
|
||||
private static Logger logger = LogManager.getLogger();
|
||||
public static void load(){
|
||||
logger.info("Loading Command...");
|
||||
Reflections reflections = new Reflections("net.Broken.Command");
|
||||
Set<Class<? extends Commande>> modules = reflections.getSubTypesOf(Commande.class);
|
||||
|
||||
logger.info("Find " + modules.size() + " Command:");
|
||||
for (Class<? extends Commande> command : modules) {
|
||||
|
||||
String reference = command.getName();
|
||||
String[] splited = reference.split("\\.");
|
||||
String name = splited[splited.length-1].toLowerCase();
|
||||
|
||||
logger.info("..." + name);
|
||||
try {
|
||||
MainBot.commandes.put(name, command.newInstance());
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
logger.error("Failed to load " + name + "!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Outils;
|
||||
package net.Broken.Outils.Command;
|
||||
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -12,29 +12,31 @@ import java.util.Arrays;
|
||||
*/
|
||||
|
||||
public class CommandParser {
|
||||
Logger logger = LogManager.getLogger();
|
||||
private Logger logger = LogManager.getLogger();
|
||||
public CommandContainer parse(String brt, MessageReceivedEvent e)
|
||||
{
|
||||
ArrayList<String> split =new ArrayList<String>();
|
||||
String brut =brt;
|
||||
String sansTete = brut.replaceFirst("//",""); // on retire l'entete
|
||||
String[] splitSansTete = sansTete.split(" "); // on prend l'espace comme separateur cmd/arg
|
||||
for(String s : splitSansTete){ //= pourchaque
|
||||
split.add(s); // on fait un truc que je comprend pas trop x)
|
||||
String sansTete = brut.replaceFirst("//","");
|
||||
String[] splitSansTete = sansTete.split(" ");
|
||||
|
||||
for(String s : splitSansTete){
|
||||
if(s.length()>0)
|
||||
split.add(s);
|
||||
}
|
||||
String commande = split.get(0); // on recuperre la 1er partie qui correspond a la cmd
|
||||
|
||||
String commande = split.get(0);
|
||||
String[] args = new String[split.size()-1];
|
||||
split.subList(1,split.size()).toArray(args);
|
||||
|
||||
for(int i=0;i<args.length;i++)
|
||||
{
|
||||
args[i]=args[i].replace('$',' ');
|
||||
|
||||
|
||||
}
|
||||
|
||||
logger.info("Auteur: "+e.getAuthor().getName()+", Commande: "+commande+", args: "+ Arrays.toString(args));
|
||||
|
||||
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e); //On Save toute les info dans le container
|
||||
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e);
|
||||
|
||||
}
|
||||
public class CommandContainer{
|
@ -1,4 +1,4 @@
|
||||
package net.Broken.Commandes;
|
||||
package net.Broken.Outils.Command;
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Outils.FindContentOnWebPage;
|
||||
import net.Broken.Outils.LimitChecker;
|
@ -1,5 +1,5 @@
|
||||
package net.Broken.Outils;
|
||||
import net.Broken.Commandes.Spam;
|
||||
import net.Broken.Commands.Spam;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
|
36
src/main/java/net/Broken/RestApi/ApiCommandLoader.java
Normal file
36
src/main/java/net/Broken/RestApi/ApiCommandLoader.java
Normal file
@ -0,0 +1,36 @@
|
||||
package net.Broken.RestApi;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApiCommandLoader {
|
||||
public static HashMap<String, CommandInterface> apiCommands = new HashMap<>();
|
||||
private static Logger logger = LogManager.getLogger();
|
||||
public static void load(){
|
||||
logger.info("Loading Api Command...");
|
||||
Reflections reflections = new Reflections("net.Broken.RestApi.Command");
|
||||
Set<Class<? extends CommandInterface>> modules =
|
||||
reflections.getSubTypesOf(CommandInterface.class);
|
||||
logger.info("Find " + modules.size() + " Command:");
|
||||
for (Class<? extends CommandInterface> apiClass : modules) {
|
||||
|
||||
String reference = apiClass.getName();
|
||||
String[] splited = reference.split("\\.");
|
||||
String name = splited[splited.length-1].toUpperCase();
|
||||
|
||||
logger.info("..." + name);
|
||||
|
||||
try {
|
||||
apiCommands.put(name, apiClass.newInstance());
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
logger.error("Failed to load " + name + "!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
10
src/main/java/net/Broken/RestApi/CommandInterface.java
Normal file
10
src/main/java/net/Broken/RestApi/CommandInterface.java
Normal file
@ -0,0 +1,10 @@
|
||||
package net.Broken.RestApi;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public interface CommandInterface {
|
||||
ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data);
|
||||
}
|
15
src/main/java/net/Broken/RestApi/Commands/Add.java
Normal file
15
src/main/java/net/Broken/RestApi/Commands/Add.java
Normal file
@ -0,0 +1,15 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.WebLoadUtils;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Add implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
return new WebLoadUtils(musicCommande ,data).getResponse();
|
||||
}
|
||||
}
|
22
src/main/java/net/Broken/RestApi/Commands/Flush.java
Normal file
22
src/main/java/net/Broken/RestApi/Commands/Flush.java
Normal file
@ -0,0 +1,22 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Flush implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.flush();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
22
src/main/java/net/Broken/RestApi/Commands/Next.java
Normal file
22
src/main/java/net/Broken/RestApi/Commands/Next.java
Normal file
@ -0,0 +1,22 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Next implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.nextTrack();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
22
src/main/java/net/Broken/RestApi/Commands/Pause.java
Normal file
22
src/main/java/net/Broken/RestApi/Commands/Pause.java
Normal file
@ -0,0 +1,22 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Pause implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.pause();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
22
src/main/java/net/Broken/RestApi/Commands/Play.java
Normal file
22
src/main/java/net/Broken/RestApi/Commands/Play.java
Normal file
@ -0,0 +1,22 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Play implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.resume();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
18
src/main/java/net/Broken/RestApi/Commands/Stop.java
Normal file
18
src/main/java/net/Broken/RestApi/Commands/Stop.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class Stop implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
|
||||
musicCommande.getAudioManager().stop((MessageReceivedEvent) null);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
105
src/main/java/net/Broken/RestApi/MusicWebAPIController.java
Normal file
105
src/main/java/net/Broken/RestApi/MusicWebAPIController.java
Normal file
@ -0,0 +1,105 @@
|
||||
package net.Broken.RestApi;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.DB.SavedPlaylistRepository;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.RestApi.Data.CurrentMusicData;
|
||||
import net.Broken.RestApi.Data.PlaylistData;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/music/")
|
||||
public class MusicWebAPIController {
|
||||
Logger logger = LogManager.getLogger();
|
||||
@Autowired
|
||||
public SavedPlaylistRepository savedPlaylist;
|
||||
|
||||
@RequestMapping("/currentMusicInfo")
|
||||
public CurrentMusicData getCurrentM(){
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
|
||||
if(musicCommande.audio.getGuild().getAudioManager().isConnected()){
|
||||
try {
|
||||
AudioPlayer player = musicCommande.audio.getMusicManager().player;
|
||||
AudioTrack currentTrack = player.getPlayingTrack();
|
||||
if(currentTrack == null)
|
||||
{
|
||||
return new CurrentMusicData(null,0, "STOP",false);
|
||||
}
|
||||
return new CurrentMusicData(currentTrack.getInfo(),currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused());
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new CurrentMusicData(null,0, "STOP",false);
|
||||
}
|
||||
}else
|
||||
{
|
||||
return new CurrentMusicData(null,0, "DISCONNECTED",false);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/getPlaylist")
|
||||
public PlaylistData getPlaylist(){
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
List<AudioTrackInfo> list = null;
|
||||
try {
|
||||
list = musicCommande.getAudioManager().getMusicManager().scheduler.getList();
|
||||
return new PlaylistData(list);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new PlaylistData(list);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/command", method = RequestMethod.POST)
|
||||
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data){
|
||||
|
||||
if(data.command != null) {
|
||||
logger.info("receive command: " + data.command);
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
|
||||
if(ApiCommandLoader.apiCommands.containsKey(data.command))
|
||||
return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande,data);
|
||||
else
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Unknown Command"), HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
else
|
||||
logger.info("Null");
|
||||
return new ResponseEntity<>(new CommandResponseData(null, null), HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// DB Test Ignore it
|
||||
|
||||
// @RequestMapping(value = "/test", method = RequestMethod.GET)
|
||||
// public ResponseEntity<String> test(){
|
||||
// SavedPlaylistEntity savedPlaylistEntity = new SavedPlaylistEntity();
|
||||
// savedPlaylistEntity.setAutorName("Test");
|
||||
// savedPlaylistEntity.setName("Playlist de test");
|
||||
// savedPlaylist.save(savedPlaylistEntity);
|
||||
// logger.info(savedPlaylistEntity);
|
||||
// return new ResponseEntity<String>("OK",HttpStatus.OK);
|
||||
// }
|
||||
// @GetMapping(path="/all")
|
||||
// public @ResponseBody Iterable<SavedPlaylistEntity> getAllUsers() {
|
||||
// // This returns a JSON or XML with the users
|
||||
// return savedPlaylist.findAll();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,128 +0,0 @@
|
||||
package net.Broken.RestApi;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import net.Broken.Commandes.Music;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.RestApi.Data.CurrentMusicData;
|
||||
import net.Broken.RestApi.Data.PlaylistData;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.Broken.audio.NotConectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.WebLoadUtils;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/music/")
|
||||
public class MusicWebController {
|
||||
Logger logger = LogManager.getLogger();
|
||||
|
||||
@RequestMapping("/currentMusicInfo")
|
||||
public CurrentMusicData test(){
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
|
||||
if(musicCommande.audio.getGuild().getAudioManager().isConnected()){
|
||||
try {
|
||||
AudioPlayer player = musicCommande.audio.getMusicManager().player;
|
||||
AudioTrack currentTrack = player.getPlayingTrack();
|
||||
if(currentTrack == null)
|
||||
{
|
||||
return new CurrentMusicData(null,0, "STOP",false);
|
||||
}
|
||||
return new CurrentMusicData(currentTrack.getInfo(),currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused());
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new CurrentMusicData(null,0, "STOP",false);
|
||||
}
|
||||
}else
|
||||
{
|
||||
return new CurrentMusicData(null,0, "DISCONNECTED",false);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/getPlaylist")
|
||||
public PlaylistData getPlaylist(){
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
List<AudioTrackInfo> list = null;
|
||||
try {
|
||||
list = musicCommande.getAudioManager().getMusicManager().scheduler.getList();
|
||||
return new PlaylistData(list);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new PlaylistData(list);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/command", method = RequestMethod.POST)
|
||||
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data){
|
||||
|
||||
if(data.command != null) {
|
||||
logger.info("receive command: " + data.command);
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
switch (data.command) {
|
||||
case "PLAY":
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.resume();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
case "PAUSE":
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.pause();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
case "NEXT":
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.nextTrack();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
case "STOP":
|
||||
musicCommande.getAudioManager().stop((MessageReceivedEvent) null);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
|
||||
case "ADD":
|
||||
return new WebLoadUtils(musicCommande ,data).getResponse();
|
||||
|
||||
case "FLUSH":
|
||||
try {
|
||||
musicCommande.getAudioManager().getMusicManager().scheduler.flush();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
logger.info("Null");
|
||||
return new ResponseEntity<>(new CommandResponseData(null, null), HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import net.Broken.Commandes.Music;
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -13,8 +13,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class WebLoadUtils {
|
||||
ResponseEntity<CommandResponseData> response;
|
||||
Logger logger = LogManager.getLogger();
|
||||
|
Loading…
Reference in New Issue
Block a user