Merge branch 'develop'
This commit is contained in:
@@ -13,5 +13,6 @@
|
||||
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/>
|
||||
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/>
|
||||
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/luaj-jse-3.0.1.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -35,3 +35,7 @@ invite=1
|
||||
shutdown=1
|
||||
addguildrole=1
|
||||
allowedguildrole=1
|
||||
guildroleremove=1
|
||||
guildroleadd=1
|
||||
guildroleallowed=1
|
||||
fetch=1
|
||||
|
||||
Binary file not shown.
+4
-2
@@ -4,6 +4,7 @@ boop=
|
||||
tony, stark, dontfeelgood, dontfeelsogood=
|
||||
yeet=
|
||||
role=
|
||||
guildroleremove=
|
||||
ping=
|
||||
rating=
|
||||
roll=
|
||||
@@ -12,13 +13,12 @@ choose=
|
||||
poll=
|
||||
rpstart=
|
||||
bet=
|
||||
addguildrole=
|
||||
perish, thenperish=
|
||||
teey=
|
||||
stats=
|
||||
allowedguildrole=
|
||||
beans=
|
||||
eightball, 8ball=
|
||||
guildroleadd=
|
||||
vote=
|
||||
results=
|
||||
wolfram=
|
||||
@@ -32,8 +32,10 @@ rpend=
|
||||
rpg=
|
||||
tweet=
|
||||
java, jdoodle=
|
||||
guildroleallowed=
|
||||
help=
|
||||
buildHelp=
|
||||
fetch=
|
||||
invite=
|
||||
shutdown=
|
||||
|
||||
|
||||
+27
-11
@@ -13,6 +13,11 @@ HelpDisplay=You can get help with a specific command by typing `!help command`!\
|
||||
RollError=Didn't work ;3;
|
||||
RollInfo=Based on input of xdy where x is number of dice and y is faces kitty will roll that amount of dice, display the individual rolls and total
|
||||
|
||||
[CommandGuildRoleAllowed]
|
||||
GuildRoleAllowedInfo=
|
||||
GuildRoleAllowedSuccess=Added %s to the allowed roles!
|
||||
GuildRoleAllowedDuplicate=Can't add the same role twice!
|
||||
|
||||
[CommandStats]
|
||||
StatsInfo=Displays the actively running KittyBot application information
|
||||
|
||||
@@ -20,6 +25,12 @@ StatsInfo=Displays the actively running KittyBot application information
|
||||
TweetInfo=Kitty will tweet to her personal twitter account
|
||||
TweetError=Tweet command failed!
|
||||
|
||||
[CommandGuildRoleAdd]
|
||||
GuildRoleAddSuccess=Added %s to %s
|
||||
GuildRoleAddFailure=Failed to add %s to %s
|
||||
GuildRoleAddNotAllowed=You are not allowed to add %s!
|
||||
GuildRoleAddInfo=Add a role to yourself!
|
||||
|
||||
[CommandRole]
|
||||
RoleInfo=Will show the current role you have, Admins can change others roles with input of 'role x @y' with x being blacklist, general, mod, or admin. Blacklist will not allow the user to interact with kitty anymore, general mod and admin will give the user access to those commands.
|
||||
RoleStandardResponse=Your role is
|
||||
@@ -49,11 +60,6 @@ StarkInfo=Snaps your icon or the icon of a friend you mentioned
|
||||
[CommandYeet]
|
||||
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]
|
||||
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!
|
||||
@@ -126,6 +132,16 @@ BoopInfo=Kitty will react with a counter
|
||||
BoopStandard=Woah! %s booped me! That's %s total!
|
||||
BoopMultiple=%s booped several others - %s!
|
||||
|
||||
[CommandFetch]
|
||||
FetchError=That no picture!
|
||||
FetchEat=Me eat now *monch %s*
|
||||
FetchInfo=Throw a custom emote and me bring it back!
|
||||
FetchCatchRun=*Catches and runs away with %s*
|
||||
FetchRunAway=*Runs away and doesn't return for a long time*
|
||||
FetchBringBack=Me gots it! %s
|
||||
FetchBringBackWrong=Me gots it! %s
|
||||
FetchStare=*Stares at %s*
|
||||
|
||||
[CommandInfo]
|
||||
InfoResponse=I'm made by `Rin#8904` and `Reverie Wisp#3703`!\nYou can find more info about me along with a Patreon link to support us and GitHub link for filing bugs https://www.rinsnowmew.com/bot/
|
||||
InfoInfo=Provides author info and a link to Kitty's website
|
||||
@@ -166,17 +182,17 @@ EightBallYes10=Signs point to yes.
|
||||
[CommandInvite]
|
||||
InviteInfo=Provides a direct invite link for KittyBot
|
||||
|
||||
[CommandGuildRoleRemove]
|
||||
GuildRoleRemoveNotAllowed=You're not allowed to add %s
|
||||
GuildRoleRemoveFailure=Couldn't remove %s from %s
|
||||
GuildRoleRemoveSuccess=Removed %s from %s!
|
||||
GuildRoleRemoveInfo=
|
||||
|
||||
[CommandWolfram]
|
||||
WolframError=Something went wrong!
|
||||
WolframInfo=Will query wolframalpha with your question and give a full image output of the answer
|
||||
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]
|
||||
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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Example plugin stub. This function is called and passed the input message.
|
||||
-- If nil is returned, the plugin is considered to have not run, but if any
|
||||
-- other value is returned, it's interpreted as a string and sent back to the user.
|
||||
function plugin(message)
|
||||
return nil;
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
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 CommandFetch extends Command
|
||||
{
|
||||
public CommandFetch(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("FetchInfo"); }
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String emote = input.args.split(" ")[0];
|
||||
if(emote.startsWith("<") && emote.endsWith(">"))
|
||||
{
|
||||
int num = (int)(Math.random() * 6) + 1;
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
res.Call(String.format(LocStrings.Stub("FetchBringBack"), emote));
|
||||
break;
|
||||
case 2:
|
||||
res.Call(String.format(LocStrings.Stub("FetchRunAway")));
|
||||
break;
|
||||
case 3:
|
||||
res.Call(String.format(LocStrings.Stub("FetchBringBackWrong"), guild.emoji.get((int)(Math.random() * guild.emoji.size()) + 1)));
|
||||
break;
|
||||
case 4:
|
||||
res.Call(String.format(LocStrings.Stub("FetchEat"), emote));
|
||||
break;
|
||||
case 5:
|
||||
res.Call(String.format(LocStrings.Stub("FetchCatchRun"), emote));
|
||||
break;
|
||||
case 6:
|
||||
res.Call(String.format(LocStrings.Stub("FetchStare"), user.name));
|
||||
break;
|
||||
default:
|
||||
res.Call("" + num);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("FetchError")));
|
||||
System.out.println(emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,12 @@ import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandAddGuildRole extends Command
|
||||
public class CommandGuildRoleAdd extends Command
|
||||
{
|
||||
public CommandAddGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
public CommandGuildRoleAdd(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("AddGuildRoleInfo"); };
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleAddInfo"); };
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -25,16 +25,16 @@ public class CommandAddGuildRole extends Command
|
||||
{
|
||||
if(guild.control.addRole(user.discordID, role))
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleSuccess"), role, user.name));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddSuccess"), role, user.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleFailure"), role, user.name));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddFailure"), role, user.name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleNotAllowed"), role));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddNotAllowed"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -10,12 +10,12 @@ import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandAllowedGuildRole extends Command
|
||||
public class CommandGuildRoleAllowed extends Command
|
||||
{
|
||||
public CommandAllowedGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
public CommandGuildRoleAllowed(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("AllowedGuildRoleInfo"); }
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleAllowedInfo"); }
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -27,12 +27,12 @@ public class CommandAllowedGuildRole extends Command
|
||||
role = roles[i].trim();
|
||||
if(guild.allowedRole.contains(role))
|
||||
{
|
||||
res.Call(LocStrings.Stub("AllowedGuildRoleDuplicate"));
|
||||
res.Call(LocStrings.Stub("GuildRoleAllowedDuplicate"));
|
||||
}
|
||||
else
|
||||
{
|
||||
guild.allowedRole.add(role);
|
||||
res.Call(String.format(LocStrings.Stub("AllowedGuildRoleSuccess"), role));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAllowedSuccess"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 CommandGuildRoleRemove extends Command
|
||||
{
|
||||
public CommandGuildRoleRemove(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleRemoveInfo"); };
|
||||
|
||||
@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.removeRole(user.discordID, role))
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveSuccess"), role, user.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveFailure"), role, user.name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveNotAllowed"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,14 @@
|
||||
package core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import commands.CommandAddGuildRole;
|
||||
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 commands.*;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.*;
|
||||
import net.dv8tion.jda.core.entities.Emote;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import utils.AdminControl;
|
||||
@@ -75,6 +39,9 @@ public class ObjectBuilderFactory
|
||||
// RPManger for tracking RP system
|
||||
private static RPManager rpManager;
|
||||
|
||||
// Plugin manager
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||
@@ -136,6 +103,17 @@ public class ObjectBuilderFactory
|
||||
// look up the guild.
|
||||
String uid = event.getGuild().getId();
|
||||
|
||||
List<Emote> emotes = event.getGuild().getEmotes();
|
||||
ArrayList<String> emotesString = new ArrayList<String>();
|
||||
String emote;
|
||||
String emoteFix;
|
||||
for(int i = 0; i < emotes.size(); i++)
|
||||
{
|
||||
emote = emotes.get(i).toString();
|
||||
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
||||
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
||||
emotesString.add(emoteFix);
|
||||
}
|
||||
// once we're lazily initialized, we can synchronize w/ the
|
||||
// guildCache object now instead of having to use a mutex.
|
||||
KittyGuild guild = null;
|
||||
@@ -149,7 +127,7 @@ public class ObjectBuilderFactory
|
||||
else
|
||||
{
|
||||
// Construct a new guild with defaults
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()));
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString);
|
||||
DatabaseManager.instance.Register(guild);
|
||||
guildCache.put(uid, guild);
|
||||
}
|
||||
@@ -363,13 +341,15 @@ public class ObjectBuilderFactory
|
||||
|
||||
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("allowedguildrole"), new CommandAllowedGuildRole(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleallowed"), new CommandGuildRoleAllowed(KittyRole.Admin, 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("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
|
||||
|
||||
manager.Register(LocCommands.Stub("addguildrole"), new CommandAddGuildRole(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleadd"), new CommandGuildRoleAdd(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleremove"), new CommandGuildRoleRemove(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("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
||||
@@ -432,6 +412,16 @@ public class ObjectBuilderFactory
|
||||
return rpManager;
|
||||
}
|
||||
|
||||
public static PluginManager ConstructPluginManager()
|
||||
{
|
||||
LazyInit();
|
||||
|
||||
if(pluginManager == null)
|
||||
pluginManager = new PluginManager("./plugins/");
|
||||
|
||||
return pluginManager;
|
||||
}
|
||||
|
||||
public static Integer GetGuildCount()
|
||||
{ synchronized(guildCache)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package core.lua;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
//To promote flexibility, plugins are lua file with predefined callbacks.
|
||||
//They are executed between the initial built-in preprocessing and the command parsing.
|
||||
public class Plugin
|
||||
{
|
||||
public Path filepath;
|
||||
public String contents;
|
||||
|
||||
public Plugin(Path filepath)
|
||||
{
|
||||
this.filepath = filepath;
|
||||
|
||||
StringBuilder contentBuilder = new StringBuilder();
|
||||
|
||||
try
|
||||
{
|
||||
Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8);
|
||||
stream.forEach(str -> contentBuilder.append(str).append("\n"));
|
||||
stream.close();
|
||||
contents = contentBuilder.toString();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
PluginLog.Error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package core.lua;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
// This class wraps the lua layer - provides all the processing and function
|
||||
// calls to the lua binding.
|
||||
public class PluginLoader
|
||||
{
|
||||
private Globals globals;
|
||||
|
||||
public PluginLoader()
|
||||
{
|
||||
globals = JsePlatform.standardGlobals();
|
||||
PluginLog.Log("Created new PluginLoader lua environment");
|
||||
}
|
||||
|
||||
public String Process(Plugin toProcess, String args)
|
||||
{
|
||||
globals.load(toProcess.contents).call();
|
||||
LuaValue pluginFunc = globals.get("plugin");
|
||||
|
||||
String output = null;
|
||||
|
||||
try
|
||||
{
|
||||
LuaValue res = pluginFunc.call(LuaValue.valueOf(args));
|
||||
|
||||
if(res.isnil())
|
||||
output = null;
|
||||
else
|
||||
output = res.toString();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
output = null;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package core.lua;
|
||||
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class PluginLog
|
||||
{
|
||||
public static void Log(String s) { GlobalLog.Log(LogFilter.Plugin, s); }
|
||||
public static void Warn(String s) { GlobalLog.Warn(LogFilter.Plugin, s); }
|
||||
public static void Error(String s) { GlobalLog.Error(LogFilter.Plugin, s); }
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package core.lua;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
// Reads in, handles, and manipulates plugins. Plugins are loaded in the order they appear in the folder.
|
||||
public class PluginManager
|
||||
{
|
||||
public PluginLoader pluginLoader;
|
||||
public final String pluginFolder;
|
||||
public ArrayList<Plugin> plugins;
|
||||
|
||||
public void AddPlugin(Path path)
|
||||
{
|
||||
plugins.add(new Plugin(path));
|
||||
}
|
||||
|
||||
public PluginManager(String folder)
|
||||
{
|
||||
this.pluginFolder = folder;
|
||||
plugins = new ArrayList<Plugin>();
|
||||
this.pluginLoader = new PluginLoader();
|
||||
|
||||
try
|
||||
{
|
||||
try (Stream<Path> paths = Files.walk(Paths.get(this.pluginFolder)))
|
||||
{
|
||||
paths.filter(Files::isRegularFile).forEach((path)->{ AddPlugin(path); });
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
PluginLog.Error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String CallAll(String input)
|
||||
{
|
||||
for(int i = 0; i < plugins.size(); ++i)
|
||||
{
|
||||
Plugin script = plugins.get(i);
|
||||
String out = pluginLoader.Process(script, input);
|
||||
|
||||
if(out != null)
|
||||
{
|
||||
PluginLog.Log("Executed plugin at " + script.filepath);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void PrintAll()
|
||||
{
|
||||
for(int i = 0; i < plugins.size(); ++i)
|
||||
PluginLog.Log(plugins.get(i).contents.toString());
|
||||
}
|
||||
}
|
||||
@@ -14,19 +14,21 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
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;
|
||||
|
||||
private String commandIndicator;
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl)
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
||||
{
|
||||
super(uniqueID);
|
||||
control = adminControl;
|
||||
this.uniqueID = uniqueID;
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
SetCommandIndicator("!");
|
||||
}
|
||||
|
||||
|
||||
+19
-10
@@ -2,6 +2,7 @@ package main;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import core.*;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRole;
|
||||
@@ -22,14 +23,15 @@ import net.dv8tion.jda.core.*;
|
||||
@SuppressWarnings("unused")
|
||||
public class Main extends ListenerAdapter
|
||||
{
|
||||
// Variables and stuff
|
||||
// Variables and bot specific objects
|
||||
private static JDA kitty;
|
||||
private static CommandManager commandManager;
|
||||
private static CommandEnabler commandEnabler;
|
||||
private static DatabaseManager databaseManager;
|
||||
private static CommandEnabler commandEnabler;
|
||||
private static CommandManager commandManager;
|
||||
private static Stats stats;
|
||||
private static RPManager rpManager;
|
||||
|
||||
private static PluginManager pluginManager;
|
||||
|
||||
// Main test location
|
||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||
{
|
||||
@@ -37,8 +39,9 @@ public class Main extends ListenerAdapter
|
||||
databaseManager = ObjectBuilderFactory.ConstructDatabaseManager();
|
||||
commandEnabler = ObjectBuilderFactory.ConstructCommandEnabler();
|
||||
commandManager = ObjectBuilderFactory.ConstructCommandManager(commandEnabler);
|
||||
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
||||
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
||||
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
||||
pluginManager = ObjectBuilderFactory.ConstructPluginManager();
|
||||
|
||||
// Bot startup
|
||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||
@@ -61,19 +64,25 @@ public class Main extends ListenerAdapter
|
||||
// Specialized uncached objects
|
||||
Response response = new Response(event, kitty);
|
||||
UserInput input = new UserInput(event, guild);
|
||||
|
||||
|
||||
// Tweak object construction as necessary
|
||||
if(!PostProcessSetup(event, user, guild, channel, response, input))
|
||||
return;
|
||||
|
||||
|
||||
// Track beans!
|
||||
user.ChangeBeans(1);
|
||||
user.ChangeBeans(1);
|
||||
|
||||
// RP logging system
|
||||
RPManager.instance.addLine(channel, user, input);
|
||||
|
||||
// Issue the command
|
||||
commandManager.InvokeOnNewThread(guild, channel, user, input, response);
|
||||
// Run plugins right before invoking the commands but after all other setup
|
||||
String output = pluginManager.CallAll(input.message);
|
||||
|
||||
// Spin up the command if no plugins ran. Otherwise, send a response.
|
||||
if(output == null)
|
||||
commandManager.InvokeOnNewThread(guild, channel, user, input, response);
|
||||
else
|
||||
response.Call(output);
|
||||
|
||||
// Run any upkeep we need to
|
||||
PerCommandUpkeep();
|
||||
|
||||
@@ -26,4 +26,17 @@ public class AdminControl
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeRole(String memberID, String roleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
guildCon.removeRolesFromMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package utils;
|
||||
public enum LogFilter
|
||||
{
|
||||
// Assign numbers as flags, so we can | ('or') them together as necessary
|
||||
Debug(0), Command(1), Core(2), Util(4), Database(8), Response(16), Network(32), Strings(64);
|
||||
Debug(0), Command(1), Core(2), Util(4), Database(8), Response(16), Network(32), Strings(64), Plugin(128);
|
||||
|
||||
private final int value;
|
||||
private LogFilter(int value)
|
||||
|
||||
Reference in New Issue
Block a user