Merge branch 'devel'
This commit is contained in:
commit
d370cce0b3
@ -53,7 +53,7 @@ dependencies {
|
||||
}
|
||||
compile("org.springframework.boot:spring-boot-starter-log4j2")
|
||||
compile("com.sedmelluq:lavaplayer:1.2.49")
|
||||
compile 'net.dv8tion:JDA:3.3.1_303'
|
||||
compile 'net.dv8tion:JDA:3.6.0_354'
|
||||
compile group: 'org.json', name: 'json', version: '20160810'
|
||||
compile 'org.springframework.security:spring-security-web:5.0.1.RELEASE'
|
||||
// JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
|
||||
|
@ -2,17 +2,20 @@ package net.Broken;
|
||||
|
||||
import net.Broken.Commands.Move;
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||
import net.Broken.DB.Repository.PlaylistRepository;
|
||||
import net.Broken.Tools.AntiSpam;
|
||||
import net.Broken.Tools.Command.CommandParser;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
import net.Broken.Tools.Moderateur;
|
||||
import net.Broken.Tools.PrivateMessage;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.ExceptionEvent;
|
||||
import net.dv8tion.jda.core.events.ReadyEvent;
|
||||
import net.dv8tion.jda.core.events.guild.GuildJoinEvent;
|
||||
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.core.events.guild.member.GuildMemberRoleRemoveEvent;
|
||||
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
|
||||
@ -21,6 +24,11 @@ import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.core.managers.GuildManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -29,8 +37,17 @@ import org.apache.logging.log4j.Logger;
|
||||
public class BotListener extends ListenerAdapter {
|
||||
private AntiSpam antispam=new AntiSpam();
|
||||
private Moderateur modo = new Moderateur();
|
||||
|
||||
private GuildPreferenceRepository guildPreferenceRepository;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
public BotListener() {
|
||||
|
||||
ApplicationContext context = SpringContext.getAppContext();
|
||||
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(ReadyEvent event) {
|
||||
@ -40,34 +57,70 @@ public class BotListener extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
||||
logger.info(event.getUser().getName()+ "join the guild, move it!");
|
||||
new Move().exc(event.getMember(),event.getJDA().getRolesByName("Newbies",true),false,event.getJDA().getGuilds().get(0),event.getJDA().getGuilds().get(0).getManager());
|
||||
TextChannel chanel = event.getGuild().getTextChannelsByName("accueil", true).get(0);
|
||||
chanel.sendMessage("Salut "+event.getUser().getAsMention()+"! Ecris ton nom, prénom, ta promotion et ton groupe ici! Un admin te donnera accées a ton groupe!").complete();
|
||||
MainBot.roleFlag = false;
|
||||
|
||||
GuildPreferenceEntity guildPref = getPreference(event.getGuild());
|
||||
|
||||
if(guildPref.isDefaultRole()){
|
||||
|
||||
logger.info(event.getUser().getName()+ "join the guild, move it!");
|
||||
|
||||
List<Role> roles = new ArrayList<>();
|
||||
roles.add(event.getGuild().getRoleById(guildPref.getDefaultRoleId()));
|
||||
|
||||
|
||||
new Move().exc(event.getMember(), roles,false,event.getGuild(),event.getGuild().getManager());
|
||||
}
|
||||
|
||||
|
||||
if(guildPref.isWelcome()){
|
||||
|
||||
TextChannel chanel = event.getGuild().getTextChannelById(guildPref.getWelcomeChanelID());
|
||||
if(chanel != null){
|
||||
String message = guildPref.getWelcomeMessage();
|
||||
message = message.replaceAll("@name", event.getMember().getAsMention());
|
||||
logger.debug(message);
|
||||
// "Salut "+event.getUser().getAsMention()+"! Ecris ton nom, prénom, ta promotion et ton groupe ici! Un admin te donnera accées a ton groupe!"
|
||||
chanel.sendMessage(message).complete();
|
||||
}
|
||||
|
||||
MainBot.roleFlag = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildMemberRoleRemove(GuildMemberRoleRemoveEvent event) {
|
||||
logger.debug(event.getUser().getName()+" leave a role");
|
||||
if(!MainBot.roleFlag){
|
||||
|
||||
if(event.getMember().getRoles().size() == 0){
|
||||
logger.info(event.getUser().getName()+ "have no roles, move it!");
|
||||
new Move().exc(event.getMember(),event.getJDA().getRolesByName("Populace",true),false,event.getJDA().getGuilds().get(0),event.getJDA().getGuilds().get(0).getManager());
|
||||
GuildPreferenceEntity guildPref = getPreference(event.getGuild());
|
||||
if(guildPref.isDefaultRole()){
|
||||
|
||||
if(!MainBot.roleFlag){
|
||||
|
||||
if(event.getMember().getRoles().size() == 0){
|
||||
|
||||
logger.info(event.getUser().getName()+ "have no roles, move it!");
|
||||
List<Role> roles = new ArrayList<>();
|
||||
roles.add(event.getGuild().getRoleById(guildPref.getDefaultRoleId()));
|
||||
|
||||
|
||||
new Move().exc(event.getMember(), roles,false,event.getGuild(),event.getGuild().getManager());
|
||||
MainBot.roleFlag = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("ignore it");
|
||||
MainBot.roleFlag = false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("ignore it");
|
||||
MainBot.roleFlag = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
|
||||
super.onGuildVoiceLeave(event);
|
||||
@ -78,43 +131,50 @@ public class BotListener extends ListenerAdapter {
|
||||
if(event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() == 1){
|
||||
logger.debug("I'm alone, close audio connection.");
|
||||
|
||||
Music music = (Music) MainBot.commandes.get("music");
|
||||
music.audio.stop();
|
||||
AudioM.getInstance(event.getGuild()).stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
// ----------------------Test pour eviter eco de commande-------------------------
|
||||
// ----------------------Preference pour eviter eco de commande-------------------------
|
||||
|
||||
|
||||
try{
|
||||
if (event.getMessage().getContent().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
if (event.getMessage().getContentRaw().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
|
||||
//On a detecter que c'etait une commande
|
||||
//System.out.println(event.getMessage().getContent());
|
||||
MainBot.handleCommand(new CommandParser().parse(event.getMessage().getContent(), event));
|
||||
MainBot.handleCommand(new CommandParser().parse(event.getMessage().getContentRaw(), event));
|
||||
|
||||
}
|
||||
else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
|
||||
{
|
||||
|
||||
if(!event.isFromType(ChannelType.PRIVATE)) {
|
||||
if (!event.getTextChannel().getName().equals("le_dongeon")) {
|
||||
Guild serveur = event.getGuild();
|
||||
GuildManager guildManager = serveur.getManager();
|
||||
Member user = event.getMember();
|
||||
|
||||
// appel de la methode d'analyse de message de "Moderateur"
|
||||
if (!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContent().length() > 0) {
|
||||
|
||||
if (modo.analyse(user, serveur, guildManager, event) == 1) {
|
||||
antispam.extermine(user, serveur, guildManager, true, event);
|
||||
}
|
||||
} else if (event.getMessage().getContent().length() == 0)
|
||||
logger.error("Image detected, ignoring it.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Guild serveur = event.getGuild();
|
||||
GuildPreferenceEntity guildPref = getPreference(serveur);
|
||||
|
||||
if(!guildPref.isAntiSpam())
|
||||
return;
|
||||
|
||||
GuildManager guildManager = serveur.getManager();
|
||||
Member user = event.getMember();
|
||||
|
||||
// appel de la methode d'analyse de message de "Moderateur"
|
||||
if (event.getMessage().getContentRaw().length() > 0) {
|
||||
|
||||
if (modo.analyse(user, serveur, guildManager, event) == 1) {
|
||||
antispam.extermine(user, serveur, guildManager, true, event);
|
||||
}
|
||||
} else if (event.getMessage().getContentRaw().length() == 0)
|
||||
logger.error("Image detected, ignoring it.");
|
||||
}
|
||||
|
||||
|
||||
@ -132,4 +192,31 @@ public class BotListener extends ListenerAdapter {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildJoin(GuildJoinEvent event) {
|
||||
logger.info("Join new guild! (" + event.getGuild().getName() + ")");
|
||||
super.onGuildJoin(event);
|
||||
getPreference(event.getGuild());
|
||||
EmbedBuilder eb = new EmbedBuilder().setColor(Color.GREEN)
|
||||
.setTitle("Hello there !")
|
||||
.setDescription("Allow me to introduce myself -- I am a CL4P-TP the discord bot, but my friends call me Claptrap ! Or they would, if any of them were real...\n"+
|
||||
"\nYou can access to my web UI with: https://bot.seb6596.ovh")
|
||||
.setImage("https://i.imgur.com/Anf1Srg.gif");
|
||||
|
||||
event.getGuild().getDefaultChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
}
|
||||
|
||||
private GuildPreferenceEntity getPreference(Guild guild){
|
||||
List<GuildPreferenceEntity> guildPrefList = guildPreferenceRepository.findByGuildId(guild.getId());
|
||||
GuildPreferenceEntity guildPref;
|
||||
if(guildPrefList.isEmpty()){
|
||||
logger.info("Generate default pref");
|
||||
guildPref = GuildPreferenceEntity.getDefault(guild);
|
||||
guildPreferenceRepository.save(guildPref);
|
||||
}
|
||||
else
|
||||
guildPref = guildPrefList.get(0);
|
||||
return guildPref;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class Flush implements Commande{
|
||||
if(limit > retrieved.size())
|
||||
limit = retrieved.size()-1;
|
||||
for(int i = 0; i<limit+1; i++){
|
||||
logger.debug(retrieved.get(i).getContent());
|
||||
logger.debug(retrieved.get(i).getContentRaw());
|
||||
retrieved.get(i).delete().queue();
|
||||
}
|
||||
}catch (NumberFormatException e){
|
||||
|
@ -9,6 +9,7 @@ import net.Broken.Tools.TableRenderer;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.Permission;
|
||||
import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Message;
|
||||
import net.dv8tion.jda.core.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
@ -36,8 +37,10 @@ public class Help implements Commande {
|
||||
//System.out.println(argsString);
|
||||
if (MainBot.commandes.containsKey(argsString))
|
||||
{
|
||||
|
||||
|
||||
Commande cmdObj = MainBot.commandes.get(argsString);
|
||||
if(!cmdObj.isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR))
|
||||
if(!cmdObj.isAdminCmd() || isAdmin(event))
|
||||
{
|
||||
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName());
|
||||
MessageEmbed messageEmbed;
|
||||
@ -118,15 +121,8 @@ public class Help implements Commande {
|
||||
nsfwTable.setHeader("NSFW Only\u00A0", "PU");
|
||||
List<String> noPu = new ArrayList<>();
|
||||
|
||||
boolean isAdmin;
|
||||
if(event.isFromType(ChannelType.PRIVATE))
|
||||
isAdmin = event.getJDA().getGuilds().get(0).getMember(event.getAuthor()).hasPermission(Permission.ADMINISTRATOR);
|
||||
else
|
||||
isAdmin = event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||
|
||||
|
||||
for (Map.Entry<String, Commande> e : MainBot.commandes.entrySet()) {
|
||||
if(!e.getValue().isAdminCmd() || isAdmin){
|
||||
if(!e.getValue().isAdminCmd() || isAdmin(event)){
|
||||
if(e.getValue().isPrivateUsable())
|
||||
table.addRow(e.getKey(), "XX");
|
||||
else if(e.getValue().isNSFW())
|
||||
@ -152,7 +148,7 @@ public class Help implements Commande {
|
||||
|
||||
|
||||
String role;
|
||||
if(isAdmin)
|
||||
if(isAdmin(event))
|
||||
role = "Admin";
|
||||
else
|
||||
role = "Non Admin";
|
||||
@ -185,4 +181,22 @@ public class Help implements Commande {
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAdmin(MessageReceivedEvent event){
|
||||
|
||||
if(event.isFromType(ChannelType.PRIVATE)){
|
||||
List<Guild> guilds = event.getAuthor().getMutualGuilds();
|
||||
for(Guild iterator : guilds){
|
||||
if(iterator.getMember(event.getAuthor()).hasPermission(Permission.ADMINISTRATOR)){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
return event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
33
src/main/java/net/Broken/Commands/Invite.java
Normal file
33
src/main/java/net/Broken/Commands/Invite.java
Normal file
@ -0,0 +1,33 @@
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Tools.PrivateMessage;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
public class Invite implements Commande{
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
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();
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateUsable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
}
|
38
src/main/java/net/Broken/Commands/ListRoles.java
Normal file
38
src/main/java/net/Broken/Commands/ListRoles.java
Normal file
@ -0,0 +1,38 @@
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.Role;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
|
||||
public class ListRoles implements Commande {
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
List<Role> roles = event.getGuild().getRoles();
|
||||
EmbedBuilder messageB = new EmbedBuilder();
|
||||
for (Role role : roles){
|
||||
messageB.addField(role.getName(),"```id: " + role.getId() + "```",false);
|
||||
}
|
||||
|
||||
messageB.setColor(Color.green);
|
||||
event.getTextChannel().sendMessage(messageB.build()).complete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateUsable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminCmd() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -20,21 +20,20 @@ import java.util.List;
|
||||
*/
|
||||
|
||||
public class Music implements Commande {
|
||||
public AudioM audio;
|
||||
Logger logger = LogManager.getLogger();
|
||||
public Music() {
|
||||
audio = AudioM.getInstance(MainBot.jda.getGuilds().get(0));
|
||||
}
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
|
||||
AudioM audio = AudioM.getInstance(event.getGuild());
|
||||
if(args.length >= 1){
|
||||
switch (args[0]){
|
||||
case "play":
|
||||
event.getTextChannel().sendTyping().queue();
|
||||
|
||||
if(args.length>=2){
|
||||
if(event.getMember().getVoiceState().inVoiceChannel()){
|
||||
|
||||
VoiceChannel voiceChanel = event.getMember().getVoiceState().getChannel();
|
||||
logger.info("Connecting to "+voiceChanel.getName()+"...");
|
||||
if(args.length ==2){
|
||||
@ -170,8 +169,4 @@ public class Music implements Commande {
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioM getAudioManager(){
|
||||
return audio;
|
||||
}
|
||||
}
|
||||
|
41
src/main/java/net/Broken/Commands/Over18/Suicide.java
Normal file
41
src/main/java/net/Broken/Commands/Over18/Suicide.java
Normal file
@ -0,0 +1,41 @@
|
||||
package net.Broken.Commands.Over18;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
import net.Broken.Tools.Redirection;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Suicide implements Commande{
|
||||
|
||||
private String redirectUrl = "https://suicidegirlsandhopefuls.tumblr.com/random";
|
||||
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
Redirection redirection = new Redirection();
|
||||
try {
|
||||
event.getTextChannel().sendMessage(redirection.get(redirectUrl)).queue();
|
||||
} catch (IOException e) {
|
||||
LogManager.getLogger().catching(e);
|
||||
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateUsable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return true;
|
||||
}
|
||||
}
|
216
src/main/java/net/Broken/Commands/Preference.java
Normal file
216
src/main/java/net/Broken/Commands/Preference.java
Normal file
@ -0,0 +1,216 @@
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||
import net.Broken.DB.Repository.GuildPreferenceRepository;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.SpringContext;
|
||||
import net.Broken.Tools.EmbedMessageUtils;
|
||||
import net.Broken.Tools.MessageTimeOut;
|
||||
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.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Preference implements Commande {
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
private GuildPreferenceRepository guildPreferenceRepository;
|
||||
|
||||
public Preference() {
|
||||
|
||||
ApplicationContext context = SpringContext.getAppContext();
|
||||
guildPreferenceRepository = (GuildPreferenceRepository) context.getBean("guildPreferenceRepository");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
if(args.length == 0){
|
||||
GuildPreferenceEntity guildPref = getPreference(event.getGuild());
|
||||
MessageEmbed message = EmbedMessageUtils.getPref(guildPref);
|
||||
event.getTextChannel().sendMessage(message).complete();
|
||||
|
||||
}
|
||||
else{
|
||||
switch (args[0]){
|
||||
case "set":
|
||||
if(args.length >= 3){
|
||||
StringBuilder val = new StringBuilder();
|
||||
for(int i = 2; i < args.length; i++){
|
||||
val.append(args[i]).append(" ");
|
||||
}
|
||||
set(event, args[1], val.toString());
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("Missing argument.\n:arrow_right: Please use `//help preference`"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nUnknown argument`\n\nMore info with `//help preference`"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateUsable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminCmd() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private GuildPreferenceEntity getPreference(Guild guild){
|
||||
List<GuildPreferenceEntity> guildPrefList = guildPreferenceRepository.findByGuildId(guild.getId());
|
||||
GuildPreferenceEntity guildPref;
|
||||
if(guildPrefList.isEmpty()){
|
||||
logger.info("Generate default pref for " + guild.getName());
|
||||
guildPref = GuildPreferenceEntity.getDefault(guild);
|
||||
guildPreferenceRepository.save(guildPref);
|
||||
}
|
||||
else
|
||||
guildPref = guildPrefList.get(0);
|
||||
return guildPref;
|
||||
}
|
||||
|
||||
|
||||
private void set(MessageReceivedEvent event, String key, String value){
|
||||
GuildPreferenceEntity pref = getPreference(event.getGuild());
|
||||
switch (key){
|
||||
case "anti_spam":
|
||||
if(value.toLowerCase().equals("true") || value.toLowerCase().equals("false")){
|
||||
boolean result = Boolean.parseBoolean(value);
|
||||
pref.setAntiSpam(result);
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Anti Spam", "```java\n" + String.valueOf(pref.isAntiSpam()) + "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}else{
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nWrong value, expect `true` or `false`\n\nMore info with `//help preference`"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "default_role":
|
||||
if(value.toLowerCase().equals("true") || value.toLowerCase().equals("false")){
|
||||
boolean result = Boolean.parseBoolean(value);
|
||||
pref.setDefaultRole(result);
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Default Role", "```java\n" + String.valueOf(pref.isDefaultRole()) + "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}else{
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nWrong value, expect `true` or `false`\n\nMore info with `//help preference`"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
break;
|
||||
case "default_role_id":
|
||||
try{
|
||||
Role role = event.getGuild().getRoleById(value);
|
||||
if(role != null){
|
||||
pref.setDefaultRoleId(role.getId());
|
||||
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Default Role ID", "```java\n" + pref.getDefaultRoleId()+ "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
}catch (NumberFormatException e){
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nRole not found!\n\nUse `//listroles` to get roles id"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
|
||||
break;
|
||||
case "welcome":
|
||||
if(value.toLowerCase().equals("true") || value.toLowerCase().equals("false")){
|
||||
boolean result = Boolean.parseBoolean(value);
|
||||
pref.setWelcome(result);
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Welcome", "```java\n" + String.valueOf(pref.isWelcome()) + "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}else{
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nWrong value, expect `true` or `false`\n\nMore info with `//help preference`"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
break;
|
||||
case "welcome_chanel_id":
|
||||
try{
|
||||
TextChannel chanel = event.getGuild().getTextChannelById(value);
|
||||
if(chanel != null){
|
||||
pref.setWelcomeChanelID(chanel.getId());
|
||||
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Welcome chanel ID", "```java\n" + pref.getWelcomeChanelID() + "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
}catch (NumberFormatException e){
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nRole not found!\n\nUse `//listroles` to get roles id"));
|
||||
Message sended = event.getTextChannel().sendMessage(msg).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
}
|
||||
break;
|
||||
case "welcome_message":
|
||||
pref.setWelcomeMessage(value);
|
||||
pref = guildPreferenceRepository.save(pref);
|
||||
EmbedBuilder eb = new EmbedBuilder().addField(":ok: Ok :ok:","",false).addField("> Welcome message", "```java\n" + pref.getWelcomeMessage() + "```", false).setColor(Color.green);
|
||||
Message sended = event.getTextChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended, event.getMessage()).start();
|
||||
break;
|
||||
default:
|
||||
MessageEmbed msg2 = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nUnknown id.\n\nUse `//preference` to see list"));
|
||||
Message sended2 = event.getTextChannel().sendMessage(msg2).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, sended2, event.getMessage()).start();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ import java.util.Objects;
|
||||
* Spam admin command
|
||||
*/
|
||||
public class Spam implements Commande {
|
||||
Logger logger = LogManager.getLogger();
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event)
|
||||
@ -97,7 +97,7 @@ public class Spam implements Commande {
|
||||
/****************************
|
||||
* On recupere l'utilisateur et le role cible
|
||||
****************************/
|
||||
List<User> userL = event.getMessage().getMentionedUsers();
|
||||
List<Member> userL = event.getMessage().getMentionedMembers();
|
||||
|
||||
|
||||
/****************************
|
||||
@ -114,14 +114,14 @@ public class Spam implements Commande {
|
||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||
}
|
||||
else {
|
||||
Member user = serveur.getMember(userL.get(0));
|
||||
Member user = userL.get(0);
|
||||
logger.info("Tentative de pardon de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName());
|
||||
/****************************
|
||||
* virif si en spammer *
|
||||
****************************/
|
||||
if (MainBot.spamUtils.containsKey(user.getUser())) {
|
||||
if (MainBot.spamUtils.get(user.getUser()).isOnSpam()) {
|
||||
MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
|
||||
if (MainBot.spamUtils.containsKey(user)) {
|
||||
if (MainBot.spamUtils.get(user).isOnSpam()) {
|
||||
MainBot.spamUtils.get(user).setOnSpam(false);
|
||||
} else {
|
||||
logger.warn("Utilisateur pas en spam.");
|
||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete();
|
||||
@ -192,9 +192,9 @@ public class Spam implements Commande {
|
||||
/****************************
|
||||
* virif pas deja en spammer *
|
||||
****************************/
|
||||
if(MainBot.spamUtils.containsKey(user.getUser()))
|
||||
if(MainBot.spamUtils.containsKey(user))
|
||||
{
|
||||
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
||||
{
|
||||
this.goSpam(user,multiStr,serveur,event);
|
||||
}
|
||||
@ -242,7 +242,7 @@ public class Spam implements Commande {
|
||||
/****************************
|
||||
* On recupere l'utilisateur et le role cible
|
||||
****************************/
|
||||
List<User> userL = event.getMessage().getMentionedUsers();
|
||||
List<Member> userL = event.getMessage().getMentionedMembers();
|
||||
|
||||
|
||||
/****************************
|
||||
@ -260,14 +260,14 @@ public class Spam implements Commande {
|
||||
|
||||
}
|
||||
else {
|
||||
Member user = serveur.getMember(userL.get(0));
|
||||
Member user = userL.get(0);
|
||||
logger.info("Tentative de reset de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName());
|
||||
|
||||
|
||||
/****************************
|
||||
* verif utilisteur trouver *
|
||||
****************************/
|
||||
if (MainBot.spamUtils.containsKey(user.getUser())) {
|
||||
if (MainBot.spamUtils.containsKey(user)) {
|
||||
logger.info("Reset du multiplicateur de " + user.getEffectiveName() + " réussi");
|
||||
Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n *Le multiplcicateur de " + user.getEffectiveName() + " a été remit a zéro.*").complete();
|
||||
List<Message> messages = new ArrayList<Message>(){{
|
||||
@ -275,7 +275,7 @@ public class Spam implements Commande {
|
||||
add(event.getMessage());
|
||||
}};
|
||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||
MainBot.spamUtils.remove(user.getUser());
|
||||
MainBot.spamUtils.remove(user);
|
||||
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ public class Spam implements Commande {
|
||||
if (args[0].equals("all"))
|
||||
{
|
||||
logger.info("Reset automatique des multiplicateur.");
|
||||
for (User unUser: MainBot.spamUtils.keySet() ) //=for(int i=0; i<saveRoleUser.size(); i++)
|
||||
for (Member unUser: MainBot.spamUtils.keySet() ) //=for(int i=0; i<saveRoleUser.size(); i++)
|
||||
{
|
||||
MainBot.message_compteur.remove(unUser);
|
||||
}
|
||||
@ -327,8 +327,8 @@ public class Spam implements Commande {
|
||||
}
|
||||
else
|
||||
{
|
||||
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user,new ArrayList<>()));
|
||||
MainBot.spamUtils.get(user.getUser()).setMultip(multi);
|
||||
MainBot.spamUtils.put(user,new UserSpamUtils(user,new ArrayList<>()));
|
||||
MainBot.spamUtils.get(user).setMultip(multi);
|
||||
}
|
||||
|
||||
new AntiSpam().extermine(user,serveur,serveur.getManager(),false,event);
|
||||
|
@ -8,6 +8,7 @@ import net.Broken.Tools.PrivateMessage;
|
||||
import net.Broken.Tools.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;
|
||||
@ -24,41 +25,41 @@ import java.util.concurrent.TimeUnit;
|
||||
* Spam Info Command
|
||||
*/
|
||||
public class SpamInfo implements Commande{
|
||||
private HashMap<User,MessageUpdater> threadHashMap = new HashMap<>();
|
||||
private HashMap<Member,MessageUpdater> threadHashMap = new HashMap<>();
|
||||
|
||||
Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
User user;
|
||||
Member user;
|
||||
if(event.getMessage().getMentionedUsers().size() == 0){
|
||||
user = event.getAuthor();
|
||||
user = event.getMember();
|
||||
}
|
||||
else {
|
||||
user = event.getMessage().getMentionedUsers().get(0);
|
||||
user = event.getMessage().getMentionedMembers().get(0);
|
||||
}
|
||||
|
||||
|
||||
Message message = null;
|
||||
if(!MainBot.spamUtils.containsKey(user)){
|
||||
if(!event.isFromType(ChannelType.PRIVATE))
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).complete();
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName() + ":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`")).complete();
|
||||
else
|
||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger);
|
||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `1`\n\t- En spam: `Non`"),logger);
|
||||
}
|
||||
else{
|
||||
UserSpamUtils util = MainBot.spamUtils.get(user);
|
||||
if(!util.isOnSpam()){
|
||||
if(!event.isFromType(ChannelType.PRIVATE))
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete();
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete();
|
||||
else
|
||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger);
|
||||
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`"),logger);
|
||||
}
|
||||
else{
|
||||
if(!event.isFromType(ChannelType.PRIVATE))
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete();
|
||||
message = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete();
|
||||
else
|
||||
message = PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`"),logger);
|
||||
message = PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`"),logger);
|
||||
}
|
||||
}
|
||||
if(message != null){
|
||||
@ -139,9 +140,9 @@ public class SpamInfo implements Commande{
|
||||
public UserSpamUtils util;
|
||||
public boolean stop;
|
||||
private int oldValue;
|
||||
private User user;
|
||||
private Member user;
|
||||
|
||||
public MessageUpdater(Message message,Message command, UserSpamUtils util,User user) {
|
||||
public MessageUpdater(Message message,Message command, UserSpamUtils util, Member user) {
|
||||
this.message = message;
|
||||
this.util = util;
|
||||
this.user = user;
|
||||
@ -151,14 +152,14 @@ public class SpamInfo implements Commande{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("Start "+user.getName()+" theard!");
|
||||
logger.debug("Start "+user.getEffectiveName()+" theard!");
|
||||
if(util != null){
|
||||
oldValue = util.getTimeLeft();
|
||||
while (util.getTimeLeft()!=0 && !stop && util.isOnSpam()){
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
if(util.getTimeLeft()%5 == 0 && oldValue - util.getTimeLeft() >= 5){
|
||||
message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete();
|
||||
message.editMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+":\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Oui`\n\t- Temps restant: `"+formatSecond(util.getTimeLeft())+"`")).complete();
|
||||
oldValue = util.getTimeLeft();
|
||||
}
|
||||
|
||||
@ -166,14 +167,14 @@ public class SpamInfo implements Commande{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
logger.debug("Kill "+user.getName()+" theard!");
|
||||
logger.debug("Kill "+user.getEffectiveName()+" theard!");
|
||||
if(stop)
|
||||
message.editMessage(new EmbedBuilder().setColor(Color.RED).setTitle("Aborted").build()).complete();
|
||||
else
|
||||
message.editMessage(EmbedMessageUtils.getSpamInfo(user.getName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete();
|
||||
message.editMessage(EmbedMessageUtils.getSpamInfo(user.getEffectiveName()+"\n\t- Multiplicateur: `"+util.getMultip()+"`\n\t- En spam: `Non`")).complete();
|
||||
|
||||
}
|
||||
logger.debug("Timer for message deletion of "+user.getName()+" stated...");
|
||||
logger.debug("Timer for message deletion of "+user.getEffectiveName()+" stated...");
|
||||
threadHashMap.remove(user);
|
||||
List<Message> messages = new ArrayList<>();
|
||||
messages.add(command);
|
||||
|
@ -1,42 +0,0 @@
|
||||
package net.Broken.Commands;
|
||||
|
||||
import net.Broken.Commande;
|
||||
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.core.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ytTest implements Commande {
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
YoutubeTools yt = YoutubeTools.getInstance(null);
|
||||
|
||||
// try {
|
||||
//// event.getTextChannel().sendMessage(yt.getRelatedVideo(args[0])).queue();
|
||||
//// AudioM.getInstance(null).getGuildMusicManager().scheduler.autoPlay();
|
||||
//
|
||||
// } catch (NotConnectedException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (NullMusicManager nullMusicManager) {
|
||||
// nullMusicManager.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivateUsable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdminCmd() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNSFW() {
|
||||
return false;
|
||||
}
|
||||
}
|
111
src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java
Normal file
111
src/main/java/net/Broken/DB/Entity/GuildPreferenceEntity.java
Normal file
@ -0,0 +1,111 @@
|
||||
package net.Broken.DB.Entity;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class GuildPreferenceEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy= GenerationType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String guildId;
|
||||
|
||||
private boolean antiSpam;
|
||||
|
||||
private boolean welcome;
|
||||
|
||||
private String welcomeMessage;
|
||||
|
||||
private String welcomeChanelID;
|
||||
|
||||
private boolean defaultRole;
|
||||
|
||||
private String defaultRoleId;
|
||||
|
||||
|
||||
public GuildPreferenceEntity(String guildId, boolean antiSpam, boolean welcome, String welcomeMessage, String welcomeChanelID, boolean defaultRole, String defaultRoleId) {
|
||||
this.guildId = guildId;
|
||||
this.antiSpam = antiSpam;
|
||||
this.welcome = welcome;
|
||||
this.welcomeMessage = welcomeMessage;
|
||||
this.welcomeChanelID = welcomeChanelID;
|
||||
this.defaultRole = defaultRole;
|
||||
this.defaultRoleId = defaultRoleId;
|
||||
}
|
||||
|
||||
public GuildPreferenceEntity(){}
|
||||
|
||||
|
||||
public static GuildPreferenceEntity getDefault(Guild guild){
|
||||
return new GuildPreferenceEntity(guild.getId(), false, false, "Welcome to this awesome server @name! ", " ", false, " ");
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getGuildId() {
|
||||
return guildId;
|
||||
}
|
||||
|
||||
public void setGuildId(String guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
public boolean isAntiSpam() {
|
||||
return antiSpam;
|
||||
}
|
||||
|
||||
public void setAntiSpam(boolean antiSpam) {
|
||||
this.antiSpam = antiSpam;
|
||||
}
|
||||
|
||||
public boolean isWelcome() {
|
||||
return welcome;
|
||||
}
|
||||
|
||||
public void setWelcome(boolean welcome) {
|
||||
this.welcome = welcome;
|
||||
}
|
||||
|
||||
public String getWelcomeMessage() {
|
||||
return welcomeMessage;
|
||||
}
|
||||
|
||||
public void setWelcomeMessage(String welcomeMessage) {
|
||||
this.welcomeMessage = welcomeMessage;
|
||||
}
|
||||
|
||||
public String getWelcomeChanelID() {
|
||||
return welcomeChanelID;
|
||||
}
|
||||
|
||||
public void setWelcomeChanelID(String welcomeChanelID) {
|
||||
this.welcomeChanelID = welcomeChanelID;
|
||||
}
|
||||
|
||||
public String getDefaultRoleId() {
|
||||
return defaultRoleId;
|
||||
}
|
||||
|
||||
public void setDefaultRoleId(String defaultRoleId) {
|
||||
this.defaultRoleId = defaultRoleId;
|
||||
}
|
||||
|
||||
public boolean isDefaultRole() {
|
||||
return defaultRole;
|
||||
}
|
||||
|
||||
public void setDefaultRole(boolean defaultRole) {
|
||||
this.defaultRole = defaultRole;
|
||||
}
|
||||
}
|
@ -33,6 +33,8 @@ public class PendingUserEntity {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
83
src/main/java/net/Broken/DB/Entity/PlaylistEntity.java
Normal file
83
src/main/java/net/Broken/DB/Entity/PlaylistEntity.java
Normal file
@ -0,0 +1,83 @@
|
||||
package net.Broken.DB.Entity;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.persistence.*;
|
||||
import javax.sound.midi.Track;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class PlaylistEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy= GenerationType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToOne
|
||||
@JoinColumn(name="userEntity_id", nullable=false)
|
||||
private UserEntity user;
|
||||
|
||||
|
||||
@OneToMany(mappedBy = "playlist")
|
||||
private List<TrackEntity> tracks;
|
||||
|
||||
|
||||
public PlaylistEntity() {
|
||||
}
|
||||
|
||||
public PlaylistEntity(String name, UserEntity user) {
|
||||
this.name = name;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public UserEntity getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(UserEntity user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public List<TrackEntity> getTracks() {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
public void setTracks(List<TrackEntity> tracks) {
|
||||
this.tracks = tracks;
|
||||
}
|
||||
|
||||
public void addTracks(TrackEntity... tracks )
|
||||
{
|
||||
if(this.tracks == null)
|
||||
this.tracks = new ArrayList<>();
|
||||
|
||||
this.tracks.addAll(Arrays.asList(tracks));
|
||||
}
|
||||
|
||||
|
||||
}
|
94
src/main/java/net/Broken/DB/Entity/TrackEntity.java
Normal file
94
src/main/java/net/Broken/DB/Entity/TrackEntity.java
Normal file
@ -0,0 +1,94 @@
|
||||
package net.Broken.DB.Entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class TrackEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy= GenerationType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String url;
|
||||
|
||||
private String identifier;
|
||||
|
||||
private Integer pos;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToOne
|
||||
@JoinColumn(name="playlistEntity_id", nullable=false)
|
||||
private PlaylistEntity playlist;
|
||||
|
||||
public TrackEntity() {
|
||||
}
|
||||
|
||||
public TrackEntity(AudioTrackInfo trackInfo, int pos, PlaylistEntity playlist) {
|
||||
this.title = trackInfo.title;
|
||||
this.url = trackInfo.uri;
|
||||
this.identifier = trackInfo.identifier;
|
||||
this.playlist = playlist;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public TrackEntity(TrackEntity trackEntity){
|
||||
this.title = trackEntity.title;
|
||||
this.url = trackEntity.url;
|
||||
this.identifier = trackEntity.identifier;
|
||||
this.pos = trackEntity.pos;
|
||||
this.playlist = trackEntity.playlist;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public PlaylistEntity getPlaylist() {
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public void setPlaylist(PlaylistEntity playlist) {
|
||||
this.playlist = playlist;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Integer getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void setPos(Integer pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package net.Broken.DB.Entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Entity for DB. Represent confirmed user account.
|
||||
@ -20,8 +22,12 @@ public class UserEntity {
|
||||
|
||||
private String apiToken;
|
||||
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
@OneToMany(mappedBy = "user")
|
||||
private List<PlaylistEntity> playlists;
|
||||
|
||||
public UserEntity() {
|
||||
}
|
||||
|
||||
@ -71,4 +77,19 @@ public class UserEntity {
|
||||
public void setApiToken(String apiToken) {
|
||||
this.apiToken = apiToken;
|
||||
}
|
||||
|
||||
public List<PlaylistEntity> getPlaylists() {
|
||||
return playlists;
|
||||
}
|
||||
|
||||
public void setPlaylists(List<PlaylistEntity> playlists) {
|
||||
this.playlists = playlists;
|
||||
}
|
||||
|
||||
public void addPlaylist(PlaylistEntity... playlists){
|
||||
if(this.playlists == null)
|
||||
this.playlists = new ArrayList<>();
|
||||
|
||||
this.playlists.addAll(Arrays.asList(playlists));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package net.Broken.DB.Repository;
|
||||
|
||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GuildPreferenceRepository extends CrudRepository<GuildPreferenceEntity, Integer> {
|
||||
List<GuildPreferenceEntity> findByGuildId(String id);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package net.Broken.DB.Repository;
|
||||
|
||||
import net.Broken.DB.Entity.PlaylistEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface PlaylistRepository extends CrudRepository<PlaylistEntity, Integer> {
|
||||
}
|
11
src/main/java/net/Broken/DB/Repository/TrackRepository.java
Normal file
11
src/main/java/net/Broken/DB/Repository/TrackRepository.java
Normal file
@ -0,0 +1,11 @@
|
||||
package net.Broken.DB.Repository;
|
||||
|
||||
import net.Broken.DB.Entity.PlaylistEntity;
|
||||
import net.Broken.DB.Entity.TrackEntity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TrackRepository extends CrudRepository<TrackEntity, Integer> {
|
||||
List<TrackEntity> findDistinctByPlaylistOrderByPos(PlaylistEntity playlistEntity);
|
||||
}
|
@ -13,9 +13,12 @@ import net.dv8tion.jda.core.OnlineStatus;
|
||||
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.entities.RichPresence;
|
||||
import net.dv8tion.jda.core.entities.impl.JDAImpl;
|
||||
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.IOException;
|
||||
@ -45,49 +48,49 @@ public class Init {
|
||||
try
|
||||
{
|
||||
|
||||
logger.info("Connection au serveur...");
|
||||
logger.info("Connecting to Discord api...");
|
||||
//connection au bot
|
||||
jda = new JDABuilder(AccountType.BOT).addEventListener(new BotListener()).setToken(token).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
||||
jda = new JDABuilder(AccountType.BOT).setToken(token).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
||||
MainBot.jda = jda;
|
||||
jda.setAutoReconnect(true);
|
||||
jda.addEventListener();
|
||||
|
||||
/*************************************
|
||||
* Definition des commande *
|
||||
*************************************/
|
||||
jda.getPresence().setGame(Game.of("Statut: Loading..."));
|
||||
jda.getPresence().setPresence(OnlineStatus.DO_NOT_DISTURB, Game.playing("Loading..."));
|
||||
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
||||
|
||||
|
||||
//On recupere le l'id serveur
|
||||
Guild serveur = jda.getGuilds().get(0);
|
||||
for( Guild server : jda.getGuilds()){
|
||||
//on recupere les utilisateur
|
||||
List<Member> utilisateurCo = server.getMembers();
|
||||
|
||||
//on recupere les utilisateur
|
||||
List<Member> utilisateurCo = serveur.getMembers();
|
||||
logger.info("Online users: "+utilisateurCo.size());
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.ONLINE))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
}
|
||||
|
||||
logger.info("Utilisatieur connecté: "+utilisateurCo.size());
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.ONLINE))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
logger.debug("Do not disturb users: ");
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.DO_NOT_DISTURB))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
}
|
||||
|
||||
logger.debug("Offline users: ");
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.OFFLINE))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Utilisatieur absent: ");
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.DO_NOT_DISTURB))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
}
|
||||
|
||||
logger.debug("Utilisatieur hors ligne: ");
|
||||
for (Member anUtilisateurCo : utilisateurCo)
|
||||
{
|
||||
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.OFFLINE))
|
||||
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
||||
}
|
||||
|
||||
MainBot.ModoTimer modotimer = new MainBot.ModoTimer();
|
||||
modotimer.start();
|
||||
|
||||
|
||||
DayListener dayListener = DayListener.getInstance();
|
||||
dayListener.addListener(new ResetSpam());
|
||||
@ -99,7 +102,7 @@ public class Init {
|
||||
|
||||
|
||||
}
|
||||
catch (LoginException | InterruptedException | RateLimitedException e)
|
||||
catch (LoginException | InterruptedException e)
|
||||
{
|
||||
logger.catching(e);
|
||||
}
|
||||
@ -112,7 +115,9 @@ public class Init {
|
||||
static void polish(JDA jda){
|
||||
CommandLoader.load();
|
||||
ApiCommandLoader.load();
|
||||
jda.getPresence().setGame(Game.of("bot.seb6596.ovh"));
|
||||
jda.addEventListener(new BotListener());
|
||||
jda.getPresence().setPresence(OnlineStatus.ONLINE, Game.playing("bot.seb6596.ovh"));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.Broken.audio.Youtube.YoutubeTools;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.Permission;
|
||||
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;
|
||||
@ -33,10 +34,10 @@ import java.util.HashMap;
|
||||
public class MainBot {
|
||||
|
||||
public static HashMap<String, Commande> commandes = new HashMap<>();
|
||||
public static HashMap<User, ArrayList<Message>> historique =new HashMap<>();
|
||||
public static HashMap<User, Integer> message_compteur =new HashMap<>();
|
||||
public static HashMap<Member, ArrayList<Message>> historique =new HashMap<>();
|
||||
public static HashMap<Member, Integer> message_compteur =new HashMap<>();
|
||||
public static boolean roleFlag = false;
|
||||
public static HashMap<User, UserSpamUtils> spamUtils = new HashMap<>();
|
||||
public static HashMap<Member, UserSpamUtils> spamUtils = new HashMap<>();
|
||||
public static JDA jda;
|
||||
public static boolean ready = false;
|
||||
|
||||
@ -111,7 +112,7 @@ public class MainBot {
|
||||
Commande cmdObj = commandes.get(cmd.commande);
|
||||
boolean isAdmin;
|
||||
if(cmd.event.isFromType(ChannelType.PRIVATE)){
|
||||
isAdmin = jda.getGuilds().get(0).getMember(cmd.event.getAuthor()).hasPermission(Permission.ADMINISTRATOR);
|
||||
isAdmin = false;
|
||||
}
|
||||
else
|
||||
isAdmin = cmd.event.getMember().hasPermission(Permission.ADMINISTRATOR);
|
||||
@ -178,33 +179,4 @@ public class MainBot {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO Change this, better use daylistener
|
||||
*/
|
||||
public static class ModoTimer extends Thread{
|
||||
|
||||
|
||||
public ModoTimer(){}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
try {
|
||||
sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (User unUser: message_compteur.keySet())
|
||||
{
|
||||
MainBot.message_compteur.put(unUser, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.Broken.RestApi;
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
@ -16,7 +17,8 @@ public interface CommandInterface {
|
||||
* @param musicCommande Current guild music command
|
||||
* @param data Received data
|
||||
* @param user User who submit RestApi command
|
||||
* @param guild
|
||||
* @return HTTP Response
|
||||
*/
|
||||
ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user);
|
||||
ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
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 net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
@ -13,7 +13,7 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Add implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
return new WebLoadUtils(musicCommande ,data, user).getResponse();
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
return new WebLoadUtils(data, user, guild, true).getResponse();
|
||||
}
|
||||
}
|
||||
|
@ -5,26 +5,19 @@ import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.Broken.audio.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.TrackScheduler;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class AutoFlowOff implements CommandInterface{
|
||||
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
AudioM audioM = AudioM.getInstance(null);
|
||||
try {
|
||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||
scheduler.setAutoFlow(false);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
LogManager.getLogger().catching(nullMusicManager);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Not connected", "connect"), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM audioM = AudioM.getInstance(guild);
|
||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||
scheduler.setAutoFlow(false);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -5,27 +5,20 @@ import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.Broken.audio.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.TrackScheduler;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public class AutoFlowOn implements CommandInterface{
|
||||
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
AudioM audioM = AudioM.getInstance(null);
|
||||
try {
|
||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||
scheduler.setAutoFlow(true);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
LogManager.getLogger().catching(nullMusicManager);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Not connected", "connect"), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM audioM = AudioM.getInstance(guild);
|
||||
TrackScheduler scheduler = audioM.getGuildMusicManager().scheduler;
|
||||
scheduler.setAutoFlow(true);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"ok"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -15,21 +16,21 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Connect implements CommandInterface{
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
AudioM audioM = AudioM.getInstance(null);
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM audioM = AudioM.getInstance(guild);
|
||||
if(data.chanelId == null)
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Missing chanelId"),HttpStatus.BAD_REQUEST);
|
||||
VoiceChannel voiceChannel = null;
|
||||
try{
|
||||
voiceChannel = audioM.getGuild().getVoiceChannelById(data.chanelId);
|
||||
voiceChannel = guild.getVoiceChannelById(data.chanelId);
|
||||
}catch (NumberFormatException ignored){}
|
||||
|
||||
if(voiceChannel == null){
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Channel Not found"), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
audioM.getGuildAudioPlayer(musicCommande.getAudioManager().getGuild());
|
||||
audioM.getGuild().getAudioManager().openAudioConnection(audioM.getGuild().getVoiceChannelById(data.chanelId));
|
||||
audioM.getGuildAudioPlayer();
|
||||
guild.getAudioManager().openAudioConnection(guild.getVoiceChannelById(data.chanelId));
|
||||
audioM.setPlayedChanel(voiceChannel);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Accepted"),HttpStatus.OK);
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package net.Broken.RestApi.Commands;
|
||||
|
||||
import net.Broken.Commands.Music;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,17 +16,13 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Dell implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
if(data.url != null) {
|
||||
try {
|
||||
if(musicCommande.getAudioManager().getGuildMusicManager().scheduler.remove(data.url)){
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
else
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"URL not found"), HttpStatus.NOT_FOUND);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
if(AudioM.getInstance(guild).getGuildMusicManager().scheduler.remove(data.url)){
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
else
|
||||
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);
|
||||
|
||||
|
@ -5,7 +5,8 @@ import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.CommandInterface;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.Broken.audio.WebLoadUtils;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,9 +16,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Disconnect implements CommandInterface{
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
Music music = (Music) MainBot.commandes.get("music");
|
||||
music.audio.stop();
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).stop();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Ok"), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,8 @@ 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.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,12 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Flush implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.flush();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).getGuildMusicManager().scheduler.flush();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ 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.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,12 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Next implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.nextTrack();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).getGuildMusicManager().scheduler.nextTrack();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ 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.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,12 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Pause implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.pause();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).getGuildMusicManager().scheduler.pause();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ 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.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -15,12 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Play implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
try {
|
||||
musicCommande.getAudioManager().getGuildMusicManager().scheduler.resume();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).getGuildMusicManager().scheduler.resume();
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ 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.AudioM;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -14,8 +16,8 @@ import org.springframework.http.ResponseEntity;
|
||||
*/
|
||||
public class Stop implements CommandInterface {
|
||||
@Override
|
||||
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data, User user) {
|
||||
musicCommande.getAudioManager().stop((MessageReceivedEvent) null);
|
||||
public ResponseEntity<CommandResponseData> action(CommandPostData data, User user, Guild guild) {
|
||||
AudioM.getInstance(guild).stop(null);
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
@ -10,5 +10,4 @@ public class CommandPostData {
|
||||
public int playlistLimit;
|
||||
public String chanelId;
|
||||
public String name;
|
||||
public String token;
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package net.Broken.RestApi.Data.Playlist;
|
||||
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
|
||||
public class AddToPlaylistData extends CommandPostData{
|
||||
|
||||
public int playlistId;
|
||||
|
||||
|
||||
public int pos;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package net.Broken.RestApi.Data.Playlist;
|
||||
|
||||
public class CreatePlaylistData {
|
||||
public String name;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package net.Broken.RestApi.Data.Playlist;
|
||||
|
||||
public class DeleteTrackData {
|
||||
public int id;
|
||||
public int playlistId;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package net.Broken.RestApi.Data.Playlist;
|
||||
|
||||
public class MoveTrackData {
|
||||
|
||||
public int playlistId;
|
||||
|
||||
public int id;
|
||||
|
||||
public int newPos;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package net.Broken.RestApi.Data.Playlist;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import net.Broken.DB.Entity.PlaylistEntity;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PlaylistResponseData {
|
||||
public String message;
|
||||
public String error;
|
||||
public PlaylistEntity playlist;
|
||||
|
||||
public PlaylistResponseData(String message, PlaylistEntity playlist) {
|
||||
this.message = message;
|
||||
this.playlist = playlist;
|
||||
}
|
||||
public PlaylistResponseData(String message, String error) {
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package net.Broken.RestApi.Data.UserManager;
|
||||
|
||||
public class GuildInfo {
|
||||
public String name;
|
||||
public String id;
|
||||
|
||||
public GuildInfo(String name, String id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -1,15 +1,43 @@
|
||||
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.TrackRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.MainBot;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/")
|
||||
public class GeneralApiController {
|
||||
|
||||
private final
|
||||
UserRepository userRepository;
|
||||
|
||||
private final
|
||||
PlaylistRepository playlistRepository;
|
||||
|
||||
private final
|
||||
TrackRepository trackRepository;
|
||||
|
||||
@Autowired
|
||||
public GeneralApiController(UserRepository userRepository, PlaylistRepository playlistRepository, TrackRepository trackRepository) {
|
||||
this.userRepository = userRepository;
|
||||
this.playlistRepository = playlistRepository;
|
||||
this.trackRepository = trackRepository;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/isReady", method = RequestMethod.GET)
|
||||
public ResponseEntity<String> isReady(){
|
||||
if(MainBot.ready){
|
||||
|
@ -9,19 +9,16 @@ import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.*;
|
||||
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
||||
import net.Broken.Tools.UserManager.UserUtils;
|
||||
import net.Broken.audio.AudioM;
|
||||
import net.Broken.audio.FindGeneral;
|
||||
import net.Broken.audio.NotConnectedException;
|
||||
import net.Broken.audio.NullMusicManager;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.VoiceChannel;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
@ -42,52 +39,67 @@ public class MusicWebAPIController {
|
||||
|
||||
|
||||
@RequestMapping("/currentMusicInfo")
|
||||
public CurrentMusicData getCurrentM(){
|
||||
public ResponseEntity<CurrentMusicData> getCurrentM(@RequestParam(value = "guild") String guildId){
|
||||
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||
if(guild == null ){
|
||||
logger.warn("Request whit no guild!");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
else{
|
||||
logger.trace("currentMusicInfo for " + guild.getName());
|
||||
}
|
||||
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
|
||||
if(musicCommande.audio.getGuild().getAudioManager().isConnected()){
|
||||
try {
|
||||
AudioPlayer player = musicCommande.audio.getGuildMusicManager().player;
|
||||
AudioTrack currentTrack = player.getPlayingTrack();
|
||||
if(currentTrack == null)
|
||||
{
|
||||
return new CurrentMusicData(null,0, "STOP",false, musicCommande.audio.getGuildMusicManager().scheduler.isAutoFlow());
|
||||
}
|
||||
UserAudioTrackData uat = new UserAudioTrackData(musicCommande.audio.getGuildMusicManager().scheduler.getCurrentPlayingTrack());
|
||||
return new CurrentMusicData(uat, currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused(), musicCommande.audio.getGuildMusicManager().scheduler.isAutoFlow());
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new CurrentMusicData(null,0, "STOP",false, false);
|
||||
if(guild.getAudioManager().isConnected()){
|
||||
AudioPlayer player = AudioM.getInstance(guild).getGuildMusicManager().player;
|
||||
AudioTrack currentTrack = player.getPlayingTrack();
|
||||
if(currentTrack == null)
|
||||
{
|
||||
return new ResponseEntity<>(new CurrentMusicData(null,0, "STOP",false, AudioM.getInstance(guild).getGuildMusicManager().scheduler.isAutoFlow()),HttpStatus.OK);
|
||||
}
|
||||
UserAudioTrackData uat = new UserAudioTrackData(AudioM.getInstance(guild).getGuildMusicManager().scheduler.getCurrentPlayingTrack());
|
||||
return new ResponseEntity<>(new CurrentMusicData(uat, currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused(), AudioM.getInstance(guild).getGuildMusicManager().scheduler.isAutoFlow()),HttpStatus.OK);
|
||||
}else
|
||||
{
|
||||
return new CurrentMusicData(null,0, "DISCONNECTED",false, false);
|
||||
return new ResponseEntity<>(new CurrentMusicData(null,0, "DISCONNECTED",false, false),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/getPlaylist")
|
||||
public PlaylistData getPlaylist(){
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
List<UserAudioTrackData> list = null;
|
||||
try {
|
||||
list = musicCommande.getAudioManager().getGuildMusicManager().scheduler.getList();
|
||||
return new PlaylistData(list);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
return new PlaylistData(list);
|
||||
public ResponseEntity<PlaylistData> getPlaylist(@RequestParam(value = "guild") String guildId){
|
||||
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||
if(guild == null ){
|
||||
logger.warn("Request whit no guild!");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
else{
|
||||
logger.trace("getPlaylist for " + guild.getName());
|
||||
}
|
||||
|
||||
List<UserAudioTrackData> list = null;
|
||||
list = AudioM.getInstance(guild).getGuildMusicManager().scheduler.getList();
|
||||
return new ResponseEntity<>(new PlaylistData(list), HttpStatus.OK);
|
||||
}
|
||||
|
||||
// TODO change token to cookie
|
||||
@RequestMapping(value = "/command", method = RequestMethod.POST)
|
||||
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request){
|
||||
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId, @CookieValue("token") String token){
|
||||
|
||||
if(data.command != null) {
|
||||
if(data.token != null) {
|
||||
if(token != null) {
|
||||
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||
if(guild == null ){
|
||||
logger.warn("Request whit no guild!");
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command,"Missing Guild!\nPlease Re-connect.","token"), HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
try {
|
||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, data.token);
|
||||
logger.info("receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName());
|
||||
Music musicCommande = (Music) MainBot.commandes.get("music");
|
||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, token);
|
||||
logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + " GUILD: " + guild.getName());
|
||||
|
||||
if (ApiCommandLoader.apiCommands.containsKey(data.command))
|
||||
return ApiCommandLoader.apiCommands.get(data.command).action(musicCommande, data, MainBot.jda.getUserById(user.getJdaId()));
|
||||
return ApiCommandLoader.apiCommands.get(data.command).action(data, MainBot.jda.getUserById(user.getJdaId()), guild);
|
||||
else
|
||||
return new ResponseEntity<>(new CommandResponseData(data.command, "Unknown Command", "command"), HttpStatus.BAD_REQUEST);
|
||||
|
||||
@ -110,12 +122,20 @@ public class MusicWebAPIController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getChanel", method = RequestMethod.GET)
|
||||
public List<ChanelData> getChanel(){
|
||||
public ResponseEntity<List<ChanelData>> getChanel(@RequestParam(value = "guild") String guildId){
|
||||
Guild guild = MainBot.jda.getGuildById(guildId);
|
||||
if(guild == null ){
|
||||
logger.warn("Request whit no guild!");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
else{
|
||||
logger.trace("getPlaylist for " + guild.getName());
|
||||
}
|
||||
List<ChanelData> temp = new ArrayList<>();
|
||||
for(VoiceChannel aChanel : FindGeneral.find(MainBot.jda.getGuilds().get(0)).getVoiceChannels()){
|
||||
for(VoiceChannel aChanel : FindGeneral.find(guild).getVoiceChannels()){
|
||||
temp.add(new ChanelData(aChanel.getName(),aChanel.getId(),aChanel.getPosition()));
|
||||
}
|
||||
return temp;
|
||||
return new ResponseEntity<>(temp, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
101
src/main/java/net/Broken/RestApi/PlaylistAPIController.java
Normal file
101
src/main/java/net/Broken/RestApi/PlaylistAPIController.java
Normal file
@ -0,0 +1,101 @@
|
||||
package net.Broken.RestApi;
|
||||
|
||||
|
||||
import net.Broken.DB.Entity.PlaylistEntity;
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.DB.Repository.PlaylistRepository;
|
||||
import net.Broken.DB.Repository.TrackRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.RestApi.Data.Playlist.*;
|
||||
import net.Broken.audio.Playlist.PlaylistManager;
|
||||
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.CookieValue;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/playlist/")
|
||||
public class PlaylistAPIController {
|
||||
|
||||
private final
|
||||
UserRepository userRepository;
|
||||
|
||||
private final
|
||||
PlaylistRepository playlistRepository;
|
||||
|
||||
private final
|
||||
TrackRepository trackRepository;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
@Autowired
|
||||
public PlaylistAPIController(UserRepository userRepository, PlaylistRepository playlistRepository, TrackRepository trackRepository) {
|
||||
this.userRepository = userRepository;
|
||||
this.playlistRepository = playlistRepository;
|
||||
this.trackRepository = trackRepository;
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/myPlaylist")
|
||||
public List<PlaylistEntity> myPlaylist(@CookieValue(value = "token", defaultValue = "") String token){
|
||||
if(token.isEmpty())
|
||||
return null;
|
||||
else{
|
||||
UserEntity user = userRepository.findByApiToken(token).get(0);
|
||||
return user.getPlaylists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/createPlaylist")
|
||||
public ResponseEntity<PlaylistResponseData> createPlaylist(@CookieValue(value = "token", defaultValue = "") String token, @RequestBody CreatePlaylistData data){
|
||||
|
||||
if(token.isEmpty())
|
||||
return new ResponseEntity<>(new PlaylistResponseData("Unknown Token!\nPlease Re-connect.", "token"), HttpStatus.UNAUTHORIZED);
|
||||
else{
|
||||
UserEntity user = userRepository.findByApiToken(token).get(0);
|
||||
PlaylistEntity playlistEntity = new PlaylistEntity(data.name, user);
|
||||
playlistEntity = playlistRepository.save(playlistEntity);
|
||||
user.addPlaylist(playlistEntity);
|
||||
userRepository.save(user);
|
||||
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlistEntity), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/addToPlaylist")
|
||||
public ResponseEntity<PlaylistResponseData> addToPlaylist(@CookieValue(value = "token", defaultValue = "") String token, @RequestBody AddToPlaylistData data){
|
||||
PlaylistManager playlistManager = PlaylistManager.getINSTANCE();
|
||||
|
||||
return playlistManager.addToPlaylist(token, data);
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/dellTrack")
|
||||
public ResponseEntity<PlaylistResponseData> dellTrack(@CookieValue(value = "token", defaultValue = "") String token, @RequestBody DeleteTrackData data){
|
||||
PlaylistManager playlistManager = PlaylistManager.getINSTANCE();
|
||||
|
||||
return playlistManager.removeTrack(token, data);
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("/moveTrack")
|
||||
public ResponseEntity<PlaylistResponseData> moveTrack(@CookieValue(value = "token", defaultValue = "") String token, @RequestBody MoveTrackData data){
|
||||
PlaylistManager playlistManager = PlaylistManager.getINSTANCE();
|
||||
|
||||
return playlistManager.moveTrack(token, data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -4,25 +4,22 @@ import net.Broken.DB.Entity.PendingUserEntity;
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.DB.Repository.PendingUserRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.RestApi.Data.UserManager.CheckResposeData;
|
||||
import net.Broken.RestApi.Data.UserManager.ConfirmData;
|
||||
import net.Broken.RestApi.Data.UserManager.UserConnectionData;
|
||||
import net.Broken.RestApi.Data.UserManager.UserInfoData;
|
||||
import net.Broken.Tools.UserManager.Exceptions.PasswordNotMatchException;
|
||||
import net.Broken.Tools.UserManager.Exceptions.TokenNotMatch;
|
||||
import net.Broken.Tools.UserManager.Exceptions.UserAlreadyRegistered;
|
||||
import net.Broken.Tools.UserManager.Exceptions.UserNotFoundException;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.UserManager.*;
|
||||
import net.Broken.Tools.UserManager.Exceptions.*;
|
||||
import net.Broken.Tools.UserManager.UserUtils;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
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.security.crypto.password.PasswordEncoder;
|
||||
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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@ -67,7 +64,6 @@ public class UserManagerAPIController {
|
||||
|
||||
@RequestMapping(value = "/confirmAccount", method = RequestMethod.POST)
|
||||
public ResponseEntity<UserConnectionData> confirAccount(@RequestBody ConfirmData data){
|
||||
//TODO move pending user to accepted and return right things
|
||||
try {
|
||||
PendingUserEntity pUser = userUtils.confirmCheckToken(pendingUserRepository, Integer.parseInt(data.id), data.checkToken);
|
||||
UserEntity user = new UserEntity(pUser, userUtils.generateApiToken());
|
||||
@ -97,5 +93,25 @@ public class UserManagerAPIController {
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getGuilds", method = RequestMethod.GET)
|
||||
public ResponseEntity<List<GuildInfo>> getGuilds(@CookieValue("token") String token){
|
||||
try {
|
||||
UserEntity userE = userUtils.getUserWithApiToken(userRepository, token);
|
||||
User user = MainBot.jda.getUserById(userE.getJdaId());
|
||||
List<GuildInfo> temp = new ArrayList<>();
|
||||
|
||||
for (Guild guild : user.getMutualGuilds()){
|
||||
temp.add(new GuildInfo(guild.getName(), guild.getId()));
|
||||
}
|
||||
return new ResponseEntity<>(temp, HttpStatus.OK);
|
||||
|
||||
|
||||
} catch (UnknownTokenException e) {
|
||||
logger.catching(e);
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
24
src/main/java/net/Broken/SpringContext.java
Normal file
24
src/main/java/net/Broken/SpringContext.java
Normal file
@ -0,0 +1,24 @@
|
||||
package net.Broken;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SpringContext implements ApplicationContextAware{
|
||||
|
||||
@Autowired
|
||||
static ApplicationContext context;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
context = applicationContext;
|
||||
}
|
||||
|
||||
|
||||
public static ApplicationContext getAppContext(){
|
||||
return context;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -43,46 +44,53 @@ public class AntiSpam {
|
||||
}
|
||||
|
||||
// On créer un nouvelle case dans le tableau des statuts si il n'y est pas
|
||||
if(!MainBot.spamUtils.containsKey(user.getUser()))
|
||||
if(!MainBot.spamUtils.containsKey(user))
|
||||
{
|
||||
List<Message> messages = new ArrayList<>();
|
||||
messages.addAll(MainBot.historique.get(user.getUser()));
|
||||
MainBot.spamUtils.put(user.getUser(),new UserSpamUtils(user,messages));
|
||||
messages.addAll(MainBot.historique.get(user));
|
||||
MainBot.spamUtils.put(user,new UserSpamUtils(user,messages));
|
||||
}
|
||||
// On verrifie que l'uttilisateur n'est pas deja en spam
|
||||
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
||||
{
|
||||
//l'utilisateur n'est pas deja en spam
|
||||
if(MainBot.spamUtils.get(user.getUser()).getMultip() != 0)
|
||||
if(MainBot.spamUtils.get(user).getMultip() != 0)
|
||||
{
|
||||
if(MainBot.spamUtils.get(user.getUser()).getMultip()<45 && incrMulti)
|
||||
if(MainBot.spamUtils.get(user).getMultip()<45 && incrMulti)
|
||||
{
|
||||
MainBot.spamUtils.get(user.getUser()).setMultip(MainBot.spamUtils.get(user.getUser()).getMultip()*2);
|
||||
MainBot.spamUtils.get(user).setMultip(MainBot.spamUtils.get(user).getMultip()*2);
|
||||
}
|
||||
}
|
||||
else
|
||||
MainBot.spamUtils.get(user.getUser()).setMultip(1);
|
||||
MainBot.spamUtils.get(user).setMultip(1);
|
||||
|
||||
logger.info("Punition de "+user.getEffectiveName()+" avec un multiplicateur de "+MainBot.spamUtils.get(user.getUser()));
|
||||
logger.info("Punition de "+user.getEffectiveName()+" avec un multiplicateur de "+MainBot.spamUtils.get(user));
|
||||
|
||||
if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
||||
if(!MainBot.spamUtils.get(user).isOnSpam())
|
||||
{
|
||||
MainBot.spamUtils.get(user.getUser()).setOnSpam(true);
|
||||
MainBot.spamUtils.get(user).setOnSpam(true);
|
||||
List<Role> spm = guild.getRolesByName("Spammer", false);
|
||||
try{
|
||||
move.exc(user, spm, true, guild, guildManager);
|
||||
MainBot.spamUtils.get(user.getUser()).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete());
|
||||
MainBot.spamUtils.get(user.getUser()).setMinuteur(new Minuteur(MainBot.spamUtils.get(user.getUser()).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event));
|
||||
MainBot.spamUtils.get(user.getUser()).launchMinuteur();
|
||||
}catch (HierarchyException e){
|
||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete();
|
||||
List<Message> messages = new ArrayList<Message>(){{
|
||||
add(rest);
|
||||
add(event.getMessage());
|
||||
}};
|
||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||
MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
|
||||
if(spm.size() != 0){
|
||||
try{
|
||||
move.exc(user, spm, true, guild, guildManager);
|
||||
MainBot.spamUtils.get(user).addMessage(event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamExtermine(user,MainBot.spamUtils.get(user.getUser()).getMultip())).complete());
|
||||
MainBot.spamUtils.get(user).setMinuteur(new Minuteur(MainBot.spamUtils.get(user).getMultip(), move.user, move.saveRoleUser, move.serveur, move.serveurManager,event));
|
||||
MainBot.spamUtils.get(user).launchMinuteur();
|
||||
}catch (HierarchyException e){
|
||||
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete();
|
||||
List<Message> messages = new ArrayList<Message>(){{
|
||||
add(rest);
|
||||
add(event.getMessage());
|
||||
}};
|
||||
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
|
||||
MainBot.spamUtils.get(user).setOnSpam(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageEmbed msg = EmbedMessageUtils.buildStandar(EmbedMessageUtils.getError("\nSpam role not found, you need to create it!"));
|
||||
event.getTextChannel().sendMessage(msg).complete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -122,7 +130,7 @@ public class AntiSpam {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("["+user.getEffectiveName()+"] Démarage pour "+multip+"min");
|
||||
while (MainBot.spamUtils.get(user.getUser()).isOnSpam())
|
||||
while (MainBot.spamUtils.get(user).isOnSpam())
|
||||
{
|
||||
try {
|
||||
sleep(1000);
|
||||
@ -148,9 +156,9 @@ public class AntiSpam {
|
||||
logger.error("Hierarchy error");
|
||||
}
|
||||
logger.info("["+user.getEffectiveName()+"] Fin des "+multip+"min");
|
||||
new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user.getUser()).getMessages()),0).start();
|
||||
MainBot.spamUtils.get(user.getUser()).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete());
|
||||
new MessageTimeOut(MainBot.spamUtils.get(user.getUser()).getMessages(),60).start();
|
||||
new MessageTimeOut(new ArrayList<>(MainBot.spamUtils.get(user).getMessages()),0).start();
|
||||
MainBot.spamUtils.get(user).clearAndAdd(chanel.sendMessage(EmbedMessageUtils.getSpamPardon(user)).complete());
|
||||
new MessageTimeOut(MainBot.spamUtils.get(user).getMessages(),60).start();
|
||||
|
||||
// #-----------------------------------------------#
|
||||
|
||||
@ -160,4 +168,6 @@ public class AntiSpam {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -101,12 +101,12 @@ public abstract class NumberedCommande implements Commande{
|
||||
}
|
||||
} else {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
logger.warn("Bad Argument: " + event.getMessage().getContent() + " From " + event.getAuthor().getName());
|
||||
logger.warn("Bad Argument: " + event.getMessage().getContentRaw() + " From " + event.getAuthor().getName());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
logger.warn("Bad Argument: " + event.getMessage().getContent() + " From " + event.getAuthor().getName());
|
||||
logger.warn("Bad Argument: " + event.getMessage().getContentRaw() + " From " + event.getAuthor().getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ public class DayListener extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
while(true)
|
||||
{ calendar = Calendar.getInstance();
|
||||
logger.debug(calendar.get(GregorianCalendar.DAY_OF_MONTH)+"/"+previousDay);
|
||||
{
|
||||
calendar = Calendar.getInstance();
|
||||
if(calendar.get(GregorianCalendar.DAY_OF_MONTH) != previousDay)
|
||||
{
|
||||
LogManager.getLogger().info("New day triggered!");
|
||||
|
@ -4,11 +4,13 @@ import net.Broken.Commands.Over18.Madame;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.Tools.DayListener.NewDayListener;
|
||||
import net.Broken.Tools.Redirection;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.TextChannel;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Daily Listener for DailyMadame
|
||||
@ -21,31 +23,50 @@ public class DailyMadame implements NewDayListener{
|
||||
boolean success=false;
|
||||
boolean error=false;
|
||||
int errorCp=0;
|
||||
TextChannel chanel = MainBot.jda.getTextChannelsByName("nsfw-over18", true).get(0);
|
||||
while(!success && !error)
|
||||
{
|
||||
try {
|
||||
List<Guild> guilds = MainBot.jda.getGuilds();
|
||||
|
||||
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
||||
logger.debug("URL: "+url);
|
||||
if(Madame.scanPageForTipeee(url, logger)){
|
||||
logger.debug("Advertisement detected! Retry! ("+url+")");
|
||||
for(Guild guild : guilds){
|
||||
TextChannel chanel = null;
|
||||
for(TextChannel iterator : guild.getTextChannels())
|
||||
{
|
||||
if(iterator.isNSFW()){
|
||||
chanel = iterator;
|
||||
break;
|
||||
}
|
||||
else{
|
||||
chanel.sendMessage("Le Daily Madame mes petits cochons :kissing_heart:\n" + url).queue();
|
||||
success=true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorCp++;
|
||||
logger.warn("Erreur de redirection. (Essais n°"+errorCp+")");
|
||||
if(errorCp>5)
|
||||
{
|
||||
logger.error("5 Erreur de redirection.");
|
||||
error=true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(chanel != null){
|
||||
while(!success && !error)
|
||||
{
|
||||
try {
|
||||
|
||||
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
||||
logger.debug("URL: "+url);
|
||||
if(Madame.scanPageForTipeee(url, logger)){
|
||||
logger.debug("Advertisement detected! Retry! ("+url+")");
|
||||
}
|
||||
else{
|
||||
chanel.sendMessage("Le Daily Madame mes petits cochons :kissing_heart:\n" + url).queue();
|
||||
success=true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorCp++;
|
||||
logger.warn("Erreur de redirection. (Essais n°"+errorCp+")");
|
||||
if(errorCp>5)
|
||||
{
|
||||
logger.error("5 Erreur de redirection.");
|
||||
error=true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.info("No NSFW chanel found for " + guild.getName() + ", ignoring it!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Broken.Tools;
|
||||
|
||||
import net.Broken.DB.Entity.GuildPreferenceEntity;
|
||||
import net.Broken.MainBot;
|
||||
import net.dv8tion.jda.core.EmbedBuilder;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
@ -105,6 +106,22 @@ public class EmbedMessageUtils {
|
||||
return new EmbedBuilder().setTitle("Command du bot ("+role+")").setDescription(message).setFooter("Utilise '//help <commande>' pour plus de détails.",MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).setColor(Color.green).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build();
|
||||
}
|
||||
|
||||
public static MessageEmbed getPref(GuildPreferenceEntity guildPref){
|
||||
EmbedBuilder messageB = new EmbedBuilder()
|
||||
.setColor(Color.green)
|
||||
.setTitle("**Guild config**")
|
||||
.setDescription("_This is the current config of bot for this Guild_")
|
||||
.addField("> Guild ID", "This is the curent guild ID\n```java\n" + guildPref.getGuildId() + "```Edit: :lock:", false)
|
||||
.addField("> Anti Spam", "Activate Spam hunter\n```java\n" + String.valueOf(guildPref.isAntiSpam()) + "```Edit: :unlock:\nKey: anti_spam", false)
|
||||
.addField("> Default Role", "Activate auto move to default role\n```java\n" + String.valueOf(guildPref.isDefaultRole()) + "```Edit: :unlock:\nKey: default_role", false)
|
||||
.addField("> Default Role ID", "Role id for auto move\n```java\n" + guildPref.getDefaultRoleId() + "```Edit: :unlock:\nKey: default_role_id", false)
|
||||
.addField("> Welcome", "Activate welcome message\n```java\n" + String.valueOf(guildPref.isWelcome()) + "```Edit: :unlock:\nKey: welcome", false)
|
||||
.addField("> Welcome chanel ID", "Chane id for welcome message\n```" + guildPref.getWelcomeChanelID() + "```Edit: :unlock:\nKey: welcome_chanel_id", false)
|
||||
.addField("> Welcome message", "Welcome message (@name for mention)\n```markdown\n" + guildPref.getWelcomeMessage() + "```Edit: :unlock:\nKey: welcome_message", false);
|
||||
return buildStandar(messageB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -41,19 +41,19 @@ public class Moderateur {
|
||||
int nbMessage = 3;
|
||||
int spam = 0;
|
||||
|
||||
if(MainBot.spamUtils.containsKey(user.getUser()) && MainBot.spamUtils.get(user.getUser()).isOnSpam()){
|
||||
MainBot.spamUtils.get(user.getUser()).addMessage(event.getMessage());
|
||||
if(MainBot.spamUtils.containsKey(user) && MainBot.spamUtils.get(user).isOnSpam()){
|
||||
MainBot.spamUtils.get(user).addMessage(event.getMessage());
|
||||
}
|
||||
|
||||
/********************************************
|
||||
* si l'USER a deja envoyé un message *
|
||||
********************************************/
|
||||
if(MainBot.historique.containsKey(user.getUser()))// Si le user a deja posté un message
|
||||
if(MainBot.historique.containsKey(user))// Si le user a deja posté un message
|
||||
{
|
||||
/********************************************
|
||||
* COPIE des infos d"historique" vers TOI[] *
|
||||
********************************************/
|
||||
thisUserHistory = (ArrayList<Message>) MainBot.historique.get(user.getUser()).clone();
|
||||
thisUserHistory = (ArrayList<Message>) MainBot.historique.get(user).clone();
|
||||
|
||||
/********************************************
|
||||
* Ajout dernier message recu + dans histo' *
|
||||
@ -61,7 +61,7 @@ public class Moderateur {
|
||||
thisUserHistory.add(0,event.getMessage());
|
||||
if(thisUserHistory.size()>nbMessage+1)
|
||||
thisUserHistory.remove(4);
|
||||
MainBot.historique.put(user.getUser(), thisUserHistory);// On ajoute dans l'historique TOI
|
||||
MainBot.historique.put(user, thisUserHistory);// On ajoute dans l'historique TOI
|
||||
|
||||
/*****************************
|
||||
* ANALYSE des messages *
|
||||
@ -69,9 +69,9 @@ public class Moderateur {
|
||||
int equalCont = 0;
|
||||
String oldMessage = "";
|
||||
for(Message aMessage : thisUserHistory){
|
||||
if(aMessage.getContent().equals(oldMessage))
|
||||
if(aMessage.getContentRaw().equals(oldMessage))
|
||||
equalCont++;
|
||||
oldMessage = aMessage.getContent();
|
||||
oldMessage = aMessage.getContentRaw();
|
||||
|
||||
}
|
||||
if(equalCont >= nbMessage){
|
||||
@ -79,9 +79,9 @@ public class Moderateur {
|
||||
logger.info("Detection de spam pour "+user.getEffectiveName()+"avec 3 messages identique: ");
|
||||
for(Message aMessage : thisUserHistory)
|
||||
{
|
||||
logger.info("\t - "+aMessage.getContent());
|
||||
logger.info("\t - "+aMessage.getContentRaw());
|
||||
}
|
||||
MainBot.historique.put(user.getUser(), new ArrayList<Message>());
|
||||
MainBot.historique.put(user, new ArrayList<Message>());
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -92,7 +92,7 @@ public class Moderateur {
|
||||
// on ajoute le dernier message dans "historique"
|
||||
thisUserHistory.add(0,event.getMessage());
|
||||
|
||||
MainBot.historique.put(user.getUser(), thisUserHistory);
|
||||
MainBot.historique.put(user, thisUserHistory);
|
||||
}
|
||||
/**********************************
|
||||
* AFFICHAGE DE HISTORIQUE *
|
||||
@ -104,24 +104,24 @@ public class Moderateur {
|
||||
/********************************************
|
||||
* Comptage du nombre de message *
|
||||
********************************************/
|
||||
if(MainBot.message_compteur.containsKey(user.getUser()))// Si le user a deja posté un message
|
||||
if(MainBot.message_compteur.containsKey(user))// Si le user a deja posté un message
|
||||
{
|
||||
int cpt = MainBot.message_compteur.get(user.getUser());
|
||||
int cpt = MainBot.message_compteur.get(user);
|
||||
cpt++;
|
||||
//System.out.println("compteur : "+cpt);
|
||||
MainBot.message_compteur.put(user.getUser(), cpt);
|
||||
MainBot.message_compteur.put(user, cpt);
|
||||
if(cpt > 5){
|
||||
MainBot.message_compteur.put(user.getUser(),0);
|
||||
MainBot.message_compteur.put(user,0);
|
||||
spam = 1;
|
||||
logger.info("Detection de spam pour "+user.getEffectiveName()+"avec 5 message en 5seg: ");
|
||||
ArrayList<Message> histo = MainBot.historique.get(user.getUser());
|
||||
ArrayList<Message> histo = MainBot.historique.get(user);
|
||||
for (Message aMessage:histo )
|
||||
{
|
||||
// logger.debug("\t*"+aMessage.getContent());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
MainBot.message_compteur.put(user.getUser(), 1);
|
||||
MainBot.message_compteur.put(user, 1);
|
||||
}
|
||||
|
||||
return spam;
|
||||
|
@ -66,7 +66,7 @@ public class UserUtils {
|
||||
PendingUserEntity pendingUserEntity = null;
|
||||
String token = "";
|
||||
|
||||
//Test if exist on register user
|
||||
//Preference if exist on register user
|
||||
if(userRepository.findByJdaId(user.getId()).size() > 0){
|
||||
logger.warn("User already registered!");
|
||||
throw new UserAlreadyRegistered();
|
||||
|
@ -22,6 +22,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class AudioM {
|
||||
@ -52,14 +53,14 @@ public class AudioM {
|
||||
private Guild guild;
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
private static AudioM INSTANCE;
|
||||
private static HashMap<Guild,AudioM> INSTANCES = new HashMap<>();
|
||||
|
||||
public static AudioM getInstance(Guild guild){
|
||||
if(INSTANCE == null){
|
||||
INSTANCE = new AudioM(guild);
|
||||
if(!INSTANCES.containsKey(guild)){
|
||||
INSTANCES.put(guild, new AudioM(guild));
|
||||
}
|
||||
|
||||
return INSTANCE;
|
||||
return INSTANCES.get(guild);
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +81,7 @@ public class AudioM {
|
||||
* @param onHead True for adding audio track on top of playlist
|
||||
*/
|
||||
public void loadAndPlay(MessageReceivedEvent event, VoiceChannel voiceChannel, final String trackUrl, int playlistLimit, boolean onHead) {
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
playedChanel = voiceChannel;
|
||||
|
||||
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
|
||||
@ -187,9 +188,9 @@ public class AudioM {
|
||||
}
|
||||
|
||||
|
||||
public GuildMusicManager getGuildAudioPlayer(Guild guild) {
|
||||
public GuildMusicManager getGuildAudioPlayer() {
|
||||
if (musicManager == null) {
|
||||
musicManager = new GuildMusicManager(playerManager);
|
||||
musicManager = new GuildMusicManager(playerManager, guild);
|
||||
}
|
||||
|
||||
guild.getAudioManager().setSendingHandler(musicManager.getSendHandler());
|
||||
@ -219,7 +220,7 @@ public class AudioM {
|
||||
* @param event
|
||||
*/
|
||||
public void skipTrack(MessageReceivedEvent event) {
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
musicManager.scheduler.nextTrack();
|
||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique suivante!")).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, message, event.getMessage()).start();
|
||||
@ -230,7 +231,7 @@ public class AudioM {
|
||||
* @param event
|
||||
*/
|
||||
public void pause(MessageReceivedEvent event) {
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
musicManager.scheduler.pause();
|
||||
|
||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Musique en pause !")).complete();
|
||||
@ -243,7 +244,7 @@ public class AudioM {
|
||||
* @param event
|
||||
*/
|
||||
public void resume (MessageReceivedEvent event) {
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
musicManager.scheduler.resume();
|
||||
|
||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("Reprise de la piste en cour !")).complete();
|
||||
@ -255,7 +256,7 @@ public class AudioM {
|
||||
* @param event
|
||||
*/
|
||||
public void info(MessageReceivedEvent event) {
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
AudioTrackInfo info = musicManager.scheduler.getInfo();
|
||||
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
|
||||
|
||||
@ -264,7 +265,7 @@ public class AudioM {
|
||||
}
|
||||
|
||||
public void flush(MessageReceivedEvent event){
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
musicManager.scheduler.flush();
|
||||
Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getMusicOk("RAZ de la playlist!")).complete();
|
||||
new MessageTimeOut(MainBot.messageTimeOut, event.getMessage(), message).start();
|
||||
@ -275,7 +276,7 @@ public class AudioM {
|
||||
* @param event
|
||||
*/
|
||||
public void list(MessageReceivedEvent event){
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(event.getGuild());
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
List<UserAudioTrackData> list = musicManager.scheduler.getList();
|
||||
StringBuilder resp = new StringBuilder();
|
||||
if(list.size() == 0){
|
||||
@ -330,19 +331,18 @@ public class AudioM {
|
||||
*/
|
||||
public void stop () {
|
||||
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer(guild);
|
||||
GuildMusicManager musicManager = getGuildAudioPlayer();
|
||||
musicManager.scheduler.stop();
|
||||
musicManager.scheduler.flush();
|
||||
playedChanel = null;
|
||||
guild.getAudioManager().closeAudioConnection();
|
||||
}
|
||||
|
||||
public GuildMusicManager getGuildMusicManager() throws NullMusicManager, NotConnectedException {
|
||||
public GuildMusicManager getGuildMusicManager(){
|
||||
if( musicManager == null)
|
||||
throw new NullMusicManager();
|
||||
else if( playedChanel == null)
|
||||
throw new NotConnectedException();
|
||||
musicManager = getGuildAudioPlayer();
|
||||
return musicManager;
|
||||
|
||||
}
|
||||
|
||||
public Guild getGuild() {
|
||||
|
@ -2,6 +2,7 @@ package net.Broken.audio;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
|
||||
/**
|
||||
* Holder for both the player and a track scheduler for one guild.
|
||||
@ -16,14 +17,17 @@ public class GuildMusicManager {
|
||||
*/
|
||||
public final TrackScheduler scheduler;
|
||||
|
||||
public final Guild guild;
|
||||
|
||||
/**
|
||||
* Creates a player and a track scheduler.
|
||||
* @param manager Audio player manager to use for creating the player.
|
||||
*/
|
||||
public GuildMusicManager(AudioPlayerManager manager) {
|
||||
public GuildMusicManager(AudioPlayerManager manager, Guild guild) {
|
||||
player = manager.createPlayer();
|
||||
scheduler = new TrackScheduler(player);
|
||||
scheduler = new TrackScheduler(player, guild);
|
||||
player.addListener(scheduler);
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,4 @@
|
||||
package net.Broken.audio.Playlist.Exception;
|
||||
|
||||
public class PlaylistNotFoundException extends Exception {
|
||||
}
|
236
src/main/java/net/Broken/audio/Playlist/PlaylistManager.java
Normal file
236
src/main/java/net/Broken/audio/Playlist/PlaylistManager.java
Normal file
@ -0,0 +1,236 @@
|
||||
package net.Broken.audio.Playlist;
|
||||
|
||||
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.TrackRepository;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.Playlist.AddToPlaylistData;
|
||||
import net.Broken.RestApi.Data.Playlist.DeleteTrackData;
|
||||
import net.Broken.RestApi.Data.Playlist.MoveTrackData;
|
||||
import net.Broken.RestApi.Data.Playlist.PlaylistResponseData;
|
||||
import net.Broken.SpringContext;
|
||||
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
||||
import net.Broken.Tools.UserManager.UserUtils;
|
||||
import net.Broken.audio.Playlist.Exception.PlaylistNotFoundException;
|
||||
import net.Broken.audio.WebLoadUtils;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 PlaylistManager() {
|
||||
ApplicationContext context = SpringContext.getAppContext();
|
||||
|
||||
playlistRepository = (PlaylistRepository) context.getBean("playlistRepository");
|
||||
trackRepository = (TrackRepository) context.getBean("trackRepository");
|
||||
userRepository = (UserRepository) context.getBean("userRepository");
|
||||
}
|
||||
|
||||
public static PlaylistManager getINSTANCE() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public ResponseEntity<PlaylistResponseData> addToPlaylist(String token, AddToPlaylistData data) {
|
||||
UserUtils userUtils = UserUtils.getInstance();
|
||||
|
||||
try {
|
||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, token);
|
||||
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
||||
|
||||
User jdaUser = MainBot.jda.getUserById(user.getJdaId());
|
||||
|
||||
WebLoadUtils webLoadUtils = new WebLoadUtils(data, jdaUser, MainBot.jda.getGuilds().get(0) , false);
|
||||
webLoadUtils.getResponse();
|
||||
|
||||
if(webLoadUtils.userAudioTrack == null){
|
||||
return TRACK_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
TrackEntity trackEntity = new TrackEntity(webLoadUtils.userAudioTrack.getAudioTrack().getInfo(), data.pos, playlist);
|
||||
|
||||
playlist = insert(playlist, trackEntity);
|
||||
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlist),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (UnknownTokenException e) {
|
||||
logger.warn("Unknown token: "+ token);
|
||||
return TOKEN_ERROR;
|
||||
} catch (PlaylistNotFoundException e) {
|
||||
logger.debug("Playlist not found: "+ data.playlistId);
|
||||
return PLAYLIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ResponseEntity<PlaylistResponseData> removeTrack(String token, DeleteTrackData data){
|
||||
UserUtils userUtils = UserUtils.getInstance();
|
||||
try {
|
||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, token);
|
||||
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
||||
|
||||
|
||||
|
||||
TrackEntity toDelete = trackRepository.findOne(data.id);
|
||||
|
||||
playlist = remove(playlist, toDelete);
|
||||
|
||||
if(playlist == null)
|
||||
{
|
||||
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
||||
return TRACK_NOT_FOUND;
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlist),HttpStatus.OK);
|
||||
|
||||
} catch (UnknownTokenException e) {
|
||||
logger.warn("Unknown token: "+ token);
|
||||
return TOKEN_ERROR;
|
||||
} catch (PlaylistNotFoundException e) {
|
||||
logger.debug("Playlist not found: "+ data.playlistId);
|
||||
return PLAYLIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
public ResponseEntity<PlaylistResponseData> moveTrack(String token, MoveTrackData data) {
|
||||
UserUtils userUtils = UserUtils.getInstance();
|
||||
try {
|
||||
UserEntity user = userUtils.getUserWithApiToken(userRepository, token);
|
||||
PlaylistEntity playlist = getPlaylist(data.playlistId);
|
||||
|
||||
|
||||
|
||||
TrackEntity toMove = trackRepository.findOne(data.id);
|
||||
|
||||
TrackEntity save = new TrackEntity(toMove);
|
||||
|
||||
playlist = remove(playlist, toMove);
|
||||
|
||||
if(playlist == null)
|
||||
{
|
||||
logger.warn("Playlist: " + data.playlistId + " Track: " + data.id);
|
||||
return TRACK_NOT_FOUND;
|
||||
}
|
||||
|
||||
save.setPos(data.newPos);
|
||||
|
||||
playlist = insert(playlist, save);
|
||||
|
||||
|
||||
|
||||
return new ResponseEntity<>(new PlaylistResponseData("Ok", playlist),HttpStatus.OK);
|
||||
|
||||
} catch (UnknownTokenException e) {
|
||||
logger.warn("Unknown token: "+ token);
|
||||
return TOKEN_ERROR;
|
||||
} catch (PlaylistNotFoundException e) {
|
||||
logger.debug("Playlist not found: "+ data.playlistId);
|
||||
return PLAYLIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
private PlaylistEntity getPlaylist(int id) throws PlaylistNotFoundException{
|
||||
PlaylistEntity playlist = playlistRepository.findOne(id);
|
||||
if(playlist == null)
|
||||
throw new PlaylistNotFoundException();
|
||||
else
|
||||
return playlist;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private PlaylistEntity insert(PlaylistEntity playlistEntity, TrackEntity trackEntity){
|
||||
List<TrackEntity> tracks = trackRepository.findDistinctByPlaylistOrderByPos(playlistEntity);
|
||||
|
||||
|
||||
boolean increase = false;
|
||||
for(TrackEntity track : tracks){
|
||||
if(track.getPos().equals(trackEntity.getPos())){
|
||||
logger.debug("Need re-organisation");
|
||||
increase = true;
|
||||
}
|
||||
|
||||
|
||||
if(increase){
|
||||
track.setPos(track.getPos() + 1);
|
||||
trackRepository.save(track);
|
||||
}
|
||||
}
|
||||
|
||||
if(!increase)
|
||||
{
|
||||
trackEntity.setPos(tracks.size());
|
||||
}
|
||||
|
||||
trackRepository.save(trackEntity);
|
||||
|
||||
playlistEntity.addTracks(trackEntity);
|
||||
|
||||
|
||||
return playlistRepository.save(playlistEntity);
|
||||
|
||||
}
|
||||
|
||||
private PlaylistEntity remove(PlaylistEntity playlistEntity, TrackEntity trackEntity){
|
||||
|
||||
if(trackEntity == null){
|
||||
logger.warn("Track not found in DB!");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<TrackEntity> tracks = trackRepository.findDistinctByPlaylistOrderByPos(playlistEntity);
|
||||
|
||||
int toDeleteIndex = tracks.indexOf(trackEntity);
|
||||
logger.debug("To delete index: " + toDeleteIndex);
|
||||
if(toDeleteIndex == -1){
|
||||
logger.warn("Track not found in playlist");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
for(int i = toDeleteIndex + 1; i< tracks.size(); i++){
|
||||
tracks.get(i).setPos(tracks.get(i).getPos() - 1);
|
||||
trackRepository.save(tracks.get(i));
|
||||
}
|
||||
|
||||
tracks.remove(trackEntity);
|
||||
trackRepository.delete(trackEntity);
|
||||
|
||||
playlistEntity.setTracks(tracks);
|
||||
playlistEntity = playlistRepository.save(playlistEntity);
|
||||
|
||||
return playlistEntity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
||||
import net.Broken.MainBot;
|
||||
import net.Broken.RestApi.Data.UserAudioTrackData;
|
||||
import net.Broken.audio.Youtube.YoutubeTools;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -23,19 +24,22 @@ import java.util.concurrent.LinkedBlockingDeque;
|
||||
public class TrackScheduler extends AudioEventAdapter {
|
||||
private final AudioPlayer player;
|
||||
private final BlockingDeque<UserAudioTrack> queue;
|
||||
private final Guild guild;
|
||||
|
||||
private UserAudioTrack currentPlayingTrack;
|
||||
private boolean autoFlow = false;
|
||||
private ArrayList<String> history = new ArrayList<>();
|
||||
Logger logger = LogManager.getLogger();
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* @param player The audio player this scheduler uses
|
||||
*/
|
||||
public TrackScheduler(AudioPlayer player) {
|
||||
public TrackScheduler(AudioPlayer player, Guild guild) {
|
||||
this.player = player;
|
||||
player.setVolume(25);
|
||||
this.queue = new LinkedBlockingDeque<>();
|
||||
this.currentPlayingTrack = null;
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,8 +181,8 @@ public class TrackScheduler extends AudioEventAdapter {
|
||||
private void needAutoPlay(){
|
||||
if((queue.size() < 1) && autoFlow && currentPlayingTrack != null){
|
||||
logger.debug("Auto add needed!");
|
||||
AudioM audioM = AudioM.getInstance(null);
|
||||
YoutubeTools youtubeTools = YoutubeTools.getInstance(null);
|
||||
AudioM audioM = AudioM.getInstance(guild);
|
||||
YoutubeTools youtubeTools = YoutubeTools.getInstance();
|
||||
try {
|
||||
String id = youtubeTools.getRelatedVideo(currentPlayingTrack.getAudioTrack().getInfo().identifier, history);
|
||||
logger.debug("Related id: "+id);
|
||||
|
@ -5,9 +5,9 @@ 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.Commands.Music;
|
||||
import net.Broken.RestApi.Data.CommandPostData;
|
||||
import net.Broken.RestApi.Data.CommandResponseData;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -18,47 +18,53 @@ import org.springframework.http.ResponseEntity;
|
||||
* Interface between WebApi and Music bot for submitting track
|
||||
*/
|
||||
public class WebLoadUtils {
|
||||
ResponseEntity<CommandResponseData> response;
|
||||
Logger logger = LogManager.getLogger();
|
||||
private ResponseEntity<CommandResponseData> response;
|
||||
private Logger logger = LogManager.getLogger();
|
||||
public UserAudioTrack userAudioTrack;
|
||||
|
||||
/**
|
||||
* Submit a track or playlist to Music bot
|
||||
* @param musicCommand The current guild music command.
|
||||
* @param data Received data from API
|
||||
* @param user User who submit the track
|
||||
* @param guild
|
||||
*/
|
||||
public WebLoadUtils(Music musicCommand, CommandPostData data, User user){
|
||||
AudioPlayerManager playerM = musicCommand.getAudioManager().getPlayerManager();
|
||||
public WebLoadUtils(CommandPostData data, User user, Guild guild, boolean submit){
|
||||
AudioPlayerManager playerM = AudioM.getInstance(guild).getPlayerManager();
|
||||
|
||||
try {
|
||||
|
||||
AudioM audioM = AudioM.getInstance(null);
|
||||
playerM.loadItemOrdered(musicCommand.getAudioManager().getGuildMusicManager(), data.url, new AudioLoadResultHandler() {
|
||||
AudioM audioM = AudioM.getInstance(guild);
|
||||
playerM.loadItemOrdered(audioM.getGuildMusicManager(), data.url, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
logger.info("Single Track detected from web!");
|
||||
|
||||
try {
|
||||
UserAudioTrack userAudioTrack = new UserAudioTrack(user, track); //TODO
|
||||
userAudioTrack = new UserAudioTrack(user, track);
|
||||
if(submit)
|
||||
audioM.play(audioM.getGuild(), audioM.getPlayedChanel(), audioM.getGuildMusicManager(), userAudioTrack, data.onHead);
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
||||
} catch (NullMusicManager | NotConnectedException nullMusicManager) {
|
||||
nullMusicManager.printStackTrace();
|
||||
}
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
|
||||
logger.info("Playlist detected from web! Limit: " + data.playlistLimit);
|
||||
audioM.playListLoader(playlist, data.playlistLimit, user, data.onHead);
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
||||
if(submit)
|
||||
{
|
||||
logger.info("Playlist detected from web! Limit: " + data.playlistLimit);
|
||||
audioM.playListLoader(playlist, data.playlistLimit, user, data.onHead);
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Loaded"), HttpStatus.OK);
|
||||
}else
|
||||
{
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Adding a list on saved playlist is currently not supported"), HttpStatus.NOT_ACCEPTABLE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
logger.warn("Cant find media ! (web)");
|
||||
logger.warn("Cant find media ! (web) url: "+ data.url);
|
||||
response = new ResponseEntity<>(new CommandResponseData("ADD", "Can't find media!"), HttpStatus.NOT_FOUND);
|
||||
|
||||
}
|
||||
@ -73,7 +79,7 @@ public class WebLoadUtils {
|
||||
while(response == null)
|
||||
Thread.sleep(10);
|
||||
|
||||
} catch (NullMusicManager | NotConnectedException | InterruptedException nullMusicManager) {
|
||||
} catch (InterruptedException nullMusicManager) {
|
||||
nullMusicManager.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -20,18 +20,16 @@ public class YoutubeTools {
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
private Guild guild;
|
||||
|
||||
private static YoutubeTools INSTANCE ;
|
||||
|
||||
private YoutubeTools(Guild guild){
|
||||
private YoutubeTools(){
|
||||
|
||||
this.guild = guild;
|
||||
}
|
||||
|
||||
public static YoutubeTools getInstance(Guild guild){
|
||||
public static YoutubeTools getInstance(){
|
||||
if(INSTANCE == null)
|
||||
INSTANCE = new YoutubeTools(guild);
|
||||
INSTANCE = new YoutubeTools();
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,25 @@
|
||||
package net.Broken.webView;
|
||||
|
||||
import net.Broken.DB.Entity.PlaylistEntity;
|
||||
import net.Broken.DB.Entity.TrackEntity;
|
||||
import net.Broken.DB.Entity.UserEntity;
|
||||
import net.Broken.DB.Repository.UserRepository;
|
||||
import net.Broken.RestApi.Commands.Play;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Web page controller for index
|
||||
*/
|
||||
@Controller
|
||||
public class GeneralWebView {
|
||||
|
||||
|
||||
@RequestMapping("/")
|
||||
public String music(Model model){
|
||||
|
||||
@ -18,4 +29,8 @@ public class GeneralWebView {
|
||||
public String loading(Model model){
|
||||
return "loading";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
```
|
||||
@list
|
||||
```
|
||||
_PU = Private Usable (Utilisable en Message Privée)_
|
||||
|
||||
**>** __**[Web UI](https://bot.seb6596.ovh )**__ :arrow_right: Music control, General server info (Coming soon)
|
||||
|
||||
_PU = Private Usable (Utilisable en Message Privée)_
|
@ -25,7 +25,7 @@
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="net.Broken" level="trace" additivity="false">
|
||||
<Logger name="net.Broken" level="debug" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="current"/>
|
||||
<AppenderRef ref="RollingFile"/>
|
||||
|
2886
src/main/resources/static/css/materialize.css
vendored
2886
src/main/resources/static/css/materialize.css
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -16,21 +16,16 @@
|
||||
|
||||
<body class="blue-grey lighten-5" >
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation" >
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li >
|
||||
<li class="">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light" href="/music" >Music Control</a>
|
||||
<li class="" >
|
||||
<a class="waves-effect waves-light" href="/music">Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
|
||||
@ -39,14 +34,25 @@
|
||||
</ul>
|
||||
|
||||
<ul id="nav-mobile" class="side-nav">
|
||||
<li class="active">
|
||||
<li class="center">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
|
||||
<li class="center">
|
||||
<a class="waves-effect waves-light" href="/music">Music Control</a>
|
||||
</li>
|
||||
|
||||
<!--TODO Connection mobile-->
|
||||
<li><div class="divider"></div></li>
|
||||
<li><a class="center nav-change-guild">Change Guild</a></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
|
||||
<li><a class="center red-text nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
|
||||
</ul>
|
||||
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
@ -55,9 +61,10 @@
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
|
||||
<a class="center blue-grey-text text-darken-4 tooltipped" data-position="left" data-delay="50" data-tooltip="It's you !" id="nav-name" style="font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center nav-change-guild" >Change Guild</a></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
@ -65,7 +72,8 @@
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
|
||||
<li><a class="center red-text nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
2
src/main/resources/static/js/jquery-3.3.1.min.js
vendored
Normal file
2
src/main/resources/static/js/jquery-3.3.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
19742
src/main/resources/static/js/materialize.js
vendored
19742
src/main/resources/static/js/materialize.js
vendored
File diff suppressed because it is too large
Load Diff
12
src/main/resources/static/js/materialize.min.js
vendored
12
src/main/resources/static/js/materialize.min.js
vendored
File diff suppressed because one or more lines are too long
@ -12,56 +12,53 @@ var btn_flush;
|
||||
var btn_add;
|
||||
var switchAutoFlow;
|
||||
var loadingFlag = false;
|
||||
var guild;
|
||||
|
||||
$(document).ready(function() {
|
||||
if(Cookies.get('guild') != undefined) {
|
||||
|
||||
btn_play = $('#btn_play');
|
||||
btn_stop = $('#btn_stop');
|
||||
btn_next = $('#btn_next');
|
||||
btn_info = $('#btn_info');
|
||||
btn_disconnect = $('#btn_disconnect');
|
||||
btn_flush = $('#flush_btn');
|
||||
btn_add = $('#add_btn');
|
||||
switchAutoFlow = $("#autoflow");
|
||||
guild = Cookies.get('guild')
|
||||
btn_play = $('#btn_play');
|
||||
btn_stop = $('#btn_stop');
|
||||
btn_next = $('#btn_next');
|
||||
btn_info = $('#btn_info');
|
||||
btn_disconnect = $('#btn_disconnect');
|
||||
btn_flush = $('#flush_btn');
|
||||
btn_add = $('#add_btn');
|
||||
switchAutoFlow = $("#autoflow");
|
||||
|
||||
setInterval("getCurentMusic()",1000);
|
||||
$('#modalAdd').modal();
|
||||
|
||||
$('#modal_current_info').modal();
|
||||
setInterval("getCurentMusic()", 1000);
|
||||
$('#modalAdd').modal();
|
||||
|
||||
$('#modalChanels').modal({
|
||||
dismissible: false // Modal can be dismissed by clicking outside of the modal
|
||||
});
|
||||
|
||||
modal_loading = $('#modal_loading');
|
||||
modal_loading.modal({
|
||||
dismissible: false
|
||||
});
|
||||
|
||||
$('.button-collapse-1').sideNav({
|
||||
menuWidth: 400, // Default is 300
|
||||
edge: 'right', // Choose the horizontal origin
|
||||
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
|
||||
draggable: true // Choose whether you can drag to open on touch screens,
|
||||
});
|
||||
$('#modal_current_info').modal();
|
||||
|
||||
$('.dropdown-button').dropdown({
|
||||
inDuration: 300,
|
||||
outDuration: 225,
|
||||
constrainWidth: false, // Does not change width of dropdown to that of the activator
|
||||
hover: false, // Activate on hover
|
||||
gutter: 0, // Spacing from edge
|
||||
belowOrigin: false, // Displays dropdown below the button
|
||||
alignment: 'left', // Displays dropdown with edge aligned to the left of button
|
||||
stopPropagation: false // Stops event propagation
|
||||
});
|
||||
$('#modalChanels').modal({
|
||||
dismissible: false // Modal can be dismissed by clicking outside of the modal
|
||||
});
|
||||
|
||||
listeners();
|
||||
modal_loading = $('#modal_loading');
|
||||
modal_loading.modal({
|
||||
dismissible: false
|
||||
});
|
||||
|
||||
|
||||
$('.dropdown-button').dropdown({
|
||||
inDuration: 300,
|
||||
outDuration: 225,
|
||||
constrainWidth: false, // Does not change width of dropdown to that of the activator
|
||||
hover: false, // Activate on hover
|
||||
gutter: 0, // Spacing from edge
|
||||
belowOrigin: false, // Displays dropdown below the button
|
||||
alignment: 'left', // Displays dropdown with edge aligned to the left of button
|
||||
stopPropagation: false // Stops event propagation
|
||||
});
|
||||
|
||||
listeners();
|
||||
}
|
||||
});
|
||||
|
||||
function getCurentMusic() {
|
||||
$.get("api/music/currentMusicInfo", function (data) {
|
||||
$.get("api/music/currentMusicInfo?guild=" + guild, function (data) {
|
||||
}).done(function (data) {
|
||||
|
||||
state = data.state;
|
||||
@ -176,7 +173,7 @@ function getCurentMusic() {
|
||||
}
|
||||
|
||||
function getPlayList() {
|
||||
$.get("api/music/getPlaylist", function (data) {
|
||||
$.get("api/music/getPlaylist?guild=" + guild, function (data) {
|
||||
}).done(function (data) {
|
||||
data = data.list;
|
||||
if(data != null && data.length != 0){
|
||||
@ -199,6 +196,7 @@ function getPlayList() {
|
||||
template.html(content);
|
||||
|
||||
$('#playlist_list').append(template);
|
||||
$('.collapsible').collapsible();
|
||||
|
||||
});
|
||||
$(".btn_dell_playlist").click(function () {
|
||||
@ -237,7 +235,7 @@ function getPlayList() {
|
||||
}
|
||||
|
||||
function getChannels(){
|
||||
$.get("api/music/getChanel", function (data) {
|
||||
$.get("api/music/getChanel?guild=" + guild, function (data) {
|
||||
}).done(function (data) {
|
||||
console.log(data);
|
||||
$('#channelForm').empty();
|
||||
@ -267,7 +265,8 @@ function updateModal(data){
|
||||
$('#modal_title').text("Title: "+ data.info.audioTrackInfo.title);
|
||||
$('#modal_author').text("Author: "+ data.info.audioTrackInfo.author);
|
||||
$('#modal_lenght').text("Duration: "+ msToTime(data.info.audioTrackInfo.length));
|
||||
$('#modal_url').text("URL: "+ data.info.audioTrackInfo.uri);
|
||||
$('#modal_url').html("<div>URL: <a target=\"_blank\" href=\""+ data.info.audioTrackInfo.uri + "\">" + data.info.audioTrackInfo.uri + "</a></div>");
|
||||
//
|
||||
$('#modal_submit').text("Submitted by: "+ data.info.user);
|
||||
|
||||
|
||||
@ -313,13 +312,12 @@ function updateControl(data){
|
||||
|
||||
function sendCommand(command){
|
||||
modal_loading.modal('open');
|
||||
command["token"] = Cookies.get('token');
|
||||
console.log(command)
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
url: "/api/music/command",
|
||||
url: "/api/music/command?guild=" + guild,
|
||||
data: JSON.stringify(command),
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
|
@ -1,5 +1,5 @@
|
||||
var nav_bar_account_link;
|
||||
var connected_link = "<a class=\"dropdown-account\" data-activates=\"dropdown_connected\"><i class=\"material-icons green-text\">account_box</i></a>";
|
||||
var connected_link = "<a class=\"dropdown-account dropdown-trigger\" data-target=\"dropdown_connected\"><i class=\"material-icons green-text\">account_box</i></a>";
|
||||
var disconnected_link = "<a class=\"waves-effect waves-light modal-trigger\" href=\"#modal_connection\"><i class=\"material-icons red-text\">account_box</i></a>";
|
||||
var input_name;
|
||||
var input_psw;
|
||||
@ -7,22 +7,29 @@ var btn_submit;
|
||||
var btn_disconnect;
|
||||
var nav_name;
|
||||
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.button-navbar-mobile').sideNav({
|
||||
$('#nav-mobile').sidenav({
|
||||
menuWidth: 400, // Default is 300
|
||||
edge: 'right', // Choose the horizontal origin
|
||||
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
|
||||
draggable: true // Choose whether you can drag to open on touch screens,
|
||||
});
|
||||
|
||||
$('#modal_guild').modal({
|
||||
dismissible: false // Modal can be dismissed by clicking outside of the modal
|
||||
});
|
||||
|
||||
|
||||
nav_bar_account_link = $("#nav-bar-account");
|
||||
input_name = $("#user_input");
|
||||
input_psw = $("#password_input");
|
||||
btn_submit = $("#btn-submit-connect");
|
||||
btn_disconnect = $("#nav-disconnect");
|
||||
btn_disconnect = $(".nav-disconnect");
|
||||
nav_name = $("#nav-name");
|
||||
|
||||
navListeners();
|
||||
if(Cookies.get('token') === undefined){
|
||||
disconnected()
|
||||
}
|
||||
@ -30,7 +37,7 @@ $(document).ready(function() {
|
||||
connected();
|
||||
}
|
||||
|
||||
navListeners();
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -55,12 +62,17 @@ function connected(){
|
||||
nav_bar_account_link.html(connected_link);
|
||||
$('.dropdown-account').dropdown({
|
||||
constrainWidth: false, // Does not change width of dropdown to that of the activator
|
||||
belowOrigin: true, // Displays dropdown below the button
|
||||
coverTrigger: false, // Displays dropdown below the button
|
||||
alignment: 'left', // Displays dropdown with edge aligned to the left of button
|
||||
stopPropagation: false // Stops event propagation
|
||||
}
|
||||
);
|
||||
nav_name.text(Cookies.get('name'));
|
||||
if (typeof needLogin !== 'undefined') {
|
||||
if (Cookies.get('guild') === undefined) {
|
||||
getGuild()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function disconnected() {
|
||||
@ -132,7 +144,57 @@ function navListeners() {
|
||||
btn_disconnect.click(function () {
|
||||
Cookies.remove('token');
|
||||
Cookies.remove('name');
|
||||
Cookies.remove('guild');
|
||||
location.reload();
|
||||
});
|
||||
|
||||
$('#guild_form').change(function () {
|
||||
if ($('#btn_ok_guild').hasClass("disabled")) {
|
||||
$('#btn_ok_guild').removeClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
$('#btn_ok_guild').click(function () {
|
||||
guild = $('input[name=guildRadio]:checked').val();
|
||||
Cookies.set('guild', guild, { expires: 31 });
|
||||
location.reload();
|
||||
|
||||
});
|
||||
|
||||
$('.nav-change-guild').click(function () {
|
||||
Cookies.remove('guild');
|
||||
location.reload();
|
||||
})
|
||||
}
|
||||
|
||||
function getGuild(){
|
||||
$.get("api/userManagement/getGuilds", function (data) {
|
||||
}).done(function (data) {
|
||||
console.log(data);
|
||||
$('#guild_form').empty();
|
||||
|
||||
if(data.length === 1){
|
||||
Cookies.set('guild', data.id, { expires: 31 });
|
||||
return;
|
||||
}
|
||||
data.forEach(function(element){
|
||||
var template = $('#radioTemplateGuild').clone();
|
||||
template.removeAttr("id");
|
||||
template.removeAttr("style");
|
||||
var content = template.html();
|
||||
content = content.replace("@name", element.name);
|
||||
content = content.replace(/@id/g, element.id);
|
||||
template.html(content);
|
||||
|
||||
$('#guild_form').append(template);
|
||||
});
|
||||
$('#modal_guild').modal('open');
|
||||
|
||||
}).fail(function (data) {
|
||||
if(!error){
|
||||
alert("Com error, please refresh.");
|
||||
error = true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
@ -3,13 +3,7 @@ var ok_passwrd = false;
|
||||
$(document).ready(function() {
|
||||
var baseUrl = window.location.protocol + "//" +window.location.host + window.location.pathname;
|
||||
console.log(baseUrl);
|
||||
$('.button-collapse-1').sideNav({
|
||||
menuWidth: 400, // Default is 300
|
||||
edge: 'right', // Choose the horizontal origin
|
||||
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
|
||||
draggable: true // Choose whether you can drag to open on touch screens,
|
||||
});
|
||||
|
||||
|
||||
var sendBtn = $('#sendBtn');
|
||||
|
||||
|
||||
|
162
src/main/resources/templates/header.html
Normal file
162
src/main/resources/templates/header.html
Normal file
@ -0,0 +1,162 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<div th:fragment="header (page)">
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation" >
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Claptrap Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li class="" th:classappend="(${page} == 'home')? 'active' : ''">
|
||||
<a class="waves-effect waves-light" href="/">Home</a>
|
||||
</li>
|
||||
<li class="" th:classappend="(${page} == 'music')? 'active' : ''">
|
||||
<a class="waves-effect waves-light" href="/music">Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account dropdown-trigger" data-target="dropdown_connected"><i class="material-icons">account_box</i></a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
<a href="#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<ul id="nav-mobile" class="sidenav">
|
||||
<li class="center" th:classappend="(${page} == 'home')? 'active' : ''">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li class="center" th:classappend="(${page} == 'music')? 'active' : ''">
|
||||
<a class="waves-effect waves-light" href="/music">Music Control</a>
|
||||
</li>
|
||||
|
||||
<li><div class="divider"></div></li>
|
||||
<li><a class="center nav-change-guild">Change Guild</a></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
|
||||
<li><a class="center red-text nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4 tooltipped" data-position="left" data-delay="50" data-tooltip="It's you !" id="nav-name" style="font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center nav-change-guild" >Change Guild</a></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
|
||||
<li><a class="center red-text nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Connection modal -->
|
||||
<!--________________________________________-->
|
||||
<div id="modal_connection" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="row center">
|
||||
<div class="col s12">
|
||||
<h3 class="" style="font-weight: bold">Sign in</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row center" style="margin-bottom: 0px">
|
||||
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">account_box</i>
|
||||
<input name="username" id="user_input" type="text" class="validate"/>
|
||||
<label for="user_input" >User Name</label>
|
||||
<span class="helper-text" data-error="User not registered!"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">security</i>
|
||||
<input name="password" id="password_input" type="password" class="validate"/>
|
||||
<label for="password_input">Password</label>
|
||||
<span class="helper-text" data-error="Wrong password!"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
|
||||
Submit<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<a class="btn waves-effect waves-light brown" href="/register">
|
||||
Create account<i class="material-icons right">person_add</i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Guild modal -->
|
||||
<!--________________________________________-->
|
||||
|
||||
<div id="modal_guild" class="modal">
|
||||
<div class="modal-content" style="padding-bottom: 0px">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<h3 class="col s12 center">Guild Selection</h3>
|
||||
<div class="col offset-s4 s4 center">
|
||||
<form id="guild_form" action="#" class="left-align">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" id="btn_ok_guild" class="modal-action modal-close waves-effect waves-green btn-flat disabled">Ok</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="radioTemplateGuild" class="" style="visibility: hidden; display: none ">
|
||||
<label>
|
||||
<input name="guildRadio" class="with-gap" type="radio" value="@id" id="@id"/>
|
||||
<span>@name</span>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- -->
|
||||
<!-- END -->
|
||||
<!-- -->
|
||||
<!--__________________________________________________________-->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -3,128 +3,33 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
|
||||
<title>Music Control - Discord Bot</title>
|
||||
<title>Discord Bot</title>
|
||||
<link rel="icon"
|
||||
type="image/x-icon"
|
||||
href="/favicon.png"/>
|
||||
|
||||
<!-- CSS -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
|
||||
<link href="/css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
<link href="/css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
</head>
|
||||
|
||||
<body class="blue-grey lighten-5" >
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light" href="/music" >Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<ul id="nav-mobile" class="side-nav">
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
|
||||
</li>
|
||||
|
||||
<!--TODO Connection mobile-->
|
||||
</ul>
|
||||
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Connection modal -->
|
||||
<!--________________________________________-->
|
||||
<div id="modal_connection" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="row center">
|
||||
<div class="col s12">
|
||||
<h3 class="" style="font-weight: bold">Sign in</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row center" style="margin-bottom: 0px">
|
||||
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">account_box</i>
|
||||
<input name="username" id="user_input" type="text" class="validate"/>
|
||||
<label for="user_input" data-error="User not registered!">User Name</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">security</i>
|
||||
<input name="password" id="password_input" type="password" class="validate"/>
|
||||
<label for="password_input" data-error="Wrong password!">Password</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
|
||||
Submit<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<a class="btn waves-effect waves-light brown" href="/register">
|
||||
Create account<i class="material-icons right">person_add</i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- -->
|
||||
<!-- END -->
|
||||
<!-- -->
|
||||
<!--__________________________________________________________-->
|
||||
<div th:replace="header :: header ('home')">...</div>
|
||||
|
||||
<div class="section no-pad-bot main" id="index-banner">
|
||||
|
||||
<div class="center center-align">
|
||||
<h2>Home Page</h2>
|
||||
<h1>Coming Soon</h1>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var needLogin = true;
|
||||
</script>
|
||||
<!-- Scripts-->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
||||
<script th:src="@{/js/jquery-3.3.1.min.js}"></script>
|
||||
<script th:src="@{/js/materialize.js}"></script>
|
||||
<script th:src="@{/js/navabar.js}"></script>
|
||||
<script th:src="@{/js/js.cookie.js}"></script>
|
||||
|
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Scripts-->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
||||
<script th:src="@{/js/jquery-3.3.1.min.js}"></script>
|
||||
|
||||
<script th:src="@{/js/materialize.js}"></script>
|
||||
<script th:src="@{/js/loading.js}"></script>
|
||||
|
@ -16,105 +16,7 @@
|
||||
|
||||
<body class="blue-grey lighten-5" >
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li class="">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light" href="/music" >Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<ul id="nav-mobile" class="side-nav">
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Connection modal -->
|
||||
<!--________________________________________-->
|
||||
<div id="modal_connection" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="row center">
|
||||
<div class="col s12">
|
||||
<h3 class="" style="font-weight: bold">Sign in</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row center" style="margin-bottom: 0px">
|
||||
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">account_box</i>
|
||||
<input name="username" id="user_input" type="text" class="validate"/>
|
||||
<label for="user_input" data-error="User not registered!">User Name</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">security</i>
|
||||
<input name="password" id="password_input" type="password" class="validate"/>
|
||||
<label for="password_input" data-error="Wrong password!">Password</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
|
||||
Submit<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<a class="btn waves-effect waves-light brown" href="/register">
|
||||
Create account<i class="material-icons right">person_add</i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- -->
|
||||
<!-- END -->
|
||||
<!-- -->
|
||||
<!--__________________________________________________________-->
|
||||
<div th:replace="header :: header ('music')">...</div>
|
||||
|
||||
<div class="section no-pad-bot main" id="index-banner">
|
||||
<div class="row">
|
||||
@ -175,10 +77,10 @@
|
||||
<th style="padding: 0px;">
|
||||
<div class="row center valign-wrapper" style="margin: 0px">
|
||||
<div class="col s3 center blue-grey-text text-darken-3"><h5><b>Playlist</b></h5></div>
|
||||
<div class="col s3 center">
|
||||
<div class="col s3 center" style="padding-right: 0px; padding-left: 0px">
|
||||
<a class="waves-effect waves-light btn modal-trigger red darken-4" id="flush_btn"><i class="material-icons">delete_sweep</i></a>
|
||||
</div>
|
||||
<div class="col s3 center" style="padding-right: 0px">
|
||||
<div class="col s3 center" style="padding-right: 0px; padding-left: 0px">
|
||||
<!-- Modal Trigger -->
|
||||
<a class="waves-effect waves-light btn modal-trigger green darken-4" id="add_btn" href="#modalAdd"><i class="material-icons">add_circle_outline</i></a>
|
||||
|
||||
@ -293,13 +195,15 @@
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<h3 class="col s12 center">Vocal Channels</h3>
|
||||
<div class="col offset-s4 s4 center">
|
||||
<form id="channelForm" action="#" class="">
|
||||
<form id="channelForm" action="#" class="left-align">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="/" class="modal-action modal-close waves-effect waves-red btn-flat ">Cancel</a>
|
||||
<a href="#!" id="btn_ok_channel" class="modal-action modal-close waves-effect waves-green btn-flat disabled">Connect</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -366,12 +270,15 @@
|
||||
|
||||
|
||||
<p id="radioTemplate" class="" style="visibility: hidden">
|
||||
<input name="vocalRadio" class="with-gap" type="radio" value="@id" id="@id"/>
|
||||
<label for="@id">@name</label>
|
||||
<label>
|
||||
<input name="vocalRadio" class="with-gap" type="radio" value="@id" id="@id"/>
|
||||
<span for="@id">@name</span>
|
||||
</label>
|
||||
|
||||
</p>
|
||||
|
||||
<!-- Scripts-->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
||||
<script th:src="@{/js/jquery-3.3.1.min.js}"></script>
|
||||
|
||||
<script>
|
||||
var needLogin = true;
|
||||
|
@ -14,105 +14,7 @@
|
||||
|
||||
<body class="blue-grey lighten-5" >
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li class="">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light" href="/music" >Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<ul id="nav-mobile" class="side-nav">
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Connection modal -->
|
||||
<!--________________________________________-->
|
||||
<div id="modal_connection" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="row center">
|
||||
<div class="col s12">
|
||||
<h3 class="" style="font-weight: bold">Sign in</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row center" style="margin-bottom: 0px">
|
||||
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">account_box</i>
|
||||
<input name="username" id="user_input" type="text" class="validate"/>
|
||||
<label for="user_input" data-error="User not registered!">User Name</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">security</i>
|
||||
<input name="password" id="password_input" type="password" class="validate"/>
|
||||
<label for="password_input" data-error="Wrong password!">Password</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
|
||||
Submit<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<a class="btn waves-effect waves-light brown" href="/register">
|
||||
Create account<i class="material-icons right">person_add</i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- -->
|
||||
<!-- END -->
|
||||
<!-- -->
|
||||
<!--__________________________________________________________-->
|
||||
<div th:replace="header :: header ('')">...</div>
|
||||
|
||||
|
||||
|
||||
@ -191,13 +93,14 @@
|
||||
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
||||
<script th:src="@{/js/jquery-3.3.1.min.js}"></script>
|
||||
<script th:src="@{/js/materialize.js}"></script>
|
||||
<script th:src="@{/js/register.js}"></script>
|
||||
<script th:src="@{/js/navabar.js}"></script>
|
||||
<script th:src="@{/js/js.cookie.js}"></script>
|
||||
|
||||
|
||||
|
||||
<script th:inline="javascript">
|
||||
/*<![CDATA[*/
|
||||
|
||||
|
@ -1,139 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
|
||||
<title>Music Control - Discord Bot</title>
|
||||
<link rel="icon"
|
||||
type="image/x-icon"
|
||||
href="/favicon.png"/>
|
||||
|
||||
<!-- CSS -->
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>
|
||||
<link href="/css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
<link href="/css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
|
||||
</head>
|
||||
|
||||
<body class="blue-grey lighten-5" >
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- NAV BAR -->
|
||||
<!-- AND -->
|
||||
<!-- LOGIN -->
|
||||
<!--__________________________________________________________-->
|
||||
<nav class="blue-grey darken-4 z-depth-3" role="navigation">
|
||||
<div class="nav-wrapper container">
|
||||
<a id="logo-container" href="/" class="brand-logo">Discord Bot</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
|
||||
<li >
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light" href="/music" >Music Control</a>
|
||||
</li>
|
||||
<li id="nav-bar-account">
|
||||
<a class="dropdown-account" data-activates="dropdown1"><i class="material-icons">account_box</i></a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<ul id="nav-mobile" class="side-nav">
|
||||
<li class="active">
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/" data-target="slide-out">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="waves-effect waves-light sidenav-trigger" href="/music" data-target="slide-out" >Music Control</a>
|
||||
</li>
|
||||
|
||||
<!--TODO Connection mobile-->
|
||||
</ul>
|
||||
<a href="#" data-activates="nav-mobile" class="button-navbar-mobile button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Dropdown connected -->
|
||||
<ul id="dropdown_connected" class="dropdown-content ">
|
||||
<li>
|
||||
<a class="center blue-grey-text text-darken-4" id="nav-name" style="text-decoration: underline; font-weight: bold"></a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Account</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="center tooltipped" data-position="left" data-delay="50" data-tooltip="Under Development!">My Playlists</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li><a class="center red-text" id="nav-disconnect" style="font-weight: bold">Disconnect</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<!--________________________________________-->
|
||||
<!-- Connection modal -->
|
||||
<!--________________________________________-->
|
||||
<div id="modal_connection" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="row center">
|
||||
<div class="col s12">
|
||||
<h3 class="" style="font-weight: bold">Sign in</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row center" style="margin-bottom: 0px">
|
||||
<form name="login_form" id="login_form" action="javascript:void(0);" onsubmit="tryConnection()">
|
||||
<div class="row" style="margin-bottom: 0px">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">account_box</i>
|
||||
<input name="username" id="user_input" type="text" class="validate"/>
|
||||
<label for="user_input" data-error="User not registered!">User Name</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input-field col s6 offset-s3">
|
||||
<i class="material-icons prefix">security</i>
|
||||
<input name="password" id="password_input" type="password" class="validate"/>
|
||||
<label for="password_input" data-error="Wrong password!">Password</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<button id="btn-submit-connect" class="btn waves-effect waves-light light-green darken-1 scale-transition scale-out" type="submit" name="action" >
|
||||
Submit<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<a class="btn waves-effect waves-light brown" href="/register">
|
||||
Create account<i class="material-icons right">person_add</i>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--__________________________________________________________-->
|
||||
<!-- -->
|
||||
<!-- END -->
|
||||
<!-- -->
|
||||
<!--__________________________________________________________-->
|
||||
|
||||
<div class="section no-pad-bot main" id="index-banner">
|
||||
|
||||
<div class="center row">
|
||||
<div class="col s12">
|
||||
<h2 th:text="Succes" th:if="!${#strings.isEmpty(code)}"></h2>
|
||||
<h2 th:text="${error}" th:if="${#strings.isEmpty(code)}"></h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scripts-->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
||||
|
||||
<script th:src="@{/js/materialize.js}"></script>
|
||||
<script th:src="@{/js/navabar.js}"></script>
|
||||
<script th:src="@{/js/js.cookie.js}"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user