= Saving allowed roles per guild
This commit is contained in:
@@ -21,7 +21,14 @@ public class CommandChangeIndicator extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
guild.SetCommandIndicator(arg.substring(0, 1));
|
||||
String indicator = arg.substring(0, 1);
|
||||
if(indicator.charAt(0) == '\n' || indicator.charAt(0) == '\t' || indicator.charAt(0) == '\r')
|
||||
{
|
||||
res.Call(LocStrings.Lookup("ChangeIndicatorError"));
|
||||
return;
|
||||
}
|
||||
|
||||
guild.SetCommandIndicator(indicator);
|
||||
res.Call(String.format(LocStrings.Stub("ChangeIndicatorChanged"), guild.GetCommandIndicator()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CommandGuildRoleAdd extends Command
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String role = input.args.split(" ")[0];
|
||||
if(guild.allowedRole.contains(role))
|
||||
if(guild.roleList.contains(role))
|
||||
{
|
||||
if(guild.control.addRole(user.discordID, role))
|
||||
{
|
||||
|
||||
@@ -25,13 +25,13 @@ public class CommandGuildRoleAllowed extends Command
|
||||
for(int i = 0; i < roles.length; i++)
|
||||
{
|
||||
role = roles[i].trim();
|
||||
if(guild.allowedRole.contains(role))
|
||||
if(guild.roleList.contains(role))
|
||||
{
|
||||
res.Call(LocStrings.Stub("GuildRoleAllowedDuplicate"));
|
||||
}
|
||||
else
|
||||
{
|
||||
guild.allowedRole.add(role);
|
||||
guild.roleList.add(role);
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAllowedSuccess"), role));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ public class CommandGuildRoleList extends Command
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String roles = "";
|
||||
if(guild.allowedRole.isEmpty())
|
||||
if(guild.roleList.isEmpty())
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleListEmpty")));
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < guild.allowedRole.size(); i++)
|
||||
for(int i = 0; i < guild.roleList.size(); i++)
|
||||
{
|
||||
if(i > 0)
|
||||
roles += " and ";
|
||||
roles += guild.allowedRole.get(i);
|
||||
roles += guild.roleList.get(i);
|
||||
}
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleListOutput"), roles));
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ public class CommandGuildRoleNotAllowed extends Command
|
||||
for(int i = 0; i < roles.length; i++)
|
||||
{
|
||||
role = roles[i].trim();
|
||||
if(guild.allowedRole.contains(role))
|
||||
if(guild.roleList.contains(role))
|
||||
{
|
||||
guild.allowedRole.remove(role);
|
||||
guild.roleList.remove(role);
|
||||
res.Call(LocStrings.Stub("GuildRoleNotAllowedSuccess"));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CommandGuildRoleRemove extends Command
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String role = input.args.split(" ")[0];
|
||||
if(guild.allowedRole.contains(role))
|
||||
if(guild.roleList.contains(role))
|
||||
{
|
||||
if(guild.control.removeRole(user.discordID, role))
|
||||
{
|
||||
|
||||
@@ -2,9 +2,9 @@ package core.benchmark;
|
||||
|
||||
import utils.GlobalLog;
|
||||
|
||||
//Logging shim
|
||||
public class BenchmarkLog
|
||||
{
|
||||
// Logging
|
||||
{
|
||||
public static void Log(String str) { GlobalLog.Log("[Benchmark] " + str); }
|
||||
public static void Warn(String str) { GlobalLog.Warn("[Benchmark] " + str); }
|
||||
public static void Error(String str) { GlobalLog.Error(" [Benchmark] " + str); }
|
||||
|
||||
@@ -7,25 +7,29 @@ import utils.AdminControl;
|
||||
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
|
||||
public class KittyGuild extends DatabaseTrackedObject
|
||||
{
|
||||
public String uniqueID;
|
||||
// Variables
|
||||
public final String uniqueID;
|
||||
public KittyRating contentRating;
|
||||
public KittyUser guildOwner;
|
||||
public boolean polling;
|
||||
public String poll;
|
||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||
public ArrayList<String> allowedRole = new ArrayList<String>();
|
||||
public ArrayList<String> emoji = new ArrayList<String>();
|
||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||
public AdminControl control;
|
||||
|
||||
// Database synced info
|
||||
public final KittyGuildRoleList roleList;
|
||||
private String commandIndicator;
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
||||
{
|
||||
super(uniqueID);
|
||||
control = adminControl;
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyGuildRoleList(uniqueID);
|
||||
|
||||
control = adminControl;
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
@@ -36,6 +40,8 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
roleList = new KittyGuildRoleList(uniqueID);
|
||||
|
||||
SetCommandIndicator(commandIndicator);
|
||||
this.contentRating = contentRating;
|
||||
@@ -64,7 +70,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
poll = null;
|
||||
return "Poll ended!";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String Serialize()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package dataStructures;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import core.DatabaseTrackedObject;
|
||||
|
||||
// Acts as a proxy of sorts for the allowedRole arraylist, keeping it tracked for a specific guild.
|
||||
public class KittyGuildRoleList extends DatabaseTrackedObject
|
||||
{
|
||||
// Variables
|
||||
private Vector<String> allowedRole = new Vector<String>();
|
||||
private final static String delimiter = "\n";
|
||||
private final static String split = "\\n";
|
||||
private final static String differentiator = "roles";
|
||||
|
||||
// Constructor - provide it with the guild ID
|
||||
public KittyGuildRoleList(String identifier)
|
||||
{
|
||||
super(identifier + differentiator);
|
||||
}
|
||||
|
||||
// Mirrored behavior
|
||||
public boolean contains(String role)
|
||||
{
|
||||
return allowedRole.contains(role);
|
||||
}
|
||||
|
||||
public void add(String role)
|
||||
{
|
||||
allowedRole.add(role);
|
||||
this.MarkDirty();
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return allowedRole.isEmpty();
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return allowedRole.size();
|
||||
}
|
||||
|
||||
public String get(int index)
|
||||
{
|
||||
return allowedRole.get(index);
|
||||
}
|
||||
|
||||
public void remove(String role)
|
||||
{
|
||||
allowedRole.remove(role);
|
||||
this.MarkDirty();
|
||||
}
|
||||
|
||||
// Writes out the roles as a single string that can be parsed back in later
|
||||
@Override
|
||||
public String Serialize()
|
||||
{
|
||||
String toSerialize = "";
|
||||
|
||||
for(int i = 0; i < allowedRole.size(); ++i)
|
||||
{
|
||||
if(i != 0)
|
||||
toSerialize += delimiter;
|
||||
|
||||
toSerialize += allowedRole.get(i);
|
||||
}
|
||||
|
||||
return toSerialize;
|
||||
}
|
||||
|
||||
// Reads in the roles as a delimited single string that needs parsing
|
||||
@Override
|
||||
public void DeSerialzie(String string)
|
||||
{
|
||||
String[] rolesSplit = string.split(split);
|
||||
|
||||
for(int i = 0; i < rolesSplit.length; ++i)
|
||||
allowedRole.add(rolesSplit[i]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user