Browse Source

Clean up old DNXCore50 code, flatten Discord.Helpers namespace

tags/docs-0.9
RogueException 9 years ago
parent
commit
8130c37040
21 changed files with 35 additions and 72 deletions
  1. +3
    -0
      src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj
  2. +5
    -4
      src/Discord.Net/API/RestClient.BuiltIn.cs
  3. +2
    -4
      src/Discord.Net/API/RestClient.SharpRest.cs
  4. +1
    -6
      src/Discord.Net/API/RestClient.cs
  5. +1
    -3
      src/Discord.Net/Collections/Messages.cs
  6. +1
    -2
      src/Discord.Net/DiscordClient.API.cs
  7. +1
    -1
      src/Discord.Net/DiscordClient.Cache.cs
  8. +1
    -1
      src/Discord.Net/DiscordClient.Events.cs
  9. +1
    -2
      src/Discord.Net/DiscordClient.cs
  10. +1
    -8
      src/Discord.Net/DiscordClientConfig.cs
  11. +2
    -6
      src/Discord.Net/DiscordSimpleClient.Voice.cs
  12. +2
    -3
      src/Discord.Net/DiscordSimpleClient.cs
  13. +3
    -7
      src/Discord.Net/DiscordSimpleClientConfig.cs
  14. +1
    -1
      src/Discord.Net/Helpers/EpochTime.cs
  15. +1
    -1
      src/Discord.Net/Helpers/Extensions.cs
  16. +1
    -1
      src/Discord.Net/Helpers/MessageCleaner.cs
  17. +0
    -1
      src/Discord.Net/WebSockets/Data/Commands.cs
  18. +2
    -7
      src/Discord.Net/WebSockets/Voice/VoiceWebSocket.cs
  19. +3
    -4
      src/Discord.Net/WebSockets/WebSocket.BuiltIn.cs
  20. +2
    -5
      src/Discord.Net/WebSockets/WebSocket.WebSocketSharp.cs
  21. +1
    -5
      src/Discord.Net/WebSockets/WebSocket.cs

+ 3
- 0
src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj View File

@@ -52,6 +52,9 @@
<Compile Include="..\Discord.Net.Commands\CommandsPlugin.Events.cs">
<Link>CommandsPlugin.Events.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Shared\TaskHelper.cs">
<Link>Shared\TaskHelper.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />


+ 5
- 4
src/Discord.Net/API/RestClient.BuiltIn.cs View File

@@ -1,4 +1,5 @@
#if DNXCORE50
/*
using Discord.API;
using System;
using System.Globalization;
using System.IO;
@@ -8,7 +9,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net.API
namespace Discord.API
{
internal class BuiltInRestEngine : IRestEngine
{
@@ -22,7 +23,7 @@ namespace Discord.Net.API
UseCookies = false,
PreAuthenticate = false //We do auth ourselves
});
_client.DefaultRequestHeaders.Add("accept", "*/*");
_client.DefaultRequestHeaders.Add("accept", "*\/*");
_client.DefaultRequestHeaders.Add("accept-encoding", "gzip,deflate");
_client.DefaultRequestHeaders.Add("user-agent", userAgent);
_client.Timeout = TimeSpan.FromMilliseconds(timeout);
@@ -63,4 +64,4 @@ namespace Discord.Net.API
}
}
}
#endif
*/

+ 2
- 4
src/Discord.Net/API/RestClient.SharpRest.cs View File

@@ -1,5 +1,4 @@
#if !DNXCORE50
using RestSharp;
using RestSharp;
using System;
using System.IO;
using System.Net.Http;
@@ -79,5 +78,4 @@ namespace Discord.API
}
}
}
}
#endif
}

+ 1
- 6
src/Discord.Net/API/RestClient.cs View File

@@ -2,7 +2,6 @@
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

@@ -24,12 +23,8 @@ namespace Discord.API
public RestClient(LogMessageSeverity logLevel, string userAgent, int timeout)
{
_logLevel = logLevel;

#if DNXCORE50
_engine = new BuiltInRestEngine(userAgent, timeout);
#else
_engine = new RestSharpRestEngine(userAgent, timeout);
#endif
}

private static readonly HttpMethod _delete = HttpMethod.Delete;


+ 1
- 3
src/Discord.Net/Collections/Messages.cs View File

@@ -1,6 +1,4 @@
using Discord.Helpers;

