Updated reference channel entities

This commit is contained in:
RogueException
2016-02-26 05:22:01 -04:00
parent d1cae981da
commit 0759f957d8
23 changed files with 298 additions and 162 deletions

View File

@@ -23,7 +23,7 @@ namespace Discord
public event EventHandler<ServerUpdatedEventArgs> ServerUpdated = delegate { };
public event EventHandler<ServerEventArgs> ServerUnavailable = delegate { };
public event EventHandler<UserEventArgs> UserBanned = delegate { };
public event EventHandler<ChannelUserEventArgs> UserIsTyping = delegate { };
public event EventHandler<TypingEventArgs> UserIsTyping = delegate { };
public event EventHandler<UserEventArgs> UserJoined = delegate { };
public event EventHandler<UserEventArgs> UserLeft = delegate { };
public event EventHandler<UserUpdatedEventArgs> UserUpdated = delegate { };

View File

@@ -29,7 +29,7 @@ namespace Discord
public string CurrentGame { get; }
public IEnumerable<Server> Servers { get; }
public IEnumerable<Channel> PrivateChannels { get; }
public IEnumerable<PrivateChannel> PrivateChannels { get; }
public IEnumerable<Region> Regions { get; }
public DiscordClient() { }
@@ -43,8 +43,8 @@ namespace Discord
public void SetStatus(UserStatus status) { }
public void SetGame(string game) { }
public Channel GetChannel(ulong id) => null;
public Task<Channel> CreatePrivateChannel(ulong userId) => null;
public PrivateChannel GetPrivateChannel(ulong id) => null;
public Task<PrivateChannel> CreatePrivateChannel(ulong userId) => null;
public Task<Invite> GetInvite(string inviteIdOrXkcd) => null;

View File

@@ -1,22 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Discord
{
public abstract class Channel : IChannel
{
public ulong Id { get; }
public abstract DiscordClient Client { get; }
public abstract ChannelType Type { get; }
public bool IsText { get; }
public bool IsVoice { get; }
public bool IsPrivate { get; }
public bool IsPublic { get; }
public abstract User CurrentUser { get; }
public abstract IEnumerable<User> Users { get; }
public abstract Task Save();
}
}

View File

@@ -1,17 +1,22 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Discord
{
public interface IChannel : IModel<ulong>
public interface IChannel : IEntity<ulong>
{
DiscordClient Client { get; }
/// <summary> Gets the type flags for this channel. </summary>
ChannelType Type { get; }
/// <summary> Gets whether this is a text channel. </summary>
bool IsText { get; }
/// <summary> Gets whether this is a voice channel. </summary>
bool IsVoice { get; }
/// <summary> Gets whether this is a private channel. </summary>
bool IsPrivate { get; }
/// <summary> Gets whether this is a public channel. </summary>
bool IsPublic { get; }
IEnumerable<User> Users { get; }
/// <summary> Gets a collection of all users in this channel. </summary>
Task<IEnumerable<User>> GetUsers();
}
}

View File

@@ -2,6 +2,7 @@
{
public interface IPrivateChannel : IChannel
{
/// <summary> Gets the recipient of the messages in this private channel. </summary>
User Recipient { get; }
}
}

View File

@@ -5,26 +5,40 @@ namespace Discord
{
public interface IPublicChannel : IChannel
{
/// <summary> Gets the server this channel is a member of. </summary>
Server Server { get; }
string Name { get; set; }
int Position { get; set; }
/// <summary> Gets a collection of permission overwrites for this channel. </summary>
IEnumerable<PermissionOverwrite> PermissionOverwrites { get; }
/// <summary> Gets the name of this public channel. </summary>
string Name { get; }
/// <summary> Gets the position of this public channel relative to others of the same type. </summary>
int Position { get; }
PermissionOverwrite? GetPermissionsRule(User user);
PermissionOverwrite? GetPermissionsRule(Role role);
Task<IEnumerable<Invite>> DownloadInvites();
Task Delete();
/// <summary> Gets the permission overwrite for a specific user, or null if one does not exist. </summary>
Task<PermissionOverwrite?> GetPermissionOverwrite(User user);
/// <summary> Gets the permission overwrite for a specific role, or null if one does not exist. </summary>
Task<PermissionOverwrite?> GetPermissionOverwrite(Role role);
/// <summary> Downloads a collection of all invites to this server. </summary>
Task<IEnumerable<Invite>> GetInvites();
/// <summary> Adds or updates the permission overwrite for the given user. </summary>
Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny);
/// <summary> Adds or updates the permission overwrite for the given user. </summary>
Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions);
/// <summary> Adds or updates the permission overwrite for the given role. </summary>
Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny);
/// <summary> Adds or updates the permission overwrite for the given role. </summary>
Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions);
/// <summary> Removes the permission overwrite for the given user, if one exists. </summary>
Task RemovePermissionOverwrite(User user);
/// <summary> Removes the permission overwrite for the given role, if one exists. </summary>
Task RemovePermissionOverwrite(Role role);
/// <summary> Creates a new invite to this channel. </summary>
/// <param name="maxAge"> Time (in seconds) until the invite expires. Set to null to never expire. </param>
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param>
/// <param name="tempMembership"> If true, a user accepting this invite will be kicked from the server after closing their client. </param>
/// <param name="withXkcd"> If true, creates a human-readable link. Not supported if maxAge is set to null. </param>
Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false);
Task AddPermissionsRule(User user, ChannelPermissions allow, ChannelPermissions deny);
Task AddPermissionsRule(User user, TriStateChannelPermissions permissions);
Task AddPermissionsRule(Role role, ChannelPermissions allow, ChannelPermissions deny);
Task AddPermissionsRule(Role role, TriStateChannelPermissions permissions);
Task RemovePermissionsRule(User user);
Task RemovePermissionsRule(Role role);
}
}

View File

@@ -6,13 +6,25 @@ namespace Discord
{
public interface ITextChannel : IChannel
{
Message GetMessage(ulong id);
Task<IEnumerable<Message>> DownloadMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before);
/// <summary> Gets the message in this text channel with the given id, or null if none was found. </summary>
Task<Message> GetMessage(ulong id);
/// <summary> Gets the last N messages from this text channel. </summary>
/// <param name="limit"> The maximum number of messages to retrieve. </param>
Task<IEnumerable<Message>> GetMessages(int limit = 100);
/// <summary> Gets a collection of messages in this channel. </summary>
/// <param name="limit"> The maximum number of messages to retrieve. </param>
/// <param name="relativeMessageId"> The message to start downloading relative to. </param>
/// <param name="relativeDir"> The direction, from relativeMessageId, to download messages in. </param>
Task<IEnumerable<Message>> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before);
/// <summary> Sends a message to this text channel. </summary>
Task<Message> SendMessage(string text, bool isTTS = false);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
Task<Message> SendFile(string filePath, string text = null, bool isTTS = false);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
Task<Message> SendFile(Stream stream, string filename, string text = null, bool isTTS = false);
/// <summary> Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds.</summary>
Task SendIsTyping();
}
}

View File

@@ -2,6 +2,7 @@
{
public interface IVoiceChannel : IChannel
{
int Bitrate { get; set; }
/// <summary> Gets the requested bitrate, in bits per second, of this voice channel. </summary>
int Bitrate { get; }
}
}

View File

@@ -1,31 +1,55 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Discord
{
public class PrivateChannel : Channel, ITextChannel, IPrivateChannel
{
public class PrivateChannel : ITextChannel, IPrivateChannel
{
/// <inheritdoc />
public ulong Id { get; }
/// <inheritdoc />
public DiscordClient Client { get; }
/// <inheritdoc />
public ModelState State { get; }
/// <inheritdoc />
public ChannelType Type { get; }
/// <inheritdoc />
public bool IsPrivate => true;
/// <inheritdoc />
public bool IsPublic => false;
/// <inheritdoc />
public bool IsText => true;
/// <inheritdoc />
public bool IsVoice => false;
/// <inheritdoc />
public Server Server { get; }
/// <inheritdoc />
public User Recipient { get; }
public IEnumerable<Message> Messages { get; }
public override DiscordClient Client => null;
public override ChannelType Type => default(ChannelType);
public override User CurrentUser => null;
public override IEnumerable<User> Users => null;
public Message GetMessage(ulong id) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null;
/// <inheritdoc />
public Task<IEnumerable<User>> GetUsers();
/// <inheritdoc />
public Task<Message> GetMessage(ulong id) => null;
/// <inheritdoc />
public Task<IEnumerable<Message>> GetMessages(int limit = 100) => null;
/// <inheritdoc />
public Task<IEnumerable<Message>> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before) => null;
/// <inheritdoc />
public Task<Message> SendMessage(string text, bool isTTS = false) => null;
public Task<Message> SendFile(string path, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task<Message> SendFile(string filePath, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task<Message> SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task SendIsTyping() => null;
public override Task Save() => null;
/// <inheritdoc />
public Task Delete() => null;
/// <inheritdoc />
public Task Update() => null;
}
}

View File

@@ -1,50 +1,94 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Discord
{
public class TextChannel : Channel, ITextChannel, IPublicChannel, IMentionable
public class TextChannel : ITextChannel, IPublicChannel, IMentionable, IModifiable<TextChannel.Properties>
{
public Server Server { get; }
public sealed class Properties
{
}
/// <inheritdoc />
public ulong Id { get; }
/// <inheritdoc />
public DiscordClient Discord { get; }
/// <inheritdoc />
public ModelState State { get; }
/// <inheritdoc />
public ChannelType Type => ChannelType.Public | ChannelType.Text;
/// <inheritdoc />
public bool IsPrivate => false;
/// <inheritdoc />
public bool IsPublic => true;
/// <inheritdoc />
public bool IsText => true;
/// <inheritdoc />
public bool IsVoice => false;
/// <inheritdoc />
public string Name { get; }
/// <inheritdoc />
public string Topic { get; }
/// <inheritdoc />
public int Position { get; }
/// <inheritdoc />
public string Mention { get; }
/// <inheritdoc />
public Server Server { get; }
/// <inheritdoc />
public IEnumerable<PermissionOverwrite> PermissionOverwrites { get; }
public IEnumerable<Message> Messages { get; }
/// <inheritdoc />
public IEnumerable<User> Users { get; }
public string Topic { get; set; }
public bool IsTyping { get; set; }
public string Name { get; set; }
public int Position { get; set; }
/// <inheritdoc />
public Task<IEnumerable<User>> GetUsers() => null;
/// <inheritdoc />
public Task<Message> GetMessage(ulong id) => null;
/// <inheritdoc />
public Task<IEnumerable<Message>> GetMessages(int limit = 100) => null;
/// <inheritdoc />
public Task<IEnumerable<Message>> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before) => null;
/// <inheritdoc />
public Task<PermissionOverwrite?> GetPermissionOverwrite(User user) => null;
/// <inheritdoc />
public Task<PermissionOverwrite?> GetPermissionOverwrite(Role role) => null;
/// <inheritdoc />
public Task<IEnumerable<Invite>> GetInvites() => null;
public override DiscordClient Client => null;
public override ChannelType Type => default(ChannelType);
public override User CurrentUser => null;
public override IEnumerable<User> Users => null;
public Message GetMessage(ulong id) => null;
public PermissionOverwrite? GetPermissionsRule(User user) => null;
public PermissionOverwrite? GetPermissionsRule(Role role) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null;
public Task<IEnumerable<Invite>> DownloadInvites() => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions) => null;
/// <inheritdoc />
public Task RemovePermissionOverwrite(User user) => null;
/// <inheritdoc />
public Task RemovePermissionOverwrite(Role role) => null;
/// <inheritdoc />
public Task<Message> SendMessage(string text, bool isTTS = false) => null;
public Task<Message> SendFile(string path, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task<Message> SendFile(string filePath, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task<Message> SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null;
/// <inheritdoc />
public Task SendIsTyping() => null;
public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool tempMembership = false, bool withXkcd = false) => null;
public Task AddPermissionsRule(User user, ChannelPermissions allow, ChannelPermissions deny) => null;
public Task AddPermissionsRule(User user, TriStateChannelPermissions permissions) => null;
public Task AddPermissionsRule(Role role, ChannelPermissions allow, ChannelPermissions deny) => null;
public Task AddPermissionsRule(Role role, TriStateChannelPermissions permissions) => null;
public Task RemovePermissionsRule(User user) => null;
public Task RemovePermissionsRule(Role role) => null;
/// <inheritdoc />
public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null;
/// <inheritdoc />
public Task Delete() => null;
public override Task Save() => null;
/// <inheritdoc />
public Task Update() => null;
/// <inheritdoc />
public Task Modify(Action<Properties> func) => null;
}
}

View File

@@ -1,49 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Discord
{
public class VoiceChannel : IPublicChannel, IVoiceChannel
public class VoiceChannel : IPublicChannel, IVoiceChannel, IModifiable<VoiceChannel.Properties>
{
public sealed class Properties
{
public int Bitrate { get; set; }
}
/// <inheritdoc />
public ulong Id { get; }
/// <inheritdoc />
public DiscordClient Client { get; }
public Server Server { get; }
/// <inheritdoc />
public ModelState State { get; }
/// <inheritdoc />
public ChannelType Type { get; }
public bool IsText { get; }
public bool IsVoice { get; }
public bool IsPrivate { get; }
public bool IsPublic { get; }
/// <inheritdoc />
public bool IsPrivate => false;
/// <inheritdoc />
public bool IsPublic => true;
/// <inheritdoc />
public bool IsText => false;
/// <inheritdoc />
public bool IsVoice => true;
/// <inheritdoc />
public string Name { get; }
/// <inheritdoc />
public int Position { get; }
/// <inheritdoc />
public int Bitrate { get; }
/// <inheritdoc />
public Server Server { get; }
/// <inheritdoc />
public IEnumerable<PermissionOverwrite> PermissionOverwrites { get; }
public IEnumerable<User> Users { get; }
public string Name { get; set; }
public int Position { get; set; }
public int Bitrate { get; set; }
/// <inheritdoc />
public PermissionOverwrite? GetPermissionOverwrite(User user) => null;
/// <inheritdoc />
public PermissionOverwrite? GetPermissionOverwrite(Role role) => null;
/// <inheritdoc />
public Task<IEnumerable<User>> GetUsers() => null;
/// <inheritdoc />
public Task<IEnumerable<Invite>> GetInvites() => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny) => null;
/// <inheritdoc />
public Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions) => null;
/// <inheritdoc />
public Task RemovePermissionOverwrite(User user) => null;
/// <inheritdoc />
public Task RemovePermissionOverwrite(Role role) => null;
public Message GetMessage(ulong id) => null;
public PermissionOverwrite? GetPermissionsRule(User user) => null;
public PermissionOverwrite? GetPermissionsRule(Role role) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit) => null;
public Task<IEnumerable<Message>> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null;
public Task<IEnumerable<Invite>> DownloadInvites() => null;
public Task<Message> SendMessage(string text, bool isTTS = false) => null;
public Task<Message> SendFile(string path, string text = null, bool isTTS = false) => null;
public Task<Message> SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null;
public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool tempMembership = false, bool withXkcd = false) => null;
public Task AddPermissionsRule(User user, ChannelPermissions allow, ChannelPermissions deny) => null;
public Task AddPermissionsRule(User user, TriStateChannelPermissions permissions) => null;
public Task AddPermissionsRule(Role role, ChannelPermissions allow, ChannelPermissions deny) => null;
public Task AddPermissionsRule(Role role, TriStateChannelPermissions permissions) => null;
public Task RemovePermissionsRule(User user) => null;
public Task RemovePermissionsRule(Role role) => null;
/// <inheritdoc />
public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null;
/// <inheritdoc />
public Task Delete() => null;
public Task Save() => null;
/// <inheritdoc />
public Task Update() => null;
/// <inheritdoc />
public Task Modify(Action<Properties> func) => null;
}
}

23
ref/Entities/IEntity.cs Normal file
View File

@@ -0,0 +1,23 @@
using System;
using System.Threading.Tasks;
namespace Discord
{
public interface IEntity<TId> : IEntity
{
/// <summary> Gets the unique identifier for this object. </summary>
TId Id { get; }
}
public interface IEntity
{
/// <summary> Gets the DiscordClient that manages this object. </summary>
DiscordClient Client { get; }
/// <summary> Gets the state of this object. </summary>
ModelState State { get; }
/// <summary> Deletes this object. </summary>
Task Delete();
/// <summary> Downloads the latest values and updates this object. </summary>
Task Update();
}
}

View File

@@ -1,13 +0,0 @@
using System.Threading.Tasks;
namespace Discord
{
public interface IModel<TId> : IModel
{
TId Id { get; }
}
public interface IModel
{
Task Save();
}
}

View File

@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;
namespace Discord
{
public interface IModifiable<TModel>
{
/// <summary> Modifies one or more of the properties of this object. </summary>
Task Modify(Action<TModel> func);
}
}

View File

@@ -4,7 +4,7 @@ using System.Threading.Tasks;
namespace Discord
{
public class Message : IModel<ulong>
public class Message : IEntity<ulong>
{
public class Attachment : File
{

View File

@@ -2,7 +2,7 @@
namespace Discord
{
public class Profile : IModel<ulong>
public class Profile : IEntity<ulong>
{
public DiscordClient Client { get; }

View File

@@ -3,7 +3,7 @@ using System.Threading.Tasks;
namespace Discord
{
public class Role : IModel<ulong>, IMentionable
public class Role : IEntity<ulong>, IMentionable
{
public DiscordClient Client { get; }

View File

@@ -4,7 +4,7 @@ using System.Threading.Tasks;
namespace Discord
{
public class Server : IModel<ulong>
public class Server : IEntity<ulong>
{
public class Emoji
{
@@ -28,7 +28,7 @@ namespace Discord
public Role EveryoneRole { get; }
public IEnumerable<string> Features { get; }
public IEnumerable<Emoji> CustomEmojis { get; }
public IEnumerable<Channel> Channels { get; }
public IEnumerable<IChannel> Channels { get; }
public IEnumerable<TextChannel> TextChannels { get; }
public IEnumerable<VoiceChannel> VoiceChannels { get; }
public IEnumerable<User> Users { get; }

View File

@@ -1,8 +1,13 @@
namespace Discord
using System;
namespace Discord
{
public enum ChannelType
[Flags]
public enum ChannelType : byte
{
Text,
Voice
Public = 0x01,
Private = 0x02,
Text = 0x10,
Voice = 0x20
}
}

View File

@@ -1,6 +1,6 @@
namespace Discord
{
public enum MessageState : byte
public enum ModelState : byte
{
/// <summary> Message did not originate from this session, or was successfully sent. </summary>
Normal = 0,

View File

@@ -4,8 +4,8 @@ namespace Discord
{
public class ChannelUpdatedEventArgs : EventArgs
{
public Channel Before => null;
public Channel After => null;
public IChannel Before => null;
public IChannel After => null;
public Server Server => null;
}
}

View File

@@ -1,8 +0,0 @@
namespace Discord
{
public class ChannelUserEventArgs
{
public Channel Channel => null;
public User User => null;
}
}

View File

@@ -0,0 +1,14 @@
namespace Discord
{
public class TypingEventArgs
{
public ITextChannel Channel { get; }
public User User { get; }
public TypingEventArgs(ITextChannel channel, User user)
{
Channel = channel;
User = user;
}
}
}