Skip to content

Commit f30f228

Browse files
committed
fix: refactored changes discussed in PR
1 parent 47e969c commit f30f228

File tree

13 files changed

+105
-34
lines changed

13 files changed

+105
-34
lines changed

src/Discord.Net/Discord.Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>7.1</LangVersion>
5+
<LangVersion>7.3</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
namespace Discord
22
{
3-
public interface IEmote : IMentionable // TODO: Is `Mention` the correct verbage here?
3+
/// <summary>
4+
/// An emote which may be used as a reaction or embedded in chat.
5+
///
6+
/// This includes Unicode emoji as well as unattached guild emotes.
7+
/// </summary>
8+
public interface IEmote : ITaggable
49
{
10+
/// <summary>
11+
/// The display-name of the emote.
12+
/// </summary>
13+
/// <remarks>
14+
/// For Unicode emoji, this is the raw value of the character, not its
15+
/// Unicode display name.
16+
/// </remarks>
517
string Name { get; }
618
}
719
}

src/Discord.Net/Entities/Emotes/IGuildEmote.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
namespace Discord
55
{
6+
/// <summary>
7+
/// An emote attached to a guild. This differs from an <see cref="IEmote"/> in that it contains
8+
/// information relevant to the source guild.
9+
/// </summary>
610
public interface IGuildEmote : IEmote, ISnowflakeEntity, IDeletable
711
{
812
/// <summary>
913
/// Gets whether this emoji is managed by an integration.
1014
/// </summary>
1115
/// <returns>
12-
/// A boolean that determines whether or not this emote is managed by a Twitch integration.
16+
/// A boolean that determines whether or not this emote is managed by an external integration, such as Twitch.
1317
/// </returns>
1418
bool IsManaged { get; }
1519
/// <summary>

src/Discord.Net/Entities/IMentionable.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Discord.Net/Entities/ITaggable.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Discord
2+
{
3+
public interface ITaggable
4+
{
5+
string Tag { get; }
6+
}
7+
}

src/Discord.Net/Entities/Roles/IRole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Discord
88
/// <summary>
99
/// Represents a generic role object to be given to a guild user.
1010
/// </summary>
11-
public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable<IRole>
11+
public interface IRole : ISnowflakeEntity, IDeletable, ITaggable, IComparable<IRole>
1212
{
1313
/// <summary>
1414
/// Gets the guild that owns this role.

src/Discord.Net/Models/Emotes/AttachedGuildEmote.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@ public AttachedGuildEmote(Model model, IGuild guild, IDiscordClient discord) : b
2222
Guild = guild;
2323
}
2424

25+
// IGuildEmote
2526
public bool IsManaged { get; set; }
2627
public bool RequireColons { get; set; }
2728
public IReadOnlyList<IRole> Roles { get; set; }
2829
public ulong? CreatorId { get; set; }
2930
public string Name { get; set; }
3031
public IGuild Guild { get; set; }
3132

32-
// IMentionable
33-
public string Mention => EmoteUtilities.FormatGuildEmote(Id, Name);
33+
// ITaggable
34+
public string Tag => EmoteUtilities.FormatGuildEmote(Id, Name);
3435

36+
// IDeleteable
3537
public Task DeleteAsync()
3638
=> Discord.Rest.DeleteGuildEmojiAsync(Guild.Id, Id);
3739

40+
// IGuildEmote
3841
public Task ModifyAsync() // TODO
3942
{
4043
throw new System.NotImplementedException();

src/Discord.Net/Models/Emotes/Emoji.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public Emoji(string name)
99
}
1010

1111
public string Name { get; set; }
12-
public string Mention => Name;
12+
public string Tag => Name;
1313
}
1414
}

src/Discord.Net/Models/Emotes/Emote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public Emote(ulong id, string name)
1313
public ulong Id { get; set; }
1414
public string Name { get; set; }
1515

16-
public string Mention => EmoteUtilities.FormatGuildEmote(Id, Name);
16+
public string Tag => EmoteUtilities.FormatGuildEmote(Id, Name);
1717
}
1818
}

src/Discord.Net/Models/Emotes/EmoteBuilder.cs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,56 @@
22

33
namespace Discord
44
{
5+
/// <summary>
6+
/// Methods to create an <see cref="IEmote"/>.
7+
/// </summary>
58
public static class EmoteBuilder
69
{
7-
public static IEmote FromEmoji(string emoji)
10+
/// <summary>
11+
/// Creates an emote from a raw unicode emoji.
12+
/// </summary>
13+
/// <param name="emoji">The unicode character this emoji should be created from.</param>
14+
public static IEmote FromUnicodeEmoji(string emoji)
815
=> new Emoji(emoji);
9-
public static IEmote FromMention(string mention)
10-
=> throw new NotImplementedException(); // TODO: emoteutil
16+
17+
/// <summary>
18+
/// Creates an emote from an escaped tag.
19+
/// </summary>
20+
/// <param name="mention">The escaped mention tag for an emote.</param>
21+
/// <exception cref="ArgumentException">Throws if the passed tag was of an invalid format.</exception>
22+
public static IEmote FromTag(string tag)
23+
{
24+
if (EmoteUtilities.TryParseGuildEmote(tag.AsSpan(), out var result))
25+
{
26+
var (id, name) = result;
27+
return new Emote(id, name);
28+
}
29+
throw new ArgumentException("Passed emote tag was of an invalid format", nameof(tag));
30+
}
31+
32+
/// <summary>
33+
/// Creates an emote from an escaped tag.
34+
/// </summary>
35+
/// <param name="tag">The escaped mention tag for an emote.</param>
36+
/// <returns>Returns true if the emote could be created; returns false if it was of an invalid format.</returns>
37+
public static bool TryFromTag(string tag, out IEmote result)
38+
{
39+
if (EmoteUtilities.TryParseGuildEmote(tag.AsSpan(), out var r))
40+
{
41+
var (id, name) = r;
42+
result = new Emote(id, name);
43+
return true;
44+
}
45+
46+
result = default;
47+
return false;
48+
}
49+
50+
/// <summary>
51+
/// Creates an emote from a raw snowflake and name.
52+
/// </summary>
53+
/// <param name="id">The snowflake ID of the guild emote.</param>
54+
/// <param name="name">The name of the guild emote.</param>
1155
public static IEmote FromID(ulong id, string name)
1256
=> new Emote(id, name);
1357
}

0 commit comments

Comments
 (0)