Browse Source

Add timestamp tag #40

pull/1923/head
quin lynch 4 years ago
parent
commit
811f27d454
6 changed files with 118 additions and 13 deletions
  1. +1
    -1
      src/Discord.Net.Core/Discord.Net.Core.csproj
  2. +56
    -0
      src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
  3. +49
    -0
      src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs
  4. +1
    -1
      src/Discord.Net.Rest/Discord.Net.Rest.csproj
  5. +1
    -1
      src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj
  6. +10
    -10
      src/Discord.Net/Discord.Net.nuspec

+ 1
- 1
src/Discord.Net.Core/Discord.Net.Core.csproj View File

@@ -8,7 +8,7 @@
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks>
<PackageId>Discord.Net.Labs.Core</PackageId>
<Version>2.4.2</Version>
<Version>2.4.3</Version>
<Product>Discord.Net.Labs.Core</Product>
<RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl>
<PackageIcon>Temporary.png</PackageIcon>


+ 56
- 0
src/Discord.Net.Core/Entities/Messages/TimestampTag.cs View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord.Entities.Messages
{
/// <summary>
/// Represents a class used to make timestamps in messages. see <see href="https://discord.com/developers/docs/reference#message-formatting-timestamp-styles"/>.
/// </summary>
public class TimestampTag
{
/// <summary>
/// Gets or sets the style of the timestamp tag.
/// </summary>
public TimestampTagStyles Style { get; set; } = TimestampTagStyles.ShortDateTime;

/// <summary>
/// Gets or sets the time for this timestamp tag.
/// </summary>
public DateTime Time { get; set; }

/// <summary>
/// Converts the current timestamp tag to the string representation supported by discord.
/// <para>
/// If the <see cref="TimestampTag.Time"/> is null then the default 0 will be used.
/// </para>
/// </summary>
/// <returns>A string thats compatable in a discord message, ex: <code>&lt;t:1625944201:f&gt;</code></returns>
public override string ToString()
{
if (Time == null)
return $"<t:0:{(char)Style}>";

var offset = (DateTimeOffset)this.Time;

return $"<t:{offset.ToUnixTimeSeconds()}:{(char)Style}>";
}

/// <summary>
/// Creates a new timestamp tag with the specified datetime object.
/// </summary>
/// <param name="time">The time of this timestamp tag.</param>
/// <param name="style">The style for this timestamp tag.</param>
/// <returns>The newly create timestamp tag.</returns>
public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
{
return new TimestampTag()
{
Style = style,
Time = time
};
}
}
}

+ 49
- 0
src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord.Entities.Messages
{
/// <summary>
/// Represents a set of styles to use with a <see cref="TimestampTag"/>
/// </summary>
public enum TimestampTagStyles
{
/// <summary>
/// A short time string: 16:20
/// </summary>
ShortTime = 116,

/// <summary>
/// A long time string: 16:20:30
/// </summary>
LongTime = 84,

/// <summary>
/// A short date string: 20/04/2021
/// </summary>
ShortDate = 100,

/// <summary>
/// A long date string: 20 April 2021
/// </summary>
LongDate = 68,

/// <summary>
/// A short datetime string: 20 April 2021 16:20
/// </summary>
ShortDateTime = 102,

/// <summary>
/// A long datetime string: Tuesday, 20 April 2021 16:20
/// </summary>
LongDateTime = 70,

/// <summary>
/// The relative time to the user: 2 months ago
/// </summary>
Relative = 82
}
}

+ 1
- 1
src/Discord.Net.Rest/Discord.Net.Rest.csproj View File

@@ -9,7 +9,7 @@
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks>
<PackageIcon>Temporary.png</PackageIcon>
<PackageProjectUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</PackageProjectUrl>
<Version>2.4.3</Version>
<Version>2.4.4</Version>
<PackageId>Discord.Net.Labs.Rest</PackageId>
<RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl>
<AssemblyVersion>2.3.4</AssemblyVersion>


+ 1
- 1
src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj View File

@@ -8,7 +8,7 @@
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net461;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>2.4.4</Version>
<Version>2.4.5</Version>
<RepositoryUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</RepositoryUrl>
<PackageProjectUrl>https://github.com/Discord-Net-Labs/Discord.Net-Labs</PackageProjectUrl>
<PackageIcon>Temporary.png</PackageIcon>


+ 10
- 10
src/Discord.Net/Discord.Net.nuspec View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Discord.Net.Labs</id>
<version>2.4.4$suffix$</version>
<version>2.4.5$suffix$</version>
<title>Discord.Net Labs</title>
<authors>Discord.Net Contributors</authors>
<owners>quinchs</owners>
@@ -14,23 +14,23 @@
<iconUrl>https://avatars.githubusercontent.com/u/84047264</iconUrl>
<dependencies>
<group targetFramework="net461">
<dependency id="Discord.Net.Labs.Core" version="2.4.2$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="Discord.Net.Labs.Core" version="2.4.2$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" />
</group>
<group targetFramework="netstandard2.1">
<dependency id="Discord.Net.Labs.Core" version="2.4.2$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.Core" version="2.4.3$suffix$" />
<dependency id="Discord.Net.Labs.Rest" version="2.4.4$suffix$" />
<dependency id="Discord.Net.Labs.WebSocket" version="2.4.5$suffix$" />
<dependency id="Discord.Net.Labs.Commands" version="2.3.5$suffix$" />
<dependency id="Discord.Net.Labs.Webhook" version="2.3.4$suffix$" />
</group>


Loading…
Cancel
Save