Implemented missing method and typing notifier
This commit is contained in:
@@ -207,8 +207,6 @@ namespace Discord.Rest
|
||||
|
||||
//Typing
|
||||
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client)
|
||||
{
|
||||
throw new NotImplementedException(); //TODO: Impl
|
||||
}
|
||||
=> new TypingNotifier(client, channel);
|
||||
}
|
||||
}
|
||||
|
||||
44
src/Discord.Net.Rest/Utils/TypingNotifier.cs
Normal file
44
src/Discord.Net.Rest/Utils/TypingNotifier.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
internal class TypingNotifier : IDisposable
|
||||
{
|
||||
private readonly BaseDiscordClient _client;
|
||||
private readonly CancellationTokenSource _cancelToken;
|
||||
private readonly ulong _channelId;
|
||||
|
||||
public TypingNotifier(BaseDiscordClient discord, IChannel channel)
|
||||
{
|
||||
_client = discord;
|
||||
_cancelToken = new CancellationTokenSource();
|
||||
_channelId = channel.Id;
|
||||
var _ = Run();
|
||||
}
|
||||
|
||||
private async Task Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
var token = _cancelToken.Token;
|
||||
while (!_cancelToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _client.ApiClient.TriggerTypingIndicatorAsync(_channelId);
|
||||
}
|
||||
catch { }
|
||||
await Task.Delay(4500, token);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cancelToken.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user