Implemented missing method and typing notifier

This commit is contained in:
RogueException
2016-10-06 01:04:04 -03:00
parent 2f3831dd6e
commit dcd94381fc
3 changed files with 47 additions and 7 deletions

View File

@@ -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);
}
}

View 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();
}
}
}

View File

@@ -24,9 +24,9 @@ namespace Discord.WebSocket
public override string Username { get { return GlobalUser.Username; } internal set { GlobalUser.Username = value; } }
public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this));
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
public SocketVoiceState? VoiceState => Guild.GetVoiceState(Id);
public bool IsSelfDeafened => VoiceState?.IsSelfDeafened ?? false;
@@ -88,9 +88,7 @@ namespace Discord.WebSocket
=> UserHelper.KickAsync(this, Discord);
public ChannelPermissions GetPermissions(IGuildChannel channel)
{
throw new NotImplementedException(); //TODO: Impl
}
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));
internal new SocketGuildUser Clone() => MemberwiseClone() as SocketGuildUser;