Skip to content

Commit bbab441

Browse files
Forgot to add a file to the last commit
1 parent 8bee88a commit bbab441

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/io/github/jdaapplications/guildbot/executor/CommandExecutor.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
*/
4444
public class CommandExecutor
4545
{
46-
private Map<String, Command> commands;
47-
4846
private final GuildBot guildBot;
47+
48+
private Map<String, Command> commands;
4949
private Map<String, Method> methods;
5050
private Map<String, Variables> vars;
5151

@@ -272,7 +272,7 @@ private synchronized void execute(final Command command, final MessageReceivedEv
272272
catch (final Exception e)
273273
{
274274
final String varName = entry.getKey();
275-
GuildBot.log.error("An error occurred while evaluating the vars \"{}\"\n{}\n{}", varName, variables.getExecutableScript(), e);
275+
GuildBot.log.error("An error occurred while evaluating the vars \"{}\"\n{}\n{}", varName, variables.getExecutableScript(), e instanceof ExecutionException ? e.getCause() : e);
276276
final String varContext = String.format("Trying to evaluate var: %#s", event.getJDA().getTextChannelById(varName));
277277
this.guildBot.handleThrowable(e, varContext);
278278
}
@@ -291,13 +291,15 @@ private synchronized void execute(final Command command, final MessageReceivedEv
291291
if (script != null)
292292
try
293293
{
294-
engineEntry.getValue().eval(method.getExecutableScript(engine));
294+
final Future<?> future = pool.submit(() -> engineEntry.getValue().eval(method.getExecutableScript(engine)));
295+
296+
future.get(command.getConfig().getInt("timeout", this.guildBot.getConfig().getInt("timeout", 5)), TimeUnit.SECONDS);
295297
}
296298
catch (final Exception e)
297299
{
298-
GuildBot.log.error("An error occurred while evaluating the method \"{}\"\n{}\n{}", methodName, method.getExecutableScript(engine), e);
300+
GuildBot.log.error("An error occurred while evaluating the method \"{}\"\n{}\n{}", methodName, method.getExecutableScript(engine), e instanceof ExecutionException ? e.getCause() : e);
299301
final String methodContext = String.format("Trying to evaluate method: %#s", event.getJDA().getTextChannelById(methodName));
300-
this.guildBot.handleThrowable(e, methodContext);
302+
this.guildBot.handleThrowable(e.getCause(), methodContext);
301303
}
302304
}
303305
}
@@ -312,7 +314,7 @@ private synchronized void execute(final Command command, final MessageReceivedEv
312314
}
313315
catch (final ExecutionException e)
314316
{
315-
result = e;
317+
result = e.getCause();
316318
}
317319
catch (TimeoutException | InterruptedException e)
318320
{

0 commit comments

Comments
 (0)