Merge branch 'develop'

This commit is contained in:
Alex
2019-05-21 00:02:57 -04:00
4 changed files with 58 additions and 17 deletions
+10 -8
View File
@@ -82,6 +82,15 @@ 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 @!
[CommandTradeBeans]
TradeBeanseStealingBeans=Stealing is wrong! *Steals 10 beans from %s*
TradeBeansNoTargetError=You have to give *someone* your beans!
TradeBeansSuccess=%s gave %s %s of their beans!
TradeBeansStealingBeans=
TradeBeansInfo=Gives another person some of your beans! Use is `tradebeans amount @person`!
TradeBeansIntParseError=That's not a real number!
TradeBeansNotEnoughError=You don't have enough beans!
[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!
@@ -228,11 +237,4 @@ MapVersion=Using mapgen v0.1
MapWidth=Width MapWidth=Width
MapHeight=Height MapHeight=Height
[CommandTradeBeans]
TradeBeansInfo=Gives another person some of your beans! Use is `tradebeans amount @person`!
TradeBeansNoTargetError=You have to give *someone* your beans!
TradeBeansIntParseError=That's not a real number!
TradeBeansNotEnoughError=You don't have enough beans!
TradeBeanseStealingBeans=Stealing is wrong! *Steals 10 beans from %s*
TradeBeansSuccess=%s gave %s %s of their beans!
+33 -2
View File
@@ -4,10 +4,13 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
import java.util.Vector;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.luaj.vm2.Globals; import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.jse.JsePlatform; import org.luaj.vm2.lib.jse.JsePlatform;
// To promote flexibility, plugins are lua file with predefined callbacks. // To promote flexibility, plugins are lua file with predefined callbacks.
@@ -45,14 +48,42 @@ public class Plugin
} }
} }
public String Run(String args, PluginUser user) public List<String> Run(String args, PluginUser user)
{ {
try try
{ {
List<String> outputs = new Vector<String>();
LuaValue res = func_plugin.call(LuaValue.valueOf(args), user.AsLua()); LuaValue res = func_plugin.call(LuaValue.valueOf(args), user.AsLua());
if(!res.isnil()) if(!res.isnil())
return res.toString(); {
if(res.istable())
{
LuaValue key = LuaValue.NIL;
while (true)
{
Varargs n = res.next(key);
key = n.arg1();
if (key.isnil())
break;
LuaValue value = n.arg(2);
outputs.add(value.toString());
}
}
else
{
System.out.println("Loc2.5 " + res.toString());
outputs.add(res.toString());
}
}
if(outputs.size() <= 0)
return null;
return outputs;
} }
catch(Exception e) catch(Exception e)
{ {
+8 -4
View File
@@ -4,6 +4,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import dataStructures.KittyUser; import dataStructures.KittyUser;
@@ -37,15 +38,18 @@ public class PluginManager
} }
} }
// Runs all plugins, returning when it gets a non-nill result. // Runs all plugins, returning when it gets a non-nill result. If there
// are mutliple strings returned in the list, it is because the plugin
// that was run returned multiple strings. Since plugins don't stack, it
// will never indicate that multiple
// Otherwise, returns null. // Otherwise, returns null.
public String RunAll(String input, KittyUser user) public List<String> RunAll(String input, KittyUser user)
{ {
for(int i = 0; i < plugins.size(); ++i) for(int i = 0; i < plugins.size(); ++i)
{ {
Plugin plugin = plugins.get(i); Plugin plugin = plugins.get(i);
String out = plugin.Run(input, new PluginUser(user)); List<String> out = plugin.Run(input, new PluginUser(user));
if(out != null) if(out != null)
{ {
PluginLog.Log("Executed plugin at " + plugin.filepath); PluginLog.Log("Executed plugin at " + plugin.filepath);
+7 -3
View File
@@ -18,6 +18,7 @@ import net.dv8tion.jda.core.hooks.ListenerAdapter;
import offline.*; import offline.*;
import utils.GlobalLog; import utils.GlobalLog;
import net.dv8tion.jda.core.*; import net.dv8tion.jda.core.*;
import java.util.*;
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation. // http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
// This is the application entry point, and bot startup location! // This is the application entry point, and bot startup location!
@@ -86,10 +87,13 @@ public class Main extends ListenerAdapter
// Run plugins right before invoking the commands but after all other setup. // Run plugins right before invoking the commands but after all other setup.
if(commandManager.InvokeOnNewThread(guild, channel, user, input, response) == false) if(commandManager.InvokeOnNewThread(guild, channel, user, input, response) == false)
{ {
String pluginOutput = pluginManager.RunAll(input.message, user); List<String> pluginOutput = pluginManager.RunAll(input.message, user);
if(pluginOutput != null) if(pluginOutput != null && pluginOutput.size() > 0)
response.Call(pluginOutput); {
for(int i = 0; i < pluginOutput.size(); ++i)
response.Call(pluginOutput.get(i));
}
} }
// Run any upkeep in post we need to // Run any upkeep in post we need to