namespace Discord.Collections
namespace Discord.Collections
{
public sealed class Messages : AsyncCollection<Message>
{


+ 1
- 2
src/Discord.Net/DiscordClient.API.cs View File

@@ -1,5 +1,4 @@
using Discord.API;
using Discord.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -797,4 +796,4 @@ namespace Discord
return _servers.TryRemove(serverId);
}
}
}
}

+ 1
- 1
src/Discord.Net/DiscordClient.Cache.cs View File

@@ -56,4 +56,4 @@ namespace Discord
public IEnumerable<User> FindUsers(string name) => _users.Find(name);

}
}
}

+ 1
- 1
src/Discord.Net/DiscordClient.Events.cs View File

@@ -275,4 +275,4 @@ namespace Discord
RaiseEvent(nameof(UserIsSpeaking), () => UserIsSpeaking(this, new UserIsSpeakingEventArgs(member, isSpeaking)));
}
}
}
}

+ 1
- 2
src/Discord.Net/DiscordClient.cs View File

@@ -1,6 +1,5 @@
using Discord.API;
using Discord.Collections;
using Discord.Helpers;
using Discord.WebSockets;
using Discord.WebSockets.Data;
using Newtonsoft.Json;
@@ -820,4 +819,4 @@ namespace Discord
_sentInitialLog = true;
}
}
}
}

+ 1
- 8
src/Discord.Net/DiscordClientConfig.cs View File

@@ -1,7 +1,4 @@
using System;
using System.Reflection;

namespace Discord
namespace Discord
{
public class DiscordClientConfig : DiscordSimpleClientConfig
{
@@ -10,13 +7,9 @@ namespace Discord
private int _messageQueueInterval = 100;

//Experimental Features
#if !DNXCORE50
/// <summary> (Experimental) Enables the client to be simultaneously connected to multiple channels at once (Discord still limits you to one channel per server). </summary>
public bool EnableVoiceMultiserver { get { return _enableVoiceMultiserver; } set { SetValue(ref _enableVoiceMultiserver, value); } }
private bool _enableVoiceMultiserver = false;
#else
internal bool EnableVoiceMultiserver => false;
#endif
/// <summary> (Experimental) Enables or disables the internal message queue. This will allow SendMessage to return immediately and handle messages internally. Messages will set the IsQueued and HasFailed properties to show their progress. </summary>
public bool UseMessageQueue { get { return _useMessageQueue; } set { SetValue(ref _useMessageQueue, value); } }
private bool _useMessageQueue = false;


+ 2
- 6
src/Discord.Net/DiscordSimpleClient.Voice.cs View File

@@ -1,8 +1,4 @@
using Discord.Helpers;
using Discord.WebSockets;
using Discord.WebSockets.Voice;
using System;
using System.Threading;
using System;
using System.Threading.Tasks;

namespace Discord
@@ -86,4 +82,4 @@ namespace Discord
await TaskHelper.CompletedTask.ConfigureAwait(false);
}
}
}
}

+ 2
- 3
src/Discord.Net/DiscordSimpleClient.cs View File

@@ -1,5 +1,4 @@
using Discord.Helpers;
using Discord.WebSockets.Data;
using Discord.WebSockets.Data;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -331,4 +330,4 @@ namespace Discord
return TaskHelper.CompletedTask;
}
}
}
}

+ 3
- 7
src/Discord.Net/DiscordSimpleClientConfig.cs View File

@@ -39,23 +39,19 @@ namespace Discord
private int _voiceBufferLength = 1000;

//Experimental Features
#if !DNXCORE50
/// <summary> (Experimental) Enables the voice websocket and UDP client and specifies how it will be used. Any option other than Disabled requires the opus .dll or .so be in the local lib/ folder. </summary>
public DiscordVoiceMode VoiceMode { get { return _voiceMode; } set { SetValue(ref _voiceMode, value); } }
private DiscordVoiceMode _voiceMode = DiscordVoiceMode.Disabled;
/// <summary> (Experimental) Enables the voice websocket and UDP client. This option requires the libsodium .dll or .so be in the local lib/ folder. </summary>
public bool EnableVoiceEncryption { get { return _enableVoiceEncryption; } set { SetValue(ref _enableVoiceEncryption, value); } }
private bool _enableVoiceEncryption = true;
#else
internal DiscordVoiceMode VoiceMode => DiscordVoiceMode.Disabled;
internal bool EnableVoiceEncryption => false;
#endif

