added prompt timeout
This commit is contained in:
parent
1536a96dcf
commit
05d8af4d0e
@ -23,6 +23,7 @@ namespace TomatenMusic.Prompt.Model
|
|||||||
public List<IPromptOption> Options { get; protected set; } = new List<IPromptOption>();
|
public List<IPromptOption> Options { get; protected set; } = new List<IPromptOption>();
|
||||||
public DiscordClient _client { get; set; }
|
public DiscordClient _client { get; set; }
|
||||||
public DiscordPromptBase LastPrompt { get; protected set; }
|
public DiscordPromptBase LastPrompt { get; protected set; }
|
||||||
|
public System.Timers.Timer TimeoutTimer { get; set; }
|
||||||
|
|
||||||
protected ILogger<DiscordPromptBase> _logger { get; set; }
|
protected ILogger<DiscordPromptBase> _logger { get; set; }
|
||||||
|
|
||||||
@ -132,6 +133,16 @@ namespace TomatenMusic.Prompt.Model
|
|||||||
Interaction = interaction;
|
Interaction = interaction;
|
||||||
Message = await interaction.CreateFollowupMessageAsync(builder);
|
Message = await interaction.CreateFollowupMessageAsync(builder);
|
||||||
State = PromptState.OPEN;
|
State = PromptState.OPEN;
|
||||||
|
|
||||||
|
long timeoutTime = (Interaction.CreationTimestamp.ToUnixTimeMilliseconds() + 900000) - DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
|
||||||
|
if (TimeoutTimer != null)
|
||||||
|
TimeoutTimer.Close();
|
||||||
|
|
||||||
|
TimeoutTimer = new System.Timers.Timer(timeoutTime);
|
||||||
|
TimeoutTimer.Elapsed += OnTimeout;
|
||||||
|
TimeoutTimer.AutoReset = false;
|
||||||
|
TimeoutTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UseAsync(DiscordMessage message)
|
public async Task UseAsync(DiscordMessage message)
|
||||||
@ -171,6 +182,22 @@ namespace TomatenMusic.Prompt.Model
|
|||||||
Message = message;
|
Message = message;
|
||||||
await EditMessageAsync(builder);
|
await EditMessageAsync(builder);
|
||||||
State = PromptState.OPEN;
|
State = PromptState.OPEN;
|
||||||
|
|
||||||
|
long timeoutTime = (Interaction.CreationTimestamp.ToUnixTimeMilliseconds() + 900000) - DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
|
||||||
|
if (TimeoutTimer != null)
|
||||||
|
TimeoutTimer.Close();
|
||||||
|
|
||||||
|
TimeoutTimer = new System.Timers.Timer(timeoutTime);
|
||||||
|
TimeoutTimer.Elapsed += OnTimeout;
|
||||||
|
TimeoutTimer.AutoReset = false;
|
||||||
|
TimeoutTimer.Start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimeout(object? sender, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
_ = InvalidateAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddGuids()
|
private void AddGuids()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user