From 472412e232b219966a045d03863aeba1ffd6d133 Mon Sep 17 00:00:00 2001 From: RogueException Date: Thu, 6 Oct 2016 04:24:24 -0300 Subject: [PATCH] Readded IMessageChannel.TriggerTypingAsync --- src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs | 4 +++- .../Extensions/SnowflakeEntityExtensions.cs | 2 +- src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs | 7 ++++++- src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs | 2 ++ .../Entities/Channels/RestGroupChannel.cs | 2 ++ src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs | 2 ++ src/Discord.Net.Rest/Utils/TypingNotifier.cs | 8 ++++---- .../Entities/Channels/SocketChannelHelper.cs | 4 ++-- .../Entities/Channels/SocketDMChannel.cs | 2 ++ .../Entities/Channels/SocketGroupChannel.cs | 2 ++ .../Entities/Channels/SocketTextChannel.cs | 2 ++ 11 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs index 77ed811eb..7c13e4a6f 100644 --- a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs @@ -30,7 +30,9 @@ namespace Discord /// Bulk deletes multiple messages. Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null); - /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. + /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. + Task TriggerTypingAsync(RequestOptions options = null); + /// Continuously broadcasts the "user is typing" message to all users in this channel until the returned object is disposed. IDisposable EnterTypingState(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Extensions/SnowflakeEntityExtensions.cs b/src/Discord.Net.Core/Extensions/SnowflakeEntityExtensions.cs index adbf31a7e..271ad9e00 100644 --- a/src/Discord.Net.Core/Extensions/SnowflakeEntityExtensions.cs +++ b/src/Discord.Net.Core/Extensions/SnowflakeEntityExtensions.cs @@ -4,7 +4,7 @@ namespace Discord.Extensions { public static class SnowflakeEntityExtensions { - //TODO: C#7 Candidate for Extension Property. + //TODO: C#7 Candidate for extension property. public static DateTimeOffset GetCreatedAt(this ISnowflakeEntity entity) => DateTimeUtils.FromSnowflake(entity.Id); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 319520386..a6c172918 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -204,7 +204,12 @@ namespace Discord.Rest } //Typing - public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client, + public static async Task TriggerTypingAsync(IMessageChannel channel, BaseDiscordClient client, + RequestOptions options = null) + { + await client.ApiClient.TriggerTypingIndicatorAsync(channel.Id, options); + } + public static IDisposable EnterTypingState(IMessageChannel channel, BaseDiscordClient client, RequestOptions options) => new TypingNotifier(client, channel, options); } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs index 3adbd3fa4..9732c65e8 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs @@ -73,6 +73,8 @@ namespace Discord.Rest public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs index 4a1ea7b87..5e9c0dcbf 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs @@ -86,6 +86,8 @@ namespace Discord.Rest public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index b90fff58f..e8c82fcb5 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -63,6 +63,8 @@ namespace Discord.Rest public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options); diff --git a/src/Discord.Net.Rest/Utils/TypingNotifier.cs b/src/Discord.Net.Rest/Utils/TypingNotifier.cs index 62d19b5a1..433553e00 100644 --- a/src/Discord.Net.Rest/Utils/TypingNotifier.cs +++ b/src/Discord.Net.Rest/Utils/TypingNotifier.cs @@ -8,14 +8,14 @@ namespace Discord.Rest { private readonly BaseDiscordClient _client; private readonly CancellationTokenSource _cancelToken; - private readonly ulong _channelId; + private readonly IMessageChannel _channel; private readonly RequestOptions _options; - public TypingNotifier(BaseDiscordClient discord, IChannel channel, RequestOptions options) + public TypingNotifier(BaseDiscordClient discord, IMessageChannel channel, RequestOptions options) { _client = discord; _cancelToken = new CancellationTokenSource(); - _channelId = channel.Id; + _channel = channel; _options = options; var _ = Run(); } @@ -29,7 +29,7 @@ namespace Discord.Rest { try { - await _client.ApiClient.TriggerTypingIndicatorAsync(_channelId); + await _channel.TriggerTypingAsync(_options); } catch { } await Task.Delay(9750, token); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs index 887499c59..06cdf6d09 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs @@ -43,7 +43,7 @@ namespace Discord.WebSocket public static void AddMessage(ISocketMessageChannel channel, DiscordSocketClient discord, SocketMessage msg) { - //C#7 Candidate for pattern matching + //TODO: C#7 Candidate for pattern matching if (channel is SocketDMChannel) (channel as SocketDMChannel).AddMessage(msg); else if (channel is SocketGroupChannel) @@ -56,7 +56,7 @@ namespace Discord.WebSocket public static SocketMessage RemoveMessage(ISocketMessageChannel channel, DiscordSocketClient discord, ulong id) { - //C#7 Candidate for pattern matching + //TODO: C#7 Candidate for pattern matching if (channel is SocketDMChannel) return (channel as SocketDMChannel).RemoveMessage(id); else if (channel is SocketGroupChannel) diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index 375dce605..00849537c 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -76,6 +76,8 @@ namespace Discord.WebSocket public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index 732296ff0..cc75139a1 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -99,6 +99,8 @@ namespace Discord.WebSocket public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 079ddfd10..4f84e6ee4 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -82,6 +82,8 @@ namespace Discord.WebSocket public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + public Task TriggerTypingAsync(RequestOptions options = null) + => ChannelHelper.TriggerTypingAsync(this, Discord, options); public IDisposable EnterTypingState(RequestOptions options = null) => ChannelHelper.EnterTypingState(this, Discord, options);