//Internals
internal bool VoiceOnly { get { return _voiceOnly; } set { SetValue(ref _voiceOnly, value); } }
private bool _voiceOnly;
internal uint VoiceClientId { get { return _voiceClientId; } set { SetValue(ref _voiceClientId, value); } }
private uint _voiceClientId;

internal virtual bool EnableVoice => _voiceMode != DiscordVoiceMode.Disabled;

internal string UserAgent
@@ -82,6 +78,6 @@ namespace Discord
var config = this.MemberwiseClone() as DiscordClientConfig;
config._isLocked = false;
return config;
}
}
}
}
}

+ 1
- 1
src/Discord.Net/Helpers/EpochTime.cs View File

@@ -1,6 +1,6 @@
using System;

namespace Discord.Helpers
namespace Discord
{
internal class EpochTime
{


+ 1
- 1
src/Discord.Net/Helpers/Extensions.cs View File

@@ -2,7 +2,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Helpers
namespace Discord
{
internal static class Extensions
{


+ 1
- 1
src/Discord.Net/Helpers/MessageCleaner.cs View File

@@ -1,6 +1,6 @@
using System.Text.RegularExpressions;

namespace Discord.Helpers
namespace Discord
{
//TODO: Better name please?
internal class MessageCleaner


+ 0
- 1
src/Discord.Net/WebSockets/Data/Commands.cs View File

@@ -2,7 +2,6 @@
#pragma warning disable CS0649
#pragma warning disable CS0169

using Discord.Helpers;
using Newtonsoft.Json;
using System.Collections.Generic;



+ 2
- 7
src/Discord.Net/WebSockets/Voice/VoiceWebSocket.cs View File

@@ -1,6 +1,5 @@
#define USE_THREAD
using Discord.Audio;
using Discord.Helpers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
@@ -143,10 +142,8 @@ namespace Discord.WebSockets.Voice
#else
tasks.Add(ReceiveVoiceAsync());
#endif

#if !DNXCORE50
tasks.Add(WatcherAsync());
#endif
if (tasks.Count > 0)
{
// We need to combine tasks into one because receiveThread is
@@ -444,7 +441,6 @@ namespace Discord.WebSockets.Voice
}).ConfigureAwait(false);
#endif
}
#if !DNXCORE50
//Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken
private Task WatcherAsync()
{
@@ -452,7 +448,6 @@ namespace Discord.WebSockets.Voice
return cancelToken.Wait()
.ContinueWith(_ => _udp.Close());
}
#endif

protected override async Task ProcessMessage(string json)
{
@@ -559,4 +554,4 @@ namespace Discord.WebSockets.Voice
});
}
}
}
}

+ 3
- 4
src/Discord.Net/WebSockets/WebSocket.BuiltIn.cs View File

@@ -1,4 +1,4 @@
#if DNXCORE50
/*
using Discord.Helpers;
using System;
using System.Collections.Concurrent;
@@ -38,8 +38,7 @@ namespace Discord.WebSockets
public Task Connect(string host, CancellationToken cancelToken)
{
_webSocket = new ClientWebSocket();
_webSocket.Options.KeepAliveInterval = TimeSpan.Zero;
return _webSocket.ConnectAsync(new Uri(host), cancelToken);
return _webSocket.ConnectAsync(new Uri(host), cancelToken);
}

public Task Disconnect()
@@ -151,4 +150,4 @@ namespace Discord.WebSockets
}
}
}
#endif
*/

+ 2
- 5
src/Discord.Net/WebSockets/WebSocket.WebSocketSharp.cs View File

@@ -1,6 +1,4 @@
#if !DNXCORE50
using Discord.Helpers;
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
@@ -100,5 +98,4 @@ namespace Discord.WebSockets
_sendQueue.Enqueue(message);
}
}
}
#endif
}

+ 1
- 5
src/Discord.Net/WebSockets/WebSocket.cs View File

@@ -64,12 +64,8 @@ namespace Discord.WebSockets
_loginTimeout = client.Config.ConnectionTimeout;
_cancelToken = new CancellationToken(true);
_connectedEvent = new ManualResetEventSlim(false);

#if DNXCORE50
_engine = new BuiltInWebSocketEngine(client.Config.WebSocketInterval);
#else
_engine = new WSSharpWebSocketEngine(this, client.Config.UserAgent, client.Config.WebSocketInterval);
#endif
_engine.ProcessMessage += async (s, e) =>
{
if (_logLevel >= LogMessageSeverity.Debug)


Loading…
Cancel
Save