Merge branch 'feature/RolesSystem' into develop

This commit is contained in:
Alex Stewart
2019-04-15 14:57:55 -07:00
8 changed files with 178 additions and 9 deletions
+2
View File
@@ -33,3 +33,5 @@ help=1
buildHelp=1 buildHelp=1
invite=1 invite=1
shutdown=1 shutdown=1
addguildrole=1
allowedguildrole=1
+3 -1
View File
@@ -12,9 +12,11 @@ choose=
poll= poll=
rpstart= rpstart=
bet= bet=
addguildrole=
perish, thenperish= perish, thenperish=
teey= teey=
stats= stats=
allowedguildrole=
beans= beans=
eightball, 8ball= eightball, 8ball=
vote= vote=
@@ -35,4 +37,4 @@ buildHelp=
invite= invite=
shutdown= shutdown=
+12 -1
View File
@@ -49,6 +49,11 @@ StarkInfo=Snaps your icon or the icon of a friend you mentioned
[CommandYeet] [CommandYeet]
YeetInfo=Yeet yourself or yeet a friend with @! YeetInfo=Yeet yourself or yeet a friend with @!
[CommandAllowedGuildRole]
AllowedGuildRoleInfo=
AllowedGuildRoleDuplicate=Can't add the same role twice!
AllowedGuildRoleSuccess=Added %s to the allowed roles!
[CommandPollVote] [CommandPollVote]
PollVoteNotValidNumber=That's not a vaild number! PollVoteNotValidNumber=That's not a vaild number!
PollVoteInfo=Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful! PollVoteInfo=Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful!
@@ -166,6 +171,12 @@ WolframError=Something went wrong!
WolframInfo=Will query wolframalpha with your question and give a full image output of the answer WolframInfo=Will query wolframalpha with your question and give a full image output of the answer
WolframNoArgs=You need to provide some arguments! WolframNoArgs=You need to provide some arguments!
[CommandAddGuildRole]
AddGuildRoleInfo=Add a role to yourself!
AddGuildRoleNotAllowed=You are not allowed to add %s!
AddGuildRoleSuccess=Added %s to %s
AddGuildRoleFailure=Failed to add %s to %s
[CommandMap] [CommandMap]
MapInfo=Generates a map! You can pass additional information if you want with the flags `-s<seed>-w<width>-h<height>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\nDefault seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s) MapInfo=Generates a map! You can pass additional information if you want with the flags `-s<seed>-w<width>-h<height>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\nDefault seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)
MapSeed=Seed MapSeed=Seed
@@ -174,4 +185,4 @@ MapVersion=Using mapgen v0.1
MapWidth=Width MapWidth=Width
MapHeight=Height MapHeight=Height
+40
View File
@@ -0,0 +1,40 @@
package commands;
import core.Command;
import core.LocStrings;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandAddGuildRole extends Command
{
public CommandAddGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("AddGuildRoleInfo"); };
@Override
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.control.addRole(user.discordID, role))
{
res.Call(String.format(LocStrings.Stub("AddGuildRoleSuccess"), role, user.name));
}
else
{
res.Call(String.format(LocStrings.Stub("AddGuildRoleFailure"), role, user.name));
}
}
else
{
res.Call(String.format(LocStrings.Stub("AddGuildRoleNotAllowed"), role));
}
}
}
+39
View File
@@ -0,0 +1,39 @@
package commands;
import core.Command;
import core.LocStrings;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandAllowedGuildRole extends Command
{
public CommandAllowedGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("AllowedGuildRoleInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
String [] roles = input.args.split(",");
String role;
for(int i = 0; i < roles.length; i++)
{
role = roles[i].trim();
if(guild.allowedRole.contains(role))
{
res.Call(LocStrings.Stub("AllowedGuildRoleDuplicate"));
}
else
{
guild.allowedRole.add(role);
res.Call(String.format(LocStrings.Stub("AllowedGuildRoleSuccess"), role));
}
}
}
}
+47 -4
View File
@@ -3,10 +3,51 @@ package core;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import commands.*; import commands.CommandAddGuildRole;
import dataStructures.*; import commands.CommandAllowedGuildRole;
import commands.CommandBeansShow;
import commands.CommandBetBeans;
import commands.CommandBlurry;
import commands.CommandBoop;
import commands.CommandChangeIndicator;
import commands.CommandChoose;
import commands.CommandColiru;
import commands.CommandDoWork;
import commands.CommandEightBall;
import commands.CommandGiveBeans;
import commands.CommandHelp;
import commands.CommandHelpBuilder;
import commands.CommandInfo;
import commands.CommandInvite;
import commands.CommandJDoodle;
import commands.CommandMap;
import commands.CommandPerish;
import commands.CommandPing;
import commands.CommandPollManage;
import commands.CommandPollResults;
import commands.CommandPollShow;
import commands.CommandPollVote;
import commands.CommandRPEnd;
import commands.CommandRPG;
import commands.CommandRPStart;
import commands.CommandRating;
import commands.CommandRole;
import commands.CommandRoll;
import commands.CommandShutdown;
import commands.CommandStark;
import commands.CommandStats;
import commands.CommandTeey;
import commands.CommandTweet;
import commands.CommandWolfram;
import commands.CommandYeet;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import utils.AdminControl;
import utils.GlobalLog; import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
@@ -95,7 +136,7 @@ public class ObjectBuilderFactory
// look up the guild. // look up the guild.
String uid = event.getGuild().getId(); String uid = event.getGuild().getId();
// ince we're lazily initialized, we can synchronize w/ the // once we're lazily initialized, we can synchronize w/ the
// guildCache object now instead of having to use a mutex. // guildCache object now instead of having to use a mutex.
KittyGuild guild = null; KittyGuild guild = null;
synchronized (guildCache) synchronized (guildCache)
@@ -108,7 +149,7 @@ public class ObjectBuilderFactory
else else
{ {
// Construct a new guild with defaults // Construct a new guild with defaults
guild = new KittyGuild(uid); guild = new KittyGuild(uid, new AdminControl(event.getGuild()));
DatabaseManager.instance.Register(guild); DatabaseManager.instance.Register(guild);
guildCache.put(uid, guild); guildCache.put(uid, guild);
} }
@@ -322,11 +363,13 @@ public class ObjectBuilderFactory
manager.Register(LocCommands.Stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe)); manager.Register(LocCommands.Stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
manager.Register(LocCommands.Stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe)); manager.Register(LocCommands.Stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
manager.Register(LocCommands.Stub("allowedguildrole"), new CommandAllowedGuildRole(KittyRole.Admin, KittyRating.Safe));
manager.Register(LocCommands.Stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe)); manager.Register(LocCommands.Stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
manager.Register(LocCommands.Stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe)); manager.Register(LocCommands.Stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
manager.Register(LocCommands.Stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe)); manager.Register(LocCommands.Stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
manager.Register(LocCommands.Stub("addguildrole"), new CommandAddGuildRole(KittyRole.General, KittyRating.Safe));
manager.Register(LocCommands.Stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe)); manager.Register(LocCommands.Stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
manager.Register(LocCommands.Stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe)); manager.Register(LocCommands.Stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
manager.Register(LocCommands.Stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe)); manager.Register(LocCommands.Stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
+6 -3
View File
@@ -2,6 +2,7 @@ package dataStructures;
import java.util.ArrayList; import java.util.ArrayList;
import core.DatabaseTrackedObject; import core.DatabaseTrackedObject;
import utils.AdminControl;
// Context for a given guild for kittybot. Primarily designed to hold guild-specific settings. // Context for a given guild for kittybot. Primarily designed to hold guild-specific settings.
public class KittyGuild extends DatabaseTrackedObject public class KittyGuild extends DatabaseTrackedObject
@@ -12,17 +13,19 @@ public class KittyGuild extends DatabaseTrackedObject
public boolean polling; public boolean polling;
public String poll; public String poll;
public ArrayList<String> hasVoted = new ArrayList<String>(); public ArrayList<String> hasVoted = new ArrayList<String>();
public ArrayList<String> allowedRole = new ArrayList<String>();
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>(); public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
public AdminControl control;
private String commandIndicator; private String commandIndicator;
// Default content for a guild // Default content for a guild
public KittyGuild(String uniqueID) public KittyGuild(String uniqueID, AdminControl adminControl)
{ {
super(uniqueID); super(uniqueID);
control = adminControl;
this.uniqueID = uniqueID; this.uniqueID = uniqueID;
this.contentRating = KittyRating.Safe; this.contentRating = KittyRating.Safe;
this.polling = false; this.polling = false;
SetCommandIndicator("!"); SetCommandIndicator("!");
} }
+29
View File
@@ -0,0 +1,29 @@
package utils;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.managers.GuildController;
public class AdminControl
{
private GuildController guildCon;
private Guild guild;
public AdminControl(Guild guild)
{
this.guild = guild;
guildCon = guild.getController();
}
public boolean addRole(String memberID, String roleName)
{
try
{
guildCon.addRolesToMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete();
}
catch(Exception e)
{
return false;
}
return true;
}
}