Updating JDA

This commit is contained in:
Sebastien 2018-04-25 16:40:21 +02:00
parent 87aa1edde4
commit 7f4e16ced9
9 changed files with 25 additions and 61 deletions

View File

@ -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...)

View File

@ -90,10 +90,10 @@ public class BotListener extends ListenerAdapter {
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()))
@ -106,12 +106,12 @@ public class BotListener extends ListenerAdapter {
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 (!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContentRaw().length() > 0) {
if (modo.analyse(user, serveur, guildManager, event) == 1) {
antispam.extermine(user, serveur, guildManager, true, event);
}
} else if (event.getMessage().getContent().length() == 0)
} else if (event.getMessage().getContentRaw().length() == 0)
logger.error("Image detected, ignoring it.");
}

View File

@ -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){

View File

@ -12,7 +12,7 @@ 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();

View File

@ -5,6 +5,7 @@ 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.entities.RichPresence;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import java.io.IOException;
@ -12,17 +13,7 @@ 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();
// }
event.getJDA().getPresence().setPresence(RichPresence.listening("Noting"),false);
}
@Override

View File

@ -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,7 +48,7 @@ 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();
MainBot.jda = jda;
@ -55,7 +58,7 @@ public class Init {
/*************************************
* 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());
@ -65,29 +68,27 @@ public class Init {
//on recupere les utilisateur
List<Member> utilisateurCo = serveur.getMembers();
logger.info("Utilisatieur connecté: "+utilisateurCo.size());
logger.info("Online users: "+utilisateurCo.size());
for (Member anUtilisateurCo : utilisateurCo)
{
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.ONLINE))
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
}
logger.debug("Utilisatieur absent: ");
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("Utilisatieur hors ligne: ");
logger.debug("Offline users: ");
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 +100,7 @@ public class Init {
}
catch (LoginException | InterruptedException | RateLimitedException e)
catch (LoginException | InterruptedException e)
{
logger.catching(e);
}
@ -112,7 +113,8 @@ public class Init {
static void polish(JDA jda){
CommandLoader.load();
ApiCommandLoader.load();
jda.getPresence().setGame(Game.of("bot.seb6596.ovh"));
jda.getPresence().setPresence(OnlineStatus.ONLINE, Game.playing("bot.seb6596.ovh"));
}
}

View File

@ -178,33 +178,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);
}
}
}
}
}

View File

@ -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;
}
}

View File

@ -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,7 +79,7 @@ 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>());
}