Update Dependencies and support NS2.0 builds (#1046)
* Update deps, fix test warnings. * Support ns2.0 * Fix typo * Remove ns1.1 support * Net.Http and Net.Websockets.Client are not needed in ns2.0 * Move to net46 per volt * Remove ns1.3 constants
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="../../Discord.Net.targets" />
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Discord.Net.Core</AssemblyName>
|
||||
<RootNamespace>Discord</RootNamespace>
|
||||
<Description>The core components for the Discord.Net library.</Description>
|
||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net45;netstandard1.1;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.1;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
|
||||
<PackageReference Include="System.Interactive.Async" Version="3.1.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -9,10 +9,9 @@ namespace Discord
|
||||
{
|
||||
/// <summary> Sends a message to this message channel. </summary>
|
||||
Task<IUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);
|
||||
#if FILESYSTEM
|
||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
|
||||
Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);
|
||||
#endif
|
||||
|
||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
|
||||
Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
@@ -15,7 +15,7 @@ namespace Discord
|
||||
{
|
||||
Stream = stream;
|
||||
}
|
||||
#if FILESYSTEM
|
||||
|
||||
/// <summary>
|
||||
/// Create the image from a file path.
|
||||
/// </summary>
|
||||
@@ -27,6 +27,6 @@ namespace Discord
|
||||
{
|
||||
Stream = File.OpenRead(path);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ namespace Discord
|
||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
#if FILESYSTEM
|
||||
/// <summary>
|
||||
/// Sends a file to the user via DM.
|
||||
/// </summary>
|
||||
@@ -45,7 +44,6 @@ namespace Discord
|
||||
{
|
||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
|
||||
=> user.Guild.AddBanAsync(user, pruneDays, reason, options);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Logging
|
||||
@@ -35,7 +35,7 @@ namespace Discord.Logging
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#if FORMATSTR
|
||||
|
||||
public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null)
|
||||
{
|
||||
try
|
||||
@@ -45,52 +45,49 @@ namespace Discord.Logging
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public Task ErrorAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Error, source, ex);
|
||||
public Task ErrorAsync(string source, string message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Error, source, message, ex);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task ErrorAsync(string source, FormattableString message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Error, source, message, ex);
|
||||
#endif
|
||||
|
||||
|
||||
public Task WarningAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Warning, source, ex);
|
||||
public Task WarningAsync(string source, string message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Warning, source, message, ex);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task WarningAsync(string source, FormattableString message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Warning, source, message, ex);
|
||||
#endif
|
||||
|
||||
|
||||
public Task InfoAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Info, source, ex);
|
||||
public Task InfoAsync(string source, string message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Info, source, message, ex);
|
||||
#if FORMATSTR
|
||||
public Task InfoAsync(string source, FormattableString message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Info, source, message, ex);
|
||||
#endif
|
||||
|
||||
|
||||
public Task VerboseAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Verbose, source, ex);
|
||||
public Task VerboseAsync(string source, string message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Verbose, source, message, ex);
|
||||
#if FORMATSTR
|
||||
public Task VerboseAsync(string source, FormattableString message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Verbose, source, message, ex);
|
||||
#endif
|
||||
|
||||
|
||||
public Task DebugAsync(string source, Exception ex)
|
||||
=> LogAsync(LogSeverity.Debug, source, ex);
|
||||
public Task DebugAsync(string source, string message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Debug, source, message, ex);
|
||||
#if FORMATSTR
|
||||
public Task DebugAsync(string source, FormattableString message, Exception ex = null)
|
||||
=> LogAsync(LogSeverity.Debug, source, message, ex);
|
||||
#endif
|
||||
|
||||
|
||||
public Logger CreateLogger(string name) => new Logger(this, name);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Logging
|
||||
@@ -20,54 +20,53 @@ namespace Discord.Logging
|
||||
=> _manager.LogAsync(severity, Name, exception);
|
||||
public Task LogAsync(LogSeverity severity, string message, Exception exception = null)
|
||||
=> _manager.LogAsync(severity, Name, message, exception);
|
||||
#if FORMATSTR
|
||||
public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null)
|
||||
=> _manager.LogAsync(severity, Name, message, exception);
|
||||
#endif
|
||||
|
||||
|
||||
public Task ErrorAsync(Exception exception)
|
||||
=> _manager.ErrorAsync(Name, exception);
|
||||
public Task ErrorAsync(string message, Exception exception = null)
|
||||
=> _manager.ErrorAsync(Name, message, exception);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task ErrorAsync(FormattableString message, Exception exception = null)
|
||||
=> _manager.ErrorAsync(Name, message, exception);
|
||||
#endif
|
||||
|
||||
|
||||
public Task WarningAsync(Exception exception)
|
||||
=> _manager.WarningAsync(Name, exception);
|
||||
public Task WarningAsync(string message, Exception exception = null)
|
||||
=> _manager.WarningAsync(Name, message, exception);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task WarningAsync(FormattableString message, Exception exception = null)
|
||||
=> _manager.WarningAsync(Name, message, exception);
|
||||
#endif
|
||||
|
||||
|
||||
public Task InfoAsync(Exception exception)
|
||||
=> _manager.InfoAsync(Name, exception);
|
||||
public Task InfoAsync(string message, Exception exception = null)
|
||||
=> _manager.InfoAsync(Name, message, exception);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task InfoAsync(FormattableString message, Exception exception = null)
|
||||
=> _manager.InfoAsync(Name, message, exception);
|
||||
#endif
|
||||
|
||||
|
||||
public Task VerboseAsync(Exception exception)
|
||||
=> _manager.VerboseAsync(Name, exception);
|
||||
public Task VerboseAsync(string message, Exception exception = null)
|
||||
=> _manager.VerboseAsync(Name, message, exception);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task VerboseAsync(FormattableString message, Exception exception = null)
|
||||
=> _manager.VerboseAsync(Name, message, exception);
|
||||
#endif
|
||||
|
||||
|
||||
public Task DebugAsync(Exception exception)
|
||||
=> _manager.DebugAsync(Name, exception);
|
||||
public Task DebugAsync(string message, Exception exception = null)
|
||||
=> _manager.DebugAsync(Name, message, exception);
|
||||
#if FORMATSTR
|
||||
|
||||
public Task DebugAsync(FormattableString message, Exception exception = null)
|
||||
=> _manager.DebugAsync(Name, message, exception);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,14 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
//Source: https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/DateTimeOffset.cs
|
||||
internal static class DateTimeUtils
|
||||
{
|
||||
#if !UNIXTIME
|
||||
private const long UnixEpochTicks = 621_355_968_000_000_000;
|
||||
private const long UnixEpochSeconds = 62_135_596_800;
|
||||
private const long UnixEpochMilliseconds = 62_135_596_800_000;
|
||||
#endif
|
||||
|
||||
public static DateTimeOffset FromTicks(long ticks)
|
||||
=> new DateTimeOffset(ticks, TimeSpan.Zero);
|
||||
public static DateTimeOffset? FromTicks(long? ticks)
|
||||
=> ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null;
|
||||
|
||||
public static DateTimeOffset FromUnixSeconds(long seconds)
|
||||
{
|
||||
#if UNIXTIME
|
||||
return DateTimeOffset.FromUnixTimeSeconds(seconds);
|
||||
#else
|
||||
long ticks = seconds * TimeSpan.TicksPerSecond + UnixEpochTicks;
|
||||
return new DateTimeOffset(ticks, TimeSpan.Zero);
|
||||
#endif
|
||||
}
|
||||
public static DateTimeOffset FromUnixMilliseconds(long milliseconds)
|
||||
{
|
||||
#if UNIXTIME
|
||||
return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds);
|
||||
#else
|
||||
long ticks = milliseconds * TimeSpan.TicksPerMillisecond + UnixEpochTicks;
|
||||
return new DateTimeOffset(ticks, TimeSpan.Zero);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static long ToUnixSeconds(DateTimeOffset dto)
|
||||
{
|
||||
#if UNIXTIME
|
||||
return dto.ToUnixTimeSeconds();
|
||||
#else
|
||||
long seconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerSecond;
|
||||
return seconds - UnixEpochSeconds;
|
||||
#endif
|
||||
}
|
||||
public static long ToUnixMilliseconds(DateTimeOffset dto)
|
||||
{
|
||||
#if UNIXTIME
|
||||
return dto.ToUnixTimeMilliseconds();
|
||||
#else
|
||||
long milliseconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerMillisecond;
|
||||
return milliseconds - UnixEpochMilliseconds;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace Discord
|
||||
public static class SnowflakeUtils
|
||||
{
|
||||
public static DateTimeOffset FromSnowflake(ulong value)
|
||||
=> DateTimeUtils.FromUnixMilliseconds((long)((value >> 22) + 1420070400000UL));
|
||||
=> DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL));
|
||||
public static ulong ToSnowflake(DateTimeOffset value)
|
||||
=> ((ulong)DateTimeUtils.ToUnixMilliseconds(value) - 1420070400000UL) << 22;
|
||||
=> ((ulong)value.ToUnixTimeMilliseconds() - 1420070400000UL) << 22;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user