diff --git a/ref/DiscordClient.Events.cs b/ref/DiscordClient.Events.cs index 42b2601e3..888ba5c99 100644 --- a/ref/DiscordClient.Events.cs +++ b/ref/DiscordClient.Events.cs @@ -23,7 +23,7 @@ namespace Discord public event EventHandler ServerUpdated = delegate { }; public event EventHandler ServerUnavailable = delegate { }; public event EventHandler UserBanned = delegate { }; - public event EventHandler UserIsTyping = delegate { }; + public event EventHandler UserIsTyping = delegate { }; public event EventHandler UserJoined = delegate { }; public event EventHandler UserLeft = delegate { }; public event EventHandler UserUpdated = delegate { }; diff --git a/ref/DiscordClient.cs b/ref/DiscordClient.cs index f2a1cb95d..166f17268 100644 --- a/ref/DiscordClient.cs +++ b/ref/DiscordClient.cs @@ -29,7 +29,7 @@ namespace Discord public string CurrentGame { get; } public IEnumerable Servers { get; } - public IEnumerable PrivateChannels { get; } + public IEnumerable PrivateChannels { get; } public IEnumerable 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 CreatePrivateChannel(ulong userId) => null; + public PrivateChannel GetPrivateChannel(ulong id) => null; + public Task CreatePrivateChannel(ulong userId) => null; public Task GetInvite(string inviteIdOrXkcd) => null; diff --git a/ref/Entities/Channels/Channel.cs b/ref/Entities/Channels/Channel.cs deleted file mode 100644 index 8cb4a1afb..000000000 --- a/ref/Entities/Channels/Channel.cs +++ /dev/null @@ -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 Users { get; } - - public abstract Task Save(); - } -} diff --git a/ref/Entities/Channels/IChannel.cs b/ref/Entities/Channels/IChannel.cs index 7fbe67208..55e723303 100644 --- a/ref/Entities/Channels/IChannel.cs +++ b/ref/Entities/Channels/IChannel.cs @@ -1,17 +1,22 @@ using System.Collections.Generic; +using System.Threading.Tasks; namespace Discord { - public interface IChannel : IModel + public interface IChannel : IEntity { - DiscordClient Client { get; } - + /// Gets the type flags for this channel. ChannelType Type { get; } + /// Gets whether this is a text channel. bool IsText { get; } + /// Gets whether this is a voice channel. bool IsVoice { get; } + /// Gets whether this is a private channel. bool IsPrivate { get; } + /// Gets whether this is a public channel. bool IsPublic { get; } - - IEnumerable Users { get; } + + /// Gets a collection of all users in this channel. + Task> GetUsers(); } } diff --git a/ref/Entities/Channels/IPrivateChannel.cs b/ref/Entities/Channels/IPrivateChannel.cs index 44d55a67f..0ac5ec3aa 100644 --- a/ref/Entities/Channels/IPrivateChannel.cs +++ b/ref/Entities/Channels/IPrivateChannel.cs @@ -2,6 +2,7 @@ { public interface IPrivateChannel : IChannel { + /// Gets the recipient of the messages in this private channel. User Recipient { get; } } } diff --git a/ref/Entities/Channels/IPublicChannel.cs b/ref/Entities/Channels/IPublicChannel.cs index 8b8f87b45..91bdf81a6 100644 --- a/ref/Entities/Channels/IPublicChannel.cs +++ b/ref/Entities/Channels/IPublicChannel.cs @@ -5,26 +5,40 @@ namespace Discord { public interface IPublicChannel : IChannel { + /// Gets the server this channel is a member of. Server Server { get; } - - string Name { get; set; } - int Position { get; set; } - + /// Gets a collection of permission overwrites for this channel. IEnumerable PermissionOverwrites { get; } + /// Gets the name of this public channel. + string Name { get; } + /// Gets the position of this public channel relative to others of the same type. + int Position { get; } - PermissionOverwrite? GetPermissionsRule(User user); - PermissionOverwrite? GetPermissionsRule(Role role); - Task> DownloadInvites(); - - Task Delete(); + /// Gets the permission overwrite for a specific user, or null if one does not exist. + Task GetPermissionOverwrite(User user); + /// Gets the permission overwrite for a specific role, or null if one does not exist. + Task GetPermissionOverwrite(Role role); + /// Downloads a collection of all invites to this server. + Task> GetInvites(); + + /// Adds or updates the permission overwrite for the given user. + Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny); + /// Adds or updates the permission overwrite for the given user. + Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions); + /// Adds or updates the permission overwrite for the given role. + Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny); + /// Adds or updates the permission overwrite for the given role. + Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions); + /// Removes the permission overwrite for the given user, if one exists. + Task RemovePermissionOverwrite(User user); + /// Removes the permission overwrite for the given role, if one exists. + Task RemovePermissionOverwrite(Role role); + /// Creates a new invite to this channel. + /// Time (in seconds) until the invite expires. Set to null to never expire. + /// The max amount of times this invite may be used. Set to null to have unlimited uses. + /// If true, a user accepting this invite will be kicked from the server after closing their client. + /// If true, creates a human-readable link. Not supported if maxAge is set to null. Task 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); } } diff --git a/ref/Entities/Channels/ITextChannel.cs b/ref/Entities/Channels/ITextChannel.cs index aa7e09435..b1449fac9 100644 --- a/ref/Entities/Channels/ITextChannel.cs +++ b/ref/Entities/Channels/ITextChannel.cs @@ -6,13 +6,25 @@ namespace Discord { public interface ITextChannel : IChannel { - Message GetMessage(ulong id); - Task> DownloadMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before); + /// Gets the message in this text channel with the given id, or null if none was found. + Task GetMessage(ulong id); + /// Gets the last N messages from this text channel. + /// The maximum number of messages to retrieve. + Task> GetMessages(int limit = 100); + /// Gets a collection of messages in this channel. + /// The maximum number of messages to retrieve. + /// The message to start downloading relative to. + /// The direction, from relativeMessageId, to download messages in. + Task> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before); + /// Sends a message to this text channel. Task SendMessage(string text, bool isTTS = false); + /// Sends a file to this text channel, with an optional caption. Task SendFile(string filePath, string text = null, bool isTTS = false); + /// Sends a file to this text channel, with an optional caption. Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false); + /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. Task SendIsTyping(); } } diff --git a/ref/Entities/Channels/IVoiceChannel.cs b/ref/Entities/Channels/IVoiceChannel.cs index 85d093209..f8c3be999 100644 --- a/ref/Entities/Channels/IVoiceChannel.cs +++ b/ref/Entities/Channels/IVoiceChannel.cs @@ -2,6 +2,7 @@ { public interface IVoiceChannel : IChannel { - int Bitrate { get; set; } + /// Gets the requested bitrate, in bits per second, of this voice channel. + int Bitrate { get; } } } diff --git a/ref/Entities/Channels/PrivateChannel.cs b/ref/Entities/Channels/PrivateChannel.cs index ca25dadab..80f3284c1 100644 --- a/ref/Entities/Channels/PrivateChannel.cs +++ b/ref/Entities/Channels/PrivateChannel.cs @@ -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 User Recipient { get; } - public IEnumerable Messages { get; } - - public override DiscordClient Client => null; - public override ChannelType Type => default(ChannelType); + public class PrivateChannel : ITextChannel, IPrivateChannel + { + /// + public ulong Id { get; } + /// + public DiscordClient Client { get; } + /// + public ModelState State { get; } + /// + public ChannelType Type { get; } + /// + public bool IsPrivate => true; + /// + public bool IsPublic => false; + /// + public bool IsText => true; + /// + public bool IsVoice => false; - public override User CurrentUser => null; - public override IEnumerable Users => null; + /// + public Server Server { get; } + /// + public User Recipient { get; } - public Message GetMessage(ulong id) => null; - public Task> DownloadMessages(int limit) => null; - public Task> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null; + /// + public Task> GetUsers(); + /// + public Task GetMessage(ulong id) => null; + /// + public Task> GetMessages(int limit = 100) => null; + /// + public Task> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before) => null; + /// public Task SendMessage(string text, bool isTTS = false) => null; - public Task SendFile(string path, string text = null, bool isTTS = false) => null; + /// + public Task SendFile(string filePath, string text = null, bool isTTS = false) => null; + /// public Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null; + /// public Task SendIsTyping() => null; - - public override Task Save() => null; + + /// + public Task Delete() => null; + /// + public Task Update() => null; } } diff --git a/ref/Entities/Channels/TextChannel.cs b/ref/Entities/Channels/TextChannel.cs index e09528e01..9b96ff02c 100644 --- a/ref/Entities/Channels/TextChannel.cs +++ b/ref/Entities/Channels/TextChannel.cs @@ -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 { - public Server Server { get; } - public string Mention { get; } - public IEnumerable PermissionOverwrites { get; } - public IEnumerable Messages { get; } + public sealed class Properties + { + } - public string Topic { get; set; } - public bool IsTyping { get; set; } - public string Name { get; set; } - public int Position { get; set; } + /// + public ulong Id { get; } + /// + public DiscordClient Discord { get; } + /// + public ModelState State { get; } + /// + public ChannelType Type => ChannelType.Public | ChannelType.Text; + /// + public bool IsPrivate => false; + /// + public bool IsPublic => true; + /// + public bool IsText => true; + /// + public bool IsVoice => false; - public override DiscordClient Client => null; - public override ChannelType Type => default(ChannelType); - public override User CurrentUser => null; - public override IEnumerable Users => null; + /// + public string Name { get; } + /// + public string Topic { get; } + /// + public int Position { get; } + /// + public string Mention { get; } + /// + public Server Server { get; } + /// + public IEnumerable PermissionOverwrites { get; } + /// + public IEnumerable Users { get; } - public Message GetMessage(ulong id) => null; - public PermissionOverwrite? GetPermissionsRule(User user) => null; - public PermissionOverwrite? GetPermissionsRule(Role role) => null; + /// + public Task> GetUsers() => null; + /// + public Task GetMessage(ulong id) => null; + /// + public Task> GetMessages(int limit = 100) => null; + /// + public Task> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before) => null; + /// + public Task GetPermissionOverwrite(User user) => null; + /// + public Task GetPermissionOverwrite(Role role) => null; + /// + public Task> GetInvites() => null; - public Task> DownloadMessages(int limit) => null; - public Task> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null; - public Task> DownloadInvites() => null; + /// + public Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny) => null; + /// + public Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions) => null; + /// + public Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny) => null; + /// + public Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions) => null; + /// + public Task RemovePermissionOverwrite(User user) => null; + /// + public Task RemovePermissionOverwrite(Role role) => null; + /// public Task SendMessage(string text, bool isTTS = false) => null; - public Task SendFile(string path, string text = null, bool isTTS = false) => null; + /// + public Task SendFile(string filePath, string text = null, bool isTTS = false) => null; + /// public Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null; + /// public Task SendIsTyping() => null; - public Task 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; + /// + public Task CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null; + /// public Task Delete() => null; - public override Task Save() => null; + /// + public Task Update() => null; + /// + public Task Modify(Action func) => null; } } diff --git a/ref/Entities/Channels/VoiceChannel.cs b/ref/Entities/Channels/VoiceChannel.cs index c38d6c40b..f1a93ce01 100644 --- a/ref/Entities/Channels/VoiceChannel.cs +++ b/ref/Entities/Channels/VoiceChannel.cs @@ -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 { + public sealed class Properties + { + public int Bitrate { get; set; } + } + + /// public ulong Id { get; } + /// public DiscordClient Client { get; } - public Server Server { get; } + /// + public ModelState State { get; } + /// public ChannelType Type { get; } - public bool IsText { get; } - public bool IsVoice { get; } - public bool IsPrivate { get; } - public bool IsPublic { get; } - public IEnumerable PermissionOverwrites { get; } - public IEnumerable Users { get; } - - public string Name { get; set; } - public int Position { get; set; } - public int Bitrate { get; set; } + /// + public bool IsPrivate => false; + /// + public bool IsPublic => true; + /// + public bool IsText => false; + /// + public bool IsVoice => true; - public Message GetMessage(ulong id) => null; - public PermissionOverwrite? GetPermissionsRule(User user) => null; - public PermissionOverwrite? GetPermissionsRule(Role role) => null; - - public Task> DownloadMessages(int limit) => null; - public Task> DownloadMessages(int limit, ulong? relativeMessageId, Relative relativeDir) => null; - public Task> DownloadInvites() => null; - - public Task SendMessage(string text, bool isTTS = false) => null; - public Task SendFile(string path, string text = null, bool isTTS = false) => null; - public Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false) => null; + /// + public string Name { get; } + /// + public int Position { get; } + /// + public int Bitrate { get; } + /// + public Server Server { get; } + /// + public IEnumerable PermissionOverwrites { get; } - public Task CreateInvite(int? maxAge = 1800, int? maxUses = default(int?), bool tempMembership = false, bool withXkcd = false) => null; + /// + public PermissionOverwrite? GetPermissionOverwrite(User user) => null; + /// + public PermissionOverwrite? GetPermissionOverwrite(Role role) => null; + /// + public Task> GetUsers() => null; + /// + public Task> GetInvites() => null; + + /// + public Task UpdatePermissionOverwrite(User user, ChannelPermissions allow, ChannelPermissions deny) => null; + /// + public Task UpdatePermissionOverwrite(User user, TriStateChannelPermissions permissions) => null; + /// + public Task UpdatePermissionOverwrite(Role role, ChannelPermissions allow, ChannelPermissions deny) => null; + /// + public Task UpdatePermissionOverwrite(Role role, TriStateChannelPermissions permissions) => null; + /// + public Task RemovePermissionOverwrite(User user) => null; + /// + public Task RemovePermissionOverwrite(Role role) => 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; + /// + public Task CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null; + /// public Task Delete() => null; - public Task Save() => null; + /// + public Task Update() => null; + /// + public Task Modify(Action func) => null; } } diff --git a/ref/Entities/IEntity.cs b/ref/Entities/IEntity.cs new file mode 100644 index 000000000..b95312519 --- /dev/null +++ b/ref/Entities/IEntity.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; + +namespace Discord +{ + public interface IEntity : IEntity + { + /// Gets the unique identifier for this object. + TId Id { get; } + } + public interface IEntity + { + /// Gets the DiscordClient that manages this object. + DiscordClient Client { get; } + /// Gets the state of this object. + ModelState State { get; } + + /// Deletes this object. + Task Delete(); + /// Downloads the latest values and updates this object. + Task Update(); + } +} diff --git a/ref/Entities/IModel.cs b/ref/Entities/IModel.cs deleted file mode 100644 index 58c016a27..000000000 --- a/ref/Entities/IModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Threading.Tasks; - -namespace Discord -{ - public interface IModel : IModel - { - TId Id { get; } - } - public interface IModel - { - Task Save(); - } -} diff --git a/ref/Entities/IModifiable.cs b/ref/Entities/IModifiable.cs new file mode 100644 index 000000000..f264c96f2 --- /dev/null +++ b/ref/Entities/IModifiable.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; + +namespace Discord +{ + public interface IModifiable + { + /// Modifies one or more of the properties of this object. + Task Modify(Action func); + } +} diff --git a/ref/Entities/Message.cs b/ref/Entities/Message.cs index f315315fc..ca019da3f 100644 --- a/ref/Entities/Message.cs +++ b/ref/Entities/Message.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace Discord { - public class Message : IModel + public class Message : IEntity { public class Attachment : File { diff --git a/ref/Entities/Profile.cs b/ref/Entities/Profile.cs index 067a58988..73965de65 100644 --- a/ref/Entities/Profile.cs +++ b/ref/Entities/Profile.cs @@ -2,7 +2,7 @@ namespace Discord { - public class Profile : IModel + public class Profile : IEntity { public DiscordClient Client { get; } diff --git a/ref/Entities/Role.cs b/ref/Entities/Role.cs index ae2c92988..b9e35dc46 100644 --- a/ref/Entities/Role.cs +++ b/ref/Entities/Role.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; namespace Discord { - public class Role : IModel, IMentionable + public class Role : IEntity, IMentionable { public DiscordClient Client { get; } diff --git a/ref/Entities/Server.cs b/ref/Entities/Server.cs index 75b98d979..0a81d8737 100644 --- a/ref/Entities/Server.cs +++ b/ref/Entities/Server.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; namespace Discord { - public class Server : IModel + public class Server : IEntity { public class Emoji { @@ -28,7 +28,7 @@ namespace Discord public Role EveryoneRole { get; } public IEnumerable Features { get; } public IEnumerable CustomEmojis { get; } - public IEnumerable Channels { get; } + public IEnumerable Channels { get; } public IEnumerable TextChannels { get; } public IEnumerable VoiceChannels { get; } public IEnumerable Users { get; } diff --git a/ref/Enums/ChannelType.cs b/ref/Enums/ChannelType.cs index 84491070b..5ebbf3aa6 100644 --- a/ref/Enums/ChannelType.cs +++ b/ref/Enums/ChannelType.cs @@ -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 } } diff --git a/ref/Enums/MessageState.cs b/ref/Enums/ModelState.cs similarity index 94% rename from ref/Enums/MessageState.cs rename to ref/Enums/ModelState.cs index 59f65614d..a4477e94d 100644 --- a/ref/Enums/MessageState.cs +++ b/ref/Enums/ModelState.cs @@ -1,6 +1,6 @@ namespace Discord { - public enum MessageState : byte + public enum ModelState : byte { /// Message did not originate from this session, or was successfully sent. Normal = 0, diff --git a/ref/Events/ChannelUpdatedEventArgs.cs b/ref/Events/ChannelUpdatedEventArgs.cs index bc93ba7ae..eee390f37 100644 --- a/ref/Events/ChannelUpdatedEventArgs.cs +++ b/ref/Events/ChannelUpdatedEventArgs.cs @@ -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; } } diff --git a/ref/Events/ChannelUserEventArgs.cs b/ref/Events/ChannelUserEventArgs.cs deleted file mode 100644 index a17856e82..000000000 --- a/ref/Events/ChannelUserEventArgs.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Discord -{ - public class ChannelUserEventArgs - { - public Channel Channel => null; - public User User => null; - } -} diff --git a/ref/Events/TypingEventArgs.cs b/ref/Events/TypingEventArgs.cs new file mode 100644 index 000000000..73d47f688 --- /dev/null +++ b/ref/Events/TypingEventArgs.cs @@ -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; + } + } +}