@@ -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, 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; | ||||
@@ -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; | ||||
@@ -32,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); | ||||
@@ -45,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."); | ||||
@@ -65,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); | ||||
@@ -333,7 +339,6 @@ namespace Discord.Commands | |||||
public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) | public async Task<IResult> ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) | ||||
{ | { | ||||
services = services ?? EmptyServiceProvider.Instance; | services = services ?? EmptyServiceProvider.Instance; | ||||
var searchResult = Search(context, input); | var searchResult = Search(context, input); | ||||
if (!searchResult.IsSuccess) | if (!searchResult.IsSuccess) | ||||
return searchResult; | return searchResult; | ||||
@@ -1,4 +1,5 @@ | |||||
using System; | using System; | ||||
using System.Collections.Generic; | |||||
namespace Discord.Commands | namespace Discord.Commands | ||||
{ | { | ||||
@@ -18,6 +19,10 @@ 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; | ||||
} | } | ||||
@@ -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; | ||||
@@ -121,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, 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) | ||||
@@ -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(); | ||||
} | } | ||||
@@ -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")); | |||||
} | |||||
} | |||||
} |
@@ -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> { | |||||
{'\"', '\"' }, | |||||
{'«', '»' }, | |||||
{'‘', '’' }, | |||||
{'“', '”' }, | |||||
{'„', '‟' }, | |||||
{'‹', '›' }, | |||||
{'‚', '‛' }, | |||||
{'《', '》' }, | |||||
{'〈', '〉' }, | |||||
{'「', '」' }, | |||||
{'『', '』' }, | |||||
{'〝', '〞' }, | |||||
{'﹁', '﹂' }, | |||||
{'﹃', '﹄' }, | |||||
{'"', '"' }, | |||||
{''', ''' }, | |||||
{'「', '」' }, | |||||
{'(', ')' }, | |||||
{'༺', '༻' }, | |||||
{'༼', '༽' }, | |||||
{'᚛', '᚜' }, | |||||
{'⁅', '⁆' }, | |||||
{'⌈', '⌉' }, | |||||
{'⌊', '⌋' }, | |||||
{'❨', '❩' }, | |||||
{'❪', '❫' }, | |||||
{'❬', '❭' }, | |||||
{'❮', '❯' }, | |||||
{'❰', '❱' }, | |||||
{'❲', '❳' }, | |||||
{'❴', '❵' }, | |||||
{'⟅', '⟆' }, | |||||
{'⟦', '⟧' }, | |||||
{'⟨', '⟩' }, | |||||
{'⟪', '⟫' }, | |||||
{'⟬', '⟭' }, | |||||
{'⟮', '⟯' }, | |||||
{'⦃', '⦄' }, | |||||
{'⦅', '⦆' }, | |||||
{'⦇', '⦈' }, | |||||
{'⦉', '⦊' }, | |||||
{'⦋', '⦌' }, | |||||
{'⦍', '⦎' }, | |||||
{'⦏', '⦐' }, | |||||
{'⦑', '⦒' }, | |||||
{'⦓', '⦔' }, | |||||
{'⦕', '⦖' }, | |||||
{'⦗', '⦘' }, | |||||
{'⧘', '⧙' }, | |||||
{'⧚', '⧛' }, | |||||
{'⧼', '⧽' }, | |||||
{'⸂', '⸃' }, | |||||
{'⸄', '⸅' }, | |||||
{'⸉', '⸊' }, | |||||
{'⸌', '⸍' }, | |||||
{'⸜', '⸝' }, | |||||
{'⸠', '⸡' }, | |||||
{'⸢', '⸣' }, | |||||
{'⸤', '⸥' }, | |||||
{'⸦', '⸧' }, | |||||
{'⸨', '⸩' }, | |||||
{'【', '】'}, | |||||
{'〔', '〕' }, | |||||
{'〖', '〗' }, | |||||
{'〘', '〙' }, | |||||
{'〚', '〛' } | |||||
}; | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -1,13 +1,13 @@ | |||||
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 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 +20,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; | ||||
@@ -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; } | |||||
} | |||||
} |
@@ -8,8 +8,7 @@ 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); | |||||
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); | ||||
@@ -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> | ||||
@@ -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); | ||||
} | } | ||||
} | |||||
} |
@@ -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> | ||||
@@ -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> | ||||
@@ -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) | ||||
@@ -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.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; } | |||||
} | |||||
} |
@@ -1,4 +1,4 @@ | |||||
namespace Discord.API.Rest | |||||
namespace Discord.API.Rest | |||||
{ | { | ||||
internal class GetReactionUsersParams | internal class GetReactionUsersParams | ||||
{ | { | ||||
@@ -618,11 +618,11 @@ 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); | ||||
@@ -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)); | ||||
@@ -1197,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) | ||||
{ | { | ||||
@@ -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; set; } | |||||
public ChannelInfo After { get; set; } | |||||
} | |||||
} |
@@ -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,50 @@ | |||||
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<RoleInfo> 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 RoleInfo(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<RoleInfo> Roles { get; } | |||||
public IUser Target { get; } | |||||
public struct RoleInfo | |||||
{ | |||||
internal RoleInfo(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; } | |||||
} | |||||
} |
@@ -0,0 +1,37 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class OverwriteCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private OverwriteCreateAuditLogData(Overwrite overwrite) | |||||
{ | |||||
Overwrite = overwrite; | |||||
} | |||||
internal static OverwriteCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var denyModel = changes.FirstOrDefault(x => x.ChangedProperty == "deny"); | |||||
var allowModel = changes.FirstOrDefault(x => x.ChangedProperty == "allow"); | |||||
var deny = denyModel.NewValue.ToObject<ulong>(); | |||||
var allow = allowModel.NewValue.ToObject<ulong>(); | |||||
var permissions = new OverwritePermissions(allow, deny); | |||||
var id = entry.Options.OverwriteTargetId.Value; | |||||
var type = entry.Options.OverwriteType; | |||||
PermissionTarget target = type == "member" ? PermissionTarget.User : PermissionTarget.Role; | |||||
return new OverwriteCreateAuditLogData(new Overwrite(id, target, permissions)); | |||||
} | |||||
public Overwrite Overwrite { get; } | |||||
} | |||||
} |
@@ -0,0 +1,42 @@ | |||||
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; | |||||
using ChangeModel = Discord.API.AuditLogChange; | |||||
using OptionModel = Discord.API.AuditLogOptions; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class OverwriteDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private OverwriteDeleteAuditLogData(Overwrite deletedOverwrite) | |||||
{ | |||||
Overwrite = deletedOverwrite; | |||||
} | |||||
internal static OverwriteDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var denyModel = changes.FirstOrDefault(x => x.ChangedProperty == "deny"); | |||||
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); | |||||
var idModel = changes.FirstOrDefault(x => x.ChangedProperty == "id"); | |||||
var allowModel = changes.FirstOrDefault(x => x.ChangedProperty == "allow"); | |||||
var deny = denyModel.OldValue.ToObject<ulong>(); | |||||
var type = typeModel.OldValue.ToObject<string>(); | |||||
var id = idModel.OldValue.ToObject<ulong>(); | |||||
var allow = allowModel.OldValue.ToObject<ulong>(); | |||||
PermissionTarget target = type == "member" ? PermissionTarget.User : PermissionTarget.Role; | |||||
return new OverwriteDeleteAuditLogData(new Overwrite(id, target, new OverwritePermissions(allow, deny))); | |||||
} | |||||
public Overwrite Overwrite { get; } | |||||
} | |||||
} |
@@ -0,0 +1,44 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class OverwriteUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private OverwriteUpdateAuditLogData(OverwritePermissions before, OverwritePermissions after, ulong targetId, PermissionTarget targetType) | |||||
{ | |||||
OldPermissions = before; | |||||
NewPermissions = after; | |||||
OverwriteTargetId = targetId; | |||||
OverwriteType = targetType; | |||||
} | |||||
internal static OverwriteUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var denyModel = changes.FirstOrDefault(x => x.ChangedProperty == "deny"); | |||||
var allowModel = changes.FirstOrDefault(x => x.ChangedProperty == "allow"); | |||||
var beforeAllow = allowModel?.OldValue?.ToObject<ulong>(); | |||||
var afterAllow = allowModel?.NewValue?.ToObject<ulong>(); | |||||
var beforeDeny = denyModel?.OldValue?.ToObject<ulong>(); | |||||
var afterDeny = denyModel?.OldValue?.ToObject<ulong>(); | |||||
var beforePermissions = new OverwritePermissions(beforeAllow ?? 0, beforeDeny ?? 0); | |||||
var afterPermissions = new OverwritePermissions(afterAllow ?? 0, afterDeny ?? 0); | |||||
PermissionTarget target = entry.Options.OverwriteType == "member" ? PermissionTarget.User : PermissionTarget.Role; | |||||
return new OverwriteUpdateAuditLogData(beforePermissions, afterPermissions, entry.Options.OverwriteTargetId.Value, target); | |||||
} | |||||
public OverwritePermissions OldPermissions { get; } | |||||
public OverwritePermissions NewPermissions { get; } | |||||
public ulong OverwriteTargetId { get; } | |||||
public PermissionTarget OverwriteType { get; } | |||||
} | |||||
} |
@@ -0,0 +1,22 @@ | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class PruneAuditLogData : IAuditLogData | |||||
{ | |||||
private PruneAuditLogData(int pruneDays, int membersRemoved) | |||||
{ | |||||
PruneDays = pruneDays; | |||||
MembersRemoved = membersRemoved; | |||||
} | |||||
internal static PruneAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
return new PruneAuditLogData(entry.Options.PruneDeleteMemberDays.Value, entry.Options.PruneMembersRemoved.Value); | |||||
} | |||||
public int PruneDays { get; } | |||||
public int MembersRemoved { get; } | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class RoleCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private RoleCreateAuditLogData(ulong id, RoleInfo props) | |||||
{ | |||||
RoleId = id; | |||||
Properties = props; | |||||
} | |||||
internal static RoleCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var colorModel = changes.FirstOrDefault(x => x.ChangedProperty == "color"); | |||||
var mentionableModel = changes.FirstOrDefault(x => x.ChangedProperty == "mentionable"); | |||||
var hoistModel = changes.FirstOrDefault(x => x.ChangedProperty == "hoist"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var permissionsModel = changes.FirstOrDefault(x => x.ChangedProperty == "permissions"); | |||||
uint? colorRaw = colorModel?.NewValue?.ToObject<uint>(); | |||||
bool? mentionable = mentionableModel?.NewValue?.ToObject<bool>(); | |||||
bool? hoist = hoistModel?.NewValue?.ToObject<bool>(); | |||||
string name = nameModel?.NewValue?.ToObject<string>(); | |||||
ulong? permissionsRaw = permissionsModel?.NewValue?.ToObject<ulong>(); | |||||
Color? color = null; | |||||
GuildPermissions? permissions = null; | |||||
if (colorRaw.HasValue) | |||||
color = new Color(colorRaw.Value); | |||||
if (permissionsRaw.HasValue) | |||||
permissions = new GuildPermissions(permissionsRaw.Value); | |||||
return new RoleCreateAuditLogData(entry.TargetId.Value, | |||||
new RoleInfo(color, mentionable, hoist, name, permissions)); | |||||
} | |||||
public ulong RoleId { get; } | |||||
public RoleInfo Properties { get; } | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class RoleDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private RoleDeleteAuditLogData(ulong id, RoleInfo props) | |||||
{ | |||||
RoleId = id; | |||||
Properties = props; | |||||
} | |||||
internal static RoleDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var colorModel = changes.FirstOrDefault(x => x.ChangedProperty == "color"); | |||||
var mentionableModel = changes.FirstOrDefault(x => x.ChangedProperty == "mentionable"); | |||||
var hoistModel = changes.FirstOrDefault(x => x.ChangedProperty == "hoist"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var permissionsModel = changes.FirstOrDefault(x => x.ChangedProperty == "permissions"); | |||||
uint? colorRaw = colorModel?.OldValue?.ToObject<uint>(); | |||||
bool? mentionable = mentionableModel?.OldValue?.ToObject<bool>(); | |||||
bool? hoist = hoistModel?.OldValue?.ToObject<bool>(); | |||||
string name = nameModel?.OldValue?.ToObject<string>(); | |||||
ulong? permissionsRaw = permissionsModel?.OldValue?.ToObject<ulong>(); | |||||
Color? color = null; | |||||
GuildPermissions? permissions = null; | |||||
if (colorRaw.HasValue) | |||||
color = new Color(colorRaw.Value); | |||||
if (permissionsRaw.HasValue) | |||||
permissions = new GuildPermissions(permissionsRaw.Value); | |||||
return new RoleDeleteAuditLogData(entry.TargetId.Value, | |||||
new RoleInfo(color, mentionable, hoist, name, permissions)); | |||||
} | |||||
public ulong RoleId { get; } | |||||
public RoleInfo Properties { get; } | |||||
} | |||||
} |
@@ -0,0 +1,21 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct RoleInfo | |||||
{ | |||||
internal RoleInfo(Color? color, bool? mentionable, bool? hoist, string name, | |||||
GuildPermissions? permissions) | |||||
{ | |||||
Color = color; | |||||
Mentionable = mentionable; | |||||
Hoist = hoist; | |||||
Name = name; | |||||
Permissions = permissions; | |||||
} | |||||
public Color? Color { get; } | |||||
public bool? Mentionable { get; } | |||||
public bool? Hoist { get; } | |||||
public string Name { get; } | |||||
public GuildPermissions? Permissions { get; } | |||||
} | |||||
} |
@@ -0,0 +1,62 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class RoleUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private RoleUpdateAuditLogData(ulong id, RoleInfo oldProps, RoleInfo newProps) | |||||
{ | |||||
RoleId = id; | |||||
Before = oldProps; | |||||
After = newProps; | |||||
} | |||||
internal static RoleUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var colorModel = changes.FirstOrDefault(x => x.ChangedProperty == "color"); | |||||
var mentionableModel = changes.FirstOrDefault(x => x.ChangedProperty == "mentionable"); | |||||
var hoistModel = changes.FirstOrDefault(x => x.ChangedProperty == "hoist"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var permissionsModel = changes.FirstOrDefault(x => x.ChangedProperty == "permissions"); | |||||
uint? oldColorRaw = colorModel?.OldValue?.ToObject<uint>(), | |||||
newColorRaw = colorModel?.NewValue?.ToObject<uint>(); | |||||
bool? oldMentionable = mentionableModel?.OldValue?.ToObject<bool>(), | |||||
newMentionable = mentionableModel?.NewValue?.ToObject<bool>(); | |||||
bool? oldHoist = hoistModel?.OldValue?.ToObject<bool>(), | |||||
newHoist = hoistModel?.NewValue?.ToObject<bool>(); | |||||
string oldName = nameModel?.OldValue?.ToObject<string>(), | |||||
newName = nameModel?.NewValue?.ToObject<string>(); | |||||
ulong? oldPermissionsRaw = permissionsModel?.OldValue?.ToObject<ulong>(), | |||||
newPermissionsRaw = permissionsModel?.OldValue?.ToObject<ulong>(); | |||||
Color? oldColor = null, | |||||
newColor = null; | |||||
GuildPermissions? oldPermissions = null, | |||||
newPermissions = null; | |||||
if (oldColorRaw.HasValue) | |||||
oldColor = new Color(oldColorRaw.Value); | |||||
if (newColorRaw.HasValue) | |||||
newColor = new Color(newColorRaw.Value); | |||||
if (oldPermissionsRaw.HasValue) | |||||
oldPermissions = new GuildPermissions(oldPermissionsRaw.Value); | |||||
if (newPermissionsRaw.HasValue) | |||||
newPermissions = new GuildPermissions(newPermissionsRaw.Value); | |||||
var oldProps = new RoleInfo(oldColor, oldMentionable, oldHoist, oldName, oldPermissions); | |||||
var newProps = new RoleInfo(newColor, newMentionable, newHoist, newName, newPermissions); | |||||
return new RoleUpdateAuditLogData(entry.TargetId.Value, oldProps, newProps); | |||||
} | |||||
public ulong RoleId { get; } | |||||
public RoleInfo Before { get; } | |||||
public RoleInfo After { get; } | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class UnbanAuditLogData : IAuditLogData | |||||
{ | |||||
private UnbanAuditLogData(IUser user) | |||||
{ | |||||
Target = user; | |||||
} | |||||
internal static UnbanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
return new UnbanAuditLogData(RestUser.Create(discord, userInfo)); | |||||
} | |||||
public IUser Target { get; } | |||||
} | |||||
} |
@@ -0,0 +1,44 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class WebhookCreateAuditLogData : IAuditLogData | |||||
{ | |||||
private WebhookCreateAuditLogData(IWebhook webhook, WebhookType type, string name, ulong channelId) | |||||
{ | |||||
Webhook = webhook; | |||||
Name = name; | |||||
Type = type; | |||||
ChannelId = channelId; | |||||
} | |||||
internal static WebhookCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var channelId = channelIdModel.NewValue.ToObject<ulong>(); | |||||
var type = typeModel.NewValue.ToObject<WebhookType>(); | |||||
var name = nameModel.NewValue.ToObject<string>(); | |||||
var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); | |||||
return new WebhookCreateAuditLogData(webhook, type, name, channelId); | |||||
} | |||||
//Corresponds to the *current* data | |||||
public IWebhook Webhook { get; } | |||||
//Corresponds to the *audit log* data | |||||
public WebhookType Type { get; } | |||||
public string Name { get; } | |||||
public ulong ChannelId { get; } | |||||
} | |||||
} |
@@ -0,0 +1,46 @@ | |||||
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 WebhookDeleteAuditLogData : IAuditLogData | |||||
{ | |||||
private WebhookDeleteAuditLogData(ulong id, ulong channel, WebhookType type, string name, string avatar) | |||||
{ | |||||
WebhookId = id; | |||||
ChannelId = channel; | |||||
Name = name; | |||||
Type = type; | |||||
Avatar = avatar; | |||||
} | |||||
internal static WebhookDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type"); | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash"); | |||||
var channelId = channelIdModel.OldValue.ToObject<ulong>(); | |||||
var type = typeModel.OldValue.ToObject<WebhookType>(); | |||||
var name = nameModel.OldValue.ToObject<string>(); | |||||
var avatarHash = avatarHashModel?.OldValue?.ToObject<string>(); | |||||
return new WebhookDeleteAuditLogData(entry.TargetId.Value, channelId, type, name, avatarHash); | |||||
} | |||||
public ulong WebhookId { get; } | |||||
public ulong ChannelId { get; } | |||||
public WebhookType Type { get; } | |||||
public string Name { get; } | |||||
public string Avatar { get; } | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
namespace Discord.Rest | |||||
{ | |||||
public struct WebhookInfo | |||||
{ | |||||
internal WebhookInfo(string name, ulong? channelId, string avatar) | |||||
{ | |||||
Name = name; | |||||
ChannelId = channelId; | |||||
Avatar = avatar; | |||||
} | |||||
public string Name { get; } | |||||
public ulong? ChannelId { get; } | |||||
public string Avatar { get; } | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
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 WebhookUpdateAuditLogData : IAuditLogData | |||||
{ | |||||
private WebhookUpdateAuditLogData(IWebhook webhook, WebhookInfo before, WebhookInfo after) | |||||
{ | |||||
Webhook = webhook; | |||||
Before = before; | |||||
After = after; | |||||
} | |||||
internal static WebhookUpdateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | |||||
{ | |||||
var changes = entry.Changes; | |||||
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); | |||||
var channelIdModel = changes.FirstOrDefault(x => x.ChangedProperty == "channel_id"); | |||||
var avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash"); | |||||
var oldName = nameModel?.OldValue?.ToObject<string>(); | |||||
var oldChannelId = channelIdModel?.OldValue?.ToObject<ulong>(); | |||||
var oldAvatar = avatarHashModel?.OldValue?.ToObject<string>(); | |||||
var before = new WebhookInfo(oldName, oldChannelId, oldAvatar); | |||||
var newName = nameModel?.NewValue?.ToObject<string>(); | |||||
var newChannelId = channelIdModel?.NewValue?.ToObject<ulong>(); | |||||
var newAvatar = avatarHashModel?.NewValue?.ToObject<string>(); | |||||
var after = new WebhookInfo(newName, newChannelId, newAvatar); | |||||
var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); | |||||
var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); | |||||
return new WebhookUpdateAuditLogData(webhook, before, after); | |||||
} | |||||
//Again, the *current* data | |||||
public IWebhook Webhook { get; } | |||||
//And the *audit log* data | |||||
public WebhookInfo Before { get; } | |||||
public WebhookInfo After { get; } | |||||
} | |||||
} |
@@ -0,0 +1,38 @@ | |||||
using System.Linq; | |||||
using Model = Discord.API.AuditLog; | |||||
using EntryModel = Discord.API.AuditLogEntry; | |||||
namespace Discord.Rest | |||||
{ | |||||
public class RestAuditLogEntry : RestEntity<ulong>, IAuditLogEntry | |||||
{ | |||||
private RestAuditLogEntry(BaseDiscordClient discord, Model fullLog, EntryModel model, IUser user) | |||||
: base(discord, model.Id) | |||||
{ | |||||
Action = model.Action; | |||||
Data = AuditLogHelper.CreateData(discord, fullLog, model); | |||||
User = user; | |||||
Reason = model.Reason; | |||||
} | |||||
internal static RestAuditLogEntry Create(BaseDiscordClient discord, Model fullLog, EntryModel model) | |||||
{ | |||||
var userInfo = fullLog.Users.FirstOrDefault(x => x.Id == model.UserId); | |||||
IUser user = null; | |||||
if (userInfo != null) | |||||
user = RestUser.Create(discord, userInfo); | |||||
return new RestAuditLogEntry(discord, fullLog, model, user); | |||||
} | |||||
/// <inheritdoc/> | |||||
public ActionType Action { get; } | |||||
/// <inheritdoc/> | |||||
public IAuditLogData Data { get; } | |||||
/// <inheritdoc/> | |||||
public IUser User { get; } | |||||
/// <inheritdoc/> | |||||
public string Reason { get; } | |||||
} | |||||
} |
@@ -184,6 +184,10 @@ namespace Discord.Rest | |||||
return RestUserMessage.Create(client, channel, client.CurrentUser, model); | return RestUserMessage.Create(client, channel, client.CurrentUser, model); | ||||
} | } | ||||
public static Task DeleteMessageAsync(IMessageChannel channel, ulong messageId, BaseDiscordClient client, | |||||
RequestOptions options) | |||||
=> MessageHelper.DeleteAsync(channel.Id, messageId, client, options); | |||||
public static async Task DeleteMessagesAsync(ITextChannel channel, BaseDiscordClient client, | public static async Task DeleteMessagesAsync(ITextChannel channel, BaseDiscordClient client, | ||||
IEnumerable<ulong> messageIds, RequestOptions options) | IEnumerable<ulong> messageIds, RequestOptions options) | ||||
{ | { | ||||
@@ -7,8 +7,7 @@ namespace Discord.Rest | |||||
public interface IRestMessageChannel : IMessageChannel | public interface IRestMessageChannel : IMessageChannel | ||||
{ | { | ||||
/// <summary> Sends a message to this message channel. </summary> | /// <summary> Sends a message to this message channel. </summary> | ||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||||
new Task<RestUserMessage> 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> | ||||
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | ||||
@@ -63,7 +63,7 @@ namespace Discord.Rest | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -72,6 +72,11 @@ namespace Discord.Rest | |||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task TriggerTypingAsync(RequestOptions options = null) | public Task TriggerTypingAsync(RequestOptions options = null) | ||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); | => ChannelHelper.TriggerTypingAsync(this, Discord, options); | ||||
public IDisposable EnterTypingState(RequestOptions options = null) | public IDisposable EnterTypingState(RequestOptions options = null) | ||||
@@ -76,7 +76,12 @@ namespace Discord.Rest | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -58,7 +58,7 @@ namespace Discord.Rest | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -67,6 +67,11 @@ namespace Discord.Rest | |||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null) | public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null) | ||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages.Select(x => x.Id), options); | => ChannelHelper.DeleteMessagesAsync(this, Discord, messages.Select(x => x.Id), options); | ||||
public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) | public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) | ||||
@@ -33,15 +33,19 @@ namespace Discord.Rest | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task TriggerTypingAsync(RequestOptions options = null) | public Task TriggerTypingAsync(RequestOptions options = null) | ||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); | => ChannelHelper.TriggerTypingAsync(this, Discord, options); | ||||
public IDisposable EnterTypingState(RequestOptions options = null) | public IDisposable EnterTypingState(RequestOptions options = null) | ||||
@@ -1,4 +1,4 @@ | |||||
using Discord.API.Rest; | |||||
using Discord.API.Rest; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
@@ -111,6 +111,11 @@ namespace Discord.Rest | |||||
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false); | var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false); | ||||
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray(); | return models.Select(x => RestBan.Create(client, x)).ToImmutableArray(); | ||||
} | } | ||||
public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options) | |||||
{ | |||||
var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false); | |||||
return RestBan.Create(client, model); | |||||
} | |||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, | public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, | ||||
ulong userId, int pruneDays, string reason, RequestOptions options) | ulong userId, int pruneDays, string reason, RequestOptions options) | ||||
@@ -140,20 +145,36 @@ namespace Discord.Rest | |||||
return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray(); | return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray(); | ||||
} | } | ||||
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, | ||||
string name, RequestOptions options) | |||||
string name, RequestOptions options, Action<TextChannelProperties> func = null) | |||||
{ | { | ||||
if (name == null) throw new ArgumentNullException(nameof(name)); | if (name == null) throw new ArgumentNullException(nameof(name)); | ||||
var args = new CreateGuildChannelParams(name, ChannelType.Text); | |||||
var props = new TextChannelProperties(); | |||||
func?.Invoke(props); | |||||
var args = new CreateGuildChannelParams(name, ChannelType.Text) | |||||
{ | |||||
CategoryId = props.CategoryId, | |||||
Topic = props.Topic, | |||||
IsNsfw = props.IsNsfw | |||||
}; | |||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
return RestTextChannel.Create(client, guild, model); | return RestTextChannel.Create(client, guild, model); | ||||
} | } | ||||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, | ||||
string name, RequestOptions options) | |||||
string name, RequestOptions options, Action<VoiceChannelProperties> func = null) | |||||
{ | { | ||||
if (name == null) throw new ArgumentNullException(nameof(name)); | if (name == null) throw new ArgumentNullException(nameof(name)); | ||||
var args = new CreateGuildChannelParams(name, ChannelType.Voice); | |||||
var props = new VoiceChannelProperties(); | |||||
func?.Invoke(props); | |||||
var args = new CreateGuildChannelParams(name, ChannelType.Voice) | |||||
{ | |||||
CategoryId = props.CategoryId, | |||||
Bitrate = props.Bitrate, | |||||
UserLimit = props.UserLimit | |||||
}; | |||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); | ||||
return RestVoiceChannel.Create(client, guild, model); | return RestVoiceChannel.Create(client, guild, model); | ||||
} | } | ||||
@@ -263,6 +284,35 @@ namespace Discord.Rest | |||||
return model.Pruned; | return model.Pruned; | ||||
} | } | ||||
// Audit logs | |||||
public static IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client, | |||||
ulong? from, int? limit, RequestOptions options) | |||||
{ | |||||
return new PagedAsyncEnumerable<RestAuditLogEntry>( | |||||
DiscordConfig.MaxAuditLogEntriesPerBatch, | |||||
async (info, ct) => | |||||
{ | |||||
var args = new GetAuditLogsParams | |||||
{ | |||||
Limit = info.PageSize | |||||
}; | |||||
if (info.Position != null) | |||||
args.BeforeEntryId = info.Position.Value; | |||||
var model = await client.ApiClient.GetAuditLogsAsync(guild.Id, args, options); | |||||
return model.Entries.Select((x) => RestAuditLogEntry.Create(client, model, x)).ToImmutableArray(); | |||||
}, | |||||
nextPage: (info, lastPage) => | |||||
{ | |||||
if (lastPage.Count != DiscordConfig.MaxAuditLogEntriesPerBatch) | |||||
return false; | |||||
info.Position = lastPage.Min(x => x.Id); | |||||
return true; | |||||
}, | |||||
start: from, | |||||
count: limit | |||||
); | |||||
} | |||||
//Webhooks | //Webhooks | ||||
public static async Task<RestWebhook> GetWebhookAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | public static async Task<RestWebhook> GetWebhookAsync(IGuild guild, BaseDiscordClient client, ulong id, RequestOptions options) | ||||
{ | { | ||||
@@ -1,4 +1,4 @@ | |||||
using Discord.Audio; | |||||
using Discord.Audio; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
@@ -140,6 +140,10 @@ namespace Discord.Rest | |||||
//Bans | //Bans | ||||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | ||||
=> GuildHelper.GetBansAsync(this, Discord, options); | => GuildHelper.GetBansAsync(this, Discord, options); | ||||
public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null) | |||||
=> GuildHelper.GetBanAsync(this, Discord, user.Id, options); | |||||
public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null) | |||||
=> GuildHelper.GetBanAsync(this, Discord, userId, options); | |||||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | ||||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | ||||
@@ -218,10 +222,10 @@ namespace Discord.Rest | |||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | |||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | ||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | ||||
@@ -264,6 +268,10 @@ namespace Discord.Rest | |||||
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) | public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) | ||||
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); | => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); | ||||
//Audit logs | |||||
public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null) | |||||
=> GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options); | |||||
//Webhooks | //Webhooks | ||||
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | ||||
=> GuildHelper.GetWebhookAsync(this, Discord, id, options); | => GuildHelper.GetWebhookAsync(this, Discord, id, options); | ||||
@@ -291,6 +299,12 @@ namespace Discord.Rest | |||||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | ||||
=> await GetBansAsync(options).ConfigureAwait(false); | => await GetBansAsync(options).ConfigureAwait(false); | ||||
/// <inheritdoc/> | |||||
async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options) | |||||
=> await GetBanAsync(user, options).ConfigureAwait(false); | |||||
/// <inheritdoc/> | |||||
async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options) | |||||
=> await GetBanAsync(userId, options).ConfigureAwait(false); | |||||
async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
@@ -369,10 +383,10 @@ namespace Discord.Rest | |||||
else | else | ||||
return null; | return null; | ||||
} | } | ||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options) | |||||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | |||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | |||||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | |||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options) | |||||
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); | |||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options) | |||||
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); | |||||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | ||||
=> await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | ||||
@@ -419,6 +433,14 @@ namespace Discord.Rest | |||||
} | } | ||||
Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } | Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } | ||||
async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogAsync(int limit, CacheMode cacheMode, RequestOptions options) | |||||
{ | |||||
if (cacheMode == CacheMode.AllowDownload) | |||||
return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); | |||||
else | |||||
return ImmutableArray.Create<IAuditLogEntry>(); | |||||
} | |||||
async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options) | async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options) | ||||
=> await GetWebhookAsync(id, options); | => await GetWebhookAsync(id, options); | ||||
async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options) | async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options) | ||||
@@ -25,10 +25,12 @@ namespace Discord.Rest | |||||
}; | }; | ||||
return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client, | |||||
public static Task DeleteAsync(IMessage msg, BaseDiscordClient client, RequestOptions options) | |||||
=> DeleteAsync(msg.Channel.Id, msg.Id, client, options); | |||||
public static async Task DeleteAsync(ulong channelId, ulong msgId, BaseDiscordClient client, | |||||
RequestOptions options) | RequestOptions options) | ||||
{ | { | ||||
await client.ApiClient.DeleteMessageAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); | |||||
await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); | |||||
} | } | ||||
public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) | public static async Task AddReactionAsync(IMessage msg, IEmote emote, BaseDiscordClient client, RequestOptions options) | ||||
@@ -46,13 +48,38 @@ namespace Discord.Rest | |||||
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options); | await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options); | ||||
} | } | ||||
public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote, | |||||
Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options) | |||||
public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote, | |||||
int? limit, BaseDiscordClient client, RequestOptions options) | |||||
{ | { | ||||
var args = new GetReactionUsersParams(); | |||||
func(args); | |||||
string emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name); | |||||
return (await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false)).Select(u => RestUser.Create(client, u)).ToImmutableArray(); | |||||
Preconditions.NotNull(emote, nameof(emote)); | |||||
var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name); | |||||
return new PagedAsyncEnumerable<IUser>( | |||||
DiscordConfig.MaxUserReactionsPerBatch, | |||||
async (info, ct) => | |||||
{ | |||||
var args = new GetReactionUsersParams | |||||
{ | |||||
Limit = info.PageSize | |||||
}; | |||||
if (info.Position != null) | |||||
args.AfterUserId = info.Position.Value; | |||||
var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false); | |||||
return models.Select(x => RestUser.Create(client, x)).ToImmutableArray(); | |||||
}, | |||||
nextPage: (info, lastPage) => | |||||
{ | |||||
if (lastPage.Count != DiscordConfig.MaxUsersPerBatch) | |||||
return false; | |||||
info.Position = lastPage.Max(x => x.Id); | |||||
return true; | |||||
}, | |||||
count: limit | |||||
); | |||||
} | } | ||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | ||||
@@ -136,8 +136,8 @@ namespace Discord.Rest | |||||
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); | => MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); | ||||
public Task RemoveAllReactionsAsync(RequestOptions options = null) | public Task RemoveAllReactionsAsync(RequestOptions options = null) | ||||
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options); | => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); | ||||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null) | |||||
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options); | |||||
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) | |||||
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); | |||||
public Task PinAsync(RequestOptions options = null) | public Task PinAsync(RequestOptions options = null) | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
@@ -165,6 +165,13 @@ namespace Discord.WebSocket | |||||
remove { _userVoiceStateUpdatedEvent.Remove(value); } | remove { _userVoiceStateUpdatedEvent.Remove(value); } | ||||
} | } | ||||
internal readonly AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>> _userVoiceStateUpdatedEvent = new AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>>(); | internal readonly AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>> _userVoiceStateUpdatedEvent = new AsyncEvent<Func<SocketUser, SocketVoiceState, SocketVoiceState, Task>>(); | ||||
/// <summary> Fired when the bot connects to a Discord voice server. </summary> | |||||
public event Func<SocketVoiceServer, Task> VoiceServerUpdated | |||||
{ | |||||
add { _voiceServerUpdatedEvent.Add(value); } | |||||
remove { _voiceServerUpdatedEvent.Remove(value); } | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketVoiceServer, Task>> _voiceServerUpdatedEvent = new AsyncEvent<Func<SocketVoiceServer, Task>>(); | |||||
/// <summary> Fired when the connected account is updated. </summary> | /// <summary> Fired when the connected account is updated. </summary> | ||||
public event Func<SocketSelfUser, SocketSelfUser, Task> CurrentUserUpdated { | public event Func<SocketSelfUser, SocketSelfUser, Task> CurrentUserUpdated { | ||||
add { _selfUpdatedEvent.Add(value); } | add { _selfUpdatedEvent.Add(value); } | ||||
@@ -129,7 +129,7 @@ namespace Discord.WebSocket | |||||
private int GetShardIdFor(ulong guildId) | private int GetShardIdFor(ulong guildId) | ||||
=> (int)((guildId >> 22) % (uint)_totalShards); | => (int)((guildId >> 22) % (uint)_totalShards); | ||||
public int GetShardIdFor(IGuild guild) | public int GetShardIdFor(IGuild guild) | ||||
=> GetShardIdFor(guild.Id); | |||||
=> GetShardIdFor(guild?.Id ?? 0); | |||||
private DiscordSocketClient GetShardFor(ulong guildId) | private DiscordSocketClient GetShardFor(ulong guildId) | ||||
=> GetShard(GetShardIdFor(guildId)); | => GetShard(GetShardIdFor(guildId)); | ||||
public DiscordSocketClient GetShardFor(IGuild guild) | public DiscordSocketClient GetShardFor(IGuild guild) | ||||
@@ -62,9 +62,9 @@ namespace Discord.WebSocket | |||||
internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient; | internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient; | ||||
public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds; | public override IReadOnlyCollection<SocketGuild> Guilds => State.Guilds; | ||||
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels; | public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => State.PrivateChannels; | ||||
public IReadOnlyCollection<SocketDMChannel> DMChannels | |||||
public IReadOnlyCollection<SocketDMChannel> DMChannels | |||||
=> State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray(); | => State.PrivateChannels.Select(x => x as SocketDMChannel).Where(x => x != null).ToImmutableArray(); | ||||
public IReadOnlyCollection<SocketGroupChannel> GroupChannels | |||||
public IReadOnlyCollection<SocketGroupChannel> GroupChannels | |||||
=> State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); | => State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); | ||||
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection(); | public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _voiceRegions.ToReadOnlyCollection(); | ||||
@@ -89,11 +89,11 @@ namespace Discord.WebSocket | |||||
_stateLock = new SemaphoreSlim(1, 1); | _stateLock = new SemaphoreSlim(1, 1); | ||||
_gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}"); | _gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}"); | ||||
_connection = new ConnectionManager(_stateLock, _gatewayLogger, config.ConnectionTimeout, | |||||
_connection = new ConnectionManager(_stateLock, _gatewayLogger, config.ConnectionTimeout, | |||||
OnConnectingAsync, OnDisconnectingAsync, x => ApiClient.Disconnected += x); | OnConnectingAsync, OnDisconnectingAsync, x => ApiClient.Disconnected += x); | ||||
_connection.Connected += () => TimedInvokeAsync(_connectedEvent, nameof(Connected)); | _connection.Connected += () => TimedInvokeAsync(_connectedEvent, nameof(Connected)); | ||||
_connection.Disconnected += (ex, recon) => TimedInvokeAsync(_disconnectedEvent, nameof(Disconnected), ex); | _connection.Disconnected += (ex, recon) => TimedInvokeAsync(_disconnectedEvent, nameof(Disconnected), ex); | ||||
_nextAudioId = 1; | _nextAudioId = 1; | ||||
_connectionGroupLock = groupLock; | _connectionGroupLock = groupLock; | ||||
_parentClient = parentClient; | _parentClient = parentClient; | ||||
@@ -104,7 +104,7 @@ namespace Discord.WebSocket | |||||
_gatewayLogger.WarningAsync("Serializer Error", e.ErrorContext.Error).GetAwaiter().GetResult(); | _gatewayLogger.WarningAsync("Serializer Error", e.ErrorContext.Error).GetAwaiter().GetResult(); | ||||
e.ErrorContext.Handled = true; | e.ErrorContext.Handled = true; | ||||
}; | }; | ||||
ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false); | ApiClient.SentGatewayMessage += async opCode => await _gatewayLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false); | ||||
ApiClient.ReceivedGatewayEvent += ProcessMessageAsync; | ApiClient.ReceivedGatewayEvent += ProcessMessageAsync; | ||||
@@ -136,7 +136,7 @@ namespace Discord.WebSocket | |||||
ApiClient.Dispose(); | ApiClient.Dispose(); | ||||
} | } | ||||
} | } | ||||
internal override async Task OnLoginAsync(TokenType tokenType, string token) | internal override async Task OnLoginAsync(TokenType tokenType, string token) | ||||
{ | { | ||||
if (_parentClient == null) | if (_parentClient == null) | ||||
@@ -154,11 +154,11 @@ namespace Discord.WebSocket | |||||
_voiceRegions = ImmutableDictionary.Create<string, RestVoiceRegion>(); | _voiceRegions = ImmutableDictionary.Create<string, RestVoiceRegion>(); | ||||
} | } | ||||
public override async Task StartAsync() | |||||
public override async Task StartAsync() | |||||
=> await _connection.StartAsync().ConfigureAwait(false); | => await _connection.StartAsync().ConfigureAwait(false); | ||||
public override async Task StopAsync() | |||||
public override async Task StopAsync() | |||||
=> await _connection.StopAsync().ConfigureAwait(false); | => await _connection.StopAsync().ConfigureAwait(false); | ||||
private async Task OnConnectingAsync() | private async Task OnConnectingAsync() | ||||
{ | { | ||||
if (_connectionGroupLock != null) | if (_connectionGroupLock != null) | ||||
@@ -181,11 +181,11 @@ namespace Discord.WebSocket | |||||
//Wait for READY | //Wait for READY | ||||
await _connection.WaitAsync().ConfigureAwait(false); | await _connection.WaitAsync().ConfigureAwait(false); | ||||
await _gatewayLogger.DebugAsync("Sending Status").ConfigureAwait(false); | await _gatewayLogger.DebugAsync("Sending Status").ConfigureAwait(false); | ||||
await SendStatusAsync().ConfigureAwait(false); | await SendStatusAsync().ConfigureAwait(false); | ||||
} | } | ||||
finally | |||||
finally | |||||
{ | { | ||||
if (_connectionGroupLock != null) | if (_connectionGroupLock != null) | ||||
{ | { | ||||
@@ -230,22 +230,22 @@ namespace Discord.WebSocket | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) | |||||
public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) | |||||
=> _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false)); | => _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options ?? RequestOptions.Default).ConfigureAwait(false)); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override SocketGuild GetGuild(ulong id) | |||||
=> State.GetGuild(id); | |||||
public override SocketGuild GetGuild(ulong id) | |||||
=> State.GetGuild(id); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override SocketChannel GetChannel(ulong id) | |||||
public override SocketChannel GetChannel(ulong id) | |||||
=> State.GetChannel(id); | => State.GetChannel(id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override SocketUser GetUser(ulong id) | |||||
public override SocketUser GetUser(ulong id) | |||||
=> State.GetUser(id); | => State.GetUser(id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override SocketUser GetUser(string username, string discriminator) | |||||
public override SocketUser GetUser(string username, string discriminator) | |||||
=> State.Users.FirstOrDefault(x => x.Discriminator == discriminator && x.Username == username); | => State.Users.FirstOrDefault(x => x.Discriminator == discriminator && x.Username == username); | ||||
internal SocketGlobalUser GetOrCreateUser(ClientState state, Discord.API.User model) | internal SocketGlobalUser GetOrCreateUser(ClientState state, Discord.API.User model) | ||||
{ | { | ||||
@@ -266,7 +266,7 @@ namespace Discord.WebSocket | |||||
return user; | return user; | ||||
}); | }); | ||||
} | } | ||||
internal void RemoveUser(ulong id) | |||||
internal void RemoveUser(ulong id) | |||||
=> State.RemoveUser(id); | => State.RemoveUser(id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -340,7 +340,7 @@ namespace Discord.WebSocket | |||||
Activity = activity; | Activity = activity; | ||||
await SendStatusAsync().ConfigureAwait(false); | await SendStatusAsync().ConfigureAwait(false); | ||||
} | } | ||||
private async Task SendStatusAsync() | private async Task SendStatusAsync() | ||||
{ | { | ||||
if (CurrentUser == null) | if (CurrentUser == null) | ||||
@@ -374,7 +374,7 @@ namespace Discord.WebSocket | |||||
if (seq != null) | if (seq != null) | ||||
_lastSeq = seq.Value; | _lastSeq = seq.Value; | ||||
_lastMessageTime = Environment.TickCount; | _lastMessageTime = Environment.TickCount; | ||||
try | try | ||||
{ | { | ||||
switch (opCode) | switch (opCode) | ||||
@@ -390,7 +390,7 @@ namespace Discord.WebSocket | |||||
case GatewayOpCode.Heartbeat: | case GatewayOpCode.Heartbeat: | ||||
{ | { | ||||
await _gatewayLogger.DebugAsync("Received Heartbeat").ConfigureAwait(false); | await _gatewayLogger.DebugAsync("Received Heartbeat").ConfigureAwait(false); | ||||
await ApiClient.SendHeartbeatAsync(_lastSeq).ConfigureAwait(false); | await ApiClient.SendHeartbeatAsync(_lastSeq).ConfigureAwait(false); | ||||
} | } | ||||
break; | break; | ||||
@@ -415,7 +415,7 @@ namespace Discord.WebSocket | |||||
_sessionId = null; | _sessionId = null; | ||||
_lastSeq = 0; | _lastSeq = 0; | ||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); | await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); | ||||
} | } | ||||
break; | break; | ||||
@@ -475,7 +475,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
else if (_connection.CancelToken.IsCancellationRequested) | else if (_connection.CancelToken.IsCancellationRequested) | ||||
return; | return; | ||||
await TimedInvokeAsync(_readyEvent, nameof(Ready)).ConfigureAwait(false); | await TimedInvokeAsync(_readyEvent, nameof(Ready)).ConfigureAwait(false); | ||||
await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false); | await _gatewayLogger.InfoAsync("Ready").ConfigureAwait(false); | ||||
}); | }); | ||||
@@ -514,7 +514,7 @@ namespace Discord.WebSocket | |||||
if (guild != null) | if (guild != null) | ||||
{ | { | ||||
guild.Update(State, data); | guild.Update(State, data); | ||||
if (_unavailableGuildCount != 0) | if (_unavailableGuildCount != 0) | ||||
_unavailableGuildCount--; | _unavailableGuildCount--; | ||||
await GuildAvailableAsync(guild).ConfigureAwait(false); | await GuildAvailableAsync(guild).ConfigureAwait(false); | ||||
@@ -1025,7 +1025,7 @@ namespace Discord.WebSocket | |||||
SocketUser user = guild.GetUser(data.User.Id); | SocketUser user = guild.GetUser(data.User.Id); | ||||
if (user == null) | if (user == null) | ||||
user = SocketUnknownUser.Create(this, State, data.User); | |||||
user = SocketUnknownUser.Create(this, State, data.User); | |||||
await TimedInvokeAsync(_userBannedEvent, nameof(UserBanned), user, guild).ConfigureAwait(false); | await TimedInvokeAsync(_userBannedEvent, nameof(UserBanned), user, guild).ConfigureAwait(false); | ||||
} | } | ||||
else | else | ||||
@@ -1325,7 +1325,7 @@ namespace Discord.WebSocket | |||||
await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), globalBefore, user).ConfigureAwait(false); | await TimedInvokeAsync(_userUpdatedEvent, nameof(UserUpdated), globalBefore, user).ConfigureAwait(false); | ||||
} | } | ||||
} | } | ||||
var before = user.Clone(); | var before = user.Clone(); | ||||
user.Update(State, data, true); | user.Update(State, data, true); | ||||
await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), before, user).ConfigureAwait(false); | await TimedInvokeAsync(_guildMemberUpdatedEvent, nameof(GuildMemberUpdated), before, user).ConfigureAwait(false); | ||||
@@ -1466,16 +1466,29 @@ namespace Discord.WebSocket | |||||
var data = (payload as JToken).ToObject<VoiceServerUpdateEvent>(_serializer); | var data = (payload as JToken).ToObject<VoiceServerUpdateEvent>(_serializer); | ||||
var guild = State.GetGuild(data.GuildId); | var guild = State.GetGuild(data.GuildId); | ||||
if (guild != null) | |||||
var isCached = guild != null; | |||||
var cachedGuild = new Cacheable<IGuild, ulong>(guild, data.GuildId, isCached, | |||||
() => Task.FromResult(State.GetGuild(data.GuildId) as IGuild)); | |||||
var voiceServer = new SocketVoiceServer(cachedGuild, data.Endpoint, data.Token); | |||||
await TimedInvokeAsync(_voiceServerUpdatedEvent, nameof(UserVoiceStateUpdated), voiceServer).ConfigureAwait(false); | |||||
if (isCached) | |||||
{ | { | ||||
string endpoint = data.Endpoint.Substring(0, data.Endpoint.LastIndexOf(':')); | |||||
var endpoint = data.Endpoint; | |||||
//Only strip out the port if the endpoint contains it | |||||
var portBegin = endpoint.LastIndexOf(':'); | |||||
if (portBegin > 0) | |||||
endpoint = endpoint.Substring(0, portBegin); | |||||
var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false); | var _ = guild.FinishConnectAudio(endpoint, data.Token).ConfigureAwait(false); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); | await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false); | ||||
return; | |||||
} | } | ||||
} | } | ||||
break; | break; | ||||
@@ -11,8 +11,7 @@ namespace Discord.WebSocket | |||||
IReadOnlyCollection<SocketMessage> CachedMessages { get; } | IReadOnlyCollection<SocketMessage> CachedMessages { get; } | ||||
/// <summary> Sends a message to this message channel. </summary> | /// <summary> Sends a message to this message channel. </summary> | ||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null); | |||||
new Task<RestUserMessage> 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> | ||||
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null); | ||||
@@ -67,7 +67,7 @@ namespace Discord.WebSocket | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -76,6 +76,11 @@ namespace Discord.WebSocket | |||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task TriggerTypingAsync(RequestOptions options = null) | public Task TriggerTypingAsync(RequestOptions options = null) | ||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); | => ChannelHelper.TriggerTypingAsync(this, Discord, options); | ||||
public IDisposable EnterTypingState(RequestOptions options = null) | public IDisposable EnterTypingState(RequestOptions options = null) | ||||
@@ -95,7 +95,7 @@ namespace Discord.WebSocket | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -104,6 +104,11 @@ namespace Discord.WebSocket | |||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task TriggerTypingAsync(RequestOptions options = null) | public Task TriggerTypingAsync(RequestOptions options = null) | ||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); | => ChannelHelper.TriggerTypingAsync(this, Discord, options); | ||||
public IDisposable EnterTypingState(RequestOptions options = null) | public IDisposable EnterTypingState(RequestOptions options = null) | ||||
@@ -75,7 +75,7 @@ namespace Discord.WebSocket | |||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null) | ||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); | ||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
public Task<RestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) | |||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); | ||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) | ||||
@@ -89,6 +89,11 @@ namespace Discord.WebSocket | |||||
public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) | public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) | ||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); | => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); | ||||
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); | |||||
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) | |||||
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); | |||||
public Task TriggerTypingAsync(RequestOptions options = null) | public Task TriggerTypingAsync(RequestOptions options = null) | ||||
=> ChannelHelper.TriggerTypingAsync(this, Discord, options); | => ChannelHelper.TriggerTypingAsync(this, Discord, options); | ||||
public IDisposable EnterTypingState(RequestOptions options = null) | public IDisposable EnterTypingState(RequestOptions options = null) | ||||
@@ -288,6 +288,10 @@ namespace Discord.WebSocket | |||||
//Bans | //Bans | ||||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null) | ||||
=> GuildHelper.GetBansAsync(this, Discord, options); | => GuildHelper.GetBansAsync(this, Discord, options); | ||||
public Task<RestBan> GetBanAsync(IUser user, RequestOptions options = null) | |||||
=> GuildHelper.GetBanAsync(this, Discord, user.Id, options); | |||||
public Task<RestBan> GetBanAsync(ulong userId, RequestOptions options = null) | |||||
=> GuildHelper.GetBanAsync(this, Discord, userId, options); | |||||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | ||||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); | ||||
@@ -311,10 +315,10 @@ namespace Discord.WebSocket | |||||
=> GetChannel(id) as SocketTextChannel; | => GetChannel(id) as SocketTextChannel; | ||||
public SocketVoiceChannel GetVoiceChannel(ulong id) | public SocketVoiceChannel GetVoiceChannel(ulong id) | ||||
=> GetChannel(id) as SocketVoiceChannel; | => GetChannel(id) as SocketVoiceChannel; | ||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); | |||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, Action<TextChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func = null, RequestOptions options = null) | |||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); | |||||
public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | public Task<RestCategoryChannel> CreateCategoryChannelAsync(string name, RequestOptions options = null) | ||||
=> GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options); | ||||
@@ -434,6 +438,10 @@ namespace Discord.WebSocket | |||||
_downloaderPromise.TrySetResultAsync(true); | _downloaderPromise.TrySetResultAsync(true); | ||||
} | } | ||||
//Audit logs | |||||
public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null) | |||||
=> GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options); | |||||
//Webhooks | //Webhooks | ||||
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) | ||||
=> GuildHelper.GetWebhookAsync(this, Discord, id, options); | => GuildHelper.GetWebhookAsync(this, Discord, id, options); | ||||
@@ -641,6 +649,12 @@ namespace Discord.WebSocket | |||||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options) | ||||
=> await GetBansAsync(options).ConfigureAwait(false); | => await GetBansAsync(options).ConfigureAwait(false); | ||||
/// <inheritdoc/> | |||||
async Task<IBan> IGuild.GetBanAsync(IUser user, RequestOptions options) | |||||
=> await GetBanAsync(user, options).ConfigureAwait(false); | |||||
/// <inheritdoc/> | |||||
async Task<IBan> IGuild.GetBanAsync(ulong userId, RequestOptions options) | |||||
=> await GetBanAsync(userId, options).ConfigureAwait(false); | |||||
Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels); | => Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels); | ||||
@@ -664,10 +678,10 @@ namespace Discord.WebSocket | |||||
=> Task.FromResult<IGuildChannel>(EmbedChannel); | => Task.FromResult<IGuildChannel>(EmbedChannel); | ||||
Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) | Task<ITextChannel> IGuild.GetSystemChannelAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<ITextChannel>(SystemChannel); | => Task.FromResult<ITextChannel>(SystemChannel); | ||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options) | |||||
=> await CreateTextChannelAsync(name, options).ConfigureAwait(false); | |||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) | |||||
=> await CreateVoiceChannelAsync(name, options).ConfigureAwait(false); | |||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, Action<TextChannelProperties> func, RequestOptions options) | |||||
=> await CreateTextChannelAsync(name, func, options).ConfigureAwait(false); | |||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, Action<VoiceChannelProperties> func, RequestOptions options) | |||||
=> await CreateVoiceChannelAsync(name, func, options).ConfigureAwait(false); | |||||
async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | async Task<ICategoryChannel> IGuild.CreateCategoryAsync(string name, RequestOptions options) | ||||
=> await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | => await CreateCategoryChannelAsync(name, options).ConfigureAwait(false); | ||||
@@ -693,6 +707,14 @@ namespace Discord.WebSocket | |||||
Task<IGuildUser> IGuild.GetOwnerAsync(CacheMode mode, RequestOptions options) | Task<IGuildUser> IGuild.GetOwnerAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildUser>(Owner); | => Task.FromResult<IGuildUser>(Owner); | ||||
async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogAsync(int limit, CacheMode cacheMode, RequestOptions options) | |||||
{ | |||||
if (cacheMode == CacheMode.AllowDownload) | |||||
return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); | |||||
else | |||||
return ImmutableArray.Create<IAuditLogEntry>(); | |||||
} | |||||
async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options) | async Task<IWebhook> IGuild.GetWebhookAsync(ulong id, RequestOptions options) | ||||
=> await GetWebhookAsync(id, options); | => await GetWebhookAsync(id, options); | ||||
async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options) | async Task<IReadOnlyCollection<IWebhook>> IGuild.GetWebhooksAsync(RequestOptions options) | ||||
@@ -130,8 +130,8 @@ namespace Discord.WebSocket | |||||
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); | => MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); | ||||
public Task RemoveAllReactionsAsync(RequestOptions options = null) | public Task RemoveAllReactionsAsync(RequestOptions options = null) | ||||
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options); | => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); | ||||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null) | |||||
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options); | |||||
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) | |||||
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); | |||||
public Task PinAsync(RequestOptions options = null) | public Task PinAsync(RequestOptions options = null) | ||||
=> MessageHelper.PinAsync(this, Discord, options); | => MessageHelper.PinAsync(this, Discord, options); | ||||
@@ -0,0 +1,21 @@ | |||||
using System.Diagnostics; | |||||
namespace Discord.WebSocket | |||||
{ | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||||
public class SocketVoiceServer | |||||
{ | |||||
public Cacheable<IGuild, ulong> Guild { get; private set; } | |||||
public string Endpoint { get; private set; } | |||||
public string Token { get; private set; } | |||||
internal SocketVoiceServer(Cacheable<IGuild, ulong> guild, string endpoint, string token) | |||||
{ | |||||
Guild = guild; | |||||
Endpoint = endpoint; | |||||
Token = token; | |||||
} | |||||
private string DebuggerDisplay => $"SocketVoiceServer ({Guild.Id})"; | |||||
} | |||||
} |
@@ -63,7 +63,7 @@ namespace Discord.Webhook | |||||
=> new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent); | => new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent); | ||||
/// <summary> Sends a message using to the channel for this webhook. Returns the ID of the created message. </summary> | /// <summary> Sends a message using to the channel for this webhook. Returns the ID of the created message. </summary> | ||||
public Task<ulong> SendMessageAsync(string text, bool isTTS = false, IEnumerable<Embed> embeds = null, | |||||
public Task<ulong> SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> embeds = null, | |||||
string username = null, string avatarUrl = null, RequestOptions options = null) | string username = null, string avatarUrl = null, RequestOptions options = null) | ||||
=> WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, options); | => WebhookClientHelper.SendMessageAsync(this, text, isTTS, embeds, username, avatarUrl, options); | ||||