mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-16 10:40:12 +00:00
fix(bot): try fixing unhandled exceptions from interactive prompts
This commit is contained in:
parent
d997f725e2
commit
c639d877f8
2 changed files with 17 additions and 5 deletions
|
|
@ -84,20 +84,32 @@ public class YesNoPrompt: BaseInteractive
|
||||||
|
|
||||||
var queue = _ctx.Services.Resolve<HandlerQueue<MessageCreateEvent>>();
|
var queue = _ctx.Services.Resolve<HandlerQueue<MessageCreateEvent>>();
|
||||||
|
|
||||||
var messageDispatch = queue.WaitFor(MessagePredicate, Timeout, cts.Token);
|
async Task WaitForMessage()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await queue.WaitFor(MessagePredicate, Timeout, cts.Token);
|
||||||
|
}
|
||||||
|
catch (TimeoutException e)
|
||||||
|
{
|
||||||
|
if (e.Message != "HandlerQueue#WaitFor timed out")
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await Start();
|
await Start();
|
||||||
|
|
||||||
cts.Token.Register(() => _tcs.TrySetException(new TimeoutException("Action timed out")));
|
var messageDispatch = WaitForMessage();
|
||||||
|
|
||||||
|
cts.Token.Register(() => _tcs.TrySetException(new TimeoutException("YesNoPrompt timed out")));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var doneTask = await Task.WhenAny(_tcs.Task, messageDispatch);
|
var doneTask = await Task.WhenAny(_tcs.Task, messageDispatch);
|
||||||
if (doneTask == messageDispatch)
|
|
||||||
await Finish();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
await Finish();
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class HandlerQueue<T>
|
||||||
{
|
{
|
||||||
var theTask = await Task.WhenAny(timeoutTask, tcs.Task);
|
var theTask = await Task.WhenAny(timeoutTask, tcs.Task);
|
||||||
if (theTask == timeoutTask)
|
if (theTask == timeoutTask)
|
||||||
throw new TimeoutException();
|
throw new TimeoutException("HandlerQueue#WaitFor timed out");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue