| @@ -1,49 +1,41 @@ | |||
| | |||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||
| # Visual Studio 14 | |||
| # Visual Studio 2012 | |||
| VisualStudioVersion = 14.0.23107.0 | |||
| MinimumVisualStudioVersion = 10.0.40219.1 | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8D7989F0-66CE-4DBB-8230-D8C811E9B1D7}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6317A2E6-8E36-4C3E-949B-3F10EC888AB9}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BE8AF3F-3CFD-433F-A380-D294A4F617C1}" | |||
| ProjectSection(SolutionItems) = preProject | |||
| global.json = global.json | |||
| EndProjectSection | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet", "dotnet", "{EA68EBE2-51C8-4440-9EF7-D633C90A5D35}" | |||
| EndProject | |||
| Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "src\Discord.Net\Discord.Net.xproj", "{ACFB060B-EC8A-4926-B293-04C01E17EE23}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet", "dotnet", "{EA68EBE2-51C8-4440-9EF7-D633C90A5D35}" | |||
| EndProject | |||
| Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net.Commands", "src\Discord.Net.Commands\Discord.Net.Commands.xproj", "{19793545-EF89-48F4-8100-3EBAAD0A9141}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{DF03D4E8-38F6-4FE1-BC52-E38124BE8AFD}" | |||
| EndProject | |||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net", "src\Discord.Net.Net45\Discord.Net.csproj", "{8D71A857-879A-4A10-859E-5FF824ED6688}" | |||
| Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "Discord.Net", "src\Discord.Net.Net45\Discord.Net.csproj", "{8D71A857-879A-4A10-859E-5FF824ED6688}" | |||
| EndProject | |||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Commands", "src\Discord.Net.Commands.Net45\Discord.Net.Commands.csproj", "{1B5603B4-6F8F-4289-B945-7BAAE523D740}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6317A2E6-8E36-4C3E-949B-3F10EC888AB9}" | |||
| EndProject | |||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Tests", "test\Discord.Net.Tests\Discord.Net.Tests.csproj", "{855D6B1D-847B-42DA-BE6A-23683EA89511}" | |||
| EndProject | |||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BE8AF3F-3CFD-433F-A380-D294A4F617C1}" | |||
| ProjectSection(SolutionItems) = preProject | |||
| global.json = global.json | |||
| EndProjectSection | |||
| EndProject | |||
| Global | |||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
| Debug|Any CPU = Debug|Any CPU | |||
| Release|Any CPU = Release|Any CPU | |||
| EndGlobalSection | |||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| {1B5603B4-6F8F-4289-B945-7BAAE523D740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {1B5603B4-6F8F-4289-B945-7BAAE523D740}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {1B5603B4-6F8F-4289-B945-7BAAE523D740}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| @@ -52,17 +44,25 @@ Global | |||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| EndGlobalSection | |||
| GlobalSection(SolutionProperties) = preSolution | |||
| HideSolutionNode = FALSE | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| EndGlobalSection | |||
| GlobalSection(NestedProjects) = preSolution | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23} = {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} | |||
| {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} = {8D7989F0-66CE-4DBB-8230-D8C811E9B1D7} | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141} = {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} | |||
| {DF03D4E8-38F6-4FE1-BC52-E38124BE8AFD} = {8D7989F0-66CE-4DBB-8230-D8C811E9B1D7} | |||
| {ACFB060B-EC8A-4926-B293-04C01E17EE23} = {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} | |||
| {19793545-EF89-48F4-8100-3EBAAD0A9141} = {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} | |||
| {8D71A857-879A-4A10-859E-5FF824ED6688} = {DF03D4E8-38F6-4FE1-BC52-E38124BE8AFD} | |||
| {1B5603B4-6F8F-4289-B945-7BAAE523D740} = {DF03D4E8-38F6-4FE1-BC52-E38124BE8AFD} | |||
| {855D6B1D-847B-42DA-BE6A-23683EA89511} = {6317A2E6-8E36-4C3E-949B-3F10EC888AB9} | |||
| EndGlobalSection | |||
| GlobalSection(SolutionProperties) = preSolution | |||
| HideSolutionNode = FALSE | |||
| EndGlobalSection | |||
| EndGlobal | |||
| @@ -1,5 +1,5 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Project ToolsVersion="4.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> | |||
| @@ -11,6 +11,7 @@ | |||
| <AssemblyName>Discord.Net.Commands</AssemblyName> | |||
| <FileAlignment>512</FileAlignment> | |||
| <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |||
| <UseMSBuildEngine>False</UseMSBuildEngine> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| @@ -20,7 +21,7 @@ | |||
| <DefineConstants>TRACE;DEBUG;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <TreatWarningsAsErrors>false</TreatWarningsAsErrors> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <DebugType>pdbonly</DebugType> | |||
| @@ -30,13 +31,8 @@ | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>4</WarningLevel> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Net45\Discord.Net.csproj"> | |||
| <Project>{8d71a857-879a-4a10-859e-5ff824ed6688}</Project> | |||
| <Name>Discord.Net</Name> | |||
| </ProjectReference> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Reference Include="System" /> | |||
| </ItemGroup> | |||
| @@ -66,4 +62,10 @@ | |||
| <Target Name="AfterBuild"> | |||
| </Target> | |||
| --> | |||
| <ItemGroup> | |||
| <ProjectReference Include="..\Discord.Net.Net45\Discord.Net.csproj"> | |||
| <Project>{8D71A857-879A-4A10-859E-5FF824ED6688}</Project> | |||
| <Name>Discord.Net</Name> | |||
| </ProjectReference> | |||
| </ItemGroup> | |||
| </Project> | |||
| @@ -21,11 +21,11 @@ namespace Discord | |||
| public CommandEventArgs(Message message, Command command, string commandText, int? permissions, string[] args) | |||
| { | |||
| Message = message; | |||
| Command = command; | |||
| CommandText = commandText; | |||
| Permissions = permissions; | |||
| Args = args; | |||
| this.Message = message; | |||
| this.Command = command; | |||
| this.CommandText = commandText; | |||
| this.Permissions = permissions; | |||
| this.Args = args; | |||
| } | |||
| } | |||
| public class CommandErrorEventArgs : CommandEventArgs | |||
| @@ -35,7 +35,7 @@ namespace Discord | |||
| public CommandErrorEventArgs(CommandEventArgs baseArgs, Exception ex) | |||
| : base(baseArgs.Message, baseArgs.Command, baseArgs.CommandText, baseArgs.Permissions, baseArgs.Args) | |||
| { | |||
| Exception = ex; | |||
| this.Exception = ex; | |||
| } | |||
| } | |||
| public partial class DiscordBotClient : DiscordClient | |||
| @@ -1,5 +1,5 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
| <Project ToolsVersion="4.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> | |||
| @@ -13,6 +13,7 @@ | |||
| <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | |||
| <NuGetPackageImportStamp> | |||
| </NuGetPackageImportStamp> | |||
| <UseMSBuildEngine>False</UseMSBuildEngine> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| @@ -22,8 +23,8 @@ | |||
| <DefineConstants>TRACE;DEBUG;NET45</DefineConstants> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <WarningLevel>2</WarningLevel> | |||
| <TreatWarningsAsErrors>false</TreatWarningsAsErrors> | |||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
| <DebugType>pdbonly</DebugType> | |||
| @@ -34,6 +35,7 @@ | |||
| <WarningLevel>4</WarningLevel> | |||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'FullDebug|AnyCPU'"> | |||
| <DebugSymbols>true</DebugSymbols> | |||
| @@ -45,18 +47,18 @@ | |||
| <PlatformTarget>AnyCPU</PlatformTarget> | |||
| <ErrorReport>prompt</ErrorReport> | |||
| <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||
| <Optimize>false</Optimize> | |||
| <LangVersion>6</LangVersion> | |||
| </PropertyGroup> | |||
| <ItemGroup> | |||
| <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | |||
| <Reference Include="System" /> | |||
| <Reference Include="System.Net.Http" /> | |||
| <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> | |||
| <HintPath>..\..\..\DiscordBot\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> | |||
| <Private>True</Private> | |||
| </Reference> | |||
| <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL"> | |||
| <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null"> | |||
| <HintPath>..\..\..\DiscordBot\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath> | |||
| <Private>True</Private> | |||
| </Reference> | |||
| <Reference Include="System" /> | |||
| <Reference Include="System.Net.Http" /> | |||
| </ItemGroup> | |||
| <ItemGroup> | |||
| <Content Include="lib\libopus.so"> | |||
| @@ -0,0 +1,112 @@ | |||
| //Ignore unused/unassigned variable warnings | |||
| #pragma warning disable CS0649 | |||
| #pragma warning disable CS0169 | |||
| using Newtonsoft.Json; | |||
| using System; | |||
| using System.Collections.Generic; | |||
| namespace Discord.API | |||
| { | |||
| //Auth | |||
| public sealed class GatewayResponse | |||
| { | |||
| [JsonProperty("url")] | |||
| public string Url; | |||
| } | |||
| public sealed class FingerprintResponse | |||
| { | |||
| [JsonProperty("fingerprint")] | |||
| public string Fingerprint; | |||
| } | |||
| public sealed class RegisterResponse | |||
| { | |||
| [JsonProperty("token")] | |||
| public string Token; | |||
| } | |||
| public sealed class LoginResponse | |||
| { | |||
| [JsonProperty("token")] | |||
| public string Token; | |||
| } | |||
| //Channels | |||
| public sealed class CreateChannelResponse : ChannelInfo { } | |||
| public sealed class DestroyChannelResponse : ChannelInfo { } | |||
| public sealed class EditChannelResponse : ChannelInfo { } | |||
| //Invites | |||
| public sealed class CreateInviteResponse : ExtendedInvite { } | |||
| public sealed class GetInviteResponse : Invite { } | |||
| public sealed class AcceptInviteResponse : Invite { } | |||
| //Messages | |||
| public sealed class SendMessageResponse : Message { } | |||
| public sealed class EditMessageResponse : Message { } | |||
| public sealed class GetMessagesResponse : List<Message> { } | |||
| //Profile | |||
| public sealed class EditProfileResponse : SelfUserInfo { } | |||
| //Servers | |||
| public sealed class CreateServerResponse : GuildInfo { } | |||
| public sealed class DeleteServerResponse : GuildInfo { } | |||
| public sealed class EditServerResponse : GuildInfo { } | |||
| //Voice | |||
| public sealed class GetRegionsResponse : List<GetRegionsResponse.RegionData> | |||
| { | |||
| public sealed class RegionData | |||
| { | |||
| [JsonProperty("sample_hostname")] | |||
| public string Hostname; | |||
| [JsonProperty("sample_port")] | |||
| public int Port; | |||
| [JsonProperty("id")] | |||
| public string Id; | |||
| [JsonProperty("name")] | |||
| public string Name; | |||
| } | |||
| } | |||
| public sealed class GetIceResponse | |||
| { | |||
| [JsonProperty("ttl")] | |||
| public string TTL; | |||
| [JsonProperty("servers")] | |||
| public ServerData[] Servers; | |||
| public sealed class ServerData | |||
| { | |||
| [JsonProperty("url")] | |||
| public string URL; | |||
| [JsonProperty("username")] | |||
| public string Username; | |||
| [JsonProperty("credential")] | |||
| public string Credential; | |||
| } | |||
| } | |||
| public sealed class GetIncidentsResponse | |||
| { | |||
| [JsonProperty("page")] | |||
| public PageData Page; | |||
| [JsonProperty("scheduled_maintenances")] | |||
| public MaintenanceData[] ScheduledMaintenances; | |||
| public sealed class PageData | |||
| { | |||
| [JsonProperty("id")] | |||
| public string Id; | |||
| [JsonProperty("name")] | |||
| public string Name; | |||
| [JsonProperty("url")] | |||
| public string Url; | |||
| [JsonProperty("updated-at")] | |||
| public DateTime UpdatedAt; | |||
| } | |||
| public sealed class MaintenanceData | |||
| { | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,293 @@ | |||
| using Discord.API; | |||
| using System; | |||
| using System.Threading; | |||
| using System.Threading.Tasks; | |||
| namespace Discord | |||
| { | |||
| /// <summary> A lightweight wrapper around the Discord API. </summary> | |||
| public class DiscordAPIClient | |||
| { | |||
| internal RestClient RestClient => _rest; | |||
| private readonly RestClient _rest; | |||
| public DiscordAPIClient(LogMessageSeverity logLevel, int timeout) | |||
| { | |||
| _rest = new RestClient(logLevel, timeout); | |||
| } | |||
| private string _token; | |||
| public string Token | |||
| { | |||
| get { return _token; } | |||
| set { _token = value; _rest.SetToken(value); } | |||
| } | |||
| private CancellationToken _cancelToken; | |||
| public CancellationToken CancelToken | |||
| { | |||
| get { return _cancelToken; } | |||
| set { _cancelToken = value; _rest.SetCancelToken(value); } | |||
| } | |||
| //Auth | |||
| public Task<GatewayResponse> Gateway() | |||
| => _rest.Get<GatewayResponse>(Endpoints.Gateway); | |||
| public Task<FingerprintResponse> Fingerprint() | |||
| => _rest.Post<FingerprintResponse>(Endpoints.AuthFingerprint); | |||
| public async Task<RegisterResponse> LoginAnonymous(string username, string fingerprint) | |||
| { | |||
| if (username == null) throw new ArgumentNullException(nameof(username)); | |||
| if (fingerprint == null) throw new ArgumentNullException(nameof(fingerprint)); | |||
| var request = new RegisterRequest { Fingerprint = fingerprint, Username = username }; | |||
| return await _rest.Post<RegisterResponse>(Endpoints.AuthRegister, request).ConfigureAwait(false); | |||
| } | |||
| public async Task<LoginResponse> Login(string email, string password) | |||
| { | |||
| if (email == null) throw new ArgumentNullException(nameof(email)); | |||
| if (password == null) throw new ArgumentNullException(nameof(password)); | |||
| var request = new LoginRequest { Email = email, Password = password }; | |||
| return await _rest.Post<LoginResponse>(Endpoints.AuthLogin, request).ConfigureAwait(false); | |||
| } | |||
| public Task Logout() | |||
| => _rest.Post(Endpoints.AuthLogout); | |||
| //Channels | |||
| public Task<CreateChannelResponse> CreateChannel(string serverId, string name, string channelType) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| if (channelType == null) throw new ArgumentNullException(nameof(channelType)); | |||
| var request = new CreateChannelRequest { Name = name, Type = channelType }; | |||
| return _rest.Post<CreateChannelResponse>(Endpoints.ServerChannels(serverId), request); | |||
| } | |||
| public Task<CreateChannelResponse> CreatePMChannel(string myId, string recipientId) | |||
| { | |||
| if (myId == null) throw new ArgumentNullException(nameof(myId)); | |||
| if (recipientId == null) throw new ArgumentNullException(nameof(recipientId)); | |||
| var request = new CreatePMChannelRequest { RecipientId = recipientId }; | |||
| return _rest.Post<CreateChannelResponse>(Endpoints.UserChannels(myId), request); | |||
| } | |||
| public Task<DestroyChannelResponse> DestroyChannel(string channelId) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| return _rest.Delete<DestroyChannelResponse>(Endpoints.Channel(channelId)); | |||
| } | |||
| public Task<EditChannelResponse> EditChannel(string channelId, string name = null, string topic = null) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| var request = new EditChannelRequest { Name = name, Topic = topic }; | |||
| return _rest.Patch<EditChannelResponse>(Endpoints.Channel(channelId), request); | |||
| } | |||
| public Task<GetMessagesResponse> GetMessages(string channelId, int count) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| return _rest.Get<GetMessagesResponse>(Endpoints.ChannelMessages(channelId, count)); | |||
| } | |||
| //Incidents | |||
| public Task<GetIncidentsResponse> GetUnresolvedIncidents() | |||
| { | |||
| return _rest.Get<GetIncidentsResponse>(Endpoints.StatusUnresolvedMaintenance); | |||
| } | |||
| public Task<GetIncidentsResponse> GetActiveIncidents() | |||
| { | |||
| return _rest.Get<GetIncidentsResponse>(Endpoints.StatusActiveMaintenance); | |||
| } | |||
| public Task<GetIncidentsResponse> GetUpcomingIncidents() | |||
| { | |||
| return _rest.Get<GetIncidentsResponse>(Endpoints.StatusUpcomingMaintenance); | |||
| } | |||
| //Invites | |||
| public Task<CreateInviteResponse> CreateInvite(string channelId, int maxAge, int maxUses, bool isTemporary, bool withXkcdPass) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| var request = new CreateInviteRequest { MaxAge = maxAge, MaxUses = maxUses, IsTemporary = isTemporary, WithXkcdPass = withXkcdPass }; | |||
| return _rest.Post<CreateInviteResponse>(Endpoints.ChannelInvites(channelId), request); | |||
| } | |||
| public Task<GetInviteResponse> GetInvite(string inviteIdOrXkcd) | |||
| { | |||
| if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); | |||
| return _rest.Get<GetInviteResponse>(Endpoints.Invite(inviteIdOrXkcd)); | |||
| } | |||
| public Task<AcceptInviteResponse> AcceptInvite(string inviteId) | |||
| { | |||
| if (inviteId == null) throw new ArgumentNullException(nameof(inviteId)); | |||
| return _rest.Post<AcceptInviteResponse>(Endpoints.Invite(inviteId)); | |||
| } | |||
| public Task DeleteInvite(string inviteId) | |||
| { | |||
| if (inviteId == null) throw new ArgumentNullException(nameof(inviteId)); | |||
| return _rest.Delete(Endpoints.Invite(inviteId)); | |||
| } | |||
| //Members | |||
| public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, string[] roles = null) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (userId == null) throw new ArgumentNullException(nameof(userId)); | |||
| var request = new EditMemberRequest { Mute = mute, Deaf = deaf, Roles = roles }; | |||
| return _rest.Patch(Endpoints.ServerMember(serverId, userId)); | |||
| } | |||
| public Task Kick(string serverId, string userId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (userId == null) throw new ArgumentNullException(nameof(userId)); | |||
| return _rest.Delete(Endpoints.ServerMember(serverId, userId)); | |||
| } | |||
| public Task Ban(string serverId, string userId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (userId == null) throw new ArgumentNullException(nameof(userId)); | |||
| return _rest.Put(Endpoints.ServerBan(serverId, userId)); | |||
| } | |||
| public Task Unban(string serverId, string userId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (userId == null) throw new ArgumentNullException(nameof(userId)); | |||
| return _rest.Delete(Endpoints.ServerBan(serverId, userId)); | |||
| } | |||
| //Messages | |||
| public Task<SendMessageResponse> SendMessage(string channelId, string message, string[] mentions = null, string nonce = null, bool isTTS = false) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| if (message == null) throw new ArgumentNullException(nameof(message)); | |||
| var request = new SendMessageRequest { Content = message, Mentions = mentions ?? new string[0], Nonce = nonce, IsTTS = isTTS ? true : false }; | |||
| return _rest.Post<SendMessageResponse>(Endpoints.ChannelMessages(channelId), request); | |||
| } | |||
| public Task<SendMessageResponse> SendFile(string channelId, string filePath) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| if (filePath == null) throw new ArgumentNullException(nameof(filePath)); | |||
| return _rest.PostFile<SendMessageResponse>(Endpoints.ChannelMessages(channelId), filePath); | |||
| } | |||
| public Task DeleteMessage(string messageId, string channelId) | |||
| { | |||
| if (messageId == null) throw new ArgumentNullException(nameof(messageId)); | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| return _rest.Delete(Endpoints.ChannelMessage(channelId, messageId)); | |||
| } | |||
| public Task<EditMessageResponse> EditMessage(string messageId, string channelId, string message = null, string[] mentions = null) | |||
| { | |||
| if (messageId == null) throw new ArgumentNullException(nameof(messageId)); | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| var request = new EditMessageRequest { Content = message, Mentions = mentions }; | |||
| return _rest.Patch<EditMessageResponse>(Endpoints.ChannelMessage(channelId, messageId), request); | |||
| } | |||
| public Task SendIsTyping(string channelId) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| return _rest.Post(Endpoints.ChannelTyping(channelId)); | |||
| } | |||
| //Permissions | |||
| public Task SetChannelPermissions(string channelId, string userOrRoleId, string idType, uint allow = 0, uint deny = 0) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| if (userOrRoleId == null) throw new ArgumentNullException(nameof(userOrRoleId)); | |||
| if (idType == null) throw new ArgumentNullException(nameof(idType)); | |||
| var request = new SetChannelPermissionsRequest { Id = userOrRoleId, Type = idType, Allow = allow, Deny = deny }; | |||
| return _rest.Put(Endpoints.ChannelPermission(channelId, userOrRoleId), request); | |||
| } | |||
| public Task DeleteChannelPermissions(string channelId, string userOrRoleId) | |||
| { | |||
| if (channelId == null) throw new ArgumentNullException(nameof(channelId)); | |||
| if (userOrRoleId == null) throw new ArgumentNullException(nameof(userOrRoleId)); | |||
| return _rest.Delete(Endpoints.ChannelPermission(channelId, userOrRoleId), null); | |||
| } | |||
| //Profile | |||
| public Task<EditProfileResponse> EditProfile(string currentPassword, | |||
| string username = null, string email = null, string password = null, | |||
| AvatarImageType avatarType = AvatarImageType.Png, byte[] avatar = null) | |||
| { | |||
| if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword)); | |||
| string avatarBase64 = null; | |||
| if (avatar != null) | |||
| { | |||
| string base64 = Convert.ToBase64String(avatar); | |||
| string type = avatarType == AvatarImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64"; | |||
| avatarBase64 = $"data:{type},/9j/{base64}"; | |||
| } | |||
| var request = new EditProfileRequest { CurrentPassword = currentPassword, Username = username, Email = email, Password = password, Avatar = avatarBase64 }; | |||
| return _rest.Patch<EditProfileResponse>(Endpoints.UserMe, request); | |||
| } | |||
| //Roles | |||
| public Task CreateRole(string serverId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| //TODO: Return a response when Discord starts giving us one | |||
| return _rest.Post(Endpoints.ServerRoles(serverId)); | |||
| } | |||
| public Task DeleteRole(string serverId, string roleId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (roleId == null) throw new ArgumentNullException(nameof(roleId)); | |||
| return _rest.Delete(Endpoints.ServerRole(serverId, roleId)); | |||
| } | |||
| public Task EditRole(string serverId, string roleId, string name = null, uint? permissions = null) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| if (roleId == null) throw new ArgumentNullException(nameof(roleId)); | |||
| var request = new EditRoleRequest { Name = name, Permissions = permissions }; | |||
| return _rest.Patch(Endpoints.ServerRole(serverId, roleId), request); | |||
| } | |||
| //Servers | |||
| public Task<CreateServerResponse> CreateServer(string name, string region) | |||
| { | |||
| if (name == null) throw new ArgumentNullException(nameof(name)); | |||
| if (region == null) throw new ArgumentNullException(nameof(region)); | |||
| var request = new CreateServerRequest { Name = name, Region = region }; | |||
| return _rest.Post<CreateServerResponse>(Endpoints.Servers, request); | |||
| } | |||
| public Task LeaveServer(string serverId) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| return _rest.Delete<DeleteServerResponse>(Endpoints.Server(serverId)); | |||
| } | |||
| public Task<EditServerResponse> EditServer(string serverId, string name = null, string region = null) | |||
| { | |||
| if (serverId == null) throw new ArgumentNullException(nameof(serverId)); | |||
| var request = new EditServerRequest { Name = name, Region = region }; | |||
| return _rest.Patch<EditServerResponse>(Endpoints.Server(serverId), request); | |||
| } | |||
| //Voice | |||
| public Task<GetRegionsResponse> GetVoiceRegions() | |||
| => _rest.Get<GetRegionsResponse>(Endpoints.VoiceRegions); | |||
| public Task<GetIceResponse> GetVoiceIce() | |||
| => _rest.Get<GetIceResponse>(Endpoints.VoiceIce); | |||
| } | |||
| } | |||
| @@ -25,7 +25,12 @@ namespace Discord | |||
| { | |||
| public readonly bool WasUnexpected; | |||
| public readonly Exception Error; | |||
| internal DisconnectedEventArgs(bool wasUnexpected, Exception error) { WasUnexpected = wasUnexpected; Error = error; } | |||
| internal DisconnectedEventArgs(bool wasUnexpected, Exception error) | |||
| { | |||
| this.WasUnexpected = wasUnexpected; | |||
| this.Error = error; | |||
| } | |||
| } | |||
| public sealed class LogMessageEventArgs : EventArgs | |||
| { | |||
| @@ -33,7 +38,12 @@ namespace Discord | |||
| public LogMessageSource Source { get; } | |||
| public string Message { get; } | |||
| internal LogMessageEventArgs(LogMessageSeverity severity, LogMessageSource source, string msg) { Severity = severity; Source = source; Message = msg; } | |||
| internal LogMessageEventArgs(LogMessageSeverity severity, LogMessageSource source, string msg) | |||
| { | |||
| this.Severity = severity; | |||
| this.Source = source; | |||
| this.Message = msg; | |||
| } | |||
| } | |||
| public sealed class ServerEventArgs : EventArgs | |||
| @@ -41,7 +51,7 @@ namespace Discord | |||
| public Server Server { get; } | |||
| public string ServerId => Server.Id; | |||
| internal ServerEventArgs(Server server) { Server = server; } | |||
| internal ServerEventArgs(Server server) { this.Server = server; } | |||
| } | |||
| public sealed class ChannelEventArgs : EventArgs | |||
| { | |||
| @@ -50,14 +60,14 @@ namespace Discord | |||
| public Server Server => Channel.Server; | |||
| public string ServerId => Channel.ServerId; | |||
| internal ChannelEventArgs(Channel channel) { Channel = channel; } | |||
| internal ChannelEventArgs(Channel channel) { this.Channel = channel; } | |||
| } | |||
| public sealed class UserEventArgs : EventArgs | |||
| { | |||
| public User User { get; } | |||
| public string UserId => User.Id; | |||
| internal UserEventArgs(User user) { User = user; } | |||
| internal UserEventArgs(User user) { this.User = user; } | |||
| } | |||
| public sealed class MessageEventArgs : EventArgs | |||
| { | |||
| @@ -71,7 +81,7 @@ namespace Discord | |||
| public User User => Member.User; | |||
| public string UserId => Message.UserId; | |||
| internal MessageEventArgs(Message msg) { Message = msg; } | |||
| internal MessageEventArgs(Message msg) { this.Message = msg; } | |||
| } | |||
| public sealed class RoleEventArgs : EventArgs | |||
| { | |||
| @@ -80,7 +90,7 @@ namespace Discord | |||
| public Server Server => Role.Server; | |||
| public string ServerId => Role.ServerId; | |||
| internal RoleEventArgs(Role role) { Role = role; } | |||
| internal RoleEventArgs(Role role) { this.Role = role; } | |||
| } | |||
| public sealed class BanEventArgs : EventArgs | |||
| { | |||
| @@ -91,9 +101,9 @@ namespace Discord | |||
| internal BanEventArgs(User user, string userId, Server server) | |||
| { | |||
| User = user; | |||
| UserId = userId; | |||
| Server = server; | |||
| this.User = user; | |||
| this.UserId = userId; | |||
| this.Server = server; | |||
| } | |||
| } | |||
| public sealed class MemberEventArgs : EventArgs | |||
| @@ -104,7 +114,7 @@ namespace Discord | |||
| public Server Server => Member.Server; | |||
| public string ServerId => Member.ServerId; | |||
| internal MemberEventArgs(Member member) { Member = member; } | |||
| internal MemberEventArgs(Member member) { this.Member = member; } | |||
| } | |||
| public sealed class UserTypingEventArgs : EventArgs | |||
| { | |||
| @@ -117,8 +127,8 @@ namespace Discord | |||
| internal UserTypingEventArgs(User user, Channel channel) | |||
| { | |||
| User = user; | |||
| Channel = channel; | |||
| this.User = user; | |||
| this.Channel = channel; | |||
| } | |||
| } | |||
| public sealed class UserIsSpeakingEventArgs : EventArgs | |||
| @@ -134,21 +144,10 @@ namespace Discord | |||
| internal UserIsSpeakingEventArgs(Member member, bool isSpeaking) | |||
| { | |||
| Member = member; | |||
| IsSpeaking = isSpeaking; | |||
| this.Member = member; | |||
| this.IsSpeaking = isSpeaking; | |||
| } | |||
| } | |||
| /*public sealed class VoiceServerUpdatedEventArgs : EventArgs | |||
| { | |||
| public Server Server { get; } | |||
| public string ServerId => Server.Id; | |||
| public string Endpoint { get; } | |||
| internal VoiceServerUpdatedEventArgs(Server server, string endpoint) | |||
| { | |||
| Server = server; | |||
| Endpoint = endpoint; | |||
| } | |||
| }*/ | |||
| public partial class DiscordClient | |||
| { | |||
| @@ -102,7 +102,7 @@ namespace Discord.WebSockets.Voice | |||
| _isClearing = false; | |||
| _udp = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); | |||
| #if !DNX451 | |||
| #if !DNX451 && !__MonoCS__ | |||
| _udp.AllowNatTraversal(true); | |||
| #endif | |||