Update to JDA 3.3 + some bug fixes
This commit is contained in:
parent
2f9df529d6
commit
e5641d73aa
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-javadoc.jar
Normal file
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-javadoc.jar
Normal file
Binary file not shown.
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-sources.jar
Normal file
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-sources.jar
Normal file
Binary file not shown.
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-withDependencies.jar
Normal file
BIN
Libraries/JDA3.3.0/JDA-3.3.0_260-withDependencies.jar
Normal file
Binary file not shown.
@ -6,7 +6,10 @@ import net.dv8tion.jda.core.entities.ChannelType;
|
|||||||
import net.dv8tion.jda.core.entities.Guild;
|
import net.dv8tion.jda.core.entities.Guild;
|
||||||
import net.dv8tion.jda.core.entities.Member;
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
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.voice.GuildVoiceJoinEvent;
|
||||||
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.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;
|
||||||
@ -33,22 +36,23 @@ public class BotListener extends ListenerAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(MessageReceivedEvent event) {
|
public void onMessageReceived(MessageReceivedEvent event) {
|
||||||
// ----------------------Test pour eviter eco de commande-------------------------
|
// ----------------------Test pour eviter eco de commande-------------------------
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
|
|
||||||
if (event.getMessage().getContent().startsWith("//") && event.getMessage().getAuthor().getId() != 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());
|
||||||
|
|
||||||
MainBot.handleCommand(MainBot.parser.parse(event.getMessage().getContent(), event));
|
MainBot.handleCommand(MainBot.parser.parse(event.getMessage().getContent(), event));
|
||||||
|
logger.debug("ok");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId() && !event.getTextChannel().getName().equals("le_dongeon"))
|
else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
|
||||||
{
|
{
|
||||||
//N'est pas une commande
|
|
||||||
|
|
||||||
|
if(!event.getTextChannel().getName().equals("le_dongeon"))
|
||||||
|
{
|
||||||
Guild serveur=event.getGuild();
|
Guild serveur=event.getGuild();
|
||||||
GuildManager guildManager = serveur.getManager();
|
GuildManager guildManager = serveur.getManager();
|
||||||
Member user = event.getMember();
|
Member user = event.getMember();
|
||||||
@ -65,19 +69,21 @@ public class BotListener extends ListenerAdapter {
|
|||||||
else if(event.getMessage().getContent().length() == 0)
|
else if(event.getMessage().getContent().length() == 0)
|
||||||
logger.error("Image detected, ignoring it.");
|
logger.error("Image detected, ignoring it.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch (Exception e)
|
// }catch (Exception e)
|
||||||
{
|
// {
|
||||||
if (e.getMessage()==null) {
|
// if (e.getMessage()==null) {
|
||||||
logger.error("NullPointerException");
|
// logger.error("NullPointerException");
|
||||||
} else {
|
// } else {
|
||||||
logger.error(e.getMessage());
|
// logger.error(e.getMessage());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package net.Broken.Commandes;
|
|||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
|
import net.Broken.Outils.PrivateMessage;
|
||||||
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -26,14 +29,22 @@ public class Help implements Commande {
|
|||||||
//System.out.println(argsString);
|
//System.out.println(argsString);
|
||||||
if (MainBot.commandes.containsKey(argsString))
|
if (MainBot.commandes.containsKey(argsString))
|
||||||
{
|
{
|
||||||
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getMember().getEffectiveName());
|
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName());
|
||||||
|
if(!event.isFromType(ChannelType.PRIVATE))
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n\n"+MainBot.commandes.get(argsString).help(args)).queue();
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n\n"+MainBot.commandes.get(argsString).help(args)).queue();
|
||||||
|
else{
|
||||||
|
PrivateMessage.send(event.getAuthor(), MainBot.commandes.get(argsString).help(args),logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(!event.isFromType(ChannelType.PRIVATE))
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Commande Inconue!__** :warning:").queue();
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Commande Inconue!__** :warning:").queue();
|
||||||
|
else{
|
||||||
|
PrivateMessage.send(event.getAuthor(),":warning: **__Commande Inconue!__** :warning:",logger);
|
||||||
|
}
|
||||||
logger.info("Commande Inconnue!");
|
logger.info("Commande Inconnue!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,8 +55,10 @@ public class Help implements Commande {
|
|||||||
txt=txt+"\n//"+e.getKey();
|
txt=txt+"\n//"+e.getKey();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(!event.isFromType(ChannelType.PRIVATE))
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right:\t**__commandes envoyées par message privé__**").queue();
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right:\t**__commandes envoyées par message privé__**").queue();
|
||||||
event.getAuthor().getPrivateChannel().sendMessage("Commandes du bot:\n\n```"+txt+"```\n\nUtilise `//help <commande>` pour plus de détails.").queue();
|
PrivateMessage.send(event.getAuthor(),"Commandes du bot:\n\n```"+txt+"```\n\nUtilise `//help <commande>` pour plus de détails.",logger);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public abstract class NumberedCommande implements Commande{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String help(String[] args) {
|
public String help(String[] args) {
|
||||||
return"`//"+this.toString().toLowerCase() +"update\n:arrow_right: *Rafraichi la liste des images.*\n`//"+this.toString().toLowerCase()+" get <numero>`\n:arrow_right: *Affiche l'image portant le numero donné*";
|
return"`//"+this.toString().toLowerCase() +" update`\n:arrow_right: *Rafraichi la liste des images.*\n`//"+this.toString().toLowerCase()+" get <numero>`\n:arrow_right: *Affiche l'image portant le numero donné*";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,12 +24,13 @@ public class SM implements Commande {
|
|||||||
Redirection redirect= new Redirection();
|
Redirection redirect= new Redirection();
|
||||||
if(event.getTextChannel().getName().equals("nsfw-over18"))
|
if(event.getTextChannel().getName().equals("nsfw-over18"))
|
||||||
{
|
{
|
||||||
try {
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: SM n'est plus disponible pour le moment. Pour plus d'info: https://lc.cx/cbSw :warning: ").queue();
|
||||||
event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue();
|
// try {
|
||||||
} catch (IOException e) {
|
// event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue();
|
||||||
logger.warn("Erreur de redirection.");
|
// } catch (IOException e) {
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue();
|
// logger.warn("Erreur de redirection.");
|
||||||
}
|
// event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ public class PingCommande implements Commande {
|
|||||||
event.getPrivateChannel().sendMessage(":arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
|
event.getPrivateChannel().sendMessage(":arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
|
||||||
else
|
else
|
||||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
|
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue();
|
||||||
LogManager.getLogger().info("pong");
|
LogManager.getLogger().debug("pong");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,14 +41,11 @@ public class MainBot {
|
|||||||
static Logger logger = LogManager.getLogger();
|
static Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
// FindContentOnWebPage.doYourJob("http://les400culs.com/2347-2/","featured-img","img");
|
|
||||||
logger.trace("trace");
|
logger.trace("trace");
|
||||||
logger.debug("debug");
|
logger.debug("debug");
|
||||||
logger.info("info");
|
logger.info("info");
|
||||||
logger.warn("warn");
|
logger.warn("warn");
|
||||||
logger.error("error");
|
logger.error("error");
|
||||||
Stop stopTh=new Stop();
|
|
||||||
stopTh.start();
|
|
||||||
/****************************
|
/****************************
|
||||||
* Initialisation *
|
* Initialisation *
|
||||||
****************************/
|
****************************/
|
||||||
@ -66,11 +63,9 @@ public class MainBot {
|
|||||||
|
|
||||||
logger.info("Connection au serveur...");
|
logger.info("Connection au serveur...");
|
||||||
//connection au bot
|
//connection au bot
|
||||||
jda = new JDABuilder(AccountType.BOT).addListener(new BotListener()).setToken(args[0]).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
jda = new JDABuilder(AccountType.BOT).addEventListener(new BotListener()).setToken(args[0]).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
||||||
jda.setAutoReconnect(true);
|
jda.setAutoReconnect(true);
|
||||||
jda.addEventListener();
|
jda.addEventListener();
|
||||||
jda.addEventListener();
|
|
||||||
|
|
||||||
okInit=true;
|
okInit=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -154,10 +149,13 @@ public class MainBot {
|
|||||||
public static void handleCommand(CommandParser.CommandContainer cmd)
|
public static void handleCommand(CommandParser.CommandContainer cmd)
|
||||||
{
|
{
|
||||||
//On verifie que la commande existe
|
//On verifie que la commande existe
|
||||||
|
|
||||||
if (commandes.containsKey(cmd.commande))
|
if (commandes.containsKey(cmd.commande))
|
||||||
{
|
{
|
||||||
|
logger.debug("ok");
|
||||||
if(cmd.event.isFromType(ChannelType.PRIVATE) && privateUsableCommand.contains(commandes.get(cmd.commande).getClass()))
|
if(cmd.event.isFromType(ChannelType.PRIVATE) && privateUsableCommand.contains(commandes.get(cmd.commande).getClass()))
|
||||||
{
|
{
|
||||||
|
|
||||||
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
commandes.get(cmd.commande).action(cmd.args, cmd.event);
|
||||||
commandes.get(cmd.commande).executed(true, cmd.event);
|
commandes.get(cmd.commande).executed(true, cmd.event);
|
||||||
}
|
}
|
||||||
@ -214,33 +212,4 @@ public class MainBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Stop extends Thread
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
String txtEntré = "";
|
|
||||||
while(!txtEntré.equals("o")&&!txtEntré.equals("O"))
|
|
||||||
{
|
|
||||||
|
|
||||||
while (!txtEntré.equals("stop"))
|
|
||||||
{
|
|
||||||
txtEntré = scanner.nextLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.warn("Etes-vous sur de vouloir arréter le Bot? (o/n)");
|
|
||||||
txtEntré = scanner.nextLine();
|
|
||||||
|
|
||||||
if(txtEntré.equals("n")||txtEntré.equals("N"))
|
|
||||||
{
|
|
||||||
logger.info("Arret du Bot annulé.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Runtime.getRuntime().exit(0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,9 @@ public class CommandParser {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
logger.info("Auteur: "+e.getMember().getEffectiveName()+", Commande: "+commande+", args: "+ Arrays.toString(args));
|
|
||||||
|
logger.info("Auteur: "+e.getAuthor().getName()+", Commande: "+commande+", args: "+ Arrays.toString(args));
|
||||||
|
|
||||||
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e); //On Save toute les info dans le container
|
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e); //On Save toute les info dans le container
|
||||||
|
|
||||||
}
|
}
|
||||||
|
22
src/net/Broken/Outils/PrivateMessage.java
Normal file
22
src/net/Broken/Outils/PrivateMessage.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package net.Broken.Outils;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.core.entities.PrivateChannel;
|
||||||
|
import net.dv8tion.jda.core.entities.User;
|
||||||
|
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by seb65 on 04/09/2017.
|
||||||
|
*/
|
||||||
|
public class PrivateMessage {
|
||||||
|
public static void send(User user, String message, Logger logger){
|
||||||
|
if(!user.hasPrivateChannel()){
|
||||||
|
logger.debug("Create Private Chanel");
|
||||||
|
|
||||||
|
user.openPrivateChannel().complete();
|
||||||
|
|
||||||
|
}
|
||||||
|
user.getJDA().getPrivateChannels().get(0).sendMessage(message).queue();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user