Merge branch 'devel'

This commit is contained in:
BrokenFire 2017-12-12 23:48:59 +01:00
commit a7523cfa9c
14 changed files with 125 additions and 38 deletions

1
.gitignore vendored
View File

@ -12,6 +12,5 @@ META-INF/
*.class *.class
*.jar
classes/artifacts/Discord_Stroumpf_Beta_jar/ classes/artifacts/Discord_Stroumpf_Beta_jar/

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: java -Dlog4j.configurationFile=/app/Heroku/log4j2.xml -jar /app/build/libs/DiscordBot-0.1.0.jar -t $TOKEN

View File

@ -4,6 +4,7 @@ buildscript {
} }
dependencies { dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE") classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE")
classpath 'org.springframework:springloaded:1.2.6.RELEASE'
} }
} }

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -2,39 +2,30 @@ package net.Broken;
import net.Broken.Commandes.Move; import net.Broken.Commandes.Move;
import net.Broken.Commandes.Music; import net.Broken.Commandes.Music;
import net.Broken.Commandes.Spam;
import net.Broken.Outils.AntiSpam; import net.Broken.Outils.AntiSpam;
import net.Broken.Outils.EmbedMessageUtils;
import net.Broken.Outils.MessageTimeOut;
import net.Broken.Outils.Moderateur; import net.Broken.Outils.Moderateur;
import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.*; import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.events.ExceptionEvent; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.ReadyEvent; import net.dv8tion.jda.core.events.ReadyEvent;
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent; 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.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.HierarchyException;
import net.dv8tion.jda.core.hooks.ListenerAdapter; import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.managers.GuildManager; import net.dv8tion.jda.core.managers.GuildManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by seb65 on 19/10/2016. * Created by seb65 on 19/10/2016.
*/ */
public class BotListener extends ListenerAdapter { public class BotListener extends ListenerAdapter {
AntiSpam antispam=new AntiSpam(); private AntiSpam antispam=new AntiSpam();
Moderateur modo = new Moderateur(); private Moderateur modo = new Moderateur();
Logger logger = LogManager.getLogger(); private Logger logger = LogManager.getLogger();
@Override @Override
@ -93,7 +84,6 @@ public class BotListener extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) { public void onMessageReceived(MessageReceivedEvent event) {
// ----------------------Test pour eviter eco de commande------------------------- // ----------------------Test pour eviter eco de commande-------------------------
if (event.getMessage().getContent().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) { if (event.getMessage().getContent().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
//On a detecter que c'etait une commande //On a detecter que c'etait une commande
//System.out.println(event.getMessage().getContent()); //System.out.println(event.getMessage().getContent());

View File

@ -56,7 +56,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
} }
else{ else{
@ -65,7 +65,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
break; break;
@ -109,7 +109,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
break; break;
@ -124,7 +124,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
break; break;
@ -134,7 +134,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
break; break;
} }
@ -145,7 +145,7 @@ public class Music implements Commande {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
} }
@ -164,4 +164,8 @@ public class Music implements Commande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
public AudioM getAudioManager(){
return audio;
}
} }

View File

