+Added SubCommand system

This commit is contained in:
Alex
2019-06-25 02:24:24 -04:00
parent 771c1ee53f
commit df7973b3d7
3 changed files with 137 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
package core;
import dataStructures.*;
import utils.GlobalLog;
import utils.LogFilter;
public abstract class SubCommand
{
private KittyRole roleLevel;
private KittyRating contentRating;
public SubCommand(KittyRole roleLevel, KittyRating contentRating)
{
this.roleLevel = roleLevel;
this.contentRating = contentRating;
}
private void Reject(KittyUser user, String reason)
{
GlobalLog.Warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
}
private boolean CanCall(KittyGuild guild, KittyChannel channel, KittyUser user)
{
if(guild.contentRating.getValue() < contentRating.getValue())
{
Reject(user, "content rating");
return false;
}
//TODO: ADD CHANNEL CHECK HERE
if(user.GetRole().getValue() >= roleLevel.getValue())
{
return true;
}
Reject(user, "permissions");
return false;
}
// Called by the Command manager - this will run the command
// if the issuing user has the permission to do so!
protected final void Invoke(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(!CanCall(guild, channel, user))
return;
OnRun(guild, channel, user, input);
}
public KittyRating Rating()
{
return contentRating;
}
public KittyRole RequiredRole()
{
return roleLevel;
}
public abstract SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input);
}