Browse Source

feature: add emote entity/model

pull/1253/head
Christopher Felegy 6 years ago
parent
commit
a138f5d1b4
7 changed files with 129 additions and 9 deletions
  1. +1
    -5
      src/Discord.Net/Entities/Emotes/IEmote.cs
  2. +39
    -2
      src/Discord.Net/Entities/Emotes/IGuildEmote.cs
  3. +0
    -2
      src/Discord.Net/Entities/Guilds/IGuild.cs
  4. +43
    -0
      src/Discord.Net/Models/Emotes/AttachedGuildEmote.cs
  5. +14
    -0
      src/Discord.Net/Models/Emotes/Emoji.cs
  6. +18
    -0
      src/Discord.Net/Models/Emotes/Emote.cs
  7. +14
    -0
      src/Discord.Net/Models/Emotes/EmoteBuilder.cs

+ 1
- 5
src/Discord.Net/Entities/Emotes/IEmote.cs View File

@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Discord
{
public interface IEmote
public interface IEmote : IMentionable // TODO: Is `Mention` the correct verbage here?
{
string Name { get; }
}


+ 39
- 2
src/Discord.Net/Entities/Emotes/IGuildEmote.cs View File

@@ -1,7 +1,44 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Discord
{
public interface IGuildEmote : IEmote
public interface IGuildEmote : IEmote, ISnowflakeEntity, IDeletable
{
// TODO
/// <summary>
/// Gets whether this emoji is managed by an integration.
/// </summary>
/// <returns>
/// A boolean that determines whether or not this emote is managed by a Twitch integration.
/// </returns>
bool IsManaged { get; }
/// <summary>
/// Gets whether this emoji must be wrapped in colons.
/// </summary>
/// <returns>
/// A boolean that determines whether or not this emote requires the use of colons in chat to be used.
/// </returns>
bool RequireColons { get; }
/// <summary>
/// Gets the roles that are allowed to use this emoji.
/// </summary>
/// <returns>
/// A read-only list containing snowflake identifiers for roles that are allowed to use this emoji.
/// </returns>
IReadOnlyList<IRole> Roles { get; }
/// <summary>
/// Gets the user ID associated with the creation of this emoji.
/// </summary>
/// <returns>
/// An <see cref="ulong"/> snowflake identifier representing the user who created this emoji;
/// <c>null</c> if unknown.
/// </returns>
ulong? CreatorId { get; }
/// <summary>
/// Gets the guild this emote sourced from.
/// </summary>
IGuild Guild { get; }

Task ModifyAsync(); // TODO
}
}

+ 0
- 2
src/Discord.Net/Entities/Guilds/IGuild.cs View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Discord
{


+ 43
- 0
src/Discord.Net/Models/Emotes/AttachedGuildEmote.cs View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Model = Wumpus.Entities.Emoji;

namespace Discord
{
internal class AttachedGuildEmote : SnowflakeEntity, IGuildEmote
{
public AttachedGuildEmote(Model model, IGuild guild, IDiscordClient discord) : base(discord)
{
IsManaged = model.Managed.GetValueOrDefault(false);
RequireColons = model.RequireColons.GetValueOrDefault(false);

Wumpus.Snowflake[] roleIds = model.RoleIds.GetValueOrDefault() ?? new Wumpus.Snowflake[0];
Role[] roles = new Role[roleIds.Length];
for (int i = 0; i < roleIds.Length; i++)
roles[i] = null; // TODO guild.GetRole()
Roles = roles;

CreatorId = model.User.IsSpecified ? model.User.Value.Id : (ulong?)null; // TODO: EntityOrId this guy
Name = model.Name.ToString();
Guild = guild;
}

public bool IsManaged { get; set; }
public bool RequireColons { get; set; }
public IReadOnlyList<IRole> Roles { get; set; }
public ulong? CreatorId { get; set; }
public string Name { get; set; }
public IGuild Guild { get; set; }

// IMentionable
public string Mention => throw new System.NotImplementedException();

public Task DeleteAsync()
=> Discord.Rest.DeleteGuildEmojiAsync(Guild.Id, Id);

public Task ModifyAsync() // TODO
{
throw new System.NotImplementedException();
}
}
}

+ 14
- 0
src/Discord.Net/Models/Emotes/Emoji.cs View File

@@ -0,0 +1,14 @@
namespace Discord
{
internal class Emoji : IEmote
{
public Emoji(string name)
{
// TODO: validation?
Name = name;
}

public string Name { get; set; }
public string Mention => Name;
}
}

+ 18
- 0
src/Discord.Net/Models/Emotes/Emote.cs View File

@@ -0,0 +1,18 @@
namespace Discord
{
// placeholder for user-constructed guild emotes
// TODO: naming - should be called GuildEmote? but does not impl IGuildEmote, so maybe not...
internal class Emote : IEmote
{
public Emote(ulong id, string name)
{
Id = id;
Name = name;
}

public ulong Id { get; set; }
public string Name { get; set; }

public string Mention => throw new System.NotImplementedException(); // TODO: EmojiUtils
}
}

+ 14
- 0
src/Discord.Net/Models/Emotes/EmoteBuilder.cs View File

@@ -0,0 +1,14 @@
using System;

namespace Discord
{
public static class EmoteBuilder
{
public static IEmote FromEmoji(string emoji)
=> new Emoji(emoji);
public static IEmote FromMention(string mention)
=> throw new NotImplementedException(); // TODO: emoteutil
public static IEmote FromID(ulong id, string name)
=> new Emote(id, name);
}
}

Loading…
Cancel
Save