@@ -1,6 +1,6 @@ | |||||
Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
# Visual Studio 15 | # Visual Studio 15 | ||||
VisualStudioVersion = 15.0.27130.0 | |||||
VisualStudioVersion = 15.0.27004.2009 | |||||
MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Core", "src\Discord.Net.Core\Discord.Net.Core.csproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" | ||||
EndProject | EndProject | ||||
@@ -22,7 +22,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Tests", "test\D | |||||
EndProject | EndProject | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Webhook", "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj", "{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Webhook", "src\Discord.Net.Webhook\Discord.Net.Webhook.csproj", "{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Analyzers", "src\Discord.Net.Analyzers\Discord.Net.Analyzers.csproj", "{BBA8E7FB-C834-40DC-822F-B112CB7F0140}" | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Net.Analyzers", "src\Discord.Net.Analyzers\Discord.Net.Analyzers.csproj", "{BBA8E7FB-C834-40DC-822F-B112CB7F0140}" | |||||
EndProject | |||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{BB59D5B5-E7B0-4BF4-8F82-D14431B2799B}" | |||||
EndProject | |||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "01_basic_ping_bot", "samples\01_basic_ping_bot\01_basic_ping_bot.csproj", "{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}" | |||||
EndProject | |||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02_commands_framework", "samples\02_commands_framework\02_commands_framework.csproj", "{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}" | |||||
EndProject | EndProject | ||||
Global | Global | ||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
@@ -130,6 +136,30 @@ Global | |||||
{BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x64.Build.0 = Release|Any CPU | {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x64.Build.0 = Release|Any CPU | ||||
{BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.ActiveCfg = Release|Any CPU | {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.ActiveCfg = Release|Any CPU | ||||
{BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.Build.0 = Release|Any CPU | {BBA8E7FB-C834-40DC-822F-B112CB7F0140}.Release|x86.Build.0 = Release|Any CPU | ||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|x64.ActiveCfg = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|x64.Build.0 = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Debug|x86.Build.0 = Debug|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|x64.ActiveCfg = Release|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|x64.Build.0 = Release|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|x86.ActiveCfg = Release|Any CPU | |||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E}.Release|x86.Build.0 = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|x64.ActiveCfg = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|x64.Build.0 = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|x86.ActiveCfg = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Debug|x86.Build.0 = Debug|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|x64.ActiveCfg = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|x64.Build.0 = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|x86.ActiveCfg = Release|Any CPU | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76}.Release|x86.Build.0 = Release|Any CPU | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
@@ -141,6 +171,8 @@ Global | |||||
{6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012} | {6BDEEC08-417B-459F-9CA3-FF8BAB18CAC7} = {B0657AAE-DCC5-4FBF-8E5D-1FB578CF3012} | ||||
{9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | {9AFAB80E-D2D3-4EDB-B58C-BACA78D1EA30} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | ||||
{BBA8E7FB-C834-40DC-822F-B112CB7F0140} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | {BBA8E7FB-C834-40DC-822F-B112CB7F0140} = {CC3D4B1C-9DE0-448B-8AE7-F3F1F3EC5C3A} | ||||
{F2FF84FB-F6AD-47E5-9EE5-18206CAE136E} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} | |||||
{4E1F1F40-B1DD-40C9-A4B1-A2046A4C9C76} = {BB59D5B5-E7B0-4BF4-8F82-D14431B2799B} | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(ExtensibilityGlobals) = postSolution | GlobalSection(ExtensibilityGlobals) = postSolution | ||||
SolutionGuid = {D2404771-EEC8-45F2-9D71-F3373F6C1495} | SolutionGuid = {D2404771-EEC8-45F2-9D71-F3373F6C1495} | ||||
@@ -16,13 +16,7 @@ | |||||
<PropertyGroup Condition=" '$(BuildNumber)' != '' And $(IsTagBuild) != 'true' "> | <PropertyGroup Condition=" '$(BuildNumber)' != '' And $(IsTagBuild) != 'true' "> | ||||
<VersionSuffix Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix> | <VersionSuffix Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix> | ||||
<VersionSuffix Condition=" '$(VersionSuffix)' == '' ">build-$(BuildNumber)</VersionSuffix> | <VersionSuffix Condition=" '$(VersionSuffix)' == '' ">build-$(BuildNumber)</VersionSuffix> | ||||
</PropertyGroup> | |||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' Or '$(TargetFramework)' == 'net45' "> | |||||
<DefineConstants>$(DefineConstants);FILESYSTEM;DEFAULTUDPCLIENT;DEFAULTWEBSOCKET</DefineConstants> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> | |||||
<DefineConstants>$(DefineConstants);FORMATSTR;UNIXTIME;MSTRYBUFFER;UDPDISPOSE</DefineConstants> | |||||
</PropertyGroup> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||||
<NoWarn>$(NoWarn);CS1573;CS1591</NoWarn> | <NoWarn>$(NoWarn);CS1573;CS1591</NoWarn> | ||||
<WarningsAsErrors>true</WarningsAsErrors> | <WarningsAsErrors>true</WarningsAsErrors> | ||||
@@ -0,0 +1,12 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<OutputType>Exe</OutputType> | |||||
<TargetFramework>netcoreapp2.0</TargetFramework> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\..\src\Discord.Net.WebSocket\Discord.Net.WebSocket.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,69 @@ | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
using Discord; | |||||
using Discord.WebSocket; | |||||
namespace _01_basic_ping_bot | |||||
{ | |||||
// This is a minimal, barebones example of using Discord.Net | |||||
// | |||||
// If writing a bot with commands, we recommend using the Discord.Net.Commands | |||||
// framework, rather than handling commands yourself, like we do in this sample. | |||||
// | |||||
// You can find samples of using the command framework: | |||||
// - Here, under the 02_commands_framework sample | |||||
// - https://github.com/foxbot/DiscordBotBase - a barebones bot template | |||||
// - https://github.com/foxbot/patek - a more feature-filled bot, utilizing more aspects of the library | |||||
class Program | |||||
{ | |||||
private DiscordSocketClient _client; | |||||
// Discord.Net heavily utilizes TAP for async, so we create | |||||
// an asynchronous context from the beginning. | |||||
static void Main(string[] args) | |||||
=> new Program().MainAsync().GetAwaiter().GetResult(); | |||||
public async Task MainAsync() | |||||
{ | |||||
_client = new DiscordSocketClient(); | |||||
_client.Log += LogAsync; | |||||
_client.Ready += ReadyAsync; | |||||
_client.MessageReceived += MessageReceivedAsync; | |||||
// Tokens should be considered secret data, and never hard-coded. | |||||
await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token")); | |||||
await _client.StartAsync(); | |||||
// Block the program until it is closed. | |||||
await Task.Delay(-1); | |||||
} | |||||
private Task LogAsync(LogMessage log) | |||||
{ | |||||
Console.WriteLine(log.ToString()); | |||||
return Task.CompletedTask; | |||||
} | |||||
// The Ready event indicates that the client has opened a | |||||
// connection and it is now safe to access the cache. | |||||
private Task ReadyAsync() | |||||
{ | |||||
Console.WriteLine($"{_client.CurrentUser} is connected!"); | |||||
return Task.CompletedTask; | |||||
} | |||||
// This is not the recommmended way to write a bot - consider | |||||
// reading over the Commands Framework sample. | |||||
private async Task MessageReceivedAsync(SocketMessage message) | |||||
{ | |||||
// The bot should never respond to itself. | |||||
if (message.Author.Id == _client.CurrentUser.Id) | |||||
return; | |||||
if (message.Content == "!ping") | |||||
await message.Channel.SendMessageAsync("pong!"); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,17 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<OutputType>Exe</OutputType> | |||||
<TargetFramework>netcoreapp2.0</TargetFramework> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\..\src\Discord.Net.Commands\Discord.Net.Commands.csproj" /> | |||||
<ProjectReference Include="..\..\src\Discord.Net.WebSocket\Discord.Net.WebSocket.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,63 @@ | |||||
using System.IO; | |||||
using System.Threading.Tasks; | |||||
using Discord; | |||||
using Discord.Commands; | |||||
using _02_commands_framework.Services; | |||||
namespace _02_commands_framework.Modules | |||||
{ | |||||
// Modules must be public and inherit from an IModuleBase | |||||
public class PublicModule : ModuleBase<SocketCommandContext> | |||||
{ | |||||
// Dependency Injection will fill this value in for us | |||||
public PictureService PictureService { get; set; } | |||||
[Command("ping")] | |||||
[Alias("pong", "hello")] | |||||
public Task PingAsync() | |||||
=> ReplyAsync("pong!"); | |||||
[Command("cat")] | |||||
public async Task CatAsync() | |||||
{ | |||||
// Get a stream containing an image of a cat | |||||
var stream = await PictureService.GetCatPictureAsync(); | |||||
// Streams must be seeked to their beginning before being uploaded! | |||||
stream.Seek(0, SeekOrigin.Begin); | |||||
await Context.Channel.SendFileAsync(stream, "cat.png"); | |||||
} | |||||
// Get info on a user, or the user who invoked the command if one is not specified | |||||
[Command("userinfo")] | |||||
public async Task UserInfoAsync(IUser user = null) | |||||
{ | |||||
user = user ?? Context.User; | |||||
await ReplyAsync(user.ToString()); | |||||
} | |||||
// Ban a user | |||||
[Command("ban")] | |||||
[RequireContext(ContextType.Guild)] | |||||
// make sure the user invoking the command can ban | |||||
[RequireUserPermission(GuildPermission.BanMembers)] | |||||
// make sure the bot itself can ban | |||||
[RequireBotPermission(GuildPermission.BanMembers)] | |||||
public async Task BanUserAsync(IGuildUser user, [Remainder] string reason = null) | |||||
{ | |||||
await user.Guild.AddBanAsync(user, reason: reason); | |||||
await ReplyAsync("ok!"); | |||||
} | |||||
// [Remainder] takes the rest of the command's arguments as one argument, rather than splitting every space | |||||
[Command("echo")] | |||||
public Task EchoAsync([Remainder] string text) | |||||
// Insert a ZWSP before the text to prevent triggering other bots! | |||||
=> ReplyAsync('\u200B' + text); | |||||
// 'params' will parse space-separated elements into a list | |||||
[Command("list")] | |||||
public Task ListAsync(params string[] objects) | |||||
=> ReplyAsync("You listed: " + string.Join("; ", objects)); | |||||
} | |||||
} |
@@ -0,0 +1,60 @@ | |||||
using System; | |||||
using System.Net.Http; | |||||
using System.Threading.Tasks; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Discord; | |||||
using Discord.WebSocket; | |||||
using Discord.Commands; | |||||
using _02_commands_framework.Services; | |||||
namespace _02_commands_framework | |||||
{ | |||||
// This is a minimal example of using Discord.Net's command | |||||
// framework - by no means does it show everything the framework | |||||
// is capable of. | |||||
// | |||||
// You can find samples of using the command framework: | |||||
// - Here, under the 02_commands_framework sample | |||||
// - https://github.com/foxbot/DiscordBotBase - a barebones bot template | |||||
// - https://github.com/foxbot/patek - a more feature-filled bot, utilizing more aspects of the library | |||||
class Program | |||||
{ | |||||
static void Main(string[] args) | |||||
=> new Program().MainAsync().GetAwaiter().GetResult(); | |||||
public async Task MainAsync() | |||||
{ | |||||
var services = ConfigureServices(); | |||||
var client = services.GetRequiredService<DiscordSocketClient>(); | |||||
client.Log += LogAsync; | |||||
services.GetRequiredService<CommandService>().Log += LogAsync; | |||||
await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token")); | |||||
await client.StartAsync(); | |||||
await services.GetRequiredService<CommandHandlingService>().InitializeAsync(); | |||||
await Task.Delay(-1); | |||||
} | |||||
private Task LogAsync(LogMessage log) | |||||
{ | |||||
Console.WriteLine(log.ToString()); | |||||
return Task.CompletedTask; | |||||
} | |||||
private IServiceProvider ConfigureServices() | |||||
{ | |||||
return new ServiceCollection() | |||||
.AddSingleton<DiscordSocketClient>() | |||||
.AddSingleton<CommandService>() | |||||
.AddSingleton<CommandHandlingService>() | |||||
.AddSingleton<HttpClient>() | |||||
.AddSingleton<PictureService>() | |||||
.BuildServiceProvider(); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,49 @@ | |||||
using System; | |||||
using System.Reflection; | |||||
using System.Threading.Tasks; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Discord; | |||||
using Discord.Commands; | |||||
using Discord.WebSocket; | |||||
namespace _02_commands_framework.Services | |||||
{ | |||||
public class CommandHandlingService | |||||
{ | |||||
private readonly CommandService _commands; | |||||
private readonly DiscordSocketClient _discord; | |||||
private readonly IServiceProvider _services; | |||||
public CommandHandlingService(IServiceProvider services) | |||||
{ | |||||
_commands = services.GetRequiredService<CommandService>(); | |||||
_discord = services.GetRequiredService<DiscordSocketClient>(); | |||||
_services = services; | |||||
_discord.MessageReceived += MessageReceivedAsync; | |||||
} | |||||
public async Task InitializeAsync() | |||||
{ | |||||
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); | |||||
} | |||||
public async Task MessageReceivedAsync(SocketMessage rawMessage) | |||||
{ | |||||
// Ignore system messages, or messages from other bots | |||||
if (!(rawMessage is SocketUserMessage message)) return; | |||||
if (message.Source != MessageSource.User) return; | |||||
// This value holds the offset where the prefix ends | |||||
var argPos = 0; | |||||
if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) return; | |||||
var context = new SocketCommandContext(_discord, message); | |||||
var result = await _commands.ExecuteAsync(context, argPos, _services); | |||||
if (result.Error.HasValue && | |||||
result.Error.Value != CommandError.UnknownCommand) // it's bad practice to send 'unknown command' errors | |||||
await context.Channel.SendMessageAsync(result.ToString()); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,20 @@ | |||||
using System.IO; | |||||
using System.Net.Http; | |||||
using System.Threading.Tasks; | |||||
namespace _02_commands_framework.Services | |||||
{ | |||||
public class PictureService | |||||
{ | |||||
private readonly HttpClient _http; | |||||
public PictureService(HttpClient http) | |||||
=> _http = http; | |||||
public async Task<Stream> GetCatPictureAsync() | |||||
{ | |||||
var resp = await _http.GetAsync("https://cataas.com/cat"); | |||||
return await resp.Content.ReadAsStreamAsync(); | |||||
} | |||||
} | |||||
} |
@@ -7,7 +7,7 @@ | |||||
<TargetFramework>netstandard1.3</TargetFramework> | <TargetFramework>netstandard1.3</TargetFramework> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.0" /> | |||||
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.0" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\Discord.Net.Commands\Discord.Net.Commands.csproj" /> | <ProjectReference Include="..\Discord.Net.Commands\Discord.Net.Commands.csproj" /> | ||||
@@ -7,6 +7,7 @@ namespace Discord.Commands | |||||
{ | { | ||||
public string Text { get; } | public string Text { get; } | ||||
public RunMode RunMode { get; set; } = RunMode.Default; | public RunMode RunMode { get; set; } = RunMode.Default; | ||||
public bool? IgnoreExtraArgs { get; set; } | |||||
public CommandAttribute() | public CommandAttribute() | ||||
{ | { | ||||
@@ -1,8 +1,7 @@ | |||||
using System; | |||||
using System; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using Microsoft.Extensions.DependencyInjection; | |||||
namespace Discord.Commands.Builders | namespace Discord.Commands.Builders | ||||
{ | { | ||||
@@ -22,6 +21,7 @@ namespace Discord.Commands.Builders | |||||
public string PrimaryAlias { get; set; } | public string PrimaryAlias { get; set; } | ||||
public RunMode RunMode { get; set; } | public RunMode RunMode { get; set; } | ||||
public int Priority { get; set; } | public int Priority { get; set; } | ||||
public bool IgnoreExtraArgs { get; set; } | |||||
public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions; | public IReadOnlyList<PreconditionAttribute> Preconditions => _preconditions; | ||||
public IReadOnlyList<ParameterBuilder> Parameters => _parameters; | public IReadOnlyList<ParameterBuilder> Parameters => _parameters; | ||||
@@ -140,4 +140,4 @@ namespace Discord.Commands.Builders | |||||
return new CommandInfo(this, info, service); | return new CommandInfo(this, info, service); | ||||
} | } | ||||
} | } | ||||
} | |||||
} |
@@ -2,7 +2,6 @@ using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Reflection; | using System.Reflection; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Microsoft.Extensions.DependencyInjection; | |||||
namespace Discord.Commands.Builders | namespace Discord.Commands.Builders | ||||
{ | { | ||||
@@ -158,6 +158,7 @@ namespace Discord.Commands | |||||
builder.AddAliases(command.Text); | builder.AddAliases(command.Text); | ||||
builder.RunMode = command.RunMode; | builder.RunMode = command.RunMode; | ||||
builder.Name = builder.Name ?? command.Text; | builder.Name = builder.Name ?? command.Text; | ||||
builder.IgnoreExtraArgs = command.IgnoreExtraArgs ?? service._ignoreExtraArgs; | |||||
break; | break; | ||||
case NameAttribute name: | case NameAttribute name: | ||||
builder.Name = name.Text; | builder.Name = name.Text; | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -13,8 +14,7 @@ namespace Discord.Commands | |||||
Parameter, | Parameter, | ||||
QuotedParameter | QuotedParameter | ||||
} | } | ||||
public static async Task<ParseResult> ParseArgsAsync(CommandInfo command, ICommandContext context, bool ignoreExtraArgs, IServiceProvider services, string input, int startPos) | |||||
public static async Task<ParseResult> ParseArgsAsync(CommandInfo command, ICommandContext context, bool ignoreExtraArgs, IServiceProvider services, string input, int startPos, IReadOnlyDictionary<char, char> aliasMap) | |||||
{ | { | ||||
ParameterInfo curParam = null; | ParameterInfo curParam = null; | ||||
StringBuilder argBuilder = new StringBuilder(input.Length); | StringBuilder argBuilder = new StringBuilder(input.Length); | ||||
@@ -24,7 +24,27 @@ namespace Discord.Commands | |||||
var argList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | var argList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | ||||
var paramList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | var paramList = ImmutableArray.CreateBuilder<TypeReaderResult>(); | ||||
bool isEscaping = false; | bool isEscaping = false; | ||||
char c; | |||||
char c, matchQuote = '\0'; | |||||
// local helper functions | |||||
bool IsOpenQuote(IReadOnlyDictionary<char, char> dict, char ch) | |||||
{ | |||||
// return if the key is contained in the dictionary if it is populated | |||||
if (dict.Count != 0) | |||||
return dict.ContainsKey(ch); | |||||
// or otherwise if it is the default double quote | |||||
return c == '\"'; | |||||
} | |||||
char GetMatch(IReadOnlyDictionary<char, char> dict, char ch) | |||||
{ | |||||
// get the corresponding value for the key, if it exists | |||||
// and if the dictionary is populated | |||||
if (dict.Count != 0 && dict.TryGetValue(c, out var value)) | |||||
return value; | |||||
// or get the default pair of the default double quote | |||||
return '\"'; | |||||
} | |||||
for (int curPos = startPos; curPos <= endPos; curPos++) | for (int curPos = startPos; curPos <= endPos; curPos++) | ||||
{ | { | ||||
@@ -74,9 +94,11 @@ namespace Discord.Commands | |||||
argBuilder.Append(c); | argBuilder.Append(c); | ||||
continue; | continue; | ||||
} | } | ||||
if (c == '\"') | |||||
if (IsOpenQuote(aliasMap, c)) | |||||
{ | { | ||||
curPart = ParserPart.QuotedParameter; | curPart = ParserPart.QuotedParameter; | ||||
matchQuote = GetMatch(aliasMap, c); | |||||
continue; | continue; | ||||
} | } | ||||
curPart = ParserPart.Parameter; | curPart = ParserPart.Parameter; | ||||
@@ -97,7 +119,7 @@ namespace Discord.Commands | |||||
} | } | ||||
else if (curPart == ParserPart.QuotedParameter) | else if (curPart == ParserPart.QuotedParameter) | ||||
{ | { | ||||
if (c == '\"') | |||||
if (c == matchQuote) | |||||
{ | { | ||||
argString = argBuilder.ToString(); //Remove quotes | argString = argBuilder.ToString(); //Remove quotes | ||||
lastArgEndPos = curPos + 1; | lastArgEndPos = curPos + 1; | ||||
@@ -110,7 +132,7 @@ namespace Discord.Commands | |||||
{ | { | ||||
if (curParam == null) | if (curParam == null) | ||||
{ | { | ||||
if (ignoreExtraArgs) | |||||
if (command.IgnoreExtraArgs) | |||||
break; | break; | ||||
else | else | ||||
return ParseResult.FromError(CommandError.BadArgCount, "The input text has too many parameters."); | return ParseResult.FromError(CommandError.BadArgCount, "The input text has too many parameters."); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
@@ -6,7 +6,6 @@ using System.Linq; | |||||
using System.Reflection; | using System.Reflection; | ||||
using System.Threading; | using System.Threading; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Discord.Commands.Builders; | using Discord.Commands.Builders; | ||||
using Discord.Logging; | using Discord.Logging; | ||||
@@ -33,6 +32,7 @@ namespace Discord.Commands | |||||
internal readonly RunMode _defaultRunMode; | internal readonly RunMode _defaultRunMode; | ||||
internal readonly Logger _cmdLogger; | internal readonly Logger _cmdLogger; | ||||
internal readonly LogManager _logManager; | internal readonly LogManager _logManager; | ||||
internal readonly IReadOnlyDictionary<char, char> _quotationMarkAliasMap; | |||||
public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x); | public IEnumerable<ModuleInfo> Modules => _moduleDefs.Select(x => x); | ||||
public IEnumerable<CommandInfo> Commands => _moduleDefs.SelectMany(x => x.Commands); | public IEnumerable<CommandInfo> Commands => _moduleDefs.SelectMany(x => x.Commands); | ||||
@@ -46,6 +46,7 @@ namespace Discord.Commands | |||||
_ignoreExtraArgs = config.IgnoreExtraArgs; | _ignoreExtraArgs = config.IgnoreExtraArgs; | ||||
_separatorChar = config.SeparatorChar; | _separatorChar = config.SeparatorChar; | ||||
_defaultRunMode = config.DefaultRunMode; | _defaultRunMode = config.DefaultRunMode; | ||||
_quotationMarkAliasMap = (config.QuotationMarkAliasMap ?? new Dictionary<char, char>()).ToImmutableDictionary(); | |||||
if (_defaultRunMode == RunMode.Default) | if (_defaultRunMode == RunMode.Default) | ||||
throw new InvalidOperationException("The default run mode cannot be set to Default."); | throw new InvalidOperationException("The default run mode cannot be set to Default."); | ||||
@@ -66,6 +67,10 @@ namespace Discord.Commands | |||||
_defaultTypeReaders[typeof(Nullable<>).MakeGenericType(type)] = NullableTypeReader.Create(type, _defaultTypeReaders[type]); | _defaultTypeReaders[typeof(Nullable<>).MakeGenericType(type)] = NullableTypeReader.Create(type, _defaultTypeReaders[type]); | ||||
} | } | ||||
var tsreader = new TimeSpanTypeReader(); | |||||
_defaultTypeReaders[typeof(TimeSpan)] = tsreader; | |||||
_defaultTypeReaders[typeof(TimeSpan?)] = NullableTypeReader.Create(typeof(TimeSpan), tsreader); | |||||
_defaultTypeReaders[typeof(string)] = | _defaultTypeReaders[typeof(string)] = | ||||
new PrimitiveTypeReader<string>((string x, out string y) => { y = x; return true; }, 0); | new PrimitiveTypeReader<string>((string x, out string y) => { y = x; return true; }, 0); | ||||
@@ -318,6 +323,8 @@ namespace Discord.Commands | |||||
//Execution | //Execution | ||||
public SearchResult Search(ICommandContext context, int argPos) | public SearchResult Search(ICommandContext context, int argPos) | ||||
=> Search(context.Message.Content.Substring(argPos)); | => Search(context.Message.Content.Substring(argPos)); | ||||
public SearchResult Search(ICommandContext context, string input) | |||||
=> Search(input); | |||||
public SearchResult Search(string input) | public SearchResult Search(string input) | ||||
{ | { | ||||
string searchInput = _caseSensitive ? input : input.ToLowerInvariant(); | string searchInput = _caseSensitive ? input : input.ToLowerInvariant(); | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
@@ -18,13 +19,11 @@ namespace Discord.Commands | |||||
/// <summary> Determines whether RunMode.Sync commands should push exceptions up to the caller. </summary> | /// <summary> Determines whether RunMode.Sync commands should push exceptions up to the caller. </summary> | ||||
public bool ThrowOnError { get; set; } = true; | public bool ThrowOnError { get; set; } = true; | ||||
/// <summary> Collection of aliases that can wrap strings for command parsing. | |||||
/// represents the opening quotation mark and the value is the corresponding closing mark.</summary> | |||||
public Dictionary<char, char> QuotationMarkAliasMap { get; set; } = QuotationAliasUtils.GetDefaultAliasMap; | |||||
/// <summary> Determines whether extra parameters should be ignored. </summary> | /// <summary> Determines whether extra parameters should be ignored. </summary> | ||||
public bool IgnoreExtraArgs { get; set; } = false; | public bool IgnoreExtraArgs { get; set; } = false; | ||||
///// <summary> Gets or sets the <see cref="IServiceProvider"/> to use. </summary> | |||||
//public IServiceProvider ServiceProvider { get; set; } = null; | |||||
///// <summary> Gets or sets a factory function for the <see cref="IServiceProvider"/> to use. </summary> | |||||
//public Func<CommandService, IServiceProvider> ServiceProviderFactory { get; set; } = null; | |||||
} | } | ||||
} | } |
@@ -1,15 +1,19 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Import Project="../../Discord.Net.targets" /> | <Import Project="../../Discord.Net.targets" /> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<AssemblyName>Discord.Net.Commands</AssemblyName> | <AssemblyName>Discord.Net.Commands</AssemblyName> | ||||
<RootNamespace>Discord.Commands</RootNamespace> | <RootNamespace>Discord.Commands</RootNamespace> | ||||
<Description>A Discord.Net extension adding support for bot commands.</Description> | <Description>A Discord.Net extension adding support for bot commands.</Description> | ||||
<TargetFrameworks>netstandard1.1</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' "> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | |||||
</ItemGroup> | |||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' "> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> | <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -1,4 +1,4 @@ | |||||
using Discord.Commands.Builders; | |||||
using Discord.Commands.Builders; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
@@ -27,6 +27,7 @@ namespace Discord.Commands | |||||
public string Remarks { get; } | public string Remarks { get; } | ||||
public int Priority { get; } | public int Priority { get; } | ||||
public bool HasVarArgs { get; } | public bool HasVarArgs { get; } | ||||
public bool IgnoreExtraArgs { get; } | |||||
public RunMode RunMode { get; } | public RunMode RunMode { get; } | ||||
public IReadOnlyList<string> Aliases { get; } | public IReadOnlyList<string> Aliases { get; } | ||||
@@ -63,6 +64,7 @@ namespace Discord.Commands | |||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray(); | ||||
HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].IsMultiple : false; | HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].IsMultiple : false; | ||||
IgnoreExtraArgs = builder.IgnoreExtraArgs; | |||||
_action = builder.Callback; | _action = builder.Callback; | ||||
_commandService = service; | _commandService = service; | ||||
@@ -119,7 +121,8 @@ namespace Discord.Commands | |||||
return ParseResult.FromError(preconditionResult); | return ParseResult.FromError(preconditionResult); | ||||
string input = searchResult.Text.Substring(startIndex); | string input = searchResult.Text.Substring(startIndex); | ||||
return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0).ConfigureAwait(false); | |||||
return await CommandParser.ParseArgsAsync(this, context, _commandService._ignoreExtraArgs, services, input, 0, _commandService._quotationMarkAliasMap).ConfigureAwait(false); | |||||
} | } | ||||
public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) | public Task<IResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services) | ||||
@@ -2,7 +2,6 @@ using System; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Reflection; | |||||
using Discord.Commands.Builders; | using Discord.Commands.Builders; | ||||
namespace Discord.Commands | namespace Discord.Commands | ||||
@@ -23,8 +22,6 @@ namespace Discord.Commands | |||||
public ModuleInfo Parent { get; } | public ModuleInfo Parent { get; } | ||||
public bool IsSubmodule => Parent != null; | public bool IsSubmodule => Parent != null; | ||||
//public TypeInfo TypeInfo { get; } | |||||
internal ModuleInfo(ModuleBuilder builder, CommandService service, IServiceProvider services, ModuleInfo parent = null) | internal ModuleInfo(ModuleBuilder builder, CommandService service, IServiceProvider services, ModuleInfo parent = null) | ||||
{ | { | ||||
Service = service; | Service = service; | ||||
@@ -35,8 +32,6 @@ namespace Discord.Commands | |||||
Group = builder.Group; | Group = builder.Group; | ||||
Parent = parent; | Parent = parent; | ||||
//TypeInfo = builder.TypeInfo; | |||||
Aliases = BuildAliases(builder, service).ToImmutableArray(); | Aliases = BuildAliases(builder, service).ToImmutableArray(); | ||||
Commands = builder.Commands.Select(x => x.Build(this, service)).ToImmutableArray(); | Commands = builder.Commands.Select(x => x.Build(this, service)).ToImmutableArray(); | ||||
Preconditions = BuildPreconditions(builder).ToImmutableArray(); | Preconditions = BuildPreconditions(builder).ToImmutableArray(); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
@@ -29,7 +29,7 @@ namespace Discord.Commands | |||||
parserBuilder[typeof(decimal)] = (TryParseDelegate<decimal>)decimal.TryParse; | parserBuilder[typeof(decimal)] = (TryParseDelegate<decimal>)decimal.TryParse; | ||||
parserBuilder[typeof(DateTime)] = (TryParseDelegate<DateTime>)DateTime.TryParse; | parserBuilder[typeof(DateTime)] = (TryParseDelegate<DateTime>)DateTime.TryParse; | ||||
parserBuilder[typeof(DateTimeOffset)] = (TryParseDelegate<DateTimeOffset>)DateTimeOffset.TryParse; | parserBuilder[typeof(DateTimeOffset)] = (TryParseDelegate<DateTimeOffset>)DateTimeOffset.TryParse; | ||||
parserBuilder[typeof(TimeSpan)] = (TryParseDelegate<TimeSpan>)TimeSpan.TryParse; | |||||
//parserBuilder[typeof(TimeSpan)] = (TryParseDelegate<TimeSpan>)TimeSpan.TryParse; | |||||
parserBuilder[typeof(char)] = (TryParseDelegate<char>)char.TryParse; | parserBuilder[typeof(char)] = (TryParseDelegate<char>)char.TryParse; | ||||
return parserBuilder.ToImmutable(); | return parserBuilder.ToImmutable(); | ||||
} | } | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Globalization; | using System.Globalization; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
internal class ChannelTypeReader<T> : TypeReader | |||||
public class ChannelTypeReader<T> : TypeReader | |||||
where T : class, IChannel | where T : class, IChannel | ||||
{ | { | ||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | ||||
@@ -1,10 +1,10 @@ | |||||
using System; | |||||
using System; | |||||
using System.Globalization; | using System.Globalization; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
internal class MessageTypeReader<T> : TypeReader | |||||
public class MessageTypeReader<T> : TypeReader | |||||
where T : class, IMessage | where T : class, IMessage | ||||
{ | { | ||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Globalization; | using System.Globalization; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
internal class RoleTypeReader<T> : TypeReader | |||||
public class RoleTypeReader<T> : TypeReader | |||||
where T : class, IRole | where T : class, IRole | ||||
{ | { | ||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | ||||
@@ -0,0 +1,35 @@ | |||||
using System; | |||||
using System.Globalization; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.Commands | |||||
{ | |||||
internal class TimeSpanTypeReader : TypeReader | |||||
{ | |||||
private static readonly string[] _formats = new[] | |||||
{ | |||||
"%d'd'%h'h'%m'm'%s's'", //4d3h2m1s | |||||
"%d'd'%h'h'%m'm'", //4d3h2m | |||||
"%d'd'%h'h'%s's'", //4d3h 1s | |||||
"%d'd'%h'h'", //4d3h | |||||
"%d'd'%m'm'%s's'", //4d 2m1s | |||||
"%d'd'%m'm'", //4d 2m | |||||
"%d'd'%s's'", //4d 1s | |||||
"%d'd'", //4d | |||||
"%h'h'%m'm'%s's'", // 3h2m1s | |||||
"%h'h'%m'm'", // 3h2m | |||||
"%h'h'%s's'", // 3h 1s | |||||
"%h'h'", // 3h | |||||
"%m'm'%s's'", // 2m1s | |||||
"%m'm'", // 2m | |||||
"%s's'", // 1s | |||||
}; | |||||
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | |||||
{ | |||||
return (TimeSpan.TryParseExact(input.ToLowerInvariant(), _formats, CultureInfo.InvariantCulture, out var timeSpan)) | |||||
? Task.FromResult(TypeReaderResult.FromSuccess(timeSpan)) | |||||
: Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Failed to parse TimeSpan")); | |||||
} | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Globalization; | using System.Globalization; | ||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
internal class UserTypeReader<T> : TypeReader | |||||
public class UserTypeReader<T> : TypeReader | |||||
where T : class, IUser | where T : class, IUser | ||||
{ | { | ||||
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) | ||||
@@ -1,7 +1,8 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Linq; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
@@ -30,6 +31,9 @@ namespace Discord.Commands | |||||
public string ErrorReason { get; } | public string ErrorReason { get; } | ||||
public bool IsSuccess => !Error.HasValue; | public bool IsSuccess => !Error.HasValue; | ||||
public object BestMatch => IsSuccess | |||||
? (Values.Count == 1 ? Values.Single().Value : Values.OrderByDescending(v => v.Score).First().Value) | |||||
: throw new InvalidOperationException("TypeReaderResult was not successful."); | |||||
private TypeReaderResult(IReadOnlyCollection<TypeReaderValue> values, CommandError? error, string errorReason) | private TypeReaderResult(IReadOnlyCollection<TypeReaderValue> values, CommandError? error, string errorReason) | ||||
{ | { | ||||
@@ -0,0 +1,95 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using System.Globalization; | |||||
namespace Discord.Commands | |||||
{ | |||||
/// <summary> | |||||
/// Utility methods for generating matching pairs of unicode quotation marks for CommandServiceConfig | |||||
/// </summary> | |||||
internal static class QuotationAliasUtils | |||||
{ | |||||
/// <summary> | |||||
/// Generates an IEnumerable of characters representing open-close pairs of | |||||
/// quotation punctuation. | |||||
/// </summary> | |||||
internal static Dictionary<char, char> GetDefaultAliasMap | |||||
{ | |||||
get | |||||
{ | |||||
// Output of a gist provided by https://gist.github.com/ufcpp | |||||
// https://gist.github.com/ufcpp/5b2cf9a9bf7d0b8743714a0b88f7edc5 | |||||
// This was not used for the implementation because of incompatibility with netstandard1.1 | |||||
return new Dictionary<char, char> { | |||||
{'\"', '\"' }, | |||||
{'«', '»' }, | |||||
{'‘', '’' }, | |||||
{'“', '”' }, | |||||
{'„', '‟' }, | |||||
{'‹', '›' }, | |||||
{'‚', '‛' }, | |||||
{'《', '》' }, | |||||
{'〈', '〉' }, | |||||
{'「', '」' }, | |||||
{'『', '』' }, | |||||
{'〝', '〞' }, | |||||
{'﹁', '﹂' }, | |||||
{'﹃', '﹄' }, | |||||
{'"', '"' }, | |||||
{''', ''' }, | |||||
{'「', '」' }, | |||||
{'(', ')' }, | |||||
{'༺', '༻' }, | |||||
{'༼', '༽' }, | |||||
{'᚛', '᚜' }, | |||||
{'⁅', '⁆' }, | |||||
{'⌈', '⌉' }, | |||||
{'⌊', '⌋' }, | |||||
{'❨', '❩' }, | |||||
{'❪', '❫' }, | |||||
{'❬', '❭' }, | |||||
{'❮', '❯' }, | |||||
{'❰', '❱' }, | |||||
{'❲', '❳' }, | |||||
{'❴', '❵' }, | |||||
{'⟅', '⟆' }, | |||||
{'⟦', '⟧' }, | |||||
{'⟨', '⟩' }, | |||||
{'⟪', '⟫' }, | |||||
{'⟬', '⟭' }, | |||||
{'⟮', '⟯' }, | |||||
{'⦃', '⦄' }, | |||||
{'⦅', '⦆' }, | |||||
{'⦇', '⦈' }, | |||||
{'⦉', '⦊' }, | |||||
{'⦋', '⦌' }, | |||||
{'⦍', '⦎' }, | |||||
{'⦏', '⦐' }, | |||||
{'⦑', '⦒' }, | |||||
{'⦓', '⦔' }, | |||||
{'⦕', '⦖' }, | |||||
{'⦗', '⦘' }, | |||||
{'⧘', '⧙' }, | |||||
{'⧚', '⧛' }, | |||||
{'⧼', '⧽' }, | |||||
{'⸂', '⸃' }, | |||||
{'⸄', '⸅' }, | |||||
{'⸉', '⸊' }, | |||||
{'⸌', '⸍' }, | |||||
{'⸜', '⸝' }, | |||||
{'⸠', '⸡' }, | |||||
{'⸢', '⸣' }, | |||||
{'⸤', '⸥' }, | |||||
{'⸦', '⸧' }, | |||||
{'⸨', '⸩' }, | |||||
{'【', '】'}, | |||||
{'〔', '〕' }, | |||||
{'〖', '〗' }, | |||||
{'〘', '〙' }, | |||||
{'〚', '〛' } | |||||
}; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -34,6 +34,8 @@ namespace Discord | |||||
public static string GetSpotifyAlbumArtUrl(string albumArtId) | public static string GetSpotifyAlbumArtUrl(string albumArtId) | ||||
=> $"https://i.scdn.co/image/{albumArtId}"; | => $"https://i.scdn.co/image/{albumArtId}"; | ||||
public static string GetSpotifyDirectUrl(string trackId) | |||||
=> $"https://open.spotify.com/track/{trackId}"; | |||||
private static string FormatToExtension(ImageFormat format, string imageId) | private static string FormatToExtension(ImageFormat format, string imageId) | ||||
{ | { | ||||
@@ -1,14 +1,15 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Import Project="../../Discord.Net.targets" /> | <Import Project="../../Discord.Net.targets" /> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<AssemblyName>Discord.Net.Core</AssemblyName> | <AssemblyName>Discord.Net.Core</AssemblyName> | ||||
<RootNamespace>Discord</RootNamespace> | <RootNamespace>Discord</RootNamespace> | ||||
<Description>The core components for the Discord.Net library.</Description> | <Description>The core components for the Discord.Net library.</Description> | ||||
<TargetFrameworks>net45;netstandard1.1;netstandard1.3</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> | |||||
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" /> | |||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> | |||||
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" /> | |||||
<PackageReference Include="System.Interactive.Async" Version="3.1.1" /> | <PackageReference Include="System.Interactive.Async" Version="3.1.1" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | |||||
</Project> |
@@ -1,13 +1,14 @@ | |||||
using System.Reflection; | |||||
using System.Reflection; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
public class DiscordConfig | public class DiscordConfig | ||||
{ | { | ||||
public const int APIVersion = 6; | |||||
public const int APIVersion = 6; | |||||
public const int VoiceAPIVersion = 3; | |||||
public static string Version { get; } = | public static string Version { get; } = | ||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? | typeof(DiscordConfig).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? | ||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetName().Version.ToString(3) ?? | |||||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetName().Version.ToString(3) ?? | |||||
"Unknown"; | "Unknown"; | ||||
public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; | public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; | ||||
@@ -20,10 +21,12 @@ namespace Discord | |||||
public const int MaxMessagesPerBatch = 100; | public const int MaxMessagesPerBatch = 100; | ||||
public const int MaxUsersPerBatch = 1000; | public const int MaxUsersPerBatch = 1000; | ||||
public const int MaxGuildsPerBatch = 100; | public const int MaxGuildsPerBatch = 100; | ||||
public const int MaxUserReactionsPerBatch = 100; | |||||
public const int MaxAuditLogEntriesPerBatch = 100; | |||||
/// <summary> Gets or sets how a request should act in the case of an error, by default. </summary> | /// <summary> Gets or sets how a request should act in the case of an error, by default. </summary> | ||||
public RetryMode DefaultRetryMode { get; set; } = RetryMode.AlwaysRetry; | public RetryMode DefaultRetryMode { get; set; } = RetryMode.AlwaysRetry; | ||||
/// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary> | /// <summary> Gets or sets the minimum log level severity that will be sent to the Log event. </summary> | ||||
public LogSeverity LogLevel { get; set; } = LogSeverity.Info; | public LogSeverity LogLevel { get; set; } = LogSeverity.Info; | ||||
@@ -7,17 +7,20 @@ namespace Discord | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public class SpotifyGame : Game | public class SpotifyGame : Game | ||||
{ | { | ||||
public IEnumerable<string> Artists { get; internal set; } | |||||
public string AlbumArt { get; internal set; } | |||||
public IReadOnlyCollection<string> Artists { get; internal set; } | |||||
public string AlbumTitle { get; internal set; } | public string AlbumTitle { get; internal set; } | ||||
public string TrackTitle { get; internal set; } | public string TrackTitle { get; internal set; } | ||||
public string SyncId { get; internal set; } | |||||
public string SessionId { get; internal set; } | |||||
public TimeSpan? Duration { get; internal set; } | public TimeSpan? Duration { get; internal set; } | ||||
public string TrackId { get; internal set; } | |||||
public string SessionId { get; internal set; } | |||||
public string AlbumArtUrl { get; internal set; } | |||||
public string TrackUrl { get; internal set; } | |||||
internal SpotifyGame() { } | internal SpotifyGame() { } | ||||
public override string ToString() => Name; | |||||
public override string ToString() => $"{string.Join(", ", Artists)} - {TrackTitle} ({Duration})"; | |||||
private string DebuggerDisplay => $"{Name} (Spotify)"; | private string DebuggerDisplay => $"{Name} (Spotify)"; | ||||
} | } | ||||
} | } |
@@ -0,0 +1,50 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// The action type within a <see cref="IAuditLogEntry"/> | |||||
/// </summary> | |||||
public enum ActionType | |||||
{ | |||||
GuildUpdated = 1, | |||||
ChannelCreated = 10, | |||||
ChannelUpdated = 11, | |||||
ChannelDeleted = 12, | |||||
OverwriteCreated = 13, | |||||
OverwriteUpdated = 14, | |||||
OverwriteDeleted = 15, | |||||
Kick = 20, | |||||
Prune = 21, | |||||
Ban = 22, | |||||
Unban = 23, | |||||
MemberUpdated = 24, | |||||
MemberRoleUpdated = 25, | |||||
RoleCreated = 30, | |||||
RoleUpdated = 31, | |||||
RoleDeleted = 32, | |||||
InviteCreated = 40, | |||||
InviteUpdated = 41, | |||||
InviteDeleted = 42, | |||||
WebhookCreated = 50, | |||||
WebhookUpdated = 51, | |||||
WebhookDeleted = 52, | |||||
EmojiCreated = 60, | |||||
EmojiUpdated = 61, | |||||
EmojiDeleted = 62, | |||||
MessageDeleted = 72 | |||||
} | |||||
} |
@@ -0,0 +1,14 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// Represents data applied to an <see cref="IAuditLogEntry"/> | |||||
/// </summary> | |||||
public interface IAuditLogData | |||||
{ } | |||||
} |
@@ -0,0 +1,34 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// Represents an entry in an audit log | |||||
/// </summary> | |||||
public interface IAuditLogEntry : IEntity<ulong> | |||||
{ | |||||
/// <summary> | |||||
/// The action which occured to create this entry | |||||
/// </summary> | |||||
ActionType Action { get; } | |||||
/// <summary> | |||||
/// The data for this entry. May be <see cref="null"/> if no data was available. | |||||
/// </summary> | |||||
IAuditLogData Data { get; } | |||||
/// <summary> | |||||
/// The user responsible for causing the changes | |||||
/// </summary> | |||||
IUser User { get; } | |||||
/// <summary> | |||||
/// The reason behind the change. May be <see cref="null"/> if no reason was provided. | |||||
/// </summary> | |||||
string Reason { get; } | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
using Discord.Audio; | |||||
using Discord.Audio; | |||||
using System; | using System; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -7,6 +7,9 @@ namespace Discord | |||||
public interface IAudioChannel : IChannel | public interface IAudioChannel : IChannel | ||||
{ | { | ||||
/// <summary> Connects to this audio channel. </summary> | /// <summary> Connects to this audio channel. </summary> | ||||
Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null); | |||||
Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false); | |||||
/// <summary> Disconnects from this audio channel. </summary> | |||||
Task DisconnectAsync(); | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -9,10 +9,6 @@ namespace Discord | |||||
/// <summary> Gets the position of this channel in the guild's channel list, relative to others of the same type. </summary> | /// <summary> Gets the position of this channel in the guild's channel list, relative to others of the same type. </summary> | ||||
int Position { get; } | int Position { get; } | ||||
/// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary> | |||||
ulong? CategoryId { get; } | |||||
/// <summary> Gets the parent channel (category) of this channel. </summary> | |||||
Task<ICategoryChannel> GetCategoryAsync(); | |||||
/// <summary> Gets the guild this channel is a member of. </summary> | /// <summary> Gets the guild this channel is a member of. </summary> | ||||
IGuild Guild { get; } | IGuild Guild { get; } | ||||
/// <summary> Gets the id of the guild this channel is a member of. </summary> | /// <summary> Gets the id of the guild this channel is a member of. </summary> | ||||
@@ -49,4 +45,4 @@ namespace Discord | |||||
/// <summary> Gets a user in this channel with the provided id.</summary> | /// <summary> Gets a user in this channel with the provided id.</summary> | ||||
new Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | new Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
} | } | ||||
} | |||||
} |
@@ -8,11 +8,10 @@ namespace Discord | |||||
public interface IMessageChannel : IChannel | public interface IMessageChannel : IChannel | ||||
{ | { | ||||
/// <summary> Sends a message to this message channel. </summary> | /// <summary> Sends a message to this message channel. </summary> | ||||
Task<IUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||||
#if FILESYSTEM | |||||
Task<IUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary> | /// <summary> Sends a file to this text channel, with an optional caption. </summary> | ||||
Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | ||||
#endif | |||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary> | /// <summary> Sends a file to this text channel, with an optional caption. </summary> | ||||
Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | ||||
@@ -30,6 +29,11 @@ namespace Discord | |||||
/// <summary> Gets a collection of pinned messages in this channel. </summary> | /// <summary> Gets a collection of pinned messages in this channel. </summary> | ||||
Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync(RequestOptions options = null); | Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync(RequestOptions options = null); | ||||
/// <summary> Deletes a message based on the message ID in this channel. </summary> | |||||
Task DeleteMessageAsync(ulong messageId, RequestOptions options = null); | |||||
/// <summary> Deletes a message based on the provided message in this channel. </summary> | |||||
Task DeleteMessageAsync(IMessage message, RequestOptions options = null); | |||||
/// <summary> Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. </summary> | /// <summary> Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. </summary> | ||||
Task TriggerTypingAsync(RequestOptions options = null); | Task TriggerTypingAsync(RequestOptions options = null); | ||||
/// <summary> Continuously broadcasts the "user is typing" message to all users in this channel until the returned object is disposed. </summary> | /// <summary> Continuously broadcasts the "user is typing" message to all users in this channel until the returned object is disposed. </summary> | ||||
@@ -0,0 +1,16 @@ | |||||
using System.Threading.Tasks; | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// A type of guild channel that can be nested within a category. | |||||
/// Contains a CategoryId that is set to the parent category, if it is set. | |||||
/// </summary> | |||||
public interface INestedChannel : IGuildChannel | |||||
{ | |||||
/// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary> | |||||
ulong? CategoryId { get; } | |||||
/// <summary> Gets the parent channel (category) of this channel, if it is set. If unset, returns null.</summary> | |||||
Task<ICategoryChannel> GetCategoryAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
} | |||||
} |
@@ -1,11 +1,11 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | using System.IO; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
public interface ITextChannel : IMessageChannel, IMentionable, IGuildChannel | |||||
public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel | |||||
{ | { | ||||
/// <summary> Checks if the channel is NSFW. </summary> | /// <summary> Checks if the channel is NSFW. </summary> | ||||
bool IsNsfw { get; } | bool IsNsfw { get; } | ||||
@@ -28,4 +28,4 @@ namespace Discord | |||||
/// <summary> Gets the webhooks for this text channel. </summary> | /// <summary> Gets the webhooks for this text channel. </summary> | ||||
Task<IReadOnlyCollection<IWebhook>> GetWebhooksAsync(RequestOptions options = null); | Task<IReadOnlyCollection<IWebhook>> GetWebhooksAsync(RequestOptions options = null); | ||||
} | } | ||||
} | |||||
} |
@@ -1,9 +1,9 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
public interface IVoiceChannel : IGuildChannel, IAudioChannel | |||||
public interface IVoiceChannel : INestedChannel, IAudioChannel | |||||
{ | { | ||||
/// <summary> Gets the bitrate, in bits per second, clients in this voice channel are requested to use. </summary> | /// <summary> Gets the bitrate, in bits per second, clients in this voice channel are requested to use. </summary> | ||||
int Bitrate { get; } | int Bitrate { get; } | ||||
@@ -13,4 +13,4 @@ namespace Discord | |||||
/// <summary> Modifies this voice channel. </summary> | /// <summary> Modifies this voice channel. </summary> | ||||
Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null); | Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null); | ||||
} | } | ||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
using Discord.Audio; | |||||
using Discord.Audio; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -66,6 +66,24 @@ namespace Discord | |||||
/// <summary> Gets a collection of all users banned on this guild. </summary> | /// <summary> Gets a collection of all users banned on this guild. </summary> | ||||
Task<IReadOnlyCollection<IBan>> GetBansAsync(RequestOptions options = null); | Task<IReadOnlyCollection<IBan>> GetBansAsync(RequestOptions options = null); | ||||
/// <summary> | |||||
/// Gets a ban object for a banned user. | |||||
/// </summary> | |||||
/// <param name="user">The banned user.</param> | |||||
/// <returns> | |||||
/// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||||
/// reason for the ban; <see langword="null"/> if the ban entry cannot be found. | |||||
/// </returns> | |||||
Task<IBan> GetBanAsync(IUser user, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Gets a ban object for a banned user. | |||||
/// </summary> | |||||
/// <param name="userId">The snowflake identifier for the banned user.</param> | |||||
/// <returns> | |||||
/// An awaitable <see cref="Task"/> containing the ban object, which contains the user information and the | |||||
/// reason for the ban; <see langword="null"/> if the ban entry cannot be found. | |||||
/// </returns> | |||||
Task<IBan> GetBanAsync(ulong userId, RequestOptions options = null); | |||||
/// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary> | /// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary> | ||||
/// <param name="pruneDays">The number of days to remove messages from this user for - must be between [0, 7]</param> | /// <param name="pruneDays">The number of days to remove messages from this user for - must be between [0, 7]</param> | ||||
Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null); | Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null); | ||||
@@ -91,9 +109,9 @@ namespace Discord | |||||
Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
/// <summary> Creates a new text channel. </summary> | /// <summary> Creates a new text channel. </summary> | ||||
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null); | |||||
Task<ITextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null); | |||||
/// <summary> Creates a new voice channel. </summary> | /// <summary> Creates a new voice channel. </summary> | ||||
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null); | |||||
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null); | |||||
/// <summary> Creates a new channel category. </summary> | /// <summary> Creates a new channel category. </summary> | ||||
Task<ICategoryChannel> CreateCategoryAsync(string name, RequestOptions options = null); | Task<ICategoryChannel> CreateCategoryAsync(string name, RequestOptions options = null); | ||||
@@ -121,6 +139,10 @@ namespace Discord | |||||
/// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary> | /// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary> | ||||
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); | Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); | ||||
/// <summary> Gets the specified number of audit log entries for this guild. </summary> | |||||
Task<IReadOnlyCollection<IAuditLogEntry>> GetAuditLogAsync(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch, | |||||
CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
/// <summary> Gets the webhook in this guild with the provided id, or null if not found. </summary> | /// <summary> Gets the webhook in this guild with the provided id, or null if not found. </summary> | ||||
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null); | Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null); | ||||
/// <summary> Gets a collection of all webhooks for this guild. </summary> | /// <summary> Gets a collection of all webhooks for this guild. </summary> | ||||
@@ -135,4 +157,4 @@ namespace Discord | |||||
/// <summary> Deletes an existing emote from this guild. </summary> | /// <summary> Deletes an existing emote from this guild. </summary> | ||||
Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null); | Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null); | ||||
} | } | ||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
namespace Discord | |||||
namespace Discord | |||||
{ | { | ||||
public interface IVoiceRegion | public interface IVoiceRegion | ||||
{ | { | ||||
@@ -10,9 +10,9 @@ | |||||
bool IsVip { get; } | bool IsVip { get; } | ||||
/// <summary> Returns true if this voice region is the closest to your machine. </summary> | /// <summary> Returns true if this voice region is the closest to your machine. </summary> | ||||
bool IsOptimal { get; } | bool IsOptimal { get; } | ||||
/// <summary> Gets an example hostname for this voice region. </summary> | |||||
string SampleHostname { get; } | |||||
/// <summary> Gets an example port for this voice region. </summary> | |||||
int SamplePort { get; } | |||||
/// <summary> Returns true if this is a deprecated voice region (avoid switching to these). </summary> | |||||
bool IsDeprecated { get; } | |||||
/// <summary> Returns true if this is a custom voice region (used for events/etc) </summary> | |||||
bool IsCustom { get; } | |||||
} | } | ||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
using System.IO; | |||||
using System.IO; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
@@ -15,7 +15,7 @@ namespace Discord | |||||
{ | { | ||||
Stream = stream; | Stream = stream; | ||||
} | } | ||||
#if FILESYSTEM | |||||
/// <summary> | /// <summary> | ||||
/// Create the image from a file path. | /// Create the image from a file path. | ||||
/// </summary> | /// </summary> | ||||
@@ -27,6 +27,6 @@ namespace Discord | |||||
{ | { | ||||
Stream = File.OpenRead(path); | Stream = File.OpenRead(path); | ||||
} | } | ||||
#endif | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
using System.Threading.Tasks; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -22,8 +22,9 @@ namespace Discord | |||||
ulong GuildId { get; } | ulong GuildId { get; } | ||||
/// <summary> Gets the name of the guild this invite is linked to. </summary> | /// <summary> Gets the name of the guild this invite is linked to. </summary> | ||||
string GuildName { get; } | string GuildName { get; } | ||||
/// <summary> Accepts this invite and joins the target guild. This will fail on bot accounts. </summary> | |||||
Task AcceptAsync(RequestOptions options = null); | |||||
/// <summary> Gets the approximated count of online members in the guild. </summary> | |||||
int? PresenceCount { get; } | |||||
/// <summary> Gets the approximated count of total members in the guild. </summary> | |||||
int? MemberCount { get; } | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Linq; | using System.Linq; | ||||
@@ -57,7 +57,18 @@ namespace Discord | |||||
Fields = fields; | Fields = fields; | ||||
} | } | ||||
public int Length => Title?.Length + Author?.Name?.Length + Description?.Length + Footer?.Text?.Length + Fields.Sum(f => f.Name.Length + f.Value.ToString().Length) ?? 0; | |||||
public int Length | |||||
{ | |||||
get | |||||
{ | |||||
int titleLength = Title?.Length ?? 0; | |||||
int authorLength = Author?.Name?.Length ?? 0; | |||||
int descriptionLength = Description?.Length ?? 0; | |||||
int footerLength = Footer?.Text?.Length ?? 0; | |||||
int fieldSum = Fields.Sum(f => f.Name?.Length + f.Value?.ToString().Length) ?? 0; | |||||
return titleLength + authorLength + descriptionLength + footerLength + fieldSum; | |||||
} | |||||
} | |||||
public override string ToString() => Title; | public override string ToString() => Title; | ||||
private string DebuggerDisplay => $"{Title} ({Type})"; | private string DebuggerDisplay => $"{Title} ({Type})"; | ||||
@@ -231,7 +231,6 @@ namespace Discord | |||||
{ | { | ||||
private string _name; | private string _name; | ||||
private string _value; | private string _value; | ||||
private EmbedField _field; | |||||
public const int MaxFieldNameLength = 256; | public const int MaxFieldNameLength = 256; | ||||
public const int MaxFieldValueLength = 1024; | public const int MaxFieldValueLength = 1024; | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -23,7 +23,7 @@ namespace Discord | |||||
/// <summary> Removes all reactions from this message. </summary> | /// <summary> Removes all reactions from this message. </summary> | ||||
Task RemoveAllReactionsAsync(RequestOptions options = null); | Task RemoveAllReactionsAsync(RequestOptions options = null); | ||||
/// <summary> Gets all users that reacted to a message with a given emote </summary> | /// <summary> Gets all users that reacted to a message with a given emote </summary> | ||||
Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit = 100, ulong? afterUserId = null, RequestOptions options = null); | |||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit, RequestOptions options = null); | |||||
/// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary> | /// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary> | ||||
string Resolve( | string Resolve( | ||||
@@ -12,7 +12,7 @@ namespace Discord | |||||
/// <summary> Gets a ChannelPermissions that grants all permissions for text channels. </summary> | /// <summary> Gets a ChannelPermissions that grants all permissions for text channels. </summary> | ||||
public static readonly ChannelPermissions Text = new ChannelPermissions(0b01100_0000000_1111111110001_010001); | public static readonly ChannelPermissions Text = new ChannelPermissions(0b01100_0000000_1111111110001_010001); | ||||
/// <summary> Gets a ChannelPermissions that grants all permissions for voice channels. </summary> | /// <summary> Gets a ChannelPermissions that grants all permissions for voice channels. </summary> | ||||
public static readonly ChannelPermissions Voice = new ChannelPermissions(0b00100_1111110_0000000000000_010001); | |||||
public static readonly ChannelPermissions Voice = new ChannelPermissions(0b00100_1111110_0000000010000_010001); | |||||
/// <summary> Gets a ChannelPermissions that grants all permissions for category channels. </summary> | /// <summary> Gets a ChannelPermissions that grants all permissions for category channels. </summary> | ||||
public static readonly ChannelPermissions Category = new ChannelPermissions(0b01100_1111110_1111111110001_010001); | public static readonly ChannelPermissions Category = new ChannelPermissions(0b01100_1111110_1111111110001_010001); | ||||
/// <summary> Gets a ChannelPermissions that grants all permissions for direct message channels. </summary> | /// <summary> Gets a ChannelPermissions that grants all permissions for direct message channels. </summary> | ||||
@@ -87,12 +87,27 @@ namespace Discord | |||||
/// <summary> Creates a new ChannelPermissions with the provided packed value. </summary> | /// <summary> Creates a new ChannelPermissions with the provided packed value. </summary> | ||||
public ChannelPermissions(ulong rawValue) { RawValue = rawValue; } | public ChannelPermissions(ulong rawValue) { RawValue = rawValue; } | ||||
private ChannelPermissions(ulong initialValue, bool? createInstantInvite = null, bool? manageChannel = null, | |||||
private ChannelPermissions(ulong initialValue, | |||||
bool? createInstantInvite = null, | |||||
bool? manageChannel = null, | |||||
bool? addReactions = null, | bool? addReactions = null, | ||||
bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||||
bool? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null) | |||||
bool? viewChannel = null, | |||||
bool? sendMessages = null, | |||||
bool? sendTTSMessages = null, | |||||
bool? manageMessages = null, | |||||
bool? embedLinks = null, | |||||
bool? attachFiles = null, | |||||
bool? readMessageHistory = null, | |||||
bool? mentionEveryone = null, | |||||
bool? useExternalEmojis = null, | |||||
bool? connect = null, | |||||
bool? speak = null, | |||||
bool? muteMembers = null, | |||||
bool? deafenMembers = null, | |||||
bool? moveMembers = null, | |||||
bool? useVoiceActivation = null, | |||||
bool? manageRoles = null, | |||||
bool? manageWebhooks = null) | |||||
{ | { | ||||
ulong value = initialValue; | ulong value = initialValue; | ||||
@@ -121,27 +136,75 @@ namespace Discord | |||||
} | } | ||||
/// <summary> Creates a new ChannelPermissions with the provided permissions. </summary> | /// <summary> Creates a new ChannelPermissions with the provided permissions. </summary> | ||||
public ChannelPermissions(bool createInstantInvite = false, bool manageChannel = false, | |||||
public ChannelPermissions( | |||||
bool createInstantInvite = false, | |||||
bool manageChannel = false, | |||||
bool addReactions = false, | bool addReactions = false, | ||||
bool viewChannel = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false, | |||||
bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false, | |||||
bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false, | |||||
bool moveMembers = false, bool useVoiceActivation = false, bool manageRoles = false, bool manageWebhooks = false) | |||||
bool viewChannel = false, | |||||
bool sendMessages = false, | |||||
bool sendTTSMessages = false, | |||||
bool manageMessages = false, | |||||
bool embedLinks = false, | |||||
bool attachFiles = false, | |||||
bool readMessageHistory = false, | |||||
bool mentionEveryone = false, | |||||
bool useExternalEmojis = false, | |||||
bool connect = false, | |||||
bool speak = false, | |||||
bool muteMembers = false, | |||||
bool deafenMembers = false, | |||||
bool moveMembers = false, | |||||
bool useVoiceActivation = false, | |||||
bool manageRoles = false, | |||||
bool manageWebhooks = false) | |||||
: this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | : this(0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | ||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | ||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks) | speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks) | ||||
{ } | { } | ||||
/// <summary> Creates a new ChannelPermissions from this one, changing the provided non-null permissions. </summary> | /// <summary> Creates a new ChannelPermissions from this one, changing the provided non-null permissions. </summary> | ||||
public ChannelPermissions Modify(bool? createInstantInvite = null, bool? manageChannel = null, | |||||
public ChannelPermissions Modify( | |||||
bool? createInstantInvite = null, | |||||
bool? manageChannel = null, | |||||
bool? addReactions = null, | bool? addReactions = null, | ||||
bool? viewChannel = null, bool? sendMessages = null, bool? sendTTSMessages = null, bool? manageMessages = null, | |||||
bool? embedLinks = null, bool? attachFiles = null, bool? readMessageHistory = null, bool? mentionEveryone = null, | |||||
bool useExternalEmojis = false, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? manageRoles = null, bool? manageWebhooks = null) | |||||
=> new ChannelPermissions(RawValue, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | |||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, | |||||
speak, muteMembers, deafenMembers, moveMembers, useVoiceActivation, manageRoles, manageWebhooks); | |||||
bool? viewChannel = null, | |||||
bool? sendMessages = null, | |||||
bool? sendTTSMessages = null, | |||||
bool? manageMessages = null, | |||||
bool? embedLinks = null, | |||||
bool? attachFiles = null, | |||||
bool? readMessageHistory = null, | |||||
bool? mentionEveryone = null, | |||||
bool? useExternalEmojis = null, | |||||
bool? connect = null, | |||||
bool? speak = null, | |||||
bool? muteMembers = null, | |||||
bool? deafenMembers = null, | |||||
bool? moveMembers = null, | |||||
bool? useVoiceActivation = null, | |||||
bool? manageRoles = null, | |||||
bool? manageWebhooks = null) | |||||
=> new ChannelPermissions(RawValue, | |||||
createInstantInvite, | |||||
manageChannel, | |||||
addReactions, | |||||
viewChannel, | |||||
sendMessages, | |||||
sendTTSMessages, | |||||
manageMessages, | |||||
embedLinks, | |||||
attachFiles, | |||||
readMessageHistory, | |||||
mentionEveryone, | |||||
useExternalEmojis, | |||||
connect, | |||||
speak, | |||||
muteMembers, | |||||
deafenMembers, | |||||
moveMembers, | |||||
useVoiceActivation, | |||||
manageRoles, | |||||
manageWebhooks); | |||||
public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission); | public bool Has(ChannelPermission permission) => Permissions.GetValue(RawValue, permission); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -16,7 +16,9 @@ namespace Discord | |||||
// Text | // Text | ||||
AddReactions = 0x00_00_00_40, | AddReactions = 0x00_00_00_40, | ||||
ViewAuditLog = 0x00_00_00_80, | ViewAuditLog = 0x00_00_00_80, | ||||
ReadMessages = 0x00_00_04_00, | |||||
[Obsolete("Use ViewChannel instead.")] | |||||
ReadMessages = ViewChannel, | |||||
ViewChannel = 0x00_00_04_00, | |||||
SendMessages = 0x00_00_08_00, | SendMessages = 0x00_00_08_00, | ||||
SendTTSMessages = 0x00_00_10_00, | SendTTSMessages = 0x00_00_10_00, | ||||
ManageMessages = 0x00_00_20_00, | ManageMessages = 0x00_00_20_00, | ||||
@@ -1,4 +1,5 @@ | |||||
using System.Collections.Generic; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
namespace Discord | namespace Discord | ||||
@@ -35,7 +36,10 @@ namespace Discord | |||||
public bool ViewAuditLog => Permissions.GetValue(RawValue, GuildPermission.ViewAuditLog); | public bool ViewAuditLog => Permissions.GetValue(RawValue, GuildPermission.ViewAuditLog); | ||||
/// <summary> If True, a user may join channels. </summary> | /// <summary> If True, a user may join channels. </summary> | ||||
public bool ReadMessages => Permissions.GetValue(RawValue, GuildPermission.ReadMessages); | |||||
[Obsolete("Use ViewChannel instead.")] | |||||
public bool ReadMessages => ViewChannel; | |||||
/// <summary> If True, a user may view channels. </summary> | |||||
public bool ViewChannel => Permissions.GetValue(RawValue, GuildPermission.ViewChannel); | |||||
/// <summary> If True, a user may send messages. </summary> | /// <summary> If True, a user may send messages. </summary> | ||||
public bool SendMessages => Permissions.GetValue(RawValue, GuildPermission.SendMessages); | public bool SendMessages => Permissions.GetValue(RawValue, GuildPermission.SendMessages); | ||||
/// <summary> If True, a user may send text-to-speech messages. </summary> | /// <summary> If True, a user may send text-to-speech messages. </summary> | ||||
@@ -80,14 +84,35 @@ namespace Discord | |||||
/// <summary> Creates a new GuildPermissions with the provided packed value. </summary> | /// <summary> Creates a new GuildPermissions with the provided packed value. </summary> | ||||
public GuildPermissions(ulong rawValue) { RawValue = rawValue; } | public GuildPermissions(ulong rawValue) { RawValue = rawValue; } | ||||
private GuildPermissions(ulong initialValue, bool? createInstantInvite = null, bool? kickMembers = null, | |||||
bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null, | |||||
bool? addReactions = null, bool? viewAuditLog = 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? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null, | |||||
bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null) | |||||
private GuildPermissions(ulong initialValue, | |||||
bool? createInstantInvite = null, | |||||
bool? kickMembers = null, | |||||
bool? banMembers = null, | |||||
bool? administrator = null, | |||||
bool? manageChannels = null, | |||||
bool? manageGuild = null, | |||||
bool? addReactions = null, | |||||
bool? viewAuditLog = null, | |||||
bool? viewChannel = null, | |||||
bool? sendMessages = null, | |||||
bool? sendTTSMessages = null, | |||||
bool? manageMessages = null, | |||||
bool? embedLinks = null, | |||||
bool? attachFiles = null, | |||||
bool? readMessageHistory = null, | |||||
bool? mentionEveryone = null, | |||||
bool? useExternalEmojis = null, | |||||
bool? connect = null, | |||||
bool? speak = null, | |||||
bool? muteMembers = null, | |||||
bool? deafenMembers = null, | |||||
bool? moveMembers = null, | |||||
bool? useVoiceActivation = null, | |||||
bool? changeNickname = null, | |||||
bool? manageNicknames = null, | |||||
bool? manageRoles = null, | |||||
bool? manageWebhooks = null, | |||||
bool? manageEmojis = null) | |||||
{ | { | ||||
ulong value = initialValue; | ulong value = initialValue; | ||||
@@ -99,7 +124,7 @@ namespace Discord | |||||
Permissions.SetValue(ref value, manageGuild, GuildPermission.ManageGuild); | Permissions.SetValue(ref value, manageGuild, GuildPermission.ManageGuild); | ||||
Permissions.SetValue(ref value, addReactions, GuildPermission.AddReactions); | Permissions.SetValue(ref value, addReactions, GuildPermission.AddReactions); | ||||
Permissions.SetValue(ref value, viewAuditLog, GuildPermission.ViewAuditLog); | Permissions.SetValue(ref value, viewAuditLog, GuildPermission.ViewAuditLog); | ||||
Permissions.SetValue(ref value, readMessages, GuildPermission.ReadMessages); | |||||
Permissions.SetValue(ref value, viewChannel, GuildPermission.ViewChannel); | |||||
Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages); | Permissions.SetValue(ref value, sendMessages, GuildPermission.SendMessages); | ||||
Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages); | Permissions.SetValue(ref value, sendTTSMessages, GuildPermission.SendTTSMessages); | ||||
Permissions.SetValue(ref value, manageMessages, GuildPermission.ManageMessages); | Permissions.SetValue(ref value, manageMessages, GuildPermission.ManageMessages); | ||||
@@ -124,34 +149,98 @@ namespace Discord | |||||
} | } | ||||
/// <summary> Creates a new GuildPermissions with the provided permissions. </summary> | /// <summary> Creates a new GuildPermissions with the provided permissions. </summary> | ||||
public GuildPermissions(bool createInstantInvite = false, bool kickMembers = false, | |||||
bool banMembers = false, bool administrator = false, bool manageChannels = false, bool manageGuild = false, | |||||
bool addReactions = false, bool viewAuditLog = false, | |||||
bool readMessages = false, bool sendMessages = false, bool sendTTSMessages = false, bool manageMessages = false, | |||||
bool embedLinks = false, bool attachFiles = false, bool readMessageHistory = false, bool mentionEveryone = false, | |||||
bool useExternalEmojis = false, bool connect = false, bool speak = false, bool muteMembers = false, bool deafenMembers = false, | |||||
bool moveMembers = false, bool useVoiceActivation = false, bool? changeNickname = false, bool? manageNicknames = false, | |||||
bool manageRoles = false, bool manageWebhooks = false, bool manageEmojis = false) | |||||
: this(0, createInstantInvite: createInstantInvite, manageRoles: manageRoles, kickMembers: kickMembers, banMembers: banMembers, | |||||
administrator: administrator, manageChannels: manageChannels, manageGuild: manageGuild, addReactions: addReactions, | |||||
viewAuditLog: viewAuditLog, readMessages: readMessages, sendMessages: sendMessages, sendTTSMessages: sendTTSMessages, | |||||
manageMessages: manageMessages, embedLinks: embedLinks, attachFiles: attachFiles, readMessageHistory: readMessageHistory, | |||||
mentionEveryone: mentionEveryone, useExternalEmojis: useExternalEmojis, connect: connect, speak: speak, muteMembers: muteMembers, | |||||
deafenMembers: deafenMembers, moveMembers: moveMembers, useVoiceActivation: useVoiceActivation, changeNickname: changeNickname, | |||||
manageNicknames: manageNicknames, manageWebhooks: manageWebhooks, manageEmojis: manageEmojis) | |||||
public GuildPermissions( | |||||
bool createInstantInvite = false, | |||||
bool kickMembers = false, | |||||
bool banMembers = false, | |||||
bool administrator = false, | |||||
bool manageChannels = false, | |||||
bool manageGuild = false, | |||||
bool addReactions = false, | |||||
bool viewAuditLog = false, | |||||
bool viewChannel = false, | |||||
bool sendMessages = false, | |||||
bool sendTTSMessages = false, | |||||
bool manageMessages = false, | |||||
bool embedLinks = false, | |||||
bool attachFiles = false, | |||||
bool readMessageHistory = false, | |||||
bool mentionEveryone = false, | |||||
bool useExternalEmojis = false, | |||||
bool connect = false, | |||||
bool speak = false, | |||||
bool muteMembers = false, | |||||
bool deafenMembers = false, | |||||
bool moveMembers = false, | |||||
bool useVoiceActivation = false, | |||||
bool changeNickname = false, | |||||
bool manageNicknames = false, | |||||
bool manageRoles = false, | |||||
bool manageWebhooks = false, | |||||
bool manageEmojis = false) | |||||
: this(0, | |||||
createInstantInvite: createInstantInvite, | |||||
manageRoles: manageRoles, | |||||
kickMembers: kickMembers, | |||||
banMembers: banMembers, | |||||
administrator: administrator, | |||||
manageChannels: manageChannels, | |||||
manageGuild: manageGuild, | |||||
addReactions: addReactions, | |||||
viewAuditLog: viewAuditLog, | |||||
viewChannel: viewChannel, | |||||
sendMessages: sendMessages, | |||||
sendTTSMessages: sendTTSMessages, | |||||
manageMessages: manageMessages, | |||||
embedLinks: embedLinks, | |||||
attachFiles: attachFiles, | |||||
readMessageHistory: readMessageHistory, | |||||
mentionEveryone: mentionEveryone, | |||||
useExternalEmojis: useExternalEmojis, | |||||
connect: connect, | |||||
speak: speak, | |||||
muteMembers: muteMembers, | |||||
deafenMembers: deafenMembers, | |||||
moveMembers: moveMembers, | |||||
useVoiceActivation: useVoiceActivation, | |||||
changeNickname: changeNickname, | |||||
manageNicknames: manageNicknames, | |||||
manageWebhooks: manageWebhooks, | |||||
manageEmojis: manageEmojis) | |||||
{ } | { } | ||||
/// <summary> Creates a new GuildPermissions from this one, changing the provided non-null permissions. </summary> | /// <summary> Creates a new GuildPermissions from this one, changing the provided non-null permissions. </summary> | ||||
public GuildPermissions Modify(bool? createInstantInvite = null, bool? kickMembers = null, | |||||
bool? banMembers = null, bool? administrator = null, bool? manageChannels = null, bool? manageGuild = null, | |||||
bool? addReactions = null, bool? viewAuditLog = 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? useExternalEmojis = null, bool? connect = null, bool? speak = null, bool? muteMembers = null, bool? deafenMembers = null, | |||||
bool? moveMembers = null, bool? useVoiceActivation = null, bool? changeNickname = null, bool? manageNicknames = null, | |||||
bool? manageRoles = null, bool? manageWebhooks = null, bool? manageEmojis = null) | |||||
public GuildPermissions Modify( | |||||
bool? createInstantInvite = null, | |||||
bool? kickMembers = null, | |||||
bool? banMembers = null, | |||||
bool? administrator = null, | |||||
bool? manageChannels = null, | |||||
bool? manageGuild = null, | |||||
bool? addReactions = null, | |||||
bool? viewAuditLog = null, | |||||
bool? viewChannel = null, | |||||
bool? sendMessages = null, | |||||
bool? sendTTSMessages = null, | |||||
bool? manageMessages = null, | |||||
bool? embedLinks = null, | |||||
bool? attachFiles = null, | |||||
bool? readMessageHistory = null, | |||||
bool? mentionEveryone = null, | |||||
bool? useExternalEmojis = null, | |||||
bool? connect = null, | |||||
bool? speak = null, | |||||
bool? muteMembers = null, | |||||
bool? deafenMembers = null, | |||||
bool? moveMembers = null, | |||||
bool? useVoiceActivation = null, | |||||
bool? changeNickname = null, | |||||
bool? manageNicknames = null, | |||||
bool? manageRoles = null, | |||||
bool? manageWebhooks = null, | |||||
bool? manageEmojis = null) | |||||
=> new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, | => new GuildPermissions(RawValue, createInstantInvite, kickMembers, banMembers, administrator, manageChannels, manageGuild, addReactions, | ||||
viewAuditLog, readMessages, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | |||||
viewAuditLog, viewChannel, sendMessages, sendTTSMessages, manageMessages, embedLinks, attachFiles, | |||||
readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, | readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, moveMembers, | ||||
useVoiceActivation, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); | useVoiceActivation, changeNickname, manageNicknames, manageRoles, manageWebhooks, manageEmojis); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Diagnostics; | using System.Diagnostics; | ||||
@@ -74,12 +74,26 @@ namespace Discord | |||||
DenyValue = denyValue; | DenyValue = denyValue; | ||||
} | } | ||||
private OverwritePermissions(ulong allowValue, ulong denyValue, PermValue? createInstantInvite = null, PermValue? manageChannel = null, | |||||
private OverwritePermissions(ulong allowValue, ulong denyValue, | |||||
PermValue? createInstantInvite = null, | |||||
PermValue? manageChannel = null, | |||||
PermValue? addReactions = null, | PermValue? addReactions = null, | ||||
PermValue? viewChannel = null, PermValue? sendMessages = null, PermValue? sendTTSMessages = null, PermValue? manageMessages = null, | |||||
PermValue? embedLinks = null, PermValue? attachFiles = null, PermValue? readMessageHistory = null, PermValue? mentionEveryone = null, | |||||
PermValue? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, | |||||
PermValue? deafenMembers = null, PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, | |||||
PermValue? viewChannel = null, | |||||
PermValue? sendMessages = null, | |||||
PermValue? sendTTSMessages = null, | |||||
PermValue? manageMessages = null, | |||||
PermValue? embedLinks = null, | |||||
PermValue? attachFiles = null, | |||||
PermValue? readMessageHistory = null, | |||||
PermValue? mentionEveryone = null, | |||||
PermValue? useExternalEmojis = null, | |||||
PermValue? connect = null, | |||||
PermValue? speak = null, | |||||
PermValue? muteMembers = null, | |||||
PermValue? deafenMembers = null, | |||||
PermValue? moveMembers = null, | |||||
PermValue? useVoiceActivation = null, | |||||
PermValue? manageRoles = null, | |||||
PermValue? manageWebhooks = null) | PermValue? manageWebhooks = null) | ||||
{ | { | ||||
Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite); | Permissions.SetValue(ref allowValue, ref denyValue, createInstantInvite, ChannelPermission.CreateInstantInvite); | ||||
@@ -108,24 +122,54 @@ namespace Discord | |||||
} | } | ||||
/// <summary> Creates a new ChannelPermissions with the provided permissions. </summary> | /// <summary> Creates a new ChannelPermissions with the provided permissions. </summary> | ||||
public OverwritePermissions(PermValue createInstantInvite = PermValue.Inherit, PermValue manageChannel = PermValue.Inherit, | |||||
public OverwritePermissions( | |||||
PermValue createInstantInvite = PermValue.Inherit, | |||||
PermValue manageChannel = PermValue.Inherit, | |||||
PermValue addReactions = PermValue.Inherit, | PermValue addReactions = PermValue.Inherit, | ||||
PermValue readMessages = PermValue.Inherit, PermValue sendMessages = PermValue.Inherit, PermValue sendTTSMessages = PermValue.Inherit, PermValue manageMessages = PermValue.Inherit, | |||||
PermValue embedLinks = PermValue.Inherit, PermValue attachFiles = PermValue.Inherit, PermValue readMessageHistory = PermValue.Inherit, PermValue mentionEveryone = PermValue.Inherit, | |||||
PermValue useExternalEmojis = PermValue.Inherit, PermValue connect = PermValue.Inherit, PermValue speak = PermValue.Inherit, PermValue muteMembers = PermValue.Inherit, PermValue deafenMembers = PermValue.Inherit, | |||||
PermValue moveMembers = PermValue.Inherit, PermValue useVoiceActivation = PermValue.Inherit, PermValue manageRoles = PermValue.Inherit, PermValue manageWebhooks = PermValue.Inherit) | |||||
: this(0, 0, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages, | |||||
PermValue viewChannel = PermValue.Inherit, | |||||
PermValue sendMessages = PermValue.Inherit, | |||||
PermValue sendTTSMessages = PermValue.Inherit, | |||||
PermValue manageMessages = PermValue.Inherit, | |||||
PermValue embedLinks = PermValue.Inherit, | |||||
PermValue attachFiles = PermValue.Inherit, | |||||
PermValue readMessageHistory = PermValue.Inherit, | |||||
PermValue mentionEveryone = PermValue.Inherit, | |||||
PermValue useExternalEmojis = PermValue.Inherit, | |||||
PermValue connect = PermValue.Inherit, | |||||
PermValue speak = PermValue.Inherit, | |||||
PermValue muteMembers = PermValue.Inherit, | |||||
PermValue deafenMembers = PermValue.Inherit, | |||||
PermValue moveMembers = PermValue.Inherit, | |||||
PermValue useVoiceActivation = PermValue.Inherit, | |||||
PermValue manageRoles = PermValue.Inherit, | |||||
PermValue manageWebhooks = PermValue.Inherit) | |||||
: this(0, 0, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | |||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, | embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, | ||||
moveMembers, useVoiceActivation, manageRoles, manageWebhooks) { } | moveMembers, useVoiceActivation, manageRoles, manageWebhooks) { } | ||||
/// <summary> Creates a new OverwritePermissions from this one, changing the provided non-null permissions. </summary> | /// <summary> Creates a new OverwritePermissions from this one, changing the provided non-null permissions. </summary> | ||||
public OverwritePermissions Modify(PermValue? createInstantInvite = null, PermValue? manageChannel = null, | |||||
public OverwritePermissions Modify( | |||||
PermValue? createInstantInvite = null, | |||||
PermValue? manageChannel = null, | |||||
PermValue? addReactions = null, | PermValue? addReactions = 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? useExternalEmojis = null, PermValue? connect = null, PermValue? speak = null, PermValue? muteMembers = null, PermValue? deafenMembers = null, | |||||
PermValue? moveMembers = null, PermValue? useVoiceActivation = null, PermValue? manageRoles = null, PermValue? manageWebhooks = null) | |||||
=> new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, readMessages, sendMessages, sendTTSMessages, manageMessages, | |||||
PermValue? viewChannel = null, | |||||
PermValue? sendMessages = null, | |||||
PermValue? sendTTSMessages = null, | |||||
PermValue? manageMessages = null, | |||||
PermValue? embedLinks = null, | |||||
PermValue? attachFiles = null, | |||||
PermValue? readMessageHistory = null, | |||||
PermValue? mentionEveryone = null, | |||||
PermValue? useExternalEmojis = null, | |||||
PermValue? connect = null, | |||||
PermValue? speak = null, | |||||
PermValue? muteMembers = null, | |||||
PermValue? deafenMembers = null, | |||||
PermValue? moveMembers = null, | |||||
PermValue? useVoiceActivation = null, | |||||
PermValue? manageRoles = null, | |||||
PermValue? manageWebhooks = null) | |||||
=> new OverwritePermissions(AllowValue, DenyValue, createInstantInvite, manageChannel, addReactions, viewChannel, sendMessages, sendTTSMessages, manageMessages, | |||||
embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, | embedLinks, attachFiles, readMessageHistory, mentionEveryone, useExternalEmojis, connect, speak, muteMembers, deafenMembers, | ||||
moveMembers, useVoiceActivation, manageRoles, manageWebhooks); | moveMembers, useVoiceActivation, manageRoles, manageWebhooks); | ||||
@@ -1,5 +1,8 @@ | |||||
using System; | using System; | ||||
using System.Diagnostics; | using System.Diagnostics; | ||||
#if NETSTANDARD2_0 || NET45 | |||||
using StandardColor = System.Drawing.Color; | |||||
#endif | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
@@ -96,7 +99,14 @@ namespace Discord | |||||
((uint)(g * 255.0f) << 8) | | ((uint)(g * 255.0f) << 8) | | ||||
(uint)(b * 255.0f); | (uint)(b * 255.0f); | ||||
} | } | ||||
#if NETSTANDARD2_0 || NET45 | |||||
public static implicit operator StandardColor(Color color) => | |||||
StandardColor.FromArgb((int)color.RawValue); | |||||
public static explicit operator Color(StandardColor color) => | |||||
new Color((uint)color.ToArgb() << 8 >> 8); | |||||
#endif | |||||
public override string ToString() => | public override string ToString() => | ||||
$"#{Convert.ToString(RawValue, 16)}"; | $"#{Convert.ToString(RawValue, 16)}"; | ||||
private string DebuggerDisplay => | private string DebuggerDisplay => | ||||
@@ -0,0 +1,14 @@ | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// Represents the type of a webhook. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// This type is currently unused, and is only returned in audit log responses. | |||||
/// </remarks> | |||||
public enum WebhookType | |||||
{ | |||||
/// <summary> An incoming webhook </summary> | |||||
Incoming = 1 | |||||
} | |||||
} |
@@ -9,7 +9,7 @@ namespace Discord | |||||
/// Sends a message to the user via DM. | /// Sends a message to the user via DM. | ||||
/// </summary> | /// </summary> | ||||
public static async Task<IUserMessage> SendMessageAsync(this IUser user, | public static async Task<IUserMessage> SendMessageAsync(this IUser user, | ||||
string text, | |||||
string text = null, | |||||
bool isTTS = false, | bool isTTS = false, | ||||
Embed embed = null, | Embed embed = null, | ||||
RequestOptions options = null) | RequestOptions options = null) | ||||
@@ -32,7 +32,6 @@ namespace Discord | |||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); | ||||
} | } | ||||
#if FILESYSTEM | |||||
/// <summary> | /// <summary> | ||||
/// Sends a file to the user via DM. | /// Sends a file to the user via DM. | ||||
/// </summary> | /// </summary> | ||||
@@ -45,7 +44,6 @@ namespace Discord | |||||
{ | { | ||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); | ||||
} | } | ||||
#endif | |||||
public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | ||||
=> user.Guild.AddBanAsync(user, pruneDays, reason, options); | => user.Guild.AddBanAsync(user, pruneDays, reason, options); | ||||
@@ -27,7 +27,7 @@ namespace Discord | |||||
Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null); | Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null); | ||||
Task<IInvite> GetInviteAsync(string inviteId, RequestOptions options = null); | |||||
Task<IInvite> GetInviteAsync(string inviteId, bool withCount = false, RequestOptions options = null); | |||||
Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null); | Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Logging | namespace Discord.Logging | ||||
@@ -35,7 +35,7 @@ namespace Discord.Logging | |||||
} | } | ||||
catch { } | catch { } | ||||
} | } | ||||
#if FORMATSTR | |||||
public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) | public async Task LogAsync(LogSeverity severity, string source, FormattableString message, Exception ex = null) | ||||
{ | { | ||||
try | try | ||||
@@ -45,52 +45,49 @@ namespace Discord.Logging | |||||
} | } | ||||
catch { } | catch { } | ||||
} | } | ||||
#endif | |||||
public Task ErrorAsync(string source, Exception ex) | public Task ErrorAsync(string source, Exception ex) | ||||
=> LogAsync(LogSeverity.Error, source, ex); | => LogAsync(LogSeverity.Error, source, ex); | ||||
public Task ErrorAsync(string source, string message, Exception ex = null) | public Task ErrorAsync(string source, string message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Error, source, message, ex); | => LogAsync(LogSeverity.Error, source, message, ex); | ||||
#if FORMATSTR | |||||
public Task ErrorAsync(string source, FormattableString message, Exception ex = null) | public Task ErrorAsync(string source, FormattableString message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Error, source, message, ex); | => LogAsync(LogSeverity.Error, source, message, ex); | ||||
#endif | |||||
public Task WarningAsync(string source, Exception ex) | public Task WarningAsync(string source, Exception ex) | ||||
=> LogAsync(LogSeverity.Warning, source, ex); | => LogAsync(LogSeverity.Warning, source, ex); | ||||
public Task WarningAsync(string source, string message, Exception ex = null) | public Task WarningAsync(string source, string message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Warning, source, message, ex); | => LogAsync(LogSeverity.Warning, source, message, ex); | ||||
#if FORMATSTR | |||||
public Task WarningAsync(string source, FormattableString message, Exception ex = null) | public Task WarningAsync(string source, FormattableString message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Warning, source, message, ex); | => LogAsync(LogSeverity.Warning, source, message, ex); | ||||
#endif | |||||
public Task InfoAsync(string source, Exception ex) | public Task InfoAsync(string source, Exception ex) | ||||
=> LogAsync(LogSeverity.Info, source, ex); | => LogAsync(LogSeverity.Info, source, ex); | ||||
public Task InfoAsync(string source, string message, Exception ex = null) | public Task InfoAsync(string source, string message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Info, source, message, ex); | => LogAsync(LogSeverity.Info, source, message, ex); | ||||
#if FORMATSTR | |||||
public Task InfoAsync(string source, FormattableString message, Exception ex = null) | public Task InfoAsync(string source, FormattableString message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Info, source, message, ex); | => LogAsync(LogSeverity.Info, source, message, ex); | ||||
#endif | |||||
public Task VerboseAsync(string source, Exception ex) | public Task VerboseAsync(string source, Exception ex) | ||||
=> LogAsync(LogSeverity.Verbose, source, ex); | => LogAsync(LogSeverity.Verbose, source, ex); | ||||
public Task VerboseAsync(string source, string message, Exception ex = null) | public Task VerboseAsync(string source, string message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Verbose, source, message, ex); | => LogAsync(LogSeverity.Verbose, source, message, ex); | ||||
#if FORMATSTR | |||||
public Task VerboseAsync(string source, FormattableString message, Exception ex = null) | public Task VerboseAsync(string source, FormattableString message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Verbose, source, message, ex); | => LogAsync(LogSeverity.Verbose, source, message, ex); | ||||
#endif | |||||
public Task DebugAsync(string source, Exception ex) | public Task DebugAsync(string source, Exception ex) | ||||
=> LogAsync(LogSeverity.Debug, source, ex); | => LogAsync(LogSeverity.Debug, source, ex); | ||||
public Task DebugAsync(string source, string message, Exception ex = null) | public Task DebugAsync(string source, string message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Debug, source, message, ex); | => LogAsync(LogSeverity.Debug, source, message, ex); | ||||
#if FORMATSTR | |||||
public Task DebugAsync(string source, FormattableString message, Exception ex = null) | public Task DebugAsync(string source, FormattableString message, Exception ex = null) | ||||
=> LogAsync(LogSeverity.Debug, source, message, ex); | => LogAsync(LogSeverity.Debug, source, message, ex); | ||||
#endif | |||||
public Logger CreateLogger(string name) => new Logger(this, name); | public Logger CreateLogger(string name) => new Logger(this, name); | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Logging | namespace Discord.Logging | ||||
@@ -20,54 +20,53 @@ namespace Discord.Logging | |||||
=> _manager.LogAsync(severity, Name, exception); | => _manager.LogAsync(severity, Name, exception); | ||||
public Task LogAsync(LogSeverity severity, string message, Exception exception = null) | public Task LogAsync(LogSeverity severity, string message, Exception exception = null) | ||||
=> _manager.LogAsync(severity, Name, message, exception); | => _manager.LogAsync(severity, Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) | public Task LogAsync(LogSeverity severity, FormattableString message, Exception exception = null) | ||||
=> _manager.LogAsync(severity, Name, message, exception); | => _manager.LogAsync(severity, Name, message, exception); | ||||
#endif | |||||
public Task ErrorAsync(Exception exception) | public Task ErrorAsync(Exception exception) | ||||
=> _manager.ErrorAsync(Name, exception); | => _manager.ErrorAsync(Name, exception); | ||||
public Task ErrorAsync(string message, Exception exception = null) | public Task ErrorAsync(string message, Exception exception = null) | ||||
=> _manager.ErrorAsync(Name, message, exception); | => _manager.ErrorAsync(Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task ErrorAsync(FormattableString message, Exception exception = null) | public Task ErrorAsync(FormattableString message, Exception exception = null) | ||||
=> _manager.ErrorAsync(Name, message, exception); | => _manager.ErrorAsync(Name, message, exception); | ||||
#endif | |||||
public Task WarningAsync(Exception exception) | public Task WarningAsync(Exception exception) | ||||
=> _manager.WarningAsync(Name, exception); | => _manager.WarningAsync(Name, exception); | ||||
public Task WarningAsync(string message, Exception exception = null) | public Task WarningAsync(string message, Exception exception = null) | ||||
=> _manager.WarningAsync(Name, message, exception); | => _manager.WarningAsync(Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task WarningAsync(FormattableString message, Exception exception = null) | public Task WarningAsync(FormattableString message, Exception exception = null) | ||||
=> _manager.WarningAsync(Name, message, exception); | => _manager.WarningAsync(Name, message, exception); | ||||
#endif | |||||
public Task InfoAsync(Exception exception) | public Task InfoAsync(Exception exception) | ||||
=> _manager.InfoAsync(Name, exception); | => _manager.InfoAsync(Name, exception); | ||||
public Task InfoAsync(string message, Exception exception = null) | public Task InfoAsync(string message, Exception exception = null) | ||||
=> _manager.InfoAsync(Name, message, exception); | => _manager.InfoAsync(Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task InfoAsync(FormattableString message, Exception exception = null) | public Task InfoAsync(FormattableString message, Exception exception = null) | ||||
=> _manager.InfoAsync(Name, message, exception); | => _manager.InfoAsync(Name, message, exception); | ||||
#endif | |||||
public Task VerboseAsync(Exception exception) | public Task VerboseAsync(Exception exception) | ||||
=> _manager.VerboseAsync(Name, exception); | => _manager.VerboseAsync(Name, exception); | ||||
public Task VerboseAsync(string message, Exception exception = null) | public Task VerboseAsync(string message, Exception exception = null) | ||||
=> _manager.VerboseAsync(Name, message, exception); | => _manager.VerboseAsync(Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task VerboseAsync(FormattableString message, Exception exception = null) | public Task VerboseAsync(FormattableString message, Exception exception = null) | ||||
=> _manager.VerboseAsync(Name, message, exception); | => _manager.VerboseAsync(Name, message, exception); | ||||
#endif | |||||
public Task DebugAsync(Exception exception) | public Task DebugAsync(Exception exception) | ||||
=> _manager.DebugAsync(Name, exception); | => _manager.DebugAsync(Name, exception); | ||||
public Task DebugAsync(string message, Exception exception = null) | public Task DebugAsync(string message, Exception exception = null) | ||||
=> _manager.DebugAsync(Name, message, exception); | => _manager.DebugAsync(Name, message, exception); | ||||
#if FORMATSTR | |||||
public Task DebugAsync(FormattableString message, Exception exception = null) | public Task DebugAsync(FormattableString message, Exception exception = null) | ||||
=> _manager.DebugAsync(Name, message, exception); | => _manager.DebugAsync(Name, message, exception); | ||||
#endif | |||||
} | } | ||||
} | } |
@@ -1,57 +1,14 @@ | |||||
using System; | |||||
using System; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
//Source: https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/DateTimeOffset.cs | //Source: https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/DateTimeOffset.cs | ||||
internal static class DateTimeUtils | internal static class DateTimeUtils | ||||
{ | { | ||||
#if !UNIXTIME | |||||
private const long UnixEpochTicks = 621_355_968_000_000_000; | |||||
private const long UnixEpochSeconds = 62_135_596_800; | |||||
private const long UnixEpochMilliseconds = 62_135_596_800_000; | |||||
#endif | |||||
public static DateTimeOffset FromTicks(long ticks) | public static DateTimeOffset FromTicks(long ticks) | ||||
=> new DateTimeOffset(ticks, TimeSpan.Zero); | => new DateTimeOffset(ticks, TimeSpan.Zero); | ||||
public static DateTimeOffset? FromTicks(long? ticks) | public static DateTimeOffset? FromTicks(long? ticks) | ||||
=> ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null; | => ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null; | ||||
public static DateTimeOffset FromUnixSeconds(long seconds) | |||||
{ | |||||
#if UNIXTIME | |||||
return DateTimeOffset.FromUnixTimeSeconds(seconds); | |||||
#else | |||||
long ticks = seconds * TimeSpan.TicksPerSecond + UnixEpochTicks; | |||||
return new DateTimeOffset(ticks, TimeSpan.Zero); | |||||
#endif | |||||
} | |||||
public static DateTimeOffset FromUnixMilliseconds(long milliseconds) | |||||
{ | |||||
#if UNIXTIME | |||||
return DateTimeOffset.FromUnixTimeMilliseconds(milliseconds); | |||||
#else | |||||
long ticks = milliseconds * TimeSpan.TicksPerMillisecond + UnixEpochTicks; | |||||
return new DateTimeOffset(ticks, TimeSpan.Zero); | |||||
#endif | |||||
} | |||||
public static long ToUnixSeconds(DateTimeOffset dto) | |||||
{ | |||||
#if UNIXTIME | |||||
return dto.ToUnixTimeSeconds(); | |||||
#else | |||||
long seconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerSecond; | |||||
return seconds - UnixEpochSeconds; | |||||
#endif | |||||
} | |||||
public static long ToUnixMilliseconds(DateTimeOffset dto) | |||||
{ | |||||
#if UNIXTIME | |||||
return dto.ToUnixTimeMilliseconds(); | |||||
#else | |||||
long milliseconds = dto.UtcDateTime.Ticks / TimeSpan.TicksPerMillisecond; | |||||
return milliseconds - UnixEpochMilliseconds; | |||||
#endif | |||||
} | |||||
} | } | ||||
} | } |
@@ -5,8 +5,8 @@ namespace Discord | |||||
public static class SnowflakeUtils | public static class SnowflakeUtils | ||||
{ | { | ||||
public static DateTimeOffset FromSnowflake(ulong value) | public static DateTimeOffset FromSnowflake(ulong value) | ||||
=> DateTimeUtils.FromUnixMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||||
=> DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||||
public static ulong ToSnowflake(DateTimeOffset value) | public static ulong ToSnowflake(DateTimeOffset value) | ||||
=> ((ulong)DateTimeUtils.ToUnixMilliseconds(value) - 1420070400000UL) << 22; | |||||
=> ((ulong)value.ToUnixTimeMilliseconds() - 1420070400000UL) << 22; | |||||
} | } | ||||
} | } |
@@ -4,9 +4,10 @@ | |||||
<AssemblyName>Discord.Net.DebugTools</AssemblyName> | <AssemblyName>Discord.Net.DebugTools</AssemblyName> | ||||
<RootNamespace>Discord</RootNamespace> | <RootNamespace>Discord</RootNamespace> | ||||
<Description>A Discord.Net extension adding some helper classes for diagnosing issues.</Description> | <Description>A Discord.Net extension adding some helper classes for diagnosing issues.</Description> | ||||
<TargetFrameworks>net45;netstandard1.3</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net45;netstandard1.3</TargetFrameworks> | |||||
<TargetFramework Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3</TargetFramework> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | |||||
</Project> |
@@ -0,0 +1,16 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API | |||||
{ | |||||
internal class AuditLog | |||||
{ | |||||
[JsonProperty("webhooks")] | |||||
public Webhook[] Webhooks { get; set; } | |||||
[JsonProperty("users")] | |||||
public User[] Users { get; set; } | |||||
[JsonProperty("audit_log_entries")] | |||||
public AuditLogEntry[] Entries { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,17 @@ | |||||
using Newtonsoft.Json; | |||||
using Newtonsoft.Json.Linq; | |||||
namespace Discord.API | |||||
{ | |||||
internal class AuditLogChange | |||||
{ | |||||
[JsonProperty("key")] | |||||
public string ChangedProperty { get; set; } | |||||
[JsonProperty("new_value")] | |||||
public JToken NewValue { get; set; } | |||||
[JsonProperty("old_value")] | |||||
public JToken OldValue { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API | |||||
{ | |||||
internal class AuditLogEntry | |||||
{ | |||||
[JsonProperty("target_id")] | |||||
public ulong? TargetId { get; set; } | |||||
[JsonProperty("user_id")] | |||||
public ulong UserId { get; set; } | |||||
[JsonProperty("changes")] | |||||
public AuditLogChange[] Changes { get; set; } | |||||
[JsonProperty("options")] | |||||
public AuditLogOptions Options { get; set; } | |||||
[JsonProperty("id")] | |||||
public ulong Id { get; set; } | |||||
[JsonProperty("action_type")] | |||||
public ActionType Action { get; set; } | |||||
[JsonProperty("reason")] | |||||
public string Reason { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API | |||||
{ | |||||
internal class AuditLogOptions | |||||
{ | |||||
//Message delete | |||||
[JsonProperty("count")] | |||||
public int? MessageDeleteCount { get; set; } | |||||
[JsonProperty("channel_id")] | |||||
public ulong? MessageDeleteChannelId { get; set; } | |||||
//Prune | |||||
[JsonProperty("delete_member_days")] | |||||
public int? PruneDeleteMemberDays { get; set; } | |||||
[JsonProperty("members_removed")] | |||||
public int? PruneMembersRemoved { get; set; } | |||||
//Overwrite Update | |||||
[JsonProperty("role_name")] | |||||
public string OverwriteRoleName { get; set; } | |||||
[JsonProperty("type")] | |||||
public string OverwriteType { get; set; } | |||||
[JsonProperty("id")] | |||||
public ulong? OverwriteTargetId { get; set; } | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API | namespace Discord.API | ||||
@@ -11,5 +11,9 @@ namespace Discord.API | |||||
public InviteGuild Guild { get; set; } | public InviteGuild Guild { get; set; } | ||||
[JsonProperty("channel")] | [JsonProperty("channel")] | ||||
public InviteChannel Channel { get; set; } | public InviteChannel Channel { get; set; } | ||||
[JsonProperty("approximate_presence_count")] | |||||
public Optional<int?> PresenceCount { get; set; } | |||||
[JsonProperty("approximate_member_count")] | |||||
public Optional<int?> MemberCount { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
using System; | using System; | ||||
@@ -12,10 +12,16 @@ namespace Discord.API | |||||
public MessageType Type { get; set; } | public MessageType Type { get; set; } | ||||
[JsonProperty("channel_id")] | [JsonProperty("channel_id")] | ||||
public ulong ChannelId { get; set; } | public ulong ChannelId { get; set; } | ||||
// ALWAYS sent on WebSocket messages | |||||
[JsonProperty("guild_id")] | |||||
public Optional<ulong> GuildId { get; set; } | |||||
[JsonProperty("webhook_id")] | [JsonProperty("webhook_id")] | ||||
public Optional<ulong> WebhookId { get; set; } | public Optional<ulong> WebhookId { get; set; } | ||||
[JsonProperty("author")] | [JsonProperty("author")] | ||||
public Optional<User> Author { get; set; } | public Optional<User> Author { get; set; } | ||||
// ALWAYS sent on WebSocket messages | |||||
[JsonProperty("member")] | |||||
public Optional<GuildMember> Member { get; set; } | |||||
[JsonProperty("content")] | [JsonProperty("content")] | ||||
public Optional<string> Content { get; set; } | public Optional<string> Content { get; set; } | ||||
[JsonProperty("timestamp")] | [JsonProperty("timestamp")] | ||||
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API | namespace Discord.API | ||||
@@ -13,9 +13,9 @@ namespace Discord.API | |||||
public bool IsVip { get; set; } | public bool IsVip { get; set; } | ||||
[JsonProperty("optimal")] | [JsonProperty("optimal")] | ||||
public bool IsOptimal { get; set; } | public bool IsOptimal { get; set; } | ||||
[JsonProperty("sample_hostname")] | |||||
public string SampleHostname { get; set; } | |||||
[JsonProperty("sample_port")] | |||||
public int SamplePort { get; set; } | |||||
[JsonProperty("deprecated")] | |||||
public bool IsDeprecated { get; set; } | |||||
[JsonProperty("custom")] | |||||
public bool IsCustom { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API | namespace Discord.API | ||||
@@ -11,6 +11,9 @@ namespace Discord.API | |||||
public ulong? ChannelId { get; set; } | public ulong? ChannelId { get; set; } | ||||
[JsonProperty("user_id")] | [JsonProperty("user_id")] | ||||
public ulong UserId { get; set; } | public ulong UserId { get; set; } | ||||
// ALWAYS sent over WebSocket, never on REST | |||||
[JsonProperty("member")] | |||||
public Optional<GuildMember> Member { get; set; } | |||||
[JsonProperty("session_id")] | [JsonProperty("session_id")] | ||||
public string SessionId { get; set; } | public string SessionId { get; set; } | ||||
[JsonProperty("deaf")] | [JsonProperty("deaf")] | ||||
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
@@ -10,9 +10,20 @@ namespace Discord.API.Rest | |||||
public string Name { get; } | public string Name { get; } | ||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
public ChannelType Type { get; } | public ChannelType Type { get; } | ||||
[JsonProperty("parent_id")] | |||||
public Optional<ulong?> CategoryId { get; set; } | |||||
//Text channels | |||||
[JsonProperty("topic")] | |||||
public Optional<string> Topic { get; set; } | |||||
[JsonProperty("nsfw")] | |||||
public Optional<bool> IsNsfw { get; set; } | |||||
//Voice channels | |||||
[JsonProperty("bitrate")] | [JsonProperty("bitrate")] | ||||
public Optional<int> Bitrate { get; set; } | public Optional<int> Bitrate { get; set; } | ||||
[JsonProperty("user_limit")] | |||||
public Optional<int?> UserLimit { get; set; } | |||||
public CreateGuildChannelParams(string name, ChannelType type) | public CreateGuildChannelParams(string name, ChannelType type) | ||||
{ | { | ||||
@@ -0,0 +1,8 @@ | |||||
namespace Discord.API.Rest | |||||
{ | |||||
class GetAuditLogsParams | |||||
{ | |||||
public Optional<int> Limit { get; set; } | |||||
public Optional<ulong> BeforeEntryId { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,7 @@ | |||||
namespace Discord.API.Rest | |||||
{ | |||||
internal class GetInviteParams | |||||
{ | |||||
public Optional<bool?> WithCounts { get; set; } | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
namespace Discord.API.Rest | |||||
namespace Discord.API.Rest | |||||
{ | { | ||||
internal class GetReactionUsersParams | internal class GetReactionUsersParams | ||||
{ | { | ||||
@@ -148,7 +148,7 @@ namespace Discord.Rest | |||||
Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | ||||
=> Task.FromResult<IReadOnlyCollection<IConnection>>(ImmutableArray.Create<IConnection>()); | => Task.FromResult<IReadOnlyCollection<IConnection>>(ImmutableArray.Create<IConnection>()); | ||||
Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||||
Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, bool withCount, RequestOptions options) | |||||
=> Task.FromResult<IInvite>(null); | => Task.FromResult<IInvite>(null); | ||||
Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
@@ -50,12 +50,16 @@ namespace Discord.Rest | |||||
return models.Select(x => RestConnection.Create(x)).ToImmutableArray(); | return models.Select(x => RestConnection.Create(x)).ToImmutableArray(); | ||||
} | } | ||||
public static async Task<RestInvite> GetInviteAsync(BaseDiscordClient client, | |||||
string inviteId, RequestOptions options) | |||||
public static async Task<RestInviteMetadata> GetInviteAsync(BaseDiscordClient client, | |||||
string inviteId, bool withCount, RequestOptions options) | |||||
{ | { | ||||
var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false); | |||||
var args = new GetInviteParams | |||||
{ | |||||
WithCounts = withCount | |||||
}; | |||||
var model = await client.ApiClient.GetInviteAsync(inviteId, args, options).ConfigureAwait(false); | |||||
if (model != null) | if (model != null) | ||||
return RestInvite.Create(client, null, null, model); | |||||
return RestInviteMetadata.Create(client, null, null, model); | |||||
return null; | return null; | ||||
} | } | ||||
@@ -1,19 +1,19 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<Import Project="../../Discord.Net.targets" /> | <Import Project="../../Discord.Net.targets" /> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<AssemblyName>Discord.Net.Rest</AssemblyName> | <AssemblyName>Discord.Net.Rest</AssemblyName> | ||||
<RootNamespace>Discord.Rest</RootNamespace> | <RootNamespace>Discord.Rest</RootNamespace> | ||||
<Description>A core Discord.Net library containing the REST client and models.</Description> | <Description>A core Discord.Net library containing the REST client and models.</Description> | ||||
<TargetFrameworks>net45;netstandard1.1;netstandard1.3</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net46;netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | <ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup Condition=" '$(TargetFramework)' != 'net45' "> | |||||
<PackageReference Include="System.Net.Http" Version="4.3.2" /> | |||||
<!-- https://github.com/dotnet/corefx/issues/19535 --> | |||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> | |||||
<PackageReference Include="System.Net.Http" Version="4.3.3" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> | |||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' "> | |||||
<Reference Include="System.Net.Http" /> | <Reference Include="System.Net.Http" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | |||||
</Project> |
@@ -618,15 +618,15 @@ namespace Discord.API | |||||
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | ||||
Preconditions.NotNull(args, nameof(args)); | Preconditions.NotNull(args, nameof(args)); | ||||
Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); | Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); | ||||
Preconditions.AtMost(args.Limit, DiscordConfig.MaxUsersPerBatch, nameof(args.Limit)); | |||||
Preconditions.AtMost(args.Limit, DiscordConfig.MaxUserReactionsPerBatch, nameof(args.Limit)); | |||||
Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); | Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); | ||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
int limit = args.Limit.GetValueOrDefault(int.MaxValue); | |||||
int limit = args.Limit.GetValueOrDefault(DiscordConfig.MaxUserReactionsPerBatch); | |||||
ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); | ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); | ||||
var ids = new BucketIds(channelId: channelId); | var ids = new BucketIds(channelId: channelId); | ||||
Expression<Func<string>> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}"; | |||||
Expression<Func<string>> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}"; | |||||
return await SendAsync<IReadOnlyCollection<User>>("GET", endpoint, ids, options: options).ConfigureAwait(false); | return await SendAsync<IReadOnlyCollection<User>>("GET", endpoint, ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) | public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) | ||||
@@ -800,6 +800,15 @@ namespace Discord.API | |||||
var ids = new BucketIds(guildId: guildId); | var ids = new BucketIds(guildId: guildId); | ||||
return await SendAsync<IReadOnlyCollection<Ban>>("GET", () => $"guilds/{guildId}/bans", ids, options: options).ConfigureAwait(false); | return await SendAsync<IReadOnlyCollection<Ban>>("GET", () => $"guilds/{guildId}/bans", ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task<Ban> GetGuildBanAsync(ulong guildId, ulong userId, RequestOptions options) | |||||
{ | |||||
Preconditions.NotEqual(userId, 0, nameof(userId)); | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); | |||||
} | |||||
public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) | public async Task CreateGuildBanAsync(ulong guildId, ulong userId, CreateGuildBanParams args, RequestOptions options = null) | ||||
{ | { | ||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | Preconditions.NotEqual(guildId, 0, nameof(guildId)); | ||||
@@ -897,7 +906,7 @@ namespace Discord.API | |||||
} | } | ||||
//Guild Invites | //Guild Invites | ||||
public async Task<Invite> GetInviteAsync(string inviteId, RequestOptions options = null) | |||||
public async Task<InviteMetadata> GetInviteAsync(string inviteId, GetInviteParams args, RequestOptions options = null) | |||||
{ | { | ||||
Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); | Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); | ||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
@@ -910,9 +919,11 @@ namespace Discord.API | |||||
if (index >= 0) | if (index >= 0) | ||||
inviteId = inviteId.Substring(index + 1); | inviteId = inviteId.Substring(index + 1); | ||||
var withCounts = args.WithCounts.GetValueOrDefault(false); | |||||
try | try | ||||
{ | { | ||||
return await SendAsync<Invite>("GET", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); | |||||
return await SendAsync<InviteMetadata>("GET", () => $"invites/{inviteId}?with_counts={withCounts}", new BucketIds(), options: options).ConfigureAwait(false); | |||||
} | } | ||||
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } | catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } | ||||
} | } | ||||
@@ -950,13 +961,6 @@ namespace Discord.API | |||||
return await SendAsync<Invite>("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); | return await SendAsync<Invite>("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task AcceptInviteAsync(string inviteId, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
await SendAsync("POST", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); | |||||
} | |||||
//Guild Members | //Guild Members | ||||
public async Task<GuildMember> GetGuildMemberAsync(ulong guildId, ulong userId, RequestOptions options = null) | public async Task<GuildMember> GetGuildMemberAsync(ulong guildId, ulong userId, RequestOptions options = null) | ||||
@@ -1202,6 +1206,26 @@ namespace Discord.API | |||||
return await SendAsync<IReadOnlyCollection<VoiceRegion>>("GET", () => $"guilds/{guildId}/regions", ids, options: options).ConfigureAwait(false); | return await SendAsync<IReadOnlyCollection<VoiceRegion>>("GET", () => $"guilds/{guildId}/regions", ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
//Audit logs | |||||
public async Task<AuditLog> GetAuditLogsAsync(ulong guildId, GetAuditLogsParams args, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
Preconditions.NotNull(args, nameof(args)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
int limit = args.Limit.GetValueOrDefault(int.MaxValue); | |||||
var ids = new BucketIds(guildId: guildId); | |||||
Expression<Func<string>> endpoint; | |||||
if (args.BeforeEntryId.IsSpecified) | |||||
endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}&before={args.BeforeEntryId.Value}"; | |||||
else | |||||
endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}"; | |||||
return await SendAsync<AuditLog>("GET", endpoint, ids, options: options).ConfigureAwait(false); | |||||
} | |||||
//Webhooks | //Webhooks | ||||
public async Task<Webhook> CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) | public async Task<Webhook> CreateWebhookAsync(ulong channelId, CreateWebhookParams args, RequestOptions options = null) | ||||
{ | { | ||||
@@ -56,8 +56,8 @@ namespace Discord.Rest | |||||
=> ClientHelper.GetConnectionsAsync(this, options); | => ClientHelper.GetConnectionsAsync(this, options); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public Task<RestInvite> GetInviteAsync(string inviteId, RequestOptions options = null) | |||||
=> ClientHelper.GetInviteAsync(this, inviteId, options); | |||||
public Task<RestInviteMetadata> GetInviteAsync(string inviteId, bool withCount = false, RequestOptions options = null) | |||||
=> ClientHelper.GetInviteAsync(this, inviteId, withCount, options); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public Task<RestGuild> GetGuildAsync(ulong id, RequestOptions options = null) | public Task<RestGuild> GetGuildAsync(ulong id, RequestOptions options = null) | ||||
@@ -131,8 +131,8 @@ namespace Discord.Rest | |||||
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | ||||
=> await GetConnectionsAsync(options).ConfigureAwait(false); | => await GetConnectionsAsync(options).ConfigureAwait(false); | ||||
async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||||
=> await GetInviteAsync(inviteId, options).ConfigureAwait(false); | |||||
async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, bool withCount, RequestOptions options) | |||||
=> await GetInviteAsync(inviteId, withCount, options).ConfigureAwait(false); | |||||
async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
@@ -0,0 +1,58 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
internal static class AuditLogHelper | |||||
{ | |||||
private static readonly Dictionary<ActionType, Func<BaseDiscordClient, Model, EntryModel, IAuditLogData>> CreateMapping | |||||
= new Dictionary<ActionType, Func<BaseDiscordClient, Model, EntryModel, IAuditLogData>>() | |||||
{ | |||||
[ActionType.GuildUpdated] = GuildUpdateAuditLogData.Create, | |||||
[ActionType.ChannelCreated] = ChannelCreateAuditLogData.Create, | |||||
[ActionType.ChannelUpdated] = ChannelUpdateAuditLogData.Create, | |||||
[ActionType.ChannelDeleted] = ChannelDeleteAuditLogData.Create, | |||||
[ActionType.OverwriteCreated] = OverwriteCreateAuditLogData.Create, | |||||
[ActionType.OverwriteUpdated] = OverwriteUpdateAuditLogData.Create, | |||||
[ActionType.OverwriteDeleted] = OverwriteDeleteAuditLogData.Create, | |||||
[ActionType.Kick] = KickAuditLogData.Create, | |||||
[ActionType.Prune] = PruneAuditLogData.Create, | |||||
[ActionType.Ban] = BanAuditLogData.Create, | |||||
[ActionType.Unban] = UnbanAuditLogData.Create, | |||||
[ActionType.MemberUpdated] = MemberUpdateAuditLogData.Create, | |||||
[ActionType.MemberRoleUpdated] = MemberRoleAuditLogData.Create, | |||||
[ActionType.RoleCreated] = RoleCreateAuditLogData.Create, | |||||
[ActionType.RoleUpdated] = RoleUpdateAuditLogData.Create, | |||||
[ActionType.RoleDeleted] = RoleDeleteAuditLogData.Create, | |||||
[ActionType.InviteCreated] = InviteCreateAuditLogData.Create, | |||||
[ActionType.InviteUpdated] = InviteUpdateAuditLogData.Create, | |||||
[ActionType.InviteDeleted] = InviteDeleteAuditLogData.Create, | |||||
[ActionType.WebhookCreated] = WebhookCreateAuditLogData.Create, | |||||
[ActionType.WebhookUpdated] = WebhookUpdateAuditLogData.Create, | |||||
[ActionType.WebhookDeleted] = WebhookDeleteAuditLogData.Create, | |||||
[ActionType.EmojiCreated] = EmoteCreateAuditLogData.Create, | |||||
[ActionType.EmojiUpdated] = EmoteUpdateAuditLogData.Create, | |||||
[ActionType.EmojiDeleted] = EmoteDeleteAuditLogData.Create, | |||||
[ActionType.MessageDeleted] = MessageDeleteAuditLogData.Create, | |||||
}; | |||||
public static IAuditLogData CreateData(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
if (CreateMapping.TryGetValue(entry.Action, out var func)) | |||||
return func(discord, log, entry); | |||||
return null; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class BanAuditLogData : IAuditLogData | |||||
{ | |||||
private BanAuditLogData(IUser user) | |||||
{ | |||||
Target = user; | |||||
} | |||||
internal static BanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
return new BanAuditLogData(RestUser.Create(discord, userInfo)); | |||||
} | |||||
public IUser Target { get; } | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
using Newtonsoft.Json.Linq; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class ChannelCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private ChannelCreateAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites) | |||||
{ | |||||
ChannelId = id; | |||||
ChannelName = name; | |||||
ChannelType = type; | |||||
Overwrites = overwrites; | |||||
} | |||||
internal static ChannelCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var overwrites = new List<Overwrite>(); | |||||
var overwritesModel = changes.FirstOrDefault(x => x.ChangedProperty == "permission_overwrites"); | |||||
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var type = typeModel.NewValue.ToObject<ChannelType>(); | |||||
var name = nameModel.NewValue.ToObject<string>(); | |||||
foreach (var overwrite in overwritesModel.NewValue) | |||||
{ | |||||
var deny = overwrite.Value<ulong>("deny"); | |||||
var _type = overwrite.Value<string>("type"); | |||||
var id = overwrite.Value<ulong>("id"); | |||||
var allow = overwrite.Value<ulong>("allow"); | |||||
PermissionTarget permType = _type == "member" ? PermissionTarget.User : PermissionTarget.Role; | |||||
overwrites.Add(new Overwrite(id, permType, new OverwritePermissions(allow, deny))); | |||||
} | |||||
return new ChannelCreateAuditLogData(entry.TargetId.Value, name, type, overwrites.ToReadOnlyCollection()); | |||||
} | |||||
public ulong ChannelId { get; } | |||||
public string ChannelName { get; } | |||||
public ChannelType ChannelType { get; } | |||||
public IReadOnlyCollection<Overwrite> Overwrites { get; } | |||||
} | |||||
} |
@@ -0,0 +1,45 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class ChannelDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private ChannelDeleteAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites) | |||||
{ | |||||
ChannelId = id; | |||||
ChannelName = name; | |||||
ChannelType = type; | |||||
Overwrites = overwrites; | |||||
} | |||||
internal static ChannelDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var overwritesModel = changes.FirstOrDefault(x => x.ChangedProperty == "permission_overwrites"); | |||||
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var overwrites = overwritesModel.OldValue.ToObject<API.Overwrite[]>() | |||||
.Select(x => new Overwrite(x.TargetId, x.TargetType, new OverwritePermissions(x.Allow, x.Deny))) | |||||
.ToList(); | |||||
var type = typeModel.OldValue.ToObject<ChannelType>(); | |||||
var name = nameModel.OldValue.ToObject<string>(); | |||||
var id = entry.TargetId.Value; | |||||
return new ChannelDeleteAuditLogData(id, name, type, overwrites.ToReadOnlyCollection()); | |||||
} | |||||
public ulong ChannelId { get; } | |||||
public string ChannelName { get; } | |||||
public ChannelType ChannelType { get; } | |||||
public IReadOnlyCollection<Overwrite> Overwrites { get; } | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct ChannelInfo | |||||
{ | |||||
internal ChannelInfo(string name, string topic, int? bitrate, int? limit) | |||||
{ | |||||
Name = name; | |||||
Topic = topic; | |||||
Bitrate = bitrate; | |||||
UserLimit = limit; | |||||
} | |||||
public string Name { get; } | |||||
public string Topic { get; } | |||||
public int? Bitrate { get; } | |||||
public int? UserLimit { get; } | |||||
} | |||||
} |
@@ -0,0 +1,45 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class ChannelUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private ChannelUpdateAuditLogData(ulong id, ChannelInfo before, ChannelInfo after) | |||||
{ | |||||
ChannelId = id; | |||||
Before = before; | |||||
After = after; | |||||
} | |||||
internal static ChannelUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var topicModel = changes.FirstOrDefault(x => x.ChangedProperty == "topic"); | |||||
var bitrateModel = changes.FirstOrDefault(x => x.ChangedProperty == "bitrate"); | |||||
var userLimitModel = changes.FirstOrDefault(x => x.ChangedProperty == "user_limit"); | |||||
string oldName = nameModel?.OldValue?.ToObject<string>(), | |||||
newName = nameModel?.NewValue?.ToObject<string>(); | |||||
string oldTopic = topicModel?.OldValue?.ToObject<string>(), | |||||
newTopic = topicModel?.NewValue?.ToObject<string>(); | |||||
int? oldBitrate = bitrateModel?.OldValue?.ToObject<int>(), | |||||
newBitrate = bitrateModel?.NewValue?.ToObject<int>(); | |||||
int? oldLimit = userLimitModel?.OldValue?.ToObject<int>(), | |||||
newLimit = userLimitModel?.NewValue?.ToObject<int>(); | |||||
var before = new ChannelInfo(oldName, oldTopic, oldBitrate, oldLimit); | |||||
var after = new ChannelInfo(newName, newTopic, newBitrate, newLimit); | |||||
return new ChannelUpdateAuditLogData(entry.TargetId.Value, before, after); | |||||
} | |||||
public ulong ChannelId { get; } | |||||
public ChannelInfo Before { get; } | |||||
public ChannelInfo After { get; } | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class EmoteCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private EmoteCreateAuditLogData(ulong id, string name) | |||||
{ | |||||
EmoteId = id; | |||||
Name = name; | |||||
} | |||||
internal static EmoteCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var change = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var emoteName = change.NewValue?.ToObject<string>(); | |||||
return new EmoteCreateAuditLogData(entry.TargetId.Value, emoteName); | |||||
} | |||||
public ulong EmoteId { get; } | |||||
public string Name { get; } | |||||
} | |||||
} |
@@ -0,0 +1,28 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class EmoteDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private EmoteDeleteAuditLogData(ulong id, string name) | |||||
{ | |||||
EmoteId = id; | |||||
Name = name; | |||||
} | |||||
internal static EmoteDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var change = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var emoteName = change.OldValue?.ToObject<string>(); | |||||
return new EmoteDeleteAuditLogData(entry.TargetId.Value, emoteName); | |||||
} | |||||
public ulong EmoteId { get; } | |||||
public string Name { get; } | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class EmoteUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private EmoteUpdateAuditLogData(ulong id, string oldName, string newName) | |||||
{ | |||||
EmoteId = id; | |||||
OldName = oldName; | |||||
NewName = newName; | |||||
} | |||||
internal static EmoteUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var change = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var newName = change.NewValue?.ToObject<string>(); | |||||
var oldName = change.OldValue?.ToObject<string>(); | |||||
return new EmoteUpdateAuditLogData(entry.TargetId.Value, oldName, newName); | |||||
} | |||||
public ulong EmoteId { get; } | |||||
public string NewName { get; } | |||||
public string OldName { get; } | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct GuildInfo | |||||
{ | |||||
internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs, | |||||
ulong? afkChannel, string name, string region, string icon, | |||||
VerificationLevel? verification, IUser owner, MfaLevel? mfa, int? filter) | |||||
{ | |||||
AfkTimeout = afkTimeout; | |||||
DefaultMessageNotifications = defaultNotifs; | |||||
AfkChannelId = afkChannel; | |||||
Name = name; | |||||
RegionId = region; | |||||
IconHash = icon; | |||||
VerificationLevel = verification; | |||||
Owner = owner; | |||||
MfaLevel = mfa; | |||||
ContentFilterLevel = filter; | |||||
} | |||||
public int? AfkTimeout { get; } | |||||
public DefaultMessageNotifications? DefaultMessageNotifications { get; } | |||||
public ulong? AfkChannelId { get; } | |||||
public string Name { get; } | |||||
public string RegionId { get; } | |||||
public string IconHash { get; } | |||||
public VerificationLevel? VerificationLevel { get; } | |||||
public IUser Owner { get; } | |||||
public MfaLevel? MfaLevel { get; } | |||||
public int? ContentFilterLevel { get; } | |||||
} | |||||
} |
@@ -0,0 +1,79 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class GuildUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private GuildUpdateAuditLogData(GuildInfo before, GuildInfo after) | |||||
{ | |||||
Before = before; | |||||
After = after; | |||||
} | |||||
internal static GuildUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var afkTimeoutModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var defaultMessageNotificationsModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var afkChannelModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var regionIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var iconHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var verificationLevelModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var ownerIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var mfaLevelModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
var contentFilterModel = changes.FirstOrDefault(x => x.ChangedProperty == "afk_timeout"); | |||||
int? oldAfkTimeout = afkTimeoutModel?.OldValue?.ToObject<int>(), | |||||
newAfkTimeout = afkTimeoutModel?.NewValue?.ToObject<int>(); | |||||
DefaultMessageNotifications? oldDefaultMessageNotifications = defaultMessageNotificationsModel?.OldValue?.ToObject<DefaultMessageNotifications>(), | |||||
newDefaultMessageNotifications = defaultMessageNotificationsModel?.NewValue?.ToObject<DefaultMessageNotifications>(); | |||||
ulong? oldAfkChannelId = afkChannelModel?.OldValue?.ToObject<ulong>(), | |||||
newAfkChannelId = afkChannelModel?.NewValue?.ToObject<ulong>(); | |||||
string oldName = nameModel?.OldValue?.ToObject<string>(), | |||||
newName = nameModel?.NewValue?.ToObject<string>(); | |||||
string oldRegionId = regionIdModel?.OldValue?.ToObject<string>(), | |||||
newRegionId = regionIdModel?.NewValue?.ToObject<string>(); | |||||
string oldIconHash = iconHashModel?.OldValue?.ToObject<string>(), | |||||
newIconHash = iconHashModel?.NewValue?.ToObject<string>(); | |||||
VerificationLevel? oldVerificationLevel = verificationLevelModel?.OldValue?.ToObject<VerificationLevel>(), | |||||
newVerificationLevel = verificationLevelModel?.NewValue?.ToObject<VerificationLevel>(); | |||||
ulong? oldOwnerId = ownerIdModel?.OldValue?.ToObject<ulong>(), | |||||
newOwnerId = ownerIdModel?.NewValue?.ToObject<ulong>(); | |||||
MfaLevel? oldMfaLevel = mfaLevelModel?.OldValue?.ToObject<MfaLevel>(), | |||||
newMfaLevel = mfaLevelModel?.NewValue?.ToObject<MfaLevel>(); | |||||
int? oldContentFilter = contentFilterModel?.OldValue?.ToObject<int>(), | |||||
newContentFilter = contentFilterModel?.NewValue?.ToObject<int>(); | |||||
IUser oldOwner = null; | |||||
if (oldOwnerId != null) | |||||
{ | |||||
var oldOwnerInfo = log.Users.FirstOrDefault(x => x.Id == oldOwnerId.Value); | |||||
oldOwner = RestUser.Create(discord, oldOwnerInfo); | |||||
} | |||||
IUser newOwner = null; | |||||
if (newOwnerId != null) | |||||
{ | |||||
var newOwnerInfo = log.Users.FirstOrDefault(x => x.Id == newOwnerId.Value); | |||||
newOwner = RestUser.Create(discord, newOwnerInfo); | |||||
} | |||||
var before = new GuildInfo(oldAfkTimeout, oldDefaultMessageNotifications, | |||||
oldAfkChannelId, oldName, oldRegionId, oldIconHash, oldVerificationLevel, oldOwner, | |||||
oldMfaLevel, oldContentFilter); | |||||
var after = new GuildInfo(newAfkTimeout, newDefaultMessageNotifications, | |||||
newAfkChannelId, newName, newRegionId, newIconHash, newVerificationLevel, newOwner, | |||||
newMfaLevel, newContentFilter); | |||||
return new GuildUpdateAuditLogData(before, after); | |||||
} | |||||
public GuildInfo Before { get; } | |||||
public GuildInfo After { get; } | |||||
} | |||||
} |
@@ -0,0 +1,55 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class InviteCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private InviteCreateAuditLogData(int maxAge, string code, bool temporary, IUser inviter, ulong channelId, int uses, int maxUses) | |||||
{ | |||||
MaxAge = maxAge; | |||||
Code = code; | |||||
Temporary = temporary; | |||||
Creator = inviter; | |||||
ChannelId = channelId; | |||||
Uses = uses; | |||||
MaxUses = maxUses; | |||||
} | |||||
internal static InviteCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var maxAgeModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_age"); | |||||
var codeModel = changes.FirstOrDefault(x => x.ChangedProperty == "code"); | |||||
var temporaryModel = changes.FirstOrDefault(x => x.ChangedProperty == "temporary"); | |||||
var inviterIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "inviter_id"); | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var usesModel = changes.FirstOrDefault(x => x.ChangedProperty == "uses"); | |||||
var maxUsesModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_uses"); | |||||
var maxAge = maxAgeModel.NewValue.ToObject<int>(); | |||||
var code = codeModel.NewValue.ToObject<string>(); | |||||
var temporary = temporaryModel.NewValue.ToObject<bool>(); | |||||
var inviterId = inviterIdModel.NewValue.ToObject<ulong>(); | |||||
var channelId = channelIdModel.NewValue.ToObject<ulong>(); | |||||
var uses = usesModel.NewValue.ToObject<int>(); | |||||
var maxUses = maxUsesModel.NewValue.ToObject<int>(); | |||||
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); | |||||
var inviter = RestUser.Create(discord, inviterInfo); | |||||
return new InviteCreateAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); | |||||
} | |||||
public int MaxAge { get; } | |||||
public string Code { get; } | |||||
public bool Temporary { get; } | |||||
public IUser Creator { get; } | |||||
public ulong ChannelId { get; } | |||||
public int Uses { get; } | |||||
public int MaxUses { get; } | |||||
} | |||||
} |
@@ -0,0 +1,55 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class InviteDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private InviteDeleteAuditLogData(int maxAge, string code, bool temporary, IUser inviter, ulong channelId, int uses, int maxUses) | |||||
{ | |||||
MaxAge = maxAge; | |||||
Code = code; | |||||
Temporary = temporary; | |||||
Creator = inviter; | |||||
ChannelId = channelId; | |||||
Uses = uses; | |||||
MaxUses = maxUses; | |||||
} | |||||
internal static InviteDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var maxAgeModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_age"); | |||||
var codeModel = changes.FirstOrDefault(x => x.ChangedProperty == "code"); | |||||
var temporaryModel = changes.FirstOrDefault(x => x.ChangedProperty == "temporary"); | |||||
var inviterIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "inviter_id"); | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var usesModel = changes.FirstOrDefault(x => x.ChangedProperty == "uses"); | |||||
var maxUsesModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_uses"); | |||||
var maxAge = maxAgeModel.OldValue.ToObject<int>(); | |||||
var code = codeModel.OldValue.ToObject<string>(); | |||||
var temporary = temporaryModel.OldValue.ToObject<bool>(); | |||||
var inviterId = inviterIdModel.OldValue.ToObject<ulong>(); | |||||
var channelId = channelIdModel.OldValue.ToObject<ulong>(); | |||||
var uses = usesModel.OldValue.ToObject<int>(); | |||||
var maxUses = maxUsesModel.OldValue.ToObject<int>(); | |||||
var inviterInfo = log.Users.FirstOrDefault(x => x.Id == inviterId); | |||||
var inviter = RestUser.Create(discord, inviterInfo); | |||||
return new InviteDeleteAuditLogData(maxAge, code, temporary, inviter, channelId, uses, maxUses); | |||||
} | |||||
public int MaxAge { get; } | |||||
public string Code { get; } | |||||
public bool Temporary { get; } | |||||
public IUser Creator { get; } | |||||
public ulong ChannelId { get; } | |||||
public int Uses { get; } | |||||
public int MaxUses { get; } | |||||
} | |||||
} |
@@ -0,0 +1,20 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct InviteInfo | |||||
{ | |||||
internal InviteInfo(int? maxAge, string code, bool? temporary, ulong? channelId, int? maxUses) | |||||
{ | |||||
MaxAge = maxAge; | |||||
Code = code; | |||||
Temporary = temporary; | |||||
ChannelId = channelId; | |||||
MaxUses = maxUses; | |||||
} | |||||
public int? MaxAge { get; } | |||||
public string Code { get; } | |||||
public bool? Temporary { get; } | |||||
public ulong? ChannelId { get; } | |||||
public int? MaxUses { get; } | |||||
} | |||||
} |
@@ -0,0 +1,46 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class InviteUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private InviteUpdateAuditLogData(InviteInfo before, InviteInfo after) | |||||
{ | |||||
Before = before; | |||||
After = after; | |||||
} | |||||
internal static InviteUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var maxAgeModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_age"); | |||||
var codeModel = changes.FirstOrDefault(x => x.ChangedProperty == "code"); | |||||
var temporaryModel = changes.FirstOrDefault(x => x.ChangedProperty == "temporary"); | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var maxUsesModel = changes.FirstOrDefault(x => x.ChangedProperty == "max_uses"); | |||||
int? oldMaxAge = maxAgeModel?.OldValue?.ToObject<int>(), | |||||
newMaxAge = maxAgeModel?.NewValue?.ToObject<int>(); | |||||
string oldCode = codeModel?.OldValue?.ToObject<string>(), | |||||
newCode = codeModel?.NewValue?.ToObject<string>(); | |||||
bool? oldTemporary = temporaryModel?.OldValue?.ToObject<bool>(), | |||||
newTemporary = temporaryModel?.NewValue?.ToObject<bool>(); | |||||
ulong? oldChannelId = channelIdModel?.OldValue?.ToObject<ulong>(), | |||||
newChannelId = channelIdModel?.NewValue?.ToObject<ulong>(); | |||||
int? oldMaxUses = maxUsesModel?.OldValue?.ToObject<int>(), | |||||
newMaxUses = maxUsesModel?.NewValue?.ToObject<int>(); | |||||
var before = new InviteInfo(oldMaxAge, oldCode, oldTemporary, oldChannelId, oldMaxUses); | |||||
var after = new InviteInfo(newMaxAge, newCode, newTemporary, newChannelId, newMaxUses); | |||||
return new InviteUpdateAuditLogData(before, after); | |||||
} | |||||
public InviteInfo Before { get; } | |||||
public InviteInfo After { get; } | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class KickAuditLogData : IAuditLogData | |||||
{ | |||||
private KickAuditLogData(RestUser user) | |||||
{ | |||||
Target = user; | |||||
} | |||||
internal static KickAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
return new KickAuditLogData(RestUser.Create(discord, userInfo)); | |||||
} | |||||
public IUser Target { get; } | |||||
} | |||||
} |
@@ -0,0 +1,36 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class MemberRoleAuditLogData : IAuditLogData | |||||
{ | |||||
private MemberRoleAuditLogData(IReadOnlyCollection<MemberRoleEditInfo> roles, IUser target) | |||||
{ | |||||
Roles = roles; | |||||
Target = target; | |||||
} | |||||
internal static MemberRoleAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var roleInfos = changes.SelectMany(x => x.NewValue.ToObject<API.Role[]>(), | |||||
(model, role) => new { model.ChangedProperty, Role = role }) | |||||
.Select(x => new MemberRoleEditInfo(x.Role.Name, x.Role.Id, x.ChangedProperty == "$add")) | |||||
.ToList(); | |||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
var user = RestUser.Create(discord, userInfo); | |||||
return new MemberRoleAuditLogData(roleInfos.ToReadOnlyCollection(), user); | |||||
} | |||||
public IReadOnlyCollection<MemberRoleEditInfo> Roles { get; } | |||||
public IUser Target { get; } | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct MemberRoleEditInfo | |||||
{ | |||||
internal MemberRoleEditInfo(string name, ulong roleId, bool added) | |||||
{ | |||||
Name = name; | |||||
RoleId = roleId; | |||||
Added = added; | |||||
} | |||||
public string Name { get; } | |||||
public ulong RoleId { get; } | |||||
public bool Added { get; } | |||||
} | |||||
} |
@@ -0,0 +1,35 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
using ChangeModel = Discord.API.AuditLogChange; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class MemberUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private MemberUpdateAuditLogData(IUser target, string newNick, string oldNick) | |||||
{ | |||||
Target = target; | |||||
NewNick = newNick; | |||||
OldNick = oldNick; | |||||
} | |||||
internal static MemberUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "nick"); | |||||
var newNick = changes.NewValue?.ToObject<string>(); | |||||
var oldNick = changes.OldValue?.ToObject<string>(); | |||||
var targetInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
var user = RestUser.Create(discord, targetInfo); | |||||
return new MemberUpdateAuditLogData(user, newNick, oldNick); | |||||
} | |||||
public IUser Target { get; } | |||||
public string NewNick { get; } | |||||
public string OldNick { get; } | |||||
} | |||||
} |
@@ -0,0 +1,22 @@ | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class MessageDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private MessageDeleteAuditLogData(ulong channelId, int count) | |||||
{ | |||||
ChannelId = channelId; | |||||
MessageCount = count; | |||||
} | |||||
internal static MessageDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
return new MessageDeleteAuditLogData(entry.Options.MessageDeleteChannelId.Value, entry.Options.MessageDeleteCount.Value); | |||||
} | |||||
public int MessageCount { get; } | |||||
public ulong ChannelId { get; } | |||||
} | |||||
} |