From 49241b9f956a95f90f4aa0878f1494b7b4cae29f Mon Sep 17 00:00:00 2001 From: NeutronStars Date: Tue, 5 Jun 2018 08:20:58 +0200 Subject: [PATCH] Update NBot 2.1.1 --- build.gradle | 2 +- src/main/java/fr/neutronstars/nbot/NBot.java | 2 +- .../nbot/command/defaut/DefaultCommand.java | 24 ++++++++++++++++++- .../nbot/command/defaut/HelpCommand.java | 2 +- .../fr/neutronstars/nbot/entity/Guild.java | 13 ++++++++++ .../nbot/listener/NBotListener.java | 13 +++++----- .../neutronstars/nbot/plugin/NBotPlugin.java | 2 +- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 8344362..7d617e8 100644 --- a/build.gradle +++ b/build.gradle @@ -10,5 +10,5 @@ repositories { } dependencies { - compile 'net.dv8tion:JDA:3.6.0_354' + compile 'net.dv8tion:JDA:3.6.0_373' } diff --git a/src/main/java/fr/neutronstars/nbot/NBot.java b/src/main/java/fr/neutronstars/nbot/NBot.java index 33194e7..3e4577a 100644 --- a/src/main/java/fr/neutronstars/nbot/NBot.java +++ b/src/main/java/fr/neutronstars/nbot/NBot.java @@ -20,7 +20,7 @@ */ public final class NBot { - private static final String NAME = "NBot", VERSION = "2.1.0", AUTHOR = "NeutronStars", JDA_VERSION = "3.6.0_354"; + private static final String NAME = "NBot", VERSION = "2.1.1", AUTHOR = "NeutronStars", JDA_VERSION = "3.6.0_373"; private static final NBotLogger logger = StaticLoggerBinder.getSingleton().getLoggerFactory().getLogger("NBot"); private static NBotServer server; diff --git a/src/main/java/fr/neutronstars/nbot/command/defaut/DefaultCommand.java b/src/main/java/fr/neutronstars/nbot/command/defaut/DefaultCommand.java index 6e39029..e5cdfb4 100644 --- a/src/main/java/fr/neutronstars/nbot/command/defaut/DefaultCommand.java +++ b/src/main/java/fr/neutronstars/nbot/command/defaut/DefaultCommand.java @@ -142,9 +142,13 @@ private void info(SelfUser user, Channel channel) EmbedBuilder builder = new EmbedBuilder(); builder.setAuthor(user.getName(), "https://discordapp.com/oauth2/authorize?client_id=" + user.getId() + "&scope=bot&permissions=2146958583", user.getAvatarUrl() == null ? null : user.getAvatarUrl() + "?size=256"); builder.setDescription("To invite the bot to your guild, click on its name above."); + builder.addBlankField(false); builder.addField("Guilds", "[>](1) " + NBot.getJDA().getGuilds().size(), true); builder.addField("Users", "[>](1) " + NBot.getJDA().getUsers().size(), true); - builder.addField("Plugins", "[>](1) " + NBot.getPluginManager().getPlugins().size(), false); + builder.addBlankField(false); + builder.addField("Plugins", "[>](1) " + NBot.getPluginManager().getPlugins().size(), true); + builder.addField("JDA version", "[>](1) "+NBot.getJdaVersion(), true); + builder.addBlankField(false); builder.setFooter("this bot use "+NBot.getName() + " v" + NBot.getVersion() + " developped by " + NBot.getAuthor(), null); builder.setColor(Color.RED); channel.sendMessageToChannel(builder.build()); @@ -221,4 +225,22 @@ else if(args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("-r")) targetCommand.removeChannel(textChannel); channel.sendMessageToChannel(user.getAsMention()+", removing channel "+textChannel.getName()+" for the command "+targetCommand.getSimpleName()+" !"); } + + @Command(name = "jda", description = "Send the link from the JDA API in GitHub.", toPrivate = true) + private void onJDA(Channel channel) + { + channel.sendMessageToChannel("https://github.com/DV8FromTheWorld/JDA"); + } + + @Command(name = "nbot", description = "Send the link from the NBot API in GitHub.", toPrivate = true) + private void onNBot(Channel channel) + { + channel.sendMessageToChannel("https://github.com/NeutronStars/NBot_v2_0"); + } + + @Command(name = "jdadoc", description = "Send the link from the JDA documentation.", toPrivate = true) + private void onJDADoc(Channel channel) + { + channel.sendMessageToChannel("http://home.dv8tion.net:8080/job/JDA/javadoc/"); + } } diff --git a/src/main/java/fr/neutronstars/nbot/command/defaut/HelpCommand.java b/src/main/java/fr/neutronstars/nbot/command/defaut/HelpCommand.java index f82dcdf..d39887c 100644 --- a/src/main/java/fr/neutronstars/nbot/command/defaut/HelpCommand.java +++ b/src/main/java/fr/neutronstars/nbot/command/defaut/HelpCommand.java @@ -30,7 +30,7 @@ private void onHelp(CommandSender sender, Channel channel, Guild guild) Map> pluginCommandsMap = CommandManager.getPluginCommands(false); for(Map.Entry> entry : pluginCommandsMap.entrySet()) - sendPrivateHelp(entry.getKey().getName()+" Commands", (User) sender, CommandManager.getDefaultCommands(false)); + sendPrivateHelp(entry.getKey().getName()+" Commands", (User) sender, entry.getValue()); return; } diff --git a/src/main/java/fr/neutronstars/nbot/entity/Guild.java b/src/main/java/fr/neutronstars/nbot/entity/Guild.java index 0f6c2ad..877b1fb 100644 --- a/src/main/java/fr/neutronstars/nbot/entity/Guild.java +++ b/src/main/java/fr/neutronstars/nbot/entity/Guild.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.core.managers.GuildManager; import net.dv8tion.jda.core.managers.GuildManagerUpdatable; import net.dv8tion.jda.core.requests.RestAction; +import net.dv8tion.jda.core.requests.restaction.MemberAction; import net.dv8tion.jda.core.requests.restaction.pagination.AuditLogPaginationAction; import net.dv8tion.jda.core.utils.cache.MemberCacheView; import net.dv8tion.jda.core.utils.cache.SnowflakeCacheView; @@ -74,6 +75,18 @@ public RestAction> retrieveRegions() return guild.retrieveRegions(); } + @Override + public RestAction> retrieveRegions(boolean includeDeprecated) + { + return guild.retrieveRegions(includeDeprecated); + } + + @Override + public MemberAction addMember(String accessToken, String userId) + { + return guild.addMember(accessToken, userId); + } + public String getName() { return guild.getName(); diff --git a/src/main/java/fr/neutronstars/nbot/listener/NBotListener.java b/src/main/java/fr/neutronstars/nbot/listener/NBotListener.java index 749d235..4958172 100644 --- a/src/main/java/fr/neutronstars/nbot/listener/NBotListener.java +++ b/src/main/java/fr/neutronstars/nbot/listener/NBotListener.java @@ -10,6 +10,7 @@ import net.dv8tion.jda.core.events.ReadyEvent; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import net.dv8tion.jda.core.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.core.hooks.EventListener; import net.dv8tion.jda.core.hooks.ListenerAdapter; import org.slf4j.impl.NBotLogger; @@ -32,6 +33,12 @@ public void onReady(ReadyEvent event) { pluginManager.enablePlugins(); + for(Object object : event.getJDA().getRegisteredListeners()) + { + if(object instanceof EventListener && object != this) + ((EventListener)object).onEvent(event); + } + StringBuilder builder = new StringBuilder("\n-------------------------------\n") .append(event.getJDA().getSelfUser().getName()).append(" is Ready.\n-------------------------------"); @@ -89,10 +96,4 @@ private void deleteFile(File file) } file.delete(); } - - @Override - public void onMessageReactionAdd(MessageReactionAddEvent event) - { - System.out.println(event.getReactionEmote()); - } } diff --git a/src/main/java/fr/neutronstars/nbot/plugin/NBotPlugin.java b/src/main/java/fr/neutronstars/nbot/plugin/NBotPlugin.java index d841486..33bd0c2 100644 --- a/src/main/java/fr/neutronstars/nbot/plugin/NBotPlugin.java +++ b/src/main/java/fr/neutronstars/nbot/plugin/NBotPlugin.java @@ -37,7 +37,7 @@ public final String[] getAuthors() public String getAuthorsToString() { - StringBuilder builder = new StringBuilder(); + StringBuilder builder = new StringBuilder(32); for(int i = 0; ; i++) { if(i == authors.length) return builder.length() > 0 ? builder.toString() : "Not author";