Added IMessage.Tags
This commit is contained in:
@@ -5,6 +5,9 @@ namespace Discord
|
||||
{
|
||||
public interface IChannel : ISnowflakeEntity
|
||||
{
|
||||
/// <summary> Gets the name of this channel. </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary> Gets a collection of all users in this channel. </summary>
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace Discord
|
||||
{
|
||||
public interface IGuildChannel : IChannel, IDeletable
|
||||
{
|
||||
/// <summary> Gets the name of this channel. </summary>
|
||||
string Name { get; }
|
||||
/// <summary> Gets the position of this channel in the guild's channel list, relative to others of the same type. </summary>
|
||||
int Position { get; }
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Model = Discord.API.EmbedProvider;
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.EmbedProvider;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public struct EmbedProvider
|
||||
{
|
||||
public string Name { get; }
|
||||
@@ -16,5 +18,8 @@ namespace Discord
|
||||
{
|
||||
return new EmbedProvider(model.Name, model.Url);
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Url})";
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Model = Discord.API.EmbedThumbnail;
|
||||
using System.Diagnostics;
|
||||
using Model = Discord.API.EmbedThumbnail;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public struct EmbedThumbnail
|
||||
{
|
||||
public string Url { get; }
|
||||
@@ -22,5 +24,8 @@ namespace Discord
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null);
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{ToString()} ({Url})";
|
||||
public override string ToString() => Width != null && Height != null ? $"{Width}x{Height}" : "0x0";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,54 @@
|
||||
using Discord.API;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public struct Emoji
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public string Name { get; }
|
||||
public int Index { get; }
|
||||
public int Length { get; }
|
||||
|
||||
public string Url => CDN.GetEmojiUrl(Id);
|
||||
|
||||
internal Emoji(ulong id, string name, int index, int length)
|
||||
internal Emoji(ulong id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Index = index;
|
||||
Length = length;
|
||||
}
|
||||
|
||||
public static Emoji Parse(string text)
|
||||
{
|
||||
Emoji result;
|
||||
if (TryParse(text, out result))
|
||||
return result;
|
||||
throw new ArgumentException("Invalid emoji format", nameof(text));
|
||||
}
|
||||
|
||||
public static bool TryParse(string text, out Emoji result)
|
||||
{
|
||||
result = default(Emoji);
|
||||
if (text.Length >= 4 && text[0] == '<' && text[1] == ':' && text[text.Length - 1] == '>')
|
||||
{
|
||||
int splitIndex = text.IndexOf(':', 2);
|
||||
if (splitIndex == -1)
|
||||
return false;
|
||||
|
||||
ulong id;
|
||||
if (!ulong.TryParse(text.Substring(splitIndex + 1, text.Length - splitIndex - 2), NumberStyles.None, CultureInfo.InvariantCulture, out id))
|
||||
return false;
|
||||
|
||||
string name = text.Substring(2, splitIndex - 2);
|
||||
result = new Emoji(id, name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace Discord
|
||||
IReadOnlyCollection<IAttachment> Attachments { get; }
|
||||
/// <summary> Returns a collection of all embeds included in this message. </summary>
|
||||
IReadOnlyCollection<IEmbed> Embeds { get; }
|
||||
/// <summary> Returns a collection of all custom emoji included in this message. </summary>
|
||||
IReadOnlyCollection<Emoji> Emojis { get; }
|
||||
/// <summary> Returns a collection of all tags included in this message's content. </summary>
|
||||
IReadOnlyCollection<ITag> Tags { get; }
|
||||
/// <summary> Returns a collection of channel ids mentioned in this message. </summary>
|
||||
IReadOnlyCollection<ulong> MentionedChannelIds { get; }
|
||||
/// <summary> Returns a collection of roles mentioned in this message. </summary>
|
||||
|
||||
11
src/Discord.Net.Core/Entities/Messages/ITag.cs
Normal file
11
src/Discord.Net.Core/Entities/Messages/ITag.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Discord
|
||||
{
|
||||
public interface ITag
|
||||
{
|
||||
int Index { get; }
|
||||
int Length { get; }
|
||||
TagType Type { get; }
|
||||
ulong Key { get; }
|
||||
object Value { get; }
|
||||
}
|
||||
}
|
||||
@@ -12,18 +12,13 @@ namespace Discord
|
||||
Task PinAsync(RequestOptions options = null);
|
||||
/// <summary> Removes this message from its channel's pinned messages. </summary>
|
||||
Task UnpinAsync(RequestOptions options = null);
|
||||
|
||||
/// <summary> Transforms this message's text into a human readable form, resolving mentions to that object's name. </summary>
|
||||
string Resolve(int startIndex, int length,
|
||||
UserMentionHandling userHandling = UserMentionHandling.Name,
|
||||
ChannelMentionHandling channelHandling = ChannelMentionHandling.Name,
|
||||
RoleMentionHandling roleHandling = RoleMentionHandling.Name,
|
||||
EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore);
|
||||
/// <summary> Transforms this message's text into a human readable form, resolving mentions to that object's name. </summary>
|
||||
|
||||
/// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary>
|
||||
string Resolve(
|
||||
UserMentionHandling userHandling = UserMentionHandling.Name,
|
||||
ChannelMentionHandling channelHandling = ChannelMentionHandling.Name,
|
||||
RoleMentionHandling roleHandling = RoleMentionHandling.Name,
|
||||
EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore);
|
||||
TagHandling userHandling = TagHandling.Name,
|
||||
TagHandling channelHandling = TagHandling.Name,
|
||||
TagHandling roleHandling = TagHandling.Name,
|
||||
TagHandling everyoneHandling = TagHandling.Ignore,
|
||||
TagHandling emojiHandling = TagHandling.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum EveryoneMentionHandling
|
||||
{
|
||||
Ignore = 0,
|
||||
Remove,
|
||||
Sanitize
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum RoleMentionHandling
|
||||
{
|
||||
Ignore = 0,
|
||||
Remove,
|
||||
Name,
|
||||
Sanitize
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum UserMentionHandling
|
||||
{
|
||||
Ignore = 0,
|
||||
Remove,
|
||||
Name,
|
||||
NameAndDiscriminator,
|
||||
Sanitize
|
||||
}
|
||||
}
|
||||
28
src/Discord.Net.Core/Entities/Messages/Tag.cs
Normal file
28
src/Discord.Net.Core/Entities/Messages/Tag.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class Tag<T> : ITag
|
||||
{
|
||||
public TagType Type { get; }
|
||||
public int Index { get; }
|
||||
public int Length { get; }
|
||||
public ulong Key { get; }
|
||||
public T Value { get; }
|
||||
|
||||
internal Tag(TagType type, int index, int length, ulong key, T value)
|
||||
{
|
||||
Type = type;
|
||||
Index = index;
|
||||
Length = length;
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay => $"{Value?.ToString() ?? "null"} ({Type})";
|
||||
public override string ToString() => $"{Value?.ToString() ?? "null"} ({Type})";
|
||||
|
||||
object ITag.Value => Value;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum ChannelMentionHandling
|
||||
public enum TagHandling
|
||||
{
|
||||
Ignore = 0,
|
||||
Remove,
|
||||
Name,
|
||||
FullName,
|
||||
Sanitize
|
||||
}
|
||||
}
|
||||
12
src/Discord.Net.Core/Entities/Messages/TagType.cs
Normal file
12
src/Discord.Net.Core/Entities/Messages/TagType.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum TagType
|
||||
{
|
||||
UserMention,
|
||||
ChannelMention,
|
||||
RoleMention,
|
||||
EveryoneMention,
|
||||
HereMention,
|
||||
Emoji
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user