@ -24,7 +24,6 @@ import java.util.HashMap;
@SpringBootApplication @SpringBootApplication
public class MainBot { public class MainBot {
public static final CommandParser parser =new CommandParser(); public static final CommandParser parser =new CommandParser();
public static HashMap<String, Commande> commandes = new HashMap<>(); public static HashMap<String, Commande> commandes = new HashMap<>();
public static HashMap<User, ArrayList<Message>> historique =new HashMap<>(); public static HashMap<User, ArrayList<Message>> historique =new HashMap<>();
@ -38,7 +37,7 @@ public class MainBot {
private static Logger logger = LogManager.getLogger(); private static Logger logger = LogManager.getLogger();
public static void main(String[] args) { public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(MainBot.class, args);
logger.trace("trace"); logger.trace("trace");
logger.debug("debug"); logger.debug("debug");
logger.info("info"); logger.info("info");
@ -63,12 +62,17 @@ public class MainBot {
} }
JDA jda = Init.initBot(token, dev); JDA jda = Init.initBot(token, dev);
ConfigurableApplicationContext ctx = SpringApplication.run(MainBot.class, args);
if(jda == null) { if(jda == null) {
System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) () -> { System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) () -> {
logger.fatal("Init error! Close application!"); logger.fatal("Init error! Close application!");
return 1; return 1;
})); }));
} }
} }
/*************************************** /***************************************
@ -106,6 +110,7 @@ public class MainBot {
logger.warn("Commande inconnue"); logger.warn("Commande inconnue");
} }
} }
/******************************* /*******************************
* RAZ Compteur Spam * * RAZ Compteur Spam *

View File

@ -0,0 +1,38 @@
package net.Broken.RestApi.Data;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackState;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CurrentMusicData {
private final AudioTrackInfo info;
private final long currentPos;
private final String state;
private final boolean pause;
public CurrentMusicData(AudioTrackInfo info, long currentPos, String state, boolean pause) {
this.info = info;
this.currentPos = currentPos;
this.state = state;
this.pause = pause;
}
public AudioTrackInfo getInfo() {
return info;
}
public long getCurrentPos() {
return currentPos;
}
public String getState() {
if(pause)
return "PAUSE";
else
return state;
}
}

View File

@ -0,0 +1,31 @@
package net.Broken.RestApi;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.Broken.Commandes.Music;
import net.Broken.MainBot;
import net.Broken.RestApi.Data.CurrentMusicData;
import net.Broken.audio.NotConectedException;
import net.Broken.audio.NullMusicManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/music/")
public class MusicWebController {
@RequestMapping("/currentMusicInfo")
public CurrentMusicData test(){
Music musicCommande = (Music) MainBot.commandes.get("music");
try {
AudioPlayer player = musicCommande.audio.getMusicManager().player;
AudioTrack currentTrack = player.getPlayingTrack();
if(currentTrack == null)
{
return new CurrentMusicData(null,0, "STOP",false);
}
return new CurrentMusicData(currentTrack.getInfo(),currentTrack.getPosition(), currentTrack.getState().toString(), player.isPaused());
} catch (NullMusicManager | NotConectedException nullMusicManager) {
return new CurrentMusicData(null,0, "STOP",false);
}
}
}

View File

@ -51,7 +51,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
play(event.getGuild(), voiceChannel, musicManager, track, onHead); play(event.getGuild(), voiceChannel, musicManager, track, onHead);
} }
@ -65,7 +65,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
int i = 0; int i = 0;
for(AudioTrack track : playlist.getTracks()){ for(AudioTrack track : playlist.getTracks()){
play(event.getGuild(), voiceChannel, musicManager, track,onHead); play(event.getGuild(), voiceChannel, musicManager, track,onHead);
@ -84,7 +84,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
@Override @Override
@ -96,7 +96,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
}); });
} }
@ -132,7 +132,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void pause(MessageReceivedEvent event) { public void pause(MessageReceivedEvent event) {
@ -144,7 +144,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void resume (MessageReceivedEvent event) { public void resume (MessageReceivedEvent event) {
@ -156,7 +156,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void info(MessageReceivedEvent event){ public void info(MessageReceivedEvent event){
@ -168,7 +168,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void flush(MessageReceivedEvent event){ public void flush(MessageReceivedEvent event){
@ -179,7 +179,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void list(MessageReceivedEvent event){ public void list(MessageReceivedEvent event){
@ -202,7 +202,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, listTimeOut).run(); new MessageTimeOut(messages, listTimeOut).start();
} }
@ -217,7 +217,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
} }
@ -232,7 +232,7 @@ public class AudioM {
add(message); add(message);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages, MainBot.messageTimeOut).run(); new MessageTimeOut(messages, MainBot.messageTimeOut).start();
} }
public void stop (GuildVoiceLeaveEvent event) { public void stop (GuildVoiceLeaveEvent event) {
@ -243,6 +243,14 @@ public class AudioM {
event.getGuild().getAudioManager().closeAudioConnection(); event.getGuild().getAudioManager().closeAudioConnection();
} }
public GuildMusicManager getMusicManager() throws NullMusicManager, NotConectedException {
if( musicManager == null)
throw new NullMusicManager();
else if( playedChanel == null)
throw new NotConectedException();
return musicManager;
}
} }

View File

@ -24,6 +24,7 @@ public class GuildMusicManager {
player = manager.createPlayer(); player = manager.createPlayer();
scheduler = new TrackScheduler(player); scheduler = new TrackScheduler(player);
player.addListener(scheduler); player.addListener(scheduler);
} }
/** /**

View File

@ -0,0 +1,4 @@
package net.Broken.audio;
public class NotConectedException extends Exception {
}

View File

@ -0,0 +1,4 @@
package net.Broken.audio;
public class NullMusicManager extends Exception {
}

View File

@ -0,0 +1 @@
server.port=${PORT}