| @@ -1,4 +0,0 @@ | |||
| |stub| Server Management | |||
| ======================== | |||
| |stub-desc| | |||
| @@ -0,0 +1,53 @@ | |||
| Server Management | |||
| ================= | |||
| Discord.Net will allow you to manage most settings of a Discord server. | |||
| Usage | |||
| ----- | |||
| You can create Channels, Invites, and Roles on a server using the CreateChannel, CreateInvite, and CreateRole function of a Server, respectively. | |||
| You may also edit a server's name, icon, and region. | |||
| .. code-block:: c# | |||
| // Create a Channel and retrieve the Channel object | |||
| var _channel = await _server.CreateChannel("announcements", ChannelType.Text); | |||
| // Create an Invite and retrieve the Invite object | |||
| var _invite = await _server.CreateInvite(maxAge: null, maxUses: 25, tempMembership: false, withXkcd: false); | |||
| // Create a Role and retrieve the Role object | |||
| var _role = await _server.CreateRole(name: "Bots", permissions: null, color: Color.DarkMagenta, isHoisted: false); | |||
| // Edit a server | |||
| var _ioStream = new System.IO.StreamReader("clock-0500-1952.png").BaseStream | |||
| _server.Edit(name: "19:52 | UTC-05:00", region: "east", icon: _ioStream, iconType: ImageType.Png); | |||
| // Prune Users | |||
| var _pruneCount = await _server.PruneUsers(30, true); | |||
| Invite Parameters | |||
| ----------------- | |||
| maxAge: The time (in seconds) until the invite expires. Use null for infinite. | |||
| maxUses: The maximum amount of uses the invite has before it expires. | |||
| tempMembership: Whether or not to kick a user when they disconnect. | |||
| withXkcd: Generate the invite with an XKCD 936 style URL | |||
| Role Parameters | |||
| --------------- | |||
| name: The name of the role | |||
| permissions: A set of ServerPermissions for the role to use by default | |||
| color: The color of the role, recommended to use Discord.Color | |||
| isHoisted: Whether a role's users should be displayed separately from other users in the user list. | |||
| Edit Parameters | |||
| --------------- | |||
| name: The server's name | |||
| region: The region the voice server is hosted in | |||
| icon: A System.IO.Stream that will read an image file | |||
| iconType: The type of image being sent (png/jpeg). | |||
| @@ -0,0 +1,22 @@ | |||
| User Management | |||
| =============== | |||
| Banning | |||
| ------- | |||
| To ban a user, invoke the Ban function on a Server object. | |||
| .. code-block:: c# | |||
| _server.Ban(_user, 30); | |||
| The pruneDays parameter, which defaults to 0, will remove all messages from a user dating back to the specified amount of days. | |||
| Kicking | |||
| ------- | |||
| To kick a user, invoke the Kick function on the User. | |||
| .. code-block:: c# | |||
| _user.Kick(); | |||
| @@ -18,14 +18,16 @@ You can get Discord.Net from NuGet: | |||
| * `Discord.Net`_ | |||
| * `Discord.Net.Commands`_ | |||
| * `Discord.Net.Modules`_ | |||
| * `Discord.Net.Audio`_ | |||
| If you have trouble installing from NuGet, try installing dependencies manually. | |||
| You can also pull the latest source from `GitHub`_ | |||
| .. _Discord.Net: https://www.nuget.org/packages/Discord.Net/0.8.1-beta2 | |||
| .. _Discord.Net.Commands: https://www.nuget.org/packages/Discord.Net.Commands/0.8.1-beta2 | |||
| .. _Discord.Net.Modules: https://www.nuget.org/packages/Discord.Net.Modules/0.8.1-beta2 | |||
| .. _Discord.Net: https://www.nuget.org/packages/Discord.Net | |||
| .. _Discord.Net.Commands: https://www.nuget.org/packages/Discord.Net.Commands | |||
| .. _Discord.Net.Modules: https://www.nuget.org/packages/Discord.Net.Modules | |||
| .. _Discord.Net.Modules: https://www.nuget.org/packages/Discord.Net.Audio | |||
| .. _GitHub: https://github.com/RogueException/Discord.Net/ | |||
| Async | |||
| @@ -29,7 +29,8 @@ This Documentation is **currently undergoing a rewrite**. Some pages (marked wit | |||
| getting_started | |||
| features/logging | |||
| features/management | |||
| features/server-management | |||
| features/user-management | |||
| features/permissions | |||
| features/commands | |||
| features/voice | |||
| @@ -0,0 +1,21 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <PropertyGroup> | |||
| <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | |||
| <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | |||
| </PropertyGroup> | |||
| <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | |||
| <PropertyGroup Label="Globals"> | |||
| <ProjectGuid>5b2afee6-fff6-4ba2-be12-61b283b72ac0</ProjectGuid> | |||
| <RootNamespace>Discord</RootNamespace> | |||
| <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | |||
| <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | |||
| </PropertyGroup> | |||
| <PropertyGroup> | |||
| <SchemaVersion>2.0</SchemaVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | |||
| <ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> | |||
| </PropertyGroup> | |||
| <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | |||
| </Project> | |||
| @@ -0,0 +1,75 @@ | |||
| using Discord.Net.Rest; | |||
| using Discord.Net.WebSockets; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.IO; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> Provides a connection to the DiscordApp service. </summary> | |||
| public class DiscordClient : IDisposable | |||
| { | |||
| public event EventHandler<LogMessageEventArgs> Log = delegate { }; | |||
| public event EventHandler LoggedIn = delegate { }; | |||
| public event EventHandler LoggedOut = delegate { }; | |||
| public event EventHandler Connected = delegate { }; | |||
| public event EventHandler Disconnected = delegate { }; | |||
| public event EventHandler<ServerEventArgs> VoiceConnected = delegate { }; | |||
| public event EventHandler<ServerEventArgs> VoiceDisconnected = delegate { }; | |||
| public event EventHandler<ChannelEventArgs> ChannelCreated = delegate { }; | |||
| public event EventHandler<ChannelUpdatedEventArgs> ChannelUpdated = delegate { }; | |||
| public event EventHandler<ChannelEventArgs> ChannelDestroyed = delegate { }; | |||
| public event EventHandler<MessageEventArgs> MessageAcknowledged = delegate { }; | |||
| public event EventHandler<MessageEventArgs> MessageDeleted = delegate { }; | |||
| public event EventHandler<MessageEventArgs> MessageReceived = delegate { }; | |||
| public event EventHandler<MessageEventArgs> MessageSent = delegate { }; | |||
| public event EventHandler<MessageUpdatedEventArgs> MessageUpdated = delegate { }; | |||
| public event EventHandler<ProfileUpdatedEventArgs> ProfileUpdated = delegate { }; | |||
| public event EventHandler<RoleEventArgs> RoleCreated = delegate { }; | |||
| public event EventHandler<RoleUpdatedEventArgs> RoleUpdated = delegate { }; | |||
| public event EventHandler<RoleEventArgs> RoleDeleted = delegate { }; | |||
| public event EventHandler<ServerEventArgs> JoinedServer = delegate { }; | |||
| public event EventHandler<ServerEventArgs> LeftServer = delegate { }; | |||
| public event EventHandler<ServerEventArgs> ServerAvailable = delegate { }; | |||
| public event EventHandler<ServerUpdatedEventArgs> ServerUpdated = delegate { }; | |||
| public event EventHandler<ServerEventArgs> ServerUnavailable = delegate { }; | |||
| public event EventHandler<UserEventArgs> UserBanned = 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 { }; | |||
| public event EventHandler<UserEventArgs> UserUnbanned = delegate { }; | |||
| public MessageQueue MessageQueue { get; } | |||
| public IRestClient RestClient { get; } | |||
| public GatewaySocket GatewaySocket { get; } | |||
| public Profile CurrentUser { get; } | |||
| public DiscordClient() { } | |||
| public DiscordClient(DiscordConfig config) { } | |||
| public Task Login(string token) => null; | |||
| public Task Logout() => null; | |||
| public Task Connect() => null; | |||
| public Task Connect(int connectionId, int totalConnections) => null; | |||
| public Task Disconnect() => null; | |||
| public Task<IEnumerable<PrivateChannel>> GetPrivateChannels() => null; | |||
| public Task<PrivateChannel> GetPrivateChannel(ulong userId) => null; | |||
| public Task<Invite> GetInvite(string inviteIdOrXkcd) => null; | |||
| public Task<IReadOnlyList<Region>> GetRegions() => null; | |||
| public Task<Region> GetRegion(string id) => null; | |||
| public Task<IEnumerable<Server>> GetServers() => null; | |||
| public Task<Server> GetServer(ulong id) => null; | |||
| public Task<PrivateChannel> CreatePrivateChannel(ulong userId) => null; | |||
| public Task<Server> CreateServer(string name, Region region, ImageType iconType = ImageType.None, Stream icon = null) => null; | |||
| public void Dispose() { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,65 @@ | |||
| using Discord.Net.Rest; | |||
| using Discord.Net.WebSockets; | |||
| using System.Reflection; | |||
| namespace Discord | |||
| { | |||
| public class DiscordConfig | |||
| { | |||
| public const int MaxMessageSize = 2000; | |||
| public const int MaxMessagesPerBatch = 100; | |||
| public const string LibName = "Discord.Net"; | |||
| public static string LibVersion => typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown"; | |||
| public const string LibUrl = "https://github.com/RogueException/Discord.Net"; | |||
| public const string ClientAPIUrl = "https://discordapp.com/api/"; | |||
| public const string CDNUrl = "https://cdn.discordapp.com/"; | |||
| public const string InviteUrl = "https://discord.gg/"; | |||
| /// <summary> Gets or sets name of your application, used in the user agent. </summary> | |||
| public string AppName { get; set; } = null; | |||
| /// <summary> Gets or sets url to your application, used in the user agent. </summary> | |||
| public string AppUrl { get; set; } = null; | |||
| /// <summary> Gets or sets the version of your application, used in the user agent. </summary> | |||
| public string AppVersion { get; set; } = null; | |||
| /// <summary> Gets or sets the minimum log level severity that will be sent to the LogMessage event. </summary> | |||
| public LogSeverity LogLevel { get; set; } = LogSeverity.Info; | |||
| /// <summary> Gets or sets the time (in milliseconds) to wait for the websocket to connect and initialize. </summary> | |||
| public int ConnectionTimeout { get; set; } = 30000; | |||
| /// <summary> Gets or sets the time (in milliseconds) to wait after an unexpected disconnect before reconnecting. </summary> | |||
| public int ReconnectDelay { get; set; } = 1000; | |||
| /// <summary> Gets or sets the time (in milliseconds) to wait after an reconnect fails before retrying. </summary> | |||
| public int FailedReconnectDelay { get; set; } = 15000; | |||
| //Performance | |||
| /// <summary> Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero disables the message cache entirely. </summary> | |||
| public int MessageCacheSize { get; set; } = 100; | |||
| /// <summary> | |||
| /// Gets or sets whether the permissions cache should be used. | |||
| /// This makes operations such as User.GetPermissions(Channel), User.ServerPermissions, Channel.GetUser, and Channel.Members much faster while increasing memory usage. | |||
| /// </summary> | |||
| public bool UsePermissionsCache { get; set; } = true; | |||
| /// <summary> Gets or sets whether the a copy of a model is generated on an update event to allow you to check which properties changed. </summary> | |||
| public bool EnablePreUpdateEvents { get; set; } = true; | |||
| /// <summary> | |||
| /// Gets or sets the max number of users a server may have for offline users to be included in the READY packet. Max is 250. | |||
| /// Decreasing this may reduce CPU usage while increasing login time and network usage. | |||
| /// </summary> | |||
| public int LargeThreshold { get; set; } = 250; | |||
| //Engines | |||
| /// <summary> Gets or sets the REST engine to use.. Defaults to DefaultRestClientProvider, which uses .Net's HttpClient class. </summary> | |||
| public IRestClientProvider RestClientProvider { get; set; } = null; | |||
| /// <summary> | |||
| /// Gets or sets the WebSocket engine to use. Defaults to DefaultWebSocketProvider, which uses .Net's WebSocketClient class. | |||
| /// WebSockets are only used if DiscordClient.Connect() is called. | |||
| /// </summary> | |||
| public IWebSocketProvider WebSocketProvider { get; set; } = null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public interface IChannel : IEntity<ulong> | |||
| { | |||
| /// <summary> Gets the type flags for this channel. </summary> | |||
| ChannelType Type { get; } | |||
| /// <summary> Gets the name of this channel. </summary> | |||
| string Name { get; } | |||
| /// <summary> Gets a user in this channel with the given id. </summary> | |||
| Task<IUser> GetUser(ulong id); | |||
| /// <summary> Gets a collection of all users in this channel. </summary> | |||
| Task<IEnumerable<IUser>> GetUsers(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,43 @@ | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public interface IPublicChannel : IChannel | |||
| { | |||
| /// <summary> Gets the server this channel is a member of. </summary> | |||
| Server Server { get; } | |||
| /// <summary> Gets a collection of permission overwrites for this channel. </summary> | |||
| IEnumerable<PermissionOverwriteEntry> PermissionOverwrites { get; } | |||
| /// <summary> Gets the position of this public channel relative to others of the same type. </summary> | |||
| int Position { get; } | |||
| /// <summary> Gets a user in this channel with the given id. </summary> | |||
| new Task<ServerUser> GetUser(ulong id); | |||
| /// <summary> Gets a collection of all users in this channel. </summary> | |||
| new Task<IEnumerable<ServerUser>> GetUsers(); | |||
| /// <summary> Gets the permission overwrite for a specific user, or null if one does not exist. </summary> | |||
| OverwritePermissions? GetPermissionOverwrite(ServerUser user); | |||
| /// <summary> Gets the permission overwrite for a specific role, or null if one does not exist. </summary> | |||
| OverwritePermissions? 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(ServerUser user, OverwritePermissions permissions); | |||
| /// <summary> Adds or updates the permission overwrite for the given role. </summary> | |||
| Task UpdatePermissionOverwrite(Role role, OverwritePermissions permissions); | |||
| /// <summary> Removes the permission overwrite for the given user, if one exists. </summary> | |||
| Task RemovePermissionOverwrite(ServerUser 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); | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| using System.Collections.Generic; | |||
| using System.IO; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public interface ITextChannel : IChannel | |||
| { | |||
| /// <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 = DiscordConfig.MaxMessagesPerBatch); | |||
| /// <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 = DiscordConfig.MaxMessagesPerBatch, 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(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,55 @@ | |||
| using System.Collections.Generic; | |||
| using System.IO; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class PrivateChannel : ITextChannel, IChannel | |||
| { | |||
| /// <inheritdoc /> | |||
| public DiscordClient Discord { get; } | |||
| /// <inheritdoc /> | |||
| public EntityState State { get; } | |||
| /// <inheritdoc /> | |||
| public ulong Id { get; } | |||
| /// <inheritdoc /> | |||
| public PrivateUser Recipient { get; } | |||
| /// <inheritdoc /> | |||
| public PrivateUser CurrentUser { get; } | |||
| /// <inheritdoc /> | |||
| ChannelType IChannel.Type => ChannelType.Private | ChannelType.Text; | |||
| /// <inheritdoc /> | |||
| public string Name { get; } | |||
| /// <inheritdoc /> | |||
| public Task<PrivateUser> GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| Task<IUser> IChannel.GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| public Task<IEnumerable<PrivateUser>> GetUsers() => null; | |||
| /// <inheritdoc /> | |||
| Task<IEnumerable<IUser>> IChannel.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<Message> SendMessage(string text, 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; | |||
| /// <inheritdoc /> | |||
| public Task Update() => null; | |||
| /// <inheritdoc /> | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,91 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.IO; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class TextChannel : ITextChannel, IMentionable, IModifiable<TextChannel.Properties> | |||
| { | |||
| public sealed class Properties | |||
| { | |||
| public string Name { get; } | |||
| public string Topic { get; } | |||
| public int Position { get; } | |||
| } | |||
| /// <inheritdoc /> | |||
| public EntityState State { get; } | |||
| /// <inheritdoc /> | |||
| public ulong Id { get; } | |||
| /// <inheritdoc /> | |||
| public Server Server { get; } | |||
| /// <inheritdoc /> | |||
| public DiscordClient Discord { get; } | |||
| /// <inheritdoc /> | |||
| public ChannelType Type => ChannelType.Public | ChannelType.Text; | |||
| /// <inheritdoc /> | |||
| public string Name { get; } | |||
| /// <inheritdoc /> | |||
| public string Topic { get; } | |||
| /// <inheritdoc /> | |||
| public int Position { get; } | |||
| /// <inheritdoc /> | |||
| public string Mention { get; } | |||
| /// <inheritdoc /> | |||
| public IEnumerable<PermissionOverwriteEntry> PermissionOverwrites { get; } | |||
| /// <inheritdoc /> | |||
| public OverwritePermissions? GetPermissionOverwrite(ServerUser user) => null; | |||
| /// <inheritdoc /> | |||
| public OverwritePermissions? GetPermissionOverwrite(Role role) => null; | |||
| /// <inheritdoc /> | |||
| public Task<ServerUser> GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| Task<IUser> IChannel.GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| public Task<IEnumerable<ServerUser>> GetUsers() => null; | |||
| /// <inheritdoc /> | |||
| Task<IEnumerable<IUser>> IChannel.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<IEnumerable<Invite>> GetInvites() => null; | |||
| /// <inheritdoc /> | |||
| public Task UpdatePermissionOverwrite(ServerUser user, OverwritePermissions permissions) => null; | |||
| /// <inheritdoc /> | |||
| public Task UpdatePermissionOverwrite(Role role, OverwritePermissions permissions) => null; | |||
| /// <inheritdoc /> | |||
| public Task RemovePermissionOverwrite(ServerUser user) => null; | |||
| /// <inheritdoc /> | |||
| public Task RemovePermissionOverwrite(Role role) => null; | |||
| /// <inheritdoc /> | |||
| public Task<Message> SendMessage(string text, 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; | |||
| /// <inheritdoc /> | |||
| public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null; | |||
| /// <inheritdoc /> | |||
| public Task Update() => null; | |||
| /// <inheritdoc /> | |||
| public Task Modify(Action<Properties> func) => null; | |||
| /// <inheritdoc /> | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,74 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class VoiceChannel : IPublicChannel, IModifiable<VoiceChannel.Properties> | |||
| { | |||
| public sealed class Properties | |||
| { | |||
| public string Name { get; } | |||
| public int Bitrate { get; set; } | |||
| public int Position { get; } | |||
| } | |||
| /// <inheritdoc /> | |||
| public ulong Id { get; } | |||
| /// <inheritdoc /> | |||
| public EntityState State { get; } | |||
| /// <inheritdoc /> | |||
| public Server Server { get; } | |||
| /// <inheritdoc /> | |||
| public DiscordClient Discord { get; } | |||
| /// <inheritdoc /> | |||
| ChannelType IChannel.Type => ChannelType.Public | ChannelType.Voice; | |||
| /// <inheritdoc /> | |||
| public string Name { get; } | |||
| /// <inheritdoc /> | |||
| public int Position { get; } | |||
| /// <inheritdoc /> | |||
| public int Bitrate { get; } | |||
| /// <inheritdoc /> | |||
| public string Mention { get; } | |||
| /// <inheritdoc /> | |||
| public IEnumerable<PermissionOverwriteEntry> PermissionOverwrites { get; } | |||
| /// <inheritdoc /> | |||
| public OverwritePermissions? GetPermissionOverwrite(ServerUser user) => null; | |||
| /// <inheritdoc /> | |||
| public OverwritePermissions? GetPermissionOverwrite(Role role) => null; | |||
| /// <inheritdoc /> | |||
| public Task<ServerUser> GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| Task<IUser> IChannel.GetUser(ulong id) => null; | |||
| /// <inheritdoc /> | |||
| public Task<IEnumerable<ServerUser>> GetUsers() => null; | |||
| /// <inheritdoc /> | |||
| Task<IEnumerable<IUser>> IChannel.GetUsers() => null; | |||
| /// <inheritdoc /> | |||
| public Task<IEnumerable<Invite>> GetInvites() => null; | |||
| /// <inheritdoc /> | |||
| public Task UpdatePermissionOverwrite(ServerUser user, OverwritePermissions permissions) => null; | |||
| /// <inheritdoc /> | |||
| public Task UpdatePermissionOverwrite(Role role, OverwritePermissions permissions) => null; | |||
| /// <inheritdoc /> | |||
| public Task RemovePermissionOverwrite(ServerUser user) => null; | |||
| /// <inheritdoc /> | |||
| public Task RemovePermissionOverwrite(Role role) => null; | |||
| /// <inheritdoc /> | |||
| public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null; | |||
| /// <inheritdoc /> | |||
| public Task Update() => null; | |||
| /// <inheritdoc /> | |||
| public Task Modify(Action<Properties> func) => null; | |||
| /// <inheritdoc /> | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| namespace Discord | |||
| { | |||
| public class Color | |||
| { | |||
| public static readonly Color Default = new Color(0); | |||
| public uint RawValue { get; } | |||
| public Color(uint rawValue) { } | |||
| public Color(byte r, byte g, byte b) { } | |||
| public Color(float r, float g, float b) { } | |||
| public byte R { get; } | |||
| public byte G { get; } | |||
| public byte B { get; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,20 @@ | |||
| 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 Discord { get; } | |||
| /// <summary> Gets the state of this object. </summary> | |||
| EntityState State { get; } | |||
| /// <summary> Downloads the latest values and updates this object. </summary> | |||
| Task Update(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,7 @@ | |||
| namespace Discord | |||
| { | |||
| public interface IMentionable | |||
| { | |||
| string Mention { get; } | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -0,0 +1,37 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class BasicInvite : IEntity<string> | |||
| { | |||
| public class TargetInfo | |||
| { | |||
| public ulong Id { get; } | |||
| public string Name { get; } | |||
| } | |||
| public class InviterInfo | |||
| { | |||
| public ulong Id { get; } | |||
| public string Name { get; } | |||
| public ushort Discriminator { get; } | |||
| public string AvatarId { get; } | |||
| public string AvatarUrl { get; } | |||
| } | |||
| string IEntity<string>.Id => Code; | |||
| public DiscordClient Discord { get; } | |||
| public EntityState State { get; } | |||
| public string Code { get; } | |||
| public string XkcdCode { get; } | |||
| public TargetInfo Server { get; } | |||
| public TargetInfo Channel { get; } | |||
| public string Url { get; } | |||
| public Task Accept() => null; | |||
| public virtual Task Update() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| using System; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class Invite : BasicInvite | |||
| { | |||
| public int? MaxAge { get; } | |||
| public int Uses { get; } | |||
| public int? MaxUses { get; } | |||
| public bool IsRevoked { get; } | |||
| public bool IsTemporary { get; } | |||
| public DateTime CreatedAt { get; } | |||
| public override Task Update() => null; | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,68 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class Message : IEntity<ulong> | |||
| { | |||
| public class Attachment : File | |||
| { | |||
| public string Id { get; } | |||
| public int Size { get; } | |||
| public string Filename { get; } | |||
| } | |||
| public class Embed | |||
| { | |||
| public string Url { get; } | |||
| public string Type { get; } | |||
| public string Title { get; } | |||
| public string Description { get; } | |||
| public EmbedLink Author { get; } | |||
| public EmbedLink Provider { get; } | |||
| public File Thumbnail { get; } | |||
| public File Video { get; } | |||
| } | |||
| public class EmbedLink | |||
| { | |||
| public string Url { get; } | |||
| public string Name { get; } | |||
| } | |||
| public class File | |||
| { | |||
| public string Url { get; } | |||
| public string ProxyUrl { get; } | |||
| public int? Width { get; } | |||
| public int? Height { get; } | |||
| } | |||
| public ulong Id { get; } | |||
| public DiscordClient Discord { get; } | |||
| public EntityState State { get; } | |||
| public ITextChannel Channel { get; } | |||
| public IUser User { get; } | |||
| public bool IsTTS { get; } | |||
| public string RawText { get; } | |||
| public string Text { get; } | |||
| public DateTime Timestamp { get; } | |||
| public DateTime? EditedTimestamp { get; } | |||
| public Attachment[] Attachments { get; } | |||
| public Embed[] Embeds { get; } | |||
| public IReadOnlyList<ServerUser> MentionedUsers { get; } | |||
| public IReadOnlyList<IPublicChannel> MentionedChannels { get; } | |||
| public IReadOnlyList<Role> MentionedRoles { get; } | |||
| public Server Server => null; | |||
| public bool IsAuthor => false; | |||
| public bool IsMentioningMe(bool includeRoles = false) => false; | |||
| public Task Update() => null; | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,53 @@ | |||
| namespace Discord | |||
| { | |||
| public struct ChannelPermissions | |||
| { | |||
| public static ChannelPermissions None { get; } | |||
| public static ChannelPermissions TextOnly { get; } | |||
| public static ChannelPermissions PrivateOnly { get; } | |||
| public static ChannelPermissions VoiceOnly { get; } | |||
| public static ChannelPermissions All(ChannelType channelType) => default(ChannelPermissions); | |||
| public uint RawValue { get; } | |||
| public bool CreateInstantInvite { get; } | |||
| public bool ManagePermission { get; } | |||
| public bool ManageChannel { get; } | |||
| public bool ReadMessages { get; } | |||
| public bool SendMessages { get; } | |||
| public bool SendTTSMessages { get; } | |||
| public bool ManageMessages { get; } | |||
| public bool EmbedLinks { get; } | |||
| public bool AttachFiles { get; } | |||
| public bool ReadMessageHistory { get; } | |||
| public bool MentionEveryone { get; } | |||
| public bool Connect { get; } | |||
| public bool Speak { get; } | |||
| public bool MuteMembers { get; } | |||
| public bool DeafenMembers { get; } | |||
| public bool MoveMembers { get; } | |||
| public bool UseVoiceActivation { get; } | |||
| public ChannelPermissions(bool? createInstantInvite = null, bool? managePermissions = null, | |||
| bool? manageChannel = null, bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null) | |||
| : this() | |||
| { | |||
| } | |||
| public ChannelPermissions(uint rawValue) | |||
| : this() | |||
| { | |||
| } | |||
| public ChannelPermissions Modify(bool? createInstantInvite = null, bool? managePermissions = null, | |||
| bool? manageChannel = null, bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, | |||
| bool? manageMessages = null, bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, | |||
| bool? mentionEveryone = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null) | |||
| => default(ChannelPermissions); | |||
| } | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| namespace Discord | |||
| { | |||
| public struct OverwritePermissions | |||
| { | |||
| public static OverwritePermissions InheritAll { get; } | |||
| public uint AllowValue { get; } | |||
| public uint DenyValue { get; } | |||
| public PermValue CreateInstantInvite { get; } | |||
| public PermValue ManagePermissions { get; } | |||
| public PermValue ManageChannel { get; } | |||
| public PermValue ReadMessages { get; } | |||
| public PermValue SendMessages { get; } | |||
| public PermValue SendTTSMessages { get; } | |||
| public PermValue ManageMessages { get; } | |||
| public PermValue EmbedLinks { get; } | |||
| public PermValue AttachFiles { get; } | |||
| public PermValue ReadMessageHistory { get; } | |||
| public PermValue MentionEveryone { get; } | |||
| public PermValue Connect { get; } | |||
| public PermValue Speak { get; } | |||
| public PermValue MuteMembers { get; } | |||
| public PermValue DeafenMembers { get; } | |||
| public PermValue MoveMembers { get; } | |||
| public PermValue UseVoiceActivation { get; } | |||
| public OverwritePermissions(PermValue? createInstantInvite = null, PermValue? managePermissions = null, | |||
| PermValue? manageChannel = null, PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, | |||
| PermValue? manageMessages = null, PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, | |||
| PermValue? mentionEveryone = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null, | |||
| PermValue? moveMembers = null, PermValue? useVoiceActivation = null) | |||
| : this() | |||
| { | |||
| } | |||
| public OverwritePermissions(uint allow = 0, uint deny = 0) | |||
| : this() | |||
| { | |||
| } | |||
| public OverwritePermissions Modify(PermValue? createInstantInvite = null, PermValue? managePermissions = null, | |||
| PermValue? manageChannel = null, PermValue? readMessages = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, | |||
| PermValue? manageMessages = null, PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, | |||
| PermValue? mentionEveryone = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null, | |||
| PermValue? moveMembers = null, PermValue? useVoiceActivation = null) | |||
| => default(OverwritePermissions); | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Discord | |||
| { | |||
| public struct PermissionOverwriteEntry | |||
| { | |||
| public PermissionTarget TargetType { get; } | |||
| public ulong TargetId { get; } | |||
| public OverwritePermissions Permissions { get; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,55 @@ | |||
| namespace Discord | |||
| { | |||
| public struct ServerPermissions | |||
| { | |||
| public static ServerPermissions None { get; } | |||
| public static ServerPermissions All { get; } | |||
| public uint RawValue { get; } | |||
| public bool CreateInstantInvite { get; } | |||
| public bool BanMembers { get; } | |||
| public bool KickMembers { get; } | |||
| public bool ManageRoles { get; } | |||
| public bool ManageChannels { get; } | |||
| public bool ManageServer { get; } | |||
| public bool ReadMessages { get; } | |||
| public bool SendMessages { get; } | |||
| public bool SendTTSMessages { get; } | |||
| public bool ManageMessages { get; } | |||
| public bool EmbedLinks { get; } | |||
| public bool AttachFiles { get; } | |||
| public bool ReadMessageHistory { get; } | |||
| public bool MentionEveryone { get; } | |||
| public bool Connect { get; } | |||
| public bool Speak { get; } | |||
| public bool MuteMembers { get; } | |||
| public bool DeafenMembers { get; } | |||
| public bool MoveMembers { get; } | |||
| public bool UseVoiceActivation { get; } | |||
| public ServerPermissions(bool? createInstantInvite = null, bool? manageRoles = null, | |||
| bool? kickMembers = null, bool? banMembers = null, bool? manageChannel = null, bool? manageServer = null, | |||
| bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null) | |||
| : this() | |||
| { | |||
| } | |||
| public ServerPermissions(uint rawValue) | |||
| : this() | |||
| { | |||
| } | |||
| public ServerPermissions Modify(bool? createInstantInvite = null, bool? manageRoles = null, | |||
| bool? kickMembers = null, bool? banMembers = null, bool? manageChannel = null, bool? manageServer = null, | |||
| bool? readMessages = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||
| bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||
| bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||
| bool? moveMembers = null, bool? useVoiceActivation = null) | |||
| => default(ServerPermissions); | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class Profile : IEntity<ulong> | |||
| { | |||
| public ulong Id { get; } | |||
| public DiscordClient Discord { get; } | |||
| public EntityState State { get; } | |||
| public string AvatarId { get; } | |||
| public string AvatarUrl { get; } | |||
| public ushort Discriminator { get; } | |||
| public string CurrentGame { get; } | |||
| public UserStatus Status { get; } | |||
| public string Mention { get; } | |||
| public string Email { get; } | |||
| public bool? IsVerified { get; } | |||
| public string Name { get; set; } | |||
| public Task Update() => null; | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| namespace Discord | |||
| { | |||
| public class Region | |||
| { | |||
| public string Id { get; } | |||
| public string Name { get; } | |||
| public string Hostname { get; } | |||
| public int Port { get; } | |||
| public bool Vip { get; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,29 @@ | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class Role : IEntity<ulong>, IMentionable | |||
| { | |||
| public ulong Id { get; } | |||
| public DiscordClient Discord { get; } | |||
| public EntityState State { get; } | |||
| public Server Server { get; } | |||
| public string Name { get; } | |||
| public bool IsHoisted { get; } | |||
| public int Position { get; } | |||
| public bool IsManaged { get; } | |||
| public ServerPermissions Permissions { get; } | |||
| public Color Color { get; } | |||
| public bool IsEveryone { get; } | |||
| public IEnumerable<ServerUser> Members { get; } | |||
| public string Mention { get; } | |||
| public Task Update() => null; | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,67 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class Server : IEntity<ulong> | |||
| { | |||
| public class Emoji | |||
| { | |||
| public string Id { get; } | |||
| public string Name { get; } | |||
| public bool IsManaged { get; } | |||
| public bool RequireColons { get; } | |||
| public IEnumerable<Role> Roles { get; } | |||
| } | |||
| public ulong Id { get; } | |||
| public DiscordClient Discord { get; } | |||
| public EntityState State { get; } | |||
| public ServerUser CurrentUser { get; } | |||
| public string IconId { get; } | |||
| public string SplashId { get; } | |||
| public string IconUrl { get; } | |||
| public string SplashUrl { get; } | |||
| public int ChannelCount { get; } | |||
| public int UserCount { get; } | |||
| public int RoleCount { get; } | |||
| public TextChannel DefaultChannel { get; } | |||
| public Role EveryoneRole { get; } | |||
| public IEnumerable<string> Features { get; } | |||
| public IEnumerable<Emoji> CustomEmojis { get; } | |||
| public IEnumerable<IChannel> Channels { get; } | |||
| public IEnumerable<TextChannel> TextChannels { get; } | |||
| public IEnumerable<VoiceChannel> VoiceChannels { get; } | |||
| public IEnumerable<ServerUser> Users { get; } | |||
| public IEnumerable<Role> Roles { get; } | |||
| public string Name { get; set; } | |||
| public Region Region { get; set; } | |||
| public int AFKTimeout { get; set; } | |||
| public DateTime JoinedAt { get; set; } | |||
| public ServerUser Owner { get; set; } | |||
| public VoiceChannel AFKChannel { get; set; } | |||
| public Task<IPublicChannel> GetChannel(ulong id) => null; | |||
| public Task<IPublicChannel> GetChannel(string mention) => null; | |||
| public Task<Role> GetRole(ulong id) => null; | |||
| public Task<ServerUser> GetUser(ulong id) => null; | |||
| public Task<ServerUser> GetUser(string name, ushort discriminator) => null; | |||
| public Task<ServerUser> GetUser(string mention) => null; | |||
| public Task<IEnumerable<ServerUser>> GetBans() => null; | |||
| public Task<IEnumerable<Invite>> GetInvites() => null; | |||
| public Task<TextChannel> CreateTextChannel(string name) => null; | |||
| public Task<VoiceChannel> CreateVoiceChannel(string name) => null; | |||
| public Task<Invite> CreateInvite(int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false) => null; | |||
| public Task<Role> CreateRole(string name, ServerPermissions? permissions = null, Color color = null, bool isHoisted = false) => null; | |||
| public Task<int> PruneUsers(int days = 30, bool simulate = false) => null; | |||
| public Task Update() => null; | |||
| public Task Leave() => null; | |||
| public Task Delete() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,19 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public interface IUser : IEntity<ulong>, IMentionable | |||
| { | |||
| bool IsPrivate { get; } | |||
| string Name { get; } | |||
| ushort Discriminator { get; } | |||
| bool IsBot { get; } | |||
| string AvatarId { get; } | |||
| string AvatarUrl { get; } | |||
| string CurrentGame { get; } | |||
| UserStatus Status { get; } | |||
| Task<PrivateChannel> GetPrivateChannel(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,43 @@ | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| //TODO: Should this be linked directly to the Profile when it represents us, instead of maintaining a cache of values? | |||
| public class PrivateUser : IUser | |||
| { | |||
| /// <inheritdoc /> | |||
| public EntityState State { get; internal set; } | |||
| /// <inheritdoc /> | |||
| public ulong Id { get; } | |||
| /// <summary> Returns the private channel for this user. </summary> | |||
| public PrivateChannel Channel { get; } | |||
| /// <inheritdoc /> | |||
| bool IUser.IsPrivate => true; | |||
| /// <inheritdoc /> | |||
| public string Name { get; } | |||
| /// <inheritdoc /> | |||
| public ushort Discriminator { get; } | |||
| /// <inheritdoc /> | |||
| public bool IsBot { get; } | |||
| /// <inheritdoc /> | |||
| public string AvatarId { get; } | |||
| /// <inheritdoc /> | |||
| public string CurrentGame { get; } | |||
| /// <inheritdoc /> | |||
| public UserStatus Status { get; } | |||
| /// <inheritdoc /> | |||
| public DiscordClient Discord => Channel.Discord; | |||
| /// <inheritdoc /> | |||
| public string AvatarUrl { get; } | |||
| /// <inheritdoc /> | |||
| public string Mention { get; } | |||
| /// <inheritdoc /> | |||
| Task<PrivateChannel> IUser.GetPrivateChannel() => Task.FromResult(Channel); | |||
| public Task Update() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,73 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| public class ServerUser : IUser | |||
| { | |||
| /// <inheritdoc /> | |||
| public EntityState State { get; } | |||
| /// <inheritdoc /> | |||
| public ulong Id { get; } | |||
| /// <summary> Returns the private channel for this user. </summary> | |||
| public Server Server { get; } | |||
| /// <inheritdoc /> | |||
| bool IUser.IsPrivate => false; | |||
| /// <inheritdoc /> | |||
| public string Name { get; } | |||
| /// <inheritdoc /> | |||
| public ushort Discriminator { get; } | |||
| /// <inheritdoc /> | |||
| public bool IsBot { get; } | |||
| /// <inheritdoc /> | |||
| public string AvatarId { get; } | |||
| /// <inheritdoc /> | |||
| public string CurrentGame { get; } | |||
| /// <inheritdoc /> | |||
| public UserStatus Status { get; } | |||
| /// <inheritdoc /> | |||
| public DateTime JoinedAt { get; } | |||
| /// <inheritdoc /> | |||
| public IReadOnlyList<Role> Roles { get; } | |||
| /// <summary> Returns true if this user has marked themselves as muted. </summary> | |||
| public bool IsSelfMuted { get; } | |||
| /// <summary> Returns true if this user has marked themselves as deafened. </summary> | |||
| public bool IsSelfDeafened { get; } | |||
| /// <summary> Returns true if the server is blocking audio from this user. </summary> | |||
| public bool IsServerMuted { get; } | |||
| /// <summary> Returns true if the server is blocking audio to this user. </summary> | |||
| public bool IsServerDeafened { get; } | |||
| /// <summary> Returns true if the server is temporarily blocking audio to/from this user. </summary> | |||
| public bool IsServerSuppressed { get; } | |||
| /// <summary> Gets this user's current voice channel. </summary> | |||
| public VoiceChannel VoiceChannel { get; } | |||
| /// <inheritdoc /> | |||
| public DiscordClient Discord { get; } | |||
| /// <inheritdoc /> | |||
| public string AvatarUrl { get; } | |||
| /// <inheritdoc /> | |||
| public string Mention { get; } | |||
| public ServerPermissions ServerPermissions { get; } | |||
| public ChannelPermissions GetPermissions(IPublicChannel channel) => default(ChannelPermissions); | |||
| /// <inheritdoc /> | |||
| public Task<PrivateChannel> GetPrivateChannel() => null; | |||
| public Task<IEnumerable<IPublicChannel>> GetChannels() => null; | |||
| public bool HasRole(Role role) => false; | |||
| public Task AddRoles(params Role[] roles) => null; | |||
| public Task RemoveRoles(params Role[] roles) => null; | |||
| public Task Update() => null; | |||
| public Task Kick() => null; | |||
| public Task Ban(int pruneDays = 0) => null; | |||
| public Task Unban() => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| [Flags] | |||
| public enum ChannelType : byte | |||
| { | |||
| Public = 0x01, | |||
| Private = 0x02, | |||
| Text = 0x10, | |||
| Voice = 0x20 | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| namespace Discord | |||
| { | |||
| public enum ConnectionState | |||
| { | |||
| Disconnected, | |||
| Connecting, | |||
| Connected, | |||
| Disconnecting | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| namespace Discord | |||
| { | |||
| public enum EntityState : byte | |||
| { | |||
| /// <summary> Object is not attached to a cache manager nor receiving live updates. </summary> | |||
| Detached = 0, | |||
| /// <summary> Object is attached to a cache manager and receiving live updates. </summary> | |||
| Attached, | |||
| /// <summary> Object was deleted. </summary> | |||
| Deleted, | |||
| /// <summary> Object is currently waiting to be created. </summary> | |||
| Queued, | |||
| /// <summary> Object's creation was aborted. </summary> | |||
| Aborted, | |||
| /// <summary> Object's creation failed. </summary> | |||
| Failed | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Discord | |||
| { | |||
| public enum ImageType | |||
| { | |||
| None, | |||
| Jpeg, | |||
| Png | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| namespace Discord | |||
| { | |||
| public enum LogSeverity | |||
| { | |||
| Critical = 0, | |||
| Error = 1, | |||
| Warning = 2, | |||
| Info = 3, | |||
| Verbose = 4, | |||
| Debug = 5 | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Discord | |||
| { | |||
| public enum PermValue | |||
| { | |||
| Allow, | |||
| Deny, | |||
| Inherit | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace Discord | |||
| { | |||
| public enum PermissionTarget | |||
| { | |||
| Role, | |||
| User | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace Discord | |||
| { | |||
| public enum Relative | |||
| { | |||
| Before, | |||
| After | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Discord | |||
| { | |||
| public enum UserStatus | |||
| { | |||
| Online, | |||
| Idle, | |||
| Offline | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class ChannelEventArgs : EventArgs | |||
| { | |||
| public IChannel Channel => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class ChannelUpdatedEventArgs : EventArgs | |||
| { | |||
| public IChannel Before => null; | |||
| public IChannel After => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class DisconnectedEventArgs : EventArgs | |||
| { | |||
| public bool WasUnexpected => false; | |||
| public Exception Exception => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class LogMessageEventArgs : EventArgs | |||
| { | |||
| public LogSeverity Severity => default(LogSeverity); | |||
| public string Source => null; | |||
| public string Message => null; | |||
| public Exception Exception => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class MessageEventArgs : EventArgs | |||
| { | |||
| public Message Message => null; | |||
| public IUser User => null; | |||
| public ITextChannel Channel => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class MessageUpdatedEventArgs : EventArgs | |||
| { | |||
| public Message Before => null; | |||
| public Message After => null; | |||
| public IUser User => null; | |||
| public ITextChannel Channel => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class ProfileUpdatedEventArgs : EventArgs | |||
| { | |||
| public Profile Before => null; | |||
| public Profile After => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class RoleEventArgs : EventArgs | |||
| { | |||
| public Role Role => null; | |||
| public Server Server => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class RoleUpdatedEventArgs : EventArgs | |||
| { | |||
| public Role Before => null; | |||
| public Role After => null; | |||
| public Server Server => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class ServerEventArgs : EventArgs | |||
| { | |||
| public Server Server => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class ServerUpdatedEventArgs : EventArgs | |||
| { | |||
| public Server Before => null; | |||
| public Server After => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| namespace Discord | |||
| { | |||
| public class TypingEventArgs | |||
| { | |||
| public ITextChannel Channel { get; } | |||
| public IUser User { get; } | |||
| public TypingEventArgs(ITextChannel channel, IUser user) | |||
| { | |||
| Channel = channel; | |||
| User = user; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class UserEventArgs : EventArgs | |||
| { | |||
| public IUser User => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using System; | |||
| namespace Discord | |||
| { | |||
| public class UserUpdatedEventArgs : EventArgs | |||
| { | |||
| public IUser Before => null; | |||
| public IUser After => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| namespace Discord | |||
| { | |||
| public static class Format | |||
| { | |||
| public static string Escape(string text) => null; | |||
| public static string Bold(string text, bool escape = true) => null; | |||
| public static string Italics(string text, bool escape = true) => null; | |||
| public static string Underline(string text, bool escape = true) => null; | |||
| public static string Strikeout(string text, bool escape = true) => null; | |||
| public static string Code(string text, string language = null) => null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| using System; | |||
| namespace Discord.Logging | |||
| { | |||
| public interface ILogger | |||
| { | |||
| LogSeverity Level { get; } | |||
| void Log(LogSeverity severity, string message, Exception exception = null); | |||
| void Error(string message, Exception exception = null); | |||
| void Error(Exception exception); | |||
| void Warning(string message, Exception exception = null); | |||
| void Warning(Exception exception); | |||
| void Info(string message, Exception exception = null); | |||
| void Info(Exception exception); | |||
| void Verbose(string message, Exception exception = null); | |||
| void Verbose(Exception exception); | |||
| void Debug(string message, Exception exception = null); | |||
| void Debug(Exception exception); | |||
| #if DOTNET5_4 | |||
| void Log(LogSeverity severity, FormattableString message, Exception exception = null); | |||
| void Error(FormattableString message, Exception exception = null); | |||
| void Warning(FormattableString message, Exception exception = null); | |||
| void Info(FormattableString message, Exception exception = null); | |||
| void Verbose(FormattableString message, Exception exception = null); | |||
| void Debug(FormattableString message, Exception exception = null); | |||
| #endif | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Discord | |||
| { | |||
| public class MessageQueue | |||
| { | |||
| public int Count { get; } | |||
| public void Clear() { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| using System; | |||
| using System.Net; | |||
| namespace Discord.Net | |||
| { | |||
| public class HttpException : Exception | |||
| { | |||
| public HttpStatusCode StatusCode { get; } | |||
| public HttpException(HttpStatusCode statusCode) | |||
| : base($"The server responded with error {(int)statusCode} ({statusCode})") | |||
| { | |||
| StatusCode = statusCode; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| namespace Discord.Net.Rest | |||
| { | |||
| public class CompletedRequestEventArgs : RequestEventArgs | |||
| { | |||
| public object Response { get; set; } | |||
| public string ResponseJson { get; set; } | |||
| public double Milliseconds { get; set; } | |||
| public CompletedRequestEventArgs(IRestRequest request, object response, string responseJson, double milliseconds) | |||
| : base(request) | |||
| { | |||
| Response = response; | |||
| ResponseJson = responseJson; | |||
| Milliseconds = milliseconds; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,23 @@ | |||
| using System; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.Net.Rest | |||
| { | |||
| public interface IRestClient | |||
| { | |||
| event EventHandler<RequestEventArgs> SendingRequest; | |||
| event EventHandler<CompletedRequestEventArgs> SentRequest; | |||
| CancellationToken CancelToken { get; } | |||
| string Token { get; } | |||
| Task<ResponseT> Send<ResponseT>(IRestRequest<ResponseT> request) | |||
| where ResponseT : class; | |||
| Task Send(IRestRequest request); | |||
| Task<ResponseT> Send<ResponseT>(IRestFileRequest<ResponseT> request) | |||
| where ResponseT : class; | |||
| Task Send(IRestFileRequest request); | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using System.Collections.Generic; | |||
| using System.Threading; | |||
| namespace Discord.Net.Rest | |||
| { | |||
| public interface IRestClientProvider | |||
| { | |||
| IRestClient Create(string baseUrl, CancellationToken cancelToken); | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| using System.IO; | |||
| namespace Discord.Net.Rest | |||
| { | |||
| public interface IRestRequest | |||
| { | |||
| string Method { get; } | |||
| string Endpoint { get; } | |||
| object Payload { get; } | |||
| } | |||
| public interface IRestRequest<ResponseT> : IRestRequest | |||
| where ResponseT : class | |||
| { | |||
| } | |||
| public interface IRestFileRequest : IRestRequest | |||
| { | |||
| string Filename { get; } | |||
| Stream Stream { get; } | |||
| } | |||
| public interface IRestFileRequest<ResponseT> : IRestFileRequest, IRestRequest<Message> | |||
| where ResponseT : class | |||
| { | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| using System; | |||
| namespace Discord.Net.Rest | |||
| { | |||
| public class RequestEventArgs : EventArgs | |||
| { | |||
| public IRestRequest Request { get; set; } | |||
| public bool Cancel { get; set; } | |||
| public RequestEventArgs(IRestRequest request) { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using System; | |||
| namespace Discord.Net | |||
| { | |||
| public class TimeoutException : OperationCanceledException | |||
| { | |||
| public TimeoutException() { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| using System; | |||
| namespace Discord.Net | |||
| { | |||
| public class WebSocketException : Exception | |||
| { | |||
| public int Code { get; } | |||
| public string Reason { get; } | |||
| public WebSocketException(int code, string reason) { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using System; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public class BinaryMessageEventArgs : EventArgs | |||
| { | |||
| public byte[] Data { get; } | |||
| public BinaryMessageEventArgs(byte[] data) { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| using Discord.Net.Rest; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public class GatewaySocket | |||
| { | |||
| public string SessionId { get; } | |||
| public event EventHandler<WebSocketEventEventArgs> ReceivedDispatch = delegate { }; | |||
| public Task Connect(IRestClient rest, CancellationToken parentCancelToken) => null; | |||
| public Task Disconnect() => null; | |||
| public void SendIdentify(string token) { } | |||
| public void SendResume() { } | |||
| public void SendHeartbeat() { } | |||
| public void SendUpdateStatus(long? idleSince, string gameName) { } | |||
| public void SendUpdateVoice(ulong? serverId, ulong? channelId, bool isSelfMuted, bool isSelfDeafened) { } | |||
| public void SendRequestMembers(IEnumerable<ulong> serverId, string query, int limit) { } | |||
| public void WaitForConnection(CancellationToken cancelToken) { } | |||
| } | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| using System; | |||
| using System.Threading; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public interface IWebSocket | |||
| { | |||
| CancellationToken CancelToken { get; } | |||
| ConnectionState State { get; } | |||
| string Host { get; set; } | |||
| event EventHandler Connected; | |||
| event EventHandler<DisconnectedEventArgs> Disconnected; | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public interface IWebSocketEngine | |||
| { | |||
| event EventHandler<BinaryMessageEventArgs> BinaryMessage; | |||
| event EventHandler<TextMessageEventArgs> TextMessage; | |||
| Task Connect(string host, CancellationToken cancelToken); | |||
| Task Disconnect(); | |||
| void QueueMessage(string message); | |||
| IEnumerable<Task> GetTasks(CancellationToken cancelToken); | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| using System.Threading; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public interface IWebSocketProvider | |||
| { | |||
| IWebSocket Create(CancellationToken cancelToken); | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using System; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public class TextMessageEventArgs : EventArgs | |||
| { | |||
| public string Message { get; } | |||
| public TextMessageEventArgs(string msg) { Message = msg; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using Newtonsoft.Json.Linq; | |||
| using System; | |||
| namespace Discord.Net.WebSockets | |||
| { | |||
| public class WebSocketEventEventArgs : EventArgs | |||
| { | |||
| public string Type { get; } | |||
| public JToken Payload { get; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,81 @@ | |||
| { | |||
| "version": "0.9.0-rc3-3", | |||
| "description": "An unofficial .Net API wrapper for the Discord client.", | |||
| "authors": [ | |||
| "RogueException" | |||
| ], | |||
| "tags": [ | |||
| "discord", | |||
| "discordapp" | |||
| ], | |||
| "projectUrl": "https://github.com/RogueException/Discord.Net", | |||
| "licenseUrl": "http://opensource.org/licenses/MIT", | |||
| "repository": { | |||
| "type": "git", | |||
| "url": "git://github.com/RogueException/Discord.Net" | |||
| }, | |||
| "compile": [ "**/*.cs", "../Discord.Net.Shared/*.cs" ], | |||
| "compilationOptions": { | |||
| "allowUnsafe": true, | |||
| "warningsAsErrors": true | |||
| }, | |||
| "configurations": { | |||
| "TestResponses": { | |||
| "compilationOptions": { | |||
| "define": [ | |||
| "DEBUG", | |||
| "TRACE", | |||
| "TEST_RESPONSES" | |||
| ] | |||
| } | |||
| } | |||
| }, | |||
| "dependencies": { | |||
| "Newtonsoft.Json": "8.0.1", | |||
| "Nito.AsyncEx": "3.0.1" | |||
| }, | |||
| "frameworks": { | |||
| "dotnet5.4": { | |||
| "dependencies": { | |||
| "System.Collections": "4.0.11-beta-23516", | |||
| "System.Collections.Concurrent": "4.0.11-beta-23516", | |||
| "System.Dynamic.Runtime": "4.0.11-beta-23516", | |||
| "System.IO.FileSystem": "4.0.1-beta-23516", | |||
| "System.IO.Compression": "4.1.0-beta-23516", | |||
| "System.Linq": "4.0.1-beta-23516", | |||
| "System.Net.Http": "4.0.1-beta-23516", | |||
| "System.Net.NameResolution": "4.0.0-beta-23516", | |||
| "System.Net.Sockets": "4.1.0-beta-23409", | |||
| "System.Net.Requests": "4.0.11-beta-23516", | |||
| "System.Net.WebSockets.Client": "4.0.0-beta-23516", | |||
| "System.Reflection": "4.1.0-beta-23516", | |||
| "System.Reflection.Emit.Lightweight": "4.0.1-beta-23516", | |||
| "System.Runtime.InteropServices": "4.0.21-beta-23516", | |||
| "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", | |||
| "System.Security.Cryptography.Algorithms": "4.0.0-beta-23516", | |||
| "System.Text.RegularExpressions": "4.0.11-beta-23516", | |||
| "System.Threading": "4.0.11-beta-23516" | |||
| } | |||
| }, | |||
| "net45": { | |||
| "frameworkAssemblies": { | |||
| "System.Runtime": { | |||
| "type": "build", | |||
| "version": "" | |||
| }, | |||
| "System.Threading.Tasks": { | |||
| "type": "build", | |||
| "version": "" | |||
| } | |||
| }, | |||
| "dependencies": { | |||
| "WebSocket4Net": "0.14.1", | |||
| "RestSharp": "105.2.3" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,128 +0,0 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |||
| <PropertyGroup> | |||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
| <ProjectGuid>{7BFEF748-B934-4621-9B11-6302E3A9F6B3}</ProjectGuid> | |||
| <OutputType>Library</OutputType> | |||
| <AppDesignerFolder>Properties</AppDesignerFolder> | |||
| <RootNamespace>Discord.Audio</RootNamespace> | |||
| <AssemblyName>Discord.Net.Audio</AssemblyName> | |||
| <FileAlignment>512</FileAlignment> | |||
| <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |||
| <UseMSBuildEngine>False</UseMSBuildEngine> | |||
| <TargetFrameworkProfile /> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| <DebugType>full</DebugType> | |||
| <Optimize>false</Optimize> | |||
| <OutputPath>bin\Debug\</OutputPath> | |||
| <DefineConstants>TRACE;DEBUG;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <LangVersion>6</LangVersion> | |||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <DebugType>pdbonly</DebugType> | |||
| <Optimize>true</Optimize> | |||
| <OutputPath>bin\Release\</OutputPath> | |||
| <DefineConstants>TRACE;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| <LangVersion>6</LangVersion> | |||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Reference Include="System" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Compile Include="..\Discord.Net.Audio\AudioClient.cs"> | |||
| <Link>AudioClient.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\AudioExtensions.cs"> | |||
| <Link>AudioExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\AudioMode.cs"> | |||
| <Link>AudioMode.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\AudioService.cs"> | |||
| <Link>AudioService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\AudioServiceConfig.cs"> | |||
| <Link>AudioServiceConfig.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\IAudioClient.cs"> | |||
| <Link>IAudioClient.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\InternalFrameEventArgs.cs"> | |||
| <Link>InternalFrameEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\InternalIsSpeakingEventArgs.cs"> | |||
| <Link>InternalIsSpeakingEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\Net\VoiceSocket.cs"> | |||
| <Link>Net\VoiceSocket.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\Opus\OpusConverter.cs"> | |||
| <Link>Opus\OpusConverter.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\Opus\OpusDecoder.cs"> | |||
| <Link>Opus\OpusDecoder.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\Opus\OpusEncoder.cs"> | |||
| <Link>Opus\OpusEncoder.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\Sodium\SecretBox.cs"> | |||
| <Link>Sodium\SecretBox.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\UserIsTalkingEventArgs.cs"> | |||
| <Link>UserIsTalkingEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\VirtualClient.cs"> | |||
| <Link>VirtualClient.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\VoiceBuffer.cs"> | |||
| <Link>VoiceBuffer.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Audio\VoiceDisconnectedEventArgs.cs"> | |||
| <Link>VoiceDisconnectedEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Net45\Discord.Net.csproj"> | |||
| <Project>{8d71a857-879a-4a10-859e-5ff824ed6688}</Project> | |||
| <Name>Discord.Net</Name> | |||
| </ProjectReference> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Content Include="..\Discord.Net.Audio\libsodium.dll"> | |||
| <Link>libsodium.dll</Link> | |||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
| </Content> | |||
| <Content Include="..\Discord.Net.Audio\opus.dll"> | |||
| <Link>opus.dll</Link> | |||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
| </Content> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Content Include="project.json" /> | |||
| <Content Include="project.lock.json"> | |||
| <DependentUpon>project.json</DependentUpon> | |||
| </Content> | |||
| </ItemGroup> | |||
| <Import Project="..\Discord.Net.Shared\Discord.Net.Shared.projitems" Label="Shared" /> | |||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||
| Other similar extension points exist, see Microsoft.Common.targets. | |||
| <Target Name="BeforeBuild"> | |||
| </Target> | |||
| <Target Name="AfterBuild"> | |||
| </Target> | |||
| --> | |||
| </Project> | |||
| @@ -1,18 +0,0 @@ | |||
| using System.Reflection; | |||
| using System.Runtime.InteropServices; | |||
| [assembly: AssemblyTitle("Discord.Net.Audio")] | |||
| [assembly: AssemblyDescription("A Discord.Net extension adding voice support.")] | |||
| [assembly: AssemblyConfiguration("")] | |||
| [assembly: AssemblyCompany("RogueException")] | |||
| [assembly: AssemblyProduct("Discord.Net.Modules")] | |||
| [assembly: AssemblyCopyright("Copyright © 2015")] | |||
| [assembly: AssemblyTrademark("")] | |||
| [assembly: AssemblyCulture("")] | |||
| [assembly: ComVisible(false)] | |||
| [assembly: Guid("76ea00e6-ea24-41e1-acb2-639c0313fa80")] | |||
| [assembly: AssemblyVersion("0.9.0.0")] | |||
| [assembly: AssemblyFileVersion("0.9.0.0")] | |||
| @@ -1,14 +0,0 @@ | |||
| { | |||
| "dependencies": { | |||
| "Newtonsoft.Json": "8.0.1", | |||
| "Nito.AsyncEx": "3.0.1" | |||
| }, | |||
| "frameworks": { | |||
| "net45": { } | |||
| }, | |||
| "runtimes": { | |||
| "win": { }, | |||
| "win-x86": { }, | |||
| "win-x64": { } | |||
| } | |||
| } | |||
| @@ -7,7 +7,6 @@ using Newtonsoft.Json; | |||
| using Nito.AsyncEx; | |||
| using System; | |||
| using System.Diagnostics; | |||
| using System.IO; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| @@ -15,35 +14,6 @@ namespace Discord.Audio | |||
| { | |||
| internal class AudioClient : IAudioClient | |||
| { | |||
| private class OutStream : Stream | |||
| { | |||
| public override bool CanRead => false; | |||
| public override bool CanSeek => false; | |||
| public override bool CanWrite => true; | |||
| private readonly AudioClient _client; | |||
| internal OutStream(AudioClient client) | |||
| { | |||
| _client = client; | |||
| } | |||
| public override long Length { get { throw new InvalidOperationException(); } } | |||
| public override long Position | |||
| { | |||
| get { throw new InvalidOperationException(); } | |||
| set { throw new InvalidOperationException(); } | |||
| } | |||
| public override void Flush() { throw new InvalidOperationException(); } | |||
| public override long Seek(long offset, SeekOrigin origin) { throw new InvalidOperationException(); } | |||
| public override void SetLength(long value) { throw new InvalidOperationException(); } | |||
| public override int Read(byte[] buffer, int offset, int count) { throw new InvalidOperationException(); } | |||
| public override void Write(byte[] buffer, int offset, int count) | |||
| { | |||
| _client.Send(buffer, offset, count); | |||
| } | |||
| } | |||
| private readonly DiscordConfig _config; | |||
| private readonly AsyncLock _connectionLock; | |||
| private readonly TaskManager _taskManager; | |||
| @@ -58,20 +28,18 @@ namespace Discord.Audio | |||
| public GatewaySocket GatewaySocket { get; } | |||
| public VoiceSocket VoiceSocket { get; } | |||
| public JsonSerializer Serializer { get; } | |||
| public Stream OutputStream { get; } | |||
| public CancellationToken CancelToken { get; private set; } | |||
| public string SessionId => GatewaySocket.SessionId; | |||
| public ConnectionState State => VoiceSocket.State; | |||
| public Server Server => VoiceSocket.Server; | |||
| public Channel Channel => VoiceSocket.Channel; | |||
| public VoiceChannel Channel => VoiceSocket.Channel; | |||
| public AudioClient(DiscordClient client, Server server, int id) | |||
| { | |||
| Id = id; | |||
| _config = client.Config; | |||
| Service = client.Services.Get<AudioService>(); | |||
| Service = client.GetService<AudioService>(); | |||
| Config = Service.Config; | |||
| Serializer = client.Serializer; | |||
| _gatewayState = (int)ConnectionState.Disconnected; | |||
| @@ -87,6 +55,25 @@ namespace Discord.Audio | |||
| //Networking | |||
| if (Config.EnableMultiserver) | |||
| { | |||
| //TODO: We can remove this hack when official API launches | |||
| var baseConfig = client.Config; | |||
| var builder = new DiscordConfigBuilder | |||
| { | |||
| AppName = baseConfig.AppName, | |||
| AppUrl = baseConfig.AppUrl, | |||
| AppVersion = baseConfig.AppVersion, | |||
| CacheToken = baseConfig.CacheDir != null, | |||
| ConnectionTimeout = baseConfig.ConnectionTimeout, | |||
| EnablePreUpdateEvents = false, | |||
| FailedReconnectDelay = baseConfig.FailedReconnectDelay, | |||
| LargeThreshold = 1, | |||
| LogLevel = baseConfig.LogLevel, | |||
| MessageCacheSize = 0, | |||
| ReconnectDelay = baseConfig.ReconnectDelay, | |||
| UsePermissionsCache = false | |||
| }; | |||
| _config = builder.Build(); | |||
| ClientAPI = new JsonRestClient(_config, DiscordConfig.ClientAPIUrl, client.Log.CreateLogger($"ClientAPI #{id}")); | |||
| GatewaySocket = new GatewaySocket(_config, client.Serializer, client.Log.CreateLogger($"Gateway #{id}")); | |||
| GatewaySocket.Connected += (s, e) => | |||
| @@ -96,11 +83,13 @@ namespace Discord.Audio | |||
| }; | |||
| } | |||
| else | |||
| { | |||
| _config = client.Config; | |||
| GatewaySocket = client.GatewaySocket; | |||
| } | |||
| GatewaySocket.ReceivedDispatch += (s, e) => OnReceivedEvent(e); | |||
| VoiceSocket = new VoiceSocket(_config, Config, client.Serializer, client.Log.CreateLogger($"Voice #{id}")); | |||
| VoiceSocket.Server = server; | |||
| OutputStream = new OutStream(this); | |||
| } | |||
| public async Task Connect() | |||
| @@ -195,7 +184,7 @@ namespace Discord.Audio | |||
| _gatewayState = (int)ConnectionState.Disconnected; | |||
| } | |||
| public async Task Join(Channel channel) | |||
| public async Task Join(VoiceChannel channel) | |||
| { | |||
| if (channel == null) throw new ArgumentNullException(nameof(channel)); | |||
| if (channel.Type != ChannelType.Voice) | |||
| @@ -209,7 +198,7 @@ namespace Discord.Audio | |||
| SendVoiceUpdate(channel.Server.Id, channel.Id); | |||
| using (await _connectionLock.LockAsync().ConfigureAwait(false)) | |||
| await Task.Run(() => VoiceSocket.WaitForConnection(CancelToken)); | |||
| await Task.Run(() => VoiceSocket.WaitForConnection(CancelToken)).ConfigureAwait(false); | |||
| } | |||
| private async void OnReceivedEvent(WebSocketEventEventArgs e) | |||
| @@ -227,7 +216,7 @@ namespace Discord.Audio | |||
| await Disconnect().ConfigureAwait(false); | |||
| else | |||
| { | |||
| var channel = Service.Client.GetChannel(data.ChannelId.Value); | |||
| var channel = Service.Client.GetChannel(data.ChannelId.Value) as VoiceChannel; | |||
| if (channel != null) | |||
| VoiceSocket.Channel = channel; | |||
| else | |||
| @@ -7,20 +7,20 @@ namespace Discord.Audio | |||
| { | |||
| public static DiscordClient UsingAudio(this DiscordClient client, AudioServiceConfig config = null) | |||
| { | |||
| client.Services.Add(new AudioService(config)); | |||
| client.AddService(new AudioService(config)); | |||
| return client; | |||
| } | |||
| public static DiscordClient UsingAudio(this DiscordClient client, Action<AudioServiceConfigBuilder> configFunc = null) | |||
| { | |||
| var builder = new AudioServiceConfigBuilder(); | |||
| configFunc(builder); | |||
| client.Services.Add(new AudioService(builder)); | |||
| client.AddService(new AudioService(builder)); | |||
| return client; | |||
| } | |||
| public static Task<IAudioClient> JoinAudio(this Channel channel) => channel.Client.Services.Get<AudioService>().Join(channel); | |||
| public static Task LeaveAudio(this Channel channel) => channel.Client.Services.Get<AudioService>().Leave(channel); | |||
| public static Task LeaveAudio(this Server server) => server.Client.Services.Get<AudioService>().Leave(server); | |||
| public static IAudioClient GetAudioClient(Server server) => server.Client.Services.Get<AudioService>().GetClient(server); | |||
| public static Task<IAudioClient> JoinAudio(this VoiceChannel channel) => channel.Client.GetService<AudioService>().Join(channel); | |||
| public static Task LeaveAudio(this VoiceChannel channel) => channel.Client.GetService<AudioService>().Leave(channel); | |||
| public static Task LeaveAudio(this Server server) => server.Client.GetService<AudioService>().Leave(server); | |||
| public static IAudioClient GetAudioClient(this Server server) => server.Client.GetService<AudioService>().GetClient(server); | |||
| } | |||
| } | |||
| @@ -113,7 +113,7 @@ namespace Discord.Audio | |||
| } | |||
| } | |||
| public async Task<IAudioClient> Join(Channel channel) | |||
| public async Task<IAudioClient> Join(VoiceChannel channel) | |||
| { | |||
| if (channel == null) throw new ArgumentNullException(nameof(channel)); | |||
| @@ -163,8 +163,8 @@ namespace Discord.Audio | |||
| } | |||
| public Task Leave(Server server) => Leave(server, null); | |||
| public Task Leave(Channel channel) => Leave(channel.Server, channel); | |||
| private async Task Leave(Server server, Channel channel) | |||
| public Task Leave(VoiceChannel channel) => Leave(channel.Server, channel); | |||
| private async Task Leave(Server server, VoiceChannel channel) | |||
| { | |||
| if (server == null) throw new ArgumentNullException(nameof(server)); | |||
| @@ -15,11 +15,9 @@ namespace Discord.Audio | |||
| /// <summary> Gets the current state of this client. </summary> | |||
| ConnectionState State { get; } | |||
| /// <summary> Gets the channel this client is currently a member of. </summary> | |||
| Channel Channel { get; } | |||
| VoiceChannel Channel { get; } | |||
| /// <summary> Gets the server this client is bound to. </summary> | |||
| Server Server { get; } | |||
| /// <summary> Gets a stream object that wraps the Send() function. </summary> | |||
| Stream OutputStream { get; } | |||
| /// <summary> Gets a cancellation token that triggers when the client is manually disconnected. </summary> | |||
| CancellationToken CancelToken { get; } | |||
| @@ -31,7 +29,7 @@ namespace Discord.Audio | |||
| VoiceSocket VoiceSocket { get; } | |||
| /// <summary> Moves the client to another channel on the same server. </summary> | |||
| Task Join(Channel channel); | |||
| Task Join(VoiceChannel channel); | |||
| /// <summary> Disconnects from the Discord server, canceling any pending requests. </summary> | |||
| Task Disconnect(); | |||
| @@ -46,7 +46,7 @@ namespace Discord.Net.WebSockets | |||
| public string Token { get; internal set; } | |||
| public Server Server { get; internal set; } | |||
| public Channel Channel { get; internal set; } | |||
| public VoiceChannel Channel { get; internal set; } | |||
| public int Ping => _ping; | |||
| internal VoiceBuffer OutputBuffer => _sendBuffer; | |||
| @@ -371,7 +371,7 @@ namespace Discord.Net.WebSockets | |||
| break; | |||
| } | |||
| } | |||
| await _udp.SendAsync(pingPacket, pingPacket.Length); | |||
| await _udp.SendAsync(pingPacket, pingPacket.Length).ConfigureAwait(false); | |||
| nextPingTicks = currentTicks + 5 * ticksPerSeconds; | |||
| } | |||
| } | |||
| @@ -395,7 +395,7 @@ namespace Discord.Net.WebSockets | |||
| //Closes the UDP socket when _disconnectToken is triggered, since UDPClient doesn't allow passing a canceltoken | |||
| private async Task WatcherAsync() | |||
| { | |||
| await CancelToken.Wait(); | |||
| await CancelToken.Wait().ConfigureAwait(false); | |||
| _udp.Close(); | |||
| } | |||
| #endif | |||
| @@ -16,8 +16,7 @@ namespace Discord.Audio | |||
| public string SessionId => _client.Server == Server ? _client.SessionId : null; | |||
| public ConnectionState State => _client.Server == Server ? _client.State : ConnectionState.Disconnected; | |||
| public Channel Channel => _client.Server == Server ? _client.Channel : null; | |||
| public Stream OutputStream => _client.Server == Server ? _client.OutputStream : null; | |||
| public VoiceChannel Channel => _client.Server == Server ? _client.Channel : null; | |||
| public CancellationToken CancelToken => _client.Server == Server ? _client.CancelToken : CancellationToken.None; | |||
| public RestClient ClientAPI => _client.Server == Server ? _client.ClientAPI : null; | |||
| @@ -31,7 +30,7 @@ namespace Discord.Audio | |||
| } | |||
| public Task Disconnect() => _client.Service.Leave(Server); | |||
| public Task Join(Channel channel) => _client.Join(channel); | |||
| public Task Join(VoiceChannel channel) => _client.Join(channel); | |||
| public void Send(byte[] data, int offset, int count) => _client.Send(data, offset, count); | |||
| public void Clear() => _client.Clear(); | |||
| @@ -1,5 +1,5 @@ | |||
| { | |||
| "version": "0.9.0-rc3", | |||
| "version": "1.0.0-alpha1", | |||
| "description": "A Discord.Net extension adding voice support.", | |||
| "authors": [ "RogueException" ], | |||
| "tags": [ "discord", "discordapp" ], | |||
| @@ -18,7 +18,7 @@ | |||
| }, | |||
| "dependencies": { | |||
| "Discord.Net": "0.9.0-rc3-3" | |||
| "Discord.Net": "1.0.0-alpha1" | |||
| }, | |||
| "frameworks": { | |||
| "net45": { }, | |||
| @@ -1,148 +0,0 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |||
| <PropertyGroup> | |||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
| <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
| <ProjectGuid>{1B5603B4-6F8F-4289-B945-7BAAE523D740}</ProjectGuid> | |||
| <OutputType>Library</OutputType> | |||
| <AppDesignerFolder>Properties</AppDesignerFolder> | |||
| <RootNamespace>Discord.Commands</RootNamespace> | |||
| <AssemblyName>Discord.Net.Commands</AssemblyName> | |||
| <FileAlignment>512</FileAlignment> | |||
| <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |||
| <UseMSBuildEngine>False</UseMSBuildEngine> | |||
| <TargetFrameworkProfile /> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| <DebugType>full</DebugType> | |||
| <Optimize>false</Optimize> | |||
| <OutputPath>bin\Debug\</OutputPath> | |||
| <DefineConstants>TRACE;DEBUG;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <LangVersion>6</LangVersion> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <DebugType>pdbonly</DebugType> | |||
| <Optimize>true</Optimize> | |||
| <OutputPath>bin\Release\</OutputPath> | |||
| <DefineConstants>TRACE;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Reference Include="System" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Compile Include="..\Discord.Net.Commands\Command.cs"> | |||
| <Link>Command.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandBuilder.cs"> | |||
| <Link>CommandBuilder.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandErrorEventArgs.cs"> | |||
| <Link>CommandErrorEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandEventArgs.cs"> | |||
| <Link>CommandEventArgs.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandExtensions.cs"> | |||
| <Link>CommandExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandMap.cs"> | |||
| <Link>CommandMap.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandParameter.cs"> | |||
| <Link>CommandParameter.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandParser.cs"> | |||
| <Link>CommandParser.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandService.cs"> | |||
| <Link>CommandService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\CommandServiceConfig.cs"> | |||
| <Link>CommandServiceConfig.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\HelpMode.cs"> | |||
| <Link>HelpMode.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\GenericPermissionChecker.cs"> | |||
| <Link>Permissions\GenericPermissionChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\IPermissionChecker.cs"> | |||
| <Link>Permissions\IPermissionChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Levels\PermissionLevelChecker.cs"> | |||
| <Link>Permissions\Levels\PermissionLevelChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Levels\PermissionLevelExtensions.cs"> | |||
| <Link>Permissions\Levels\PermissionLevelExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Levels\PermissionLevelService.cs"> | |||
| <Link>Permissions\Levels\PermissionLevelService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\BlacklistChecker.cs"> | |||
| <Link>Permissions\Users\BlacklistChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\BlacklistExtensions.cs"> | |||
| <Link>Permissions\Users\BlacklistExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\BlacklistService.cs"> | |||
| <Link>Permissions\Users\BlacklistService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\UserlistService.cs"> | |||
| <Link>Permissions\Users\UserlistService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\WhitelistChecker.cs"> | |||
| <Link>Permissions\Users\WhitelistChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\WhitelistExtensions.cs"> | |||
| <Link>Permissions\Users\WhitelistExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Userlist\WhitelistService.cs"> | |||
| <Link>Permissions\Users\WhitelistService.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Visibility\PrivateChecker.cs"> | |||
| <Link>Permissions\Visibility\PrivateChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Visibility\PrivateExtensions.cs"> | |||
| <Link>Permissions\Visibility\PrivateExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Visibility\PublicChecker.cs"> | |||
| <Link>Permissions\Visibility\PublicChecker.cs</Link> | |||
| </Compile> | |||
| <Compile Include="..\Discord.Net.Commands\Permissions\Visibility\PublicExtensions.cs"> | |||
| <Link>Permissions\Visibility\PublicExtensions.cs</Link> | |||
| </Compile> | |||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Net45\Discord.Net.csproj"> | |||
| <Project>{8d71a857-879a-4a10-859e-5ff824ed6688}</Project> | |||
| <Name>Discord.Net</Name> | |||
| </ProjectReference> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Content Include="project.json" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Content Include="project.lock.json"> | |||
| <DependentUpon>project.json</DependentUpon> | |||
| </Content> | |||
| </ItemGroup> | |||
| <Import Project="..\Discord.Net.Shared\Discord.Net.Shared.projitems" Label="Shared" /> | |||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||
| Other similar extension points exist, see Microsoft.Common.targets. | |||
| <Target Name="BeforeBuild"> | |||
| </Target> | |||
| <Target Name="AfterBuild"> | |||
| </Target> | |||
| --> | |||
| </Project> | |||
| @@ -1,18 +0,0 @@ | |||
| using System.Reflection; | |||
| using System.Runtime.InteropServices; | |||
| [assembly: AssemblyTitle("Discord.Net.Commands")] | |||
| [assembly: AssemblyDescription("A Discord.Net extension adding basic command support.")] | |||
| [assembly: AssemblyConfiguration("")] | |||
| [assembly: AssemblyCompany("RogueException")] | |||
| [assembly: AssemblyProduct("Discord.Net.Commands")] | |||
| [assembly: AssemblyCopyright("Copyright © 2015")] | |||
| [assembly: AssemblyTrademark("")] | |||
| [assembly: AssemblyCulture("")] | |||
| [assembly: ComVisible(false)] | |||
| [assembly: Guid("76ea00e6-ea24-41e1-acb2-639c0313fa80")] | |||
| [assembly: AssemblyVersion("0.9.0.0")] | |||
| [assembly: AssemblyFileVersion("0.9.0.0")] | |||
| @@ -1,10 +0,0 @@ | |||
| { | |||
| "frameworks": { | |||
| "net45": { } | |||
| }, | |||
| "runtimes": { | |||
| "win": { }, | |||
| "win-x86": { }, | |||
| "win-x64": { } | |||
| } | |||
| } | |||
| @@ -52,7 +52,7 @@ namespace Discord.Commands | |||
| _checks = checks; | |||
| } | |||
| internal bool CanRun(User user, Channel channel, out string error) | |||
| internal bool CanRun(User user, ITextChannel channel, out string error) | |||
| { | |||
| for (int i = 0; i < _checks.Length; i++) | |||
| { | |||
| @@ -79,7 +79,7 @@ namespace Discord.Commands | |||
| _checks.Add(check); | |||
| return this; | |||
| } | |||
| public CommandBuilder AddCheck(Func<Command, User, Channel, bool> checkFunc, string errorMsg = null) | |||
| public CommandBuilder AddCheck(Func<Command, User, ITextChannel, bool> checkFunc, string errorMsg = null) | |||
| { | |||
| _checks.Add(new GenericPermissionChecker(checkFunc, errorMsg)); | |||
| return this; | |||
| @@ -145,7 +145,7 @@ namespace Discord.Commands | |||
| { | |||
| _checks.Add(checker); | |||
| } | |||
| public void AddCheck(Func<Command, User, Channel, bool> checkFunc, string errorMsg = null) | |||
| public void AddCheck(Func<Command, User, ITextChannel, bool> checkFunc, string errorMsg = null) | |||
| { | |||
| _checks.Add(new GenericPermissionChecker(checkFunc, errorMsg)); | |||
| } | |||
| @@ -10,8 +10,7 @@ namespace Discord.Commands | |||
| public Command Command { get; } | |||
| public User User => Message.User; | |||
| public Channel Channel => Message.Channel; | |||
| public Server Server => Message.Channel.Server; | |||
| public ITextChannel Channel => Message.Channel; | |||
| public CommandEventArgs(Message message, Command command, string[] args) | |||
| { | |||
| @@ -6,14 +6,14 @@ namespace Discord.Commands | |||
| { | |||
| public static DiscordClient UsingCommands(this DiscordClient client, CommandServiceConfig config = null) | |||
| { | |||
| client.Services.Add(new CommandService(config)); | |||
| client.AddService(new CommandService(config)); | |||
| return client; | |||
| } | |||
| public static DiscordClient UsingCommands(this DiscordClient client, Action<CommandServiceConfigBuilder> configFunc = null) | |||
| { | |||
| var builder = new CommandServiceConfigBuilder(); | |||
| configFunc(builder); | |||
| client.Services.Add(new CommandService(builder)); | |||
| client.AddService(new CommandService(builder)); | |||
| return client; | |||
| } | |||
| } | |||
| @@ -116,7 +116,7 @@ namespace Discord.Commands | |||
| } | |||
| } | |||
| public bool CanRun(User user, Channel channel, out string error) | |||
| public bool CanRun(User user, ITextChannel channel, out string error) | |||
| { | |||
| error = null; | |||
| if (_commands.Count > 0) | |||
| @@ -63,7 +63,7 @@ namespace Discord.Commands | |||
| .Description("Returns information about commands.") | |||
| .Do(async e => | |||
| { | |||
| Channel replyChannel = Config.HelpMode == HelpMode.Public ? e.Channel : await e.User.CreatePMChannel().ConfigureAwait(false); | |||
| ITextChannel replyChannel = Config.HelpMode == HelpMode.Public ? e.Channel : await e.User.CreatePMChannel().ConfigureAwait(false); | |||
| if (e.Args.Length > 0) //Show command help | |||
| { | |||
| var map = _map.GetItem(string.Join(" ", e.Args)); | |||
| @@ -97,10 +97,15 @@ namespace Discord.Commands | |||
| //Check for mention | |||
| if (cmdMsg == null && Config.AllowMentionPrefix) | |||
| { | |||
| if (msg.StartsWith(client.CurrentUser.Mention)) | |||
| cmdMsg = msg.Substring(client.CurrentUser.Mention.Length + 1); | |||
| else if (msg.StartsWith($"@{client.CurrentUser.Name}")) | |||
| cmdMsg = msg.Substring(client.CurrentUser.Name.Length + 1); | |||
| string mention = client.CurrentUser.Mention; | |||
| if (msg.StartsWith(mention) && msg.Length > mention.Length) | |||
| cmdMsg = msg.Substring(mention.Length + 1); | |||
| else | |||
| { | |||
| mention = $"@{client.CurrentUser.Name}"; | |||
| if (msg.StartsWith(mention) && msg.Length > mention.Length) | |||
| cmdMsg = msg.Substring(mention.Length + 1); | |||
| } | |||
| } | |||
| //Check using custom activator | |||
| @@ -170,7 +175,7 @@ namespace Discord.Commands | |||
| }; | |||
| } | |||
| public Task ShowGeneralHelp(User user, Channel channel, Channel replyChannel = null) | |||
| public Task ShowGeneralHelp(User user, ITextChannel channel, ITextChannel replyChannel = null) | |||
| { | |||
| StringBuilder output = new StringBuilder(); | |||
| bool isFirstCategory = true; | |||
| @@ -214,32 +219,12 @@ namespace Discord.Commands | |||
| if (output.Length == 0) | |||
| output.Append("There are no commands you have permission to run."); | |||
| else | |||
| { | |||
| output.Append("\n\n"); | |||
| //TODO: Should prefix be stated in the help message or not? | |||
| /*StringBuilder builder = new StringBuilder(); | |||
| if (Config.PrefixChar != null) | |||
| { | |||
| builder.Append('`'); | |||
| builder.Append(Config.PrefixChar.Value); | |||
| builder.Append('`'); | |||
| } | |||
| if (Config.AllowMentionPrefix) | |||
| { | |||
| if (builder.Length > 0) | |||
| builder.Append(" or "); | |||
| builder.Append(Client.CurrentUser.Mention); | |||
| } | |||
| if (builder.Length > 0) | |||
| output.AppendLine($"Start your message with {builder.ToString()} to run a command.");*/ | |||
| output.AppendLine($"Run `help <command>` for more information."); | |||
| } | |||
| output.AppendLine("\n\nRun `help <command>` for more information."); | |||
| return (replyChannel ?? channel).SendMessage(output.ToString()); | |||
| } | |||
| private Task ShowCommandHelp(CommandMap map, User user, Channel channel, Channel replyChannel = null) | |||
| private Task ShowCommandHelp(CommandMap map, User user, ITextChannel channel, ITextChannel replyChannel = null) | |||
| { | |||
| StringBuilder output = new StringBuilder(); | |||
| @@ -250,9 +235,7 @@ namespace Discord.Commands | |||
| { | |||
| foreach (var cmd in cmds) | |||
| { | |||
| if (!cmd.CanRun(user, channel, out error)) { } | |||
| //output.AppendLine(error ?? DefaultPermissionError); | |||
| else | |||
| if (cmd.CanRun(user, channel, out error)) | |||
| { | |||
| if (isFirstCmd) | |||
| isFirstCmd = false; | |||
| @@ -294,7 +277,7 @@ namespace Discord.Commands | |||
| return (replyChannel ?? channel).SendMessage(output.ToString()); | |||
| } | |||
| public Task ShowCommandHelp(Command command, User user, Channel channel, Channel replyChannel = null) | |||
| public Task ShowCommandHelp(Command command, User user, ITextChannel channel, ITextChannel replyChannel = null) | |||
| { | |||
| StringBuilder output = new StringBuilder(); | |||
| string error; | |||
| @@ -304,7 +287,7 @@ namespace Discord.Commands | |||
| ShowCommandHelpInternal(command, user, channel, output); | |||
| return (replyChannel ?? channel).SendMessage(output.ToString()); | |||
| } | |||
| private void ShowCommandHelpInternal(Command command, User user, Channel channel, StringBuilder output) | |||
| private void ShowCommandHelpInternal(Command command, User user, ITextChannel channel, StringBuilder output) | |||
| { | |||
| output.Append('`'); | |||
| output.Append(command.Text); | |||
| @@ -4,16 +4,16 @@ namespace Discord.Commands.Permissions | |||
| { | |||
| internal class GenericPermissionChecker : IPermissionChecker | |||
| { | |||
| private readonly Func<Command, User, Channel, bool> _checkFunc; | |||
| private readonly Func<Command, User, ITextChannel, bool> _checkFunc; | |||
| private readonly string _error; | |||
| public GenericPermissionChecker(Func<Command, User, Channel, bool> checkFunc, string error = null) | |||
| public GenericPermissionChecker(Func<Command, User, ITextChannel, bool> checkFunc, string error = null) | |||
| { | |||
| _checkFunc = checkFunc; | |||
| _error = error; | |||
| } | |||
| public bool CanRun(Command command, User user, Channel channel, out string error) | |||
| public bool CanRun(Command command, User user, ITextChannel channel, out string error) | |||
| { | |||
| error = _error; | |||
| return _checkFunc(command, user, channel); | |||
| @@ -2,6 +2,6 @@ | |||
| { | |||
| public interface IPermissionChecker | |||
| { | |||
| bool CanRun(Command command, User user, Channel channel, out string error); | |||
| bool CanRun(Command command, User user, ITextChannel channel, out string error); | |||
| } | |||
| } | |||
| @@ -1,24 +0,0 @@ | |||
| namespace Discord.Commands.Permissions.Levels | |||
| { | |||
| public class PermissionLevelChecker : IPermissionChecker | |||
| { | |||
| private readonly PermissionLevelService _service; | |||
| private readonly int _minPermissions; | |||
| public PermissionLevelService Service => _service; | |||
| public int MinPermissions => _minPermissions; | |||
| internal PermissionLevelChecker(DiscordClient client, int minPermissions) | |||
| { | |||
| _service = client.Services.Get<PermissionLevelService>(true); | |||
| _minPermissions = minPermissions; | |||
| } | |||
| public bool CanRun(Command command, User user, Channel channel, out string error) | |||
| { | |||
| error = null; //Use default error text. | |||
| int permissions = _service.GetPermissionLevel(user, channel); | |||
| return permissions >= _minPermissions; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,29 +0,0 @@ | |||
| using System; | |||
| namespace Discord.Commands.Permissions.Levels | |||
| { | |||
| public static class PermissionLevelExtensions | |||
| { | |||
| public static DiscordClient UsingPermissionLevels(this DiscordClient client, Func<User, Channel, int> permissionResolver) | |||
| { | |||
| client.Services.Add(new PermissionLevelService(permissionResolver)); | |||
| return client; | |||
| } | |||
| public static CommandBuilder MinPermissions(this CommandBuilder builder, int minPermissions) | |||
| { | |||
| builder.AddCheck(new PermissionLevelChecker(builder.Service.Client, minPermissions)); | |||
| return builder; | |||
| } | |||
| public static CommandGroupBuilder MinPermissions(this CommandGroupBuilder builder, int minPermissions) | |||
| { | |||
| builder.AddCheck(new PermissionLevelChecker(builder.Service.Client, minPermissions)); | |||
| return builder; | |||
| } | |||
| public static CommandService MinPermissions(this CommandService service, int minPermissions) | |||
| { | |||
| service.Root.AddCheck(new PermissionLevelChecker(service.Client, minPermissions)); | |||
| return service; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,23 +0,0 @@ | |||
| using System; | |||
| namespace Discord.Commands.Permissions.Levels | |||
| { | |||
| public class PermissionLevelService : IService | |||
| { | |||
| private readonly Func<User, Channel, int> _getPermissionsFunc; | |||
| private DiscordClient _client; | |||
| public DiscordClient Client => _client; | |||
| public PermissionLevelService(Func<User, Channel, int> getPermissionsFunc) | |||
| { | |||
| _getPermissionsFunc = getPermissionsFunc; | |||
| } | |||
| public void Install(DiscordClient client) | |||
| { | |||
| _client = client; | |||
| } | |||
| public int GetPermissionLevel(User user, Channel channel) => _getPermissionsFunc(user, channel); | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| namespace Discord.Commands.Permissions.Userlist | |||
| { | |||
| public class BlacklistChecker : IPermissionChecker | |||
| { | |||
| private readonly BlacklistService _service; | |||
| internal BlacklistChecker(DiscordClient client) | |||
| { | |||
| _service = client.Services.Get<BlacklistService>(true); | |||
| } | |||
| public bool CanRun(Command command, User user, Channel channel, out string error) | |||
| { | |||
| error = null; //Use default error text. | |||
| return _service.CanRun(user); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,48 +0,0 @@ | |||
| using System.Collections.Generic; | |||
| namespace Discord.Commands.Permissions.Userlist | |||
| { | |||
| public static class BlacklistExtensions | |||
| { | |||
| public static DiscordClient UsingGlobalBlacklist(this DiscordClient client, params ulong[] initialUserIds) | |||
| { | |||
| client.Services.Add(new BlacklistService(initialUserIds)); | |||
| return client; | |||
| } | |||
| public static CommandBuilder UseGlobalBlacklist(this CommandBuilder builder) | |||
| { | |||
| builder.AddCheck(new BlacklistChecker(builder.Service.Client)); | |||
| return builder; | |||
| } | |||
| public static CommandGroupBuilder UseGlobalBlacklist(this CommandGroupBuilder builder) | |||
| { | |||
| builder.AddCheck(new BlacklistChecker(builder.Service.Client)); | |||
| return builder; | |||
| } | |||
| public static CommandService UseGlobalBlacklist(this CommandService service) | |||
| { | |||
| service.Root.AddCheck(new BlacklistChecker(service.Client)); | |||
| return service; | |||
| } | |||
| public static IEnumerable<ulong> GetBlacklistedUserIds(this DiscordClient client) | |||
| => client.Services.Get<BlacklistService>().UserIds; | |||
| public static void BlacklistUser(this DiscordClient client, User user) | |||
| { | |||
| client.Services.Get<BlacklistService>().Add(user.Id); | |||
| } | |||
| public static void BlacklistUser(this DiscordClient client, ulong userId) | |||
| { | |||
| client.Services.Get<BlacklistService>().Add(userId); | |||
| } | |||
| public static void UnBlacklistUser(this DiscordClient client, User user) | |||
| { | |||
| client.Services.Get<BlacklistService>().Remove(user.Id); | |||
| } | |||
| public static void UnBlacklistUser(this DiscordClient client, ulong userId) | |||
| { | |||
| client.Services.Get<BlacklistService>().Remove(userId); | |||
| } | |||
| } | |||
| } | |||