Skip to content

Commit

Permalink
Update NBot 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NeutronStars committed Apr 20, 2018
1 parent 6881029 commit 7960888
Show file tree
Hide file tree
Showing 21 changed files with 981 additions and 119 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ repositories {
}

dependencies {
compile 'net.dv8tion:JDA:3.5.1_348'
compile 'net.dv8tion:JDA:3.6.0_354'
}
7 changes: 6 additions & 1 deletion src/main/java/fr/neutronstars/nbot/NBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public final class NBot
{
private static final String NAME = "NBot", VERSION = "2.0.4", AUTHOR = "NeutronStars";
private static final String NAME = "NBot", VERSION = "2.1.0", AUTHOR = "NeutronStars", JDA_VERSION = "3.6.0_354";
private static final NBotLogger logger = StaticLoggerBinder.getSingleton().getLoggerFactory().getLogger("NBot");
private static NBotServer server;

Expand Down Expand Up @@ -50,6 +50,11 @@ public static String getVersion()
return VERSION;
}

public static String getJdaVersion()
{
return JDA_VERSION;
}

public static String getAuthor()
{
return AUTHOR;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/fr/neutronstars/nbot/NBotStart.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package fr.neutronstars.nbot;

import fr.neutronstars.nbot.command.CommandBuilder;
import fr.neutronstars.nbot.command.CommandManager;
import fr.neutronstars.nbot.command.defaut.ConsoleCommand;
import fr.neutronstars.nbot.command.defaut.DefaultCommand;
import fr.neutronstars.nbot.command.defaut.HelpCommand;
import fr.neutronstars.nbot.exception.NBotConfigurationException;
import fr.neutronstars.nbot.plugin.PluginManager;
import fr.neutronstars.nbot.util.Configuration;
Expand All @@ -20,17 +23,18 @@ public static void main(String... args)
{
System.setProperty("file.encoding", "UTF-8");

loadFolders("guilds", "plugins", "config");
loadFolders("guilds", "plugins", "config", "tmp");

Configuration configuration = loadConfiguration();
setDefaultConfiguration(configuration);

NBotLogger.load(configuration);

logger.info(String.format("Starting %1$s v%2$s by %3$s...", NBot.getName(), NBot.getVersion(), NBot.getAuthor()));
logger.info(String.format("Loading libraries of JDA v%1$s...", NBot.getJdaVersion()));

PluginManager pluginManager = new PluginManager(configuration.getString("loadedFormat"), configuration.getString("enabledFormat"), configuration.getString("disabledFormat"));
CommandManager.registerCommand(new DefaultCommand(), null);
CommandManager.registerCommands(null, new DefaultCommand(), new ConsoleCommand(), new HelpCommand());
pluginManager.registerCommands();

try
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/fr/neutronstars/nbot/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@
int powers() default 0;

long[] guilds() default {};
long[] channels() default {};

boolean toPrivate() default false;
boolean privateOnly() default false;

ExecutorType executor() default ExecutorType.USER;

enum ExecutorType{
USER, CONSOLE, ALL
}
}
115 changes: 115 additions & 0 deletions src/main/java/fr/neutronstars/nbot/command/CommandArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package fr.neutronstars.nbot.command;

import fr.neutronstars.nbot.entity.*;
import fr.neutronstars.nbot.entity.Channel;
import fr.neutronstars.nbot.entity.Guild;
import fr.neutronstars.nbot.entity.Message;
import fr.neutronstars.nbot.entity.User;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.*;

public class CommandArgs
{
private final JDA jda;
private final String commandToString;
private final String[] args;
private final Message message;
private final Guild guild;
private final Channel channel;
private final User user;
private final CommandSender commandSender;
private final SimpleCommand simpleCommand;
private final Category category;
private final Member member;
private final PrivateChannel privateChannel;
private final TextChannel textChannel;
private final SelfUser selfUser;

protected CommandArgs(JDA jda, String commandToString, String[] args, Message message, Guild guild, Channel channel, User user, CommandSender commandSender, SimpleCommand simpleCommand, Category category, Member member, PrivateChannel privateChannel, TextChannel textChannel, SelfUser selfUser)
{
this.jda = jda;
this.commandToString = commandToString;
this.args = args;
this.message = message;
this.guild = guild;
this.channel = channel;
this.user = user;
this.commandSender = commandSender;
this.simpleCommand = simpleCommand;
this.category = category;
this.member = member;
this.privateChannel = privateChannel;
this.textChannel = textChannel;
this.selfUser = selfUser;
}

public JDA getJda()
{
return jda;
}

public User getUser()
{
return user;
}

public TextChannel getTextChannel()
{
return textChannel;
}

public String[] getArgs()
{
return args;
}

public String getCommand()
{
return commandToString;
}

public SimpleCommand getSimpleCommand()
{
return simpleCommand;
}

public SelfUser getSelfUser()
{
return selfUser;
}

public PrivateChannel getPrivateChannel()
{
return privateChannel;
}

public Member getMember()
{
return member;
}

public Guild getGuild()
{
return guild;
}

public CommandSender getCommandSender()
{
return commandSender;
}

public Channel getChannel()
{
return channel;
}

public Category getCategory()
{
return category;
}

public Message getMessage()
{
return message;
}
}
114 changes: 114 additions & 0 deletions src/main/java/fr/neutronstars/nbot/command/CommandBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package fr.neutronstars.nbot.command;

import fr.neutronstars.nbot.plugin.NBotPlugin;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class CommandBuilder
{
private final String name, description;
private final List<Long> guilds = new ArrayList<>();
private final List<String> aliases = new ArrayList<>();
private final Command.ExecutorType executor;
private final boolean toPrivate, privateOnly;

private int power;
private Consumer<CommandArgs> consumer;

public CommandBuilder(String name, String description)
{
this(name, description, 0);
}

public CommandBuilder(String name, String description, int power)
{
this(name, description, 0, Command.ExecutorType.USER, false, false);
}

public CommandBuilder(String name, String description, boolean toPrivate, boolean privateOnly)
{
this(name, description, 0, toPrivate, privateOnly);
}

public CommandBuilder(String name, String description, int power, boolean toPrivate, boolean privateOnly)
{
this(name, description, 0, Command.ExecutorType.USER, toPrivate, privateOnly);
}

public CommandBuilder(String name, String description, int power, Command.ExecutorType executor, boolean toPrivate, boolean privateOnly)
{
this.name = name;
this.description = description;
this.power = power;
this.executor = executor;
this.toPrivate = toPrivate;
this.privateOnly = privateOnly;
}

public String getName()
{
return name;
}

public String getDescription()
{
return description;
}

public Command.ExecutorType getExecutor()
{
return executor;
}

public int getPower()
{
return power;
}

public List<Long> getGuilds()
{
return guilds;
}

public List<String> getAliases()
{
return aliases;
}

public CommandBuilder addGuild(long guildId)
{
guilds.add(guildId);
return this;
}

public boolean isToPrivate()
{
return toPrivate;
}

public boolean isPrivateOnly()
{
return privateOnly;
}

public CommandBuilder setExecutor(Consumer<CommandArgs> consumer)
{
this.consumer = consumer;
return this;
}

protected void execute(CommandArgs args)
{
if(consumer != null) consumer.accept(args);
}

public void register(NBotPlugin plugin)
{
if(plugin == null)
CommandManager.registerCommand(this, null);
else
plugin.registerCommand(this);
}
}
Loading

0 comments on commit 7960888

Please sign in to comment.