Skip to content

Commit a138f5d

Browse files
committed
feature: add emote entity/model
1 parent ac9025a commit a138f5d

File tree

7 files changed

+129
-9
lines changed

7 files changed

+129
-9
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
51
namespace Discord
62
{
7-
public interface IEmote
3+
public interface IEmote : IMentionable // TODO: Is `Mention` the correct verbage here?
84
{
95
string Name { get; }
106
}
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
14
namespace Discord
25
{
3-
public interface IGuildEmote : IEmote
6+
public interface IGuildEmote : IEmote, ISnowflakeEntity, IDeletable
47
{
5-
// TODO
8+
/// <summary>
9+
/// Gets whether this emoji is managed by an integration.
10+
/// </summary>
11+
/// <returns>
12+
/// A boolean that determines whether or not this emote is managed by a Twitch integration.
13+
/// </returns>
14+
bool IsManaged { get; }
15+
/// <summary>
16+
/// Gets whether this emoji must be wrapped in colons.
17+
/// </summary>
18+
/// <returns>
19+
/// A boolean that determines whether or not this emote requires the use of colons in chat to be used.
20+
/// </returns>
21+
bool RequireColons { get; }
22+
/// <summary>
23+
/// Gets the roles that are allowed to use this emoji.
24+
/// </summary>
25+
/// <returns>
26+
/// A read-only list containing snowflake identifiers for roles that are allowed to use this emoji.
27+
/// </returns>
28+
IReadOnlyList<IRole> Roles { get; }
29+
/// <summary>
30+
/// Gets the user ID associated with the creation of this emoji.
31+
/// </summary>
32+
/// <returns>
33+
/// An <see cref="ulong"/> snowflake identifier representing the user who created this emoji;
34+
/// <c>null</c> if unknown.
35+
/// </returns>
36+
ulong? CreatorId { get; }
37+
/// <summary>
38+
/// Gets the guild this emote sourced from.
39+
/// </summary>
40+
IGuild Guild { get; }
41+
42+
Task ModifyAsync(); // TODO
643
}
744
}

src/Discord.Net/Entities/Guilds/IGuild.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
21
using System.Collections.Generic;
3-
using System.Text;
42

53
namespace Discord
64
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Model = Wumpus.Entities.Emoji;
4+
5+
namespace Discord
6+
{
7+
internal class AttachedGuildEmote : SnowflakeEntity, IGuildEmote
8+
{
9+
public AttachedGuildEmote(Model model, IGuild guild, IDiscordClient discord) : base(discord)
10+
{
11+
IsManaged = model.Managed.GetValueOrDefault(false);
12+
RequireColons = model.RequireColons.GetValueOrDefault(false);
13+
14+
Wumpus.Snowflake[] roleIds = model.RoleIds.GetValueOrDefault() ?? new Wumpus.Snowflake[0];
15+
Role[] roles = new Role[roleIds.Length];
16+
for (int i = 0; i < roleIds.Length; i++)
17+
roles[i] = null; // TODO guild.GetRole()
18+
Roles = roles;
19+
20+
CreatorId = model.User.IsSpecified ? model.User.Value.Id : (ulong?)null; // TODO: EntityOrId this guy
21+
Name = model.Name.ToString();
22+
Guild = guild;
23+
}
24+
25+
public bool IsManaged { get; set; }
26+
public bool RequireColons { get; set; }
27+
public IReadOnlyList<IRole> Roles { get; set; }
28+
public ulong? CreatorId { get; set; }
29+
public string Name { get; set; }
30+
public IGuild Guild { get; set; }
31+
32+
// IMentionable
33+
public string Mention => throw new System.NotImplementedException();
34+
35+
public Task DeleteAsync()
36+
=> Discord.Rest.DeleteGuildEmojiAsync(Guild.Id, Id);
37+
38+
public Task ModifyAsync() // TODO
39+
{
40+
throw new System.NotImplementedException();
41+
}
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Discord
2+
{
3+
internal class Emoji : IEmote
4+
{
5+
public Emoji(string name)
6+
{
7+
// TODO: validation?
8+
Name = name;
9+
}
10+
11+
public string Name { get; set; }
12+
public string Mention => Name;
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Discord
2+
{
3+
// placeholder for user-constructed guild emotes
4+
// TODO: naming - should be called GuildEmote? but does not impl IGuildEmote, so maybe not...
5+
internal class Emote : IEmote
6+
{
7+
public Emote(ulong id, string name)
8+
{
9+
Id = id;
10+
Name = name;
11+
}
12+
13+
public ulong Id { get; set; }
14+
public string Name { get; set; }
15+
16+
public string Mention => throw new System.NotImplementedException(); // TODO: EmojiUtils
17+
}
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Discord
4+
{
5+
public static class EmoteBuilder
6+
{
7+
public static IEmote FromEmoji(string emoji)
8+
=> new Emoji(emoji);
9+
public static IEmote FromMention(string mention)
10+
=> throw new NotImplementedException(); // TODO: emoteutil
11+
public static IEmote FromID(ulong id, string name)
12+
=> new Emote(id, name);
13+
}
14+
}

0 commit comments

Comments
 (0)