| @@ -461,8 +461,8 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.GreaterThan(args.Bitrate, 0, nameof(args.Bitrate)); | |||
| Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); | |||
| Preconditions.GreaterThan(args._bitrate, 0, nameof(args.Bitrate)); | |||
| Preconditions.NotNullOrWhitespace(args._name, nameof(args.Name)); | |||
| return await SendAsync<Channel>("POST", $"guilds/{guildId}/channels", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -476,8 +476,8 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | |||
| Preconditions.AtLeast(args._position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args._name, nameof(args.Name)); | |||
| return await SendAsync<Channel>("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -485,8 +485,8 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | |||
| Preconditions.AtLeast(args._position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args._name, nameof(args.Name)); | |||
| return await SendAsync<Channel>("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -494,10 +494,10 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.GreaterThan(args.Bitrate, 0, nameof(args.Bitrate)); | |||
| Preconditions.AtLeast(args.UserLimit, 0, nameof(args.Bitrate)); | |||
| Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | |||
| Preconditions.GreaterThan(args._bitrate, 0, nameof(args.Bitrate)); | |||
| Preconditions.AtLeast(args._userLimit, 0, nameof(args.Bitrate)); | |||
| Preconditions.AtLeast(args._position, 0, nameof(args.Position)); | |||
| Preconditions.NotNullOrEmpty(args._name, nameof(args.Name)); | |||
| return await SendAsync<Channel>("PATCH", $"channels/{channelId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -606,11 +606,11 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.NotEqual(args.AFKChannelId, 0, nameof(args.AFKChannelId)); | |||
| Preconditions.AtLeast(args.AFKTimeout, 0, nameof(args.AFKTimeout)); | |||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | |||
| Preconditions.GreaterThan(args.OwnerId, 0, nameof(args.OwnerId)); | |||
| Preconditions.NotNull(args.Region, nameof(args.Region)); | |||
| Preconditions.NotEqual(args._afkChannelId, 0, nameof(args.AFKChannelId)); | |||
| Preconditions.AtLeast(args._afkTimeout, 0, nameof(args.AFKTimeout)); | |||
| Preconditions.NotNullOrEmpty(args._name, nameof(args.Name)); | |||
| Preconditions.GreaterThan(args._ownerId, 0, nameof(args.OwnerId)); | |||
| Preconditions.NotNull(args._region, nameof(args.Region)); | |||
| return await SendAsync<Guild>("PATCH", $"guilds/{guildId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -643,7 +643,7 @@ namespace Discord.API | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotEqual(userId, 0, nameof(userId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.PruneDays, 0, nameof(args.PruneDays)); | |||
| Preconditions.AtLeast(args._deleteMessageDays, 0, nameof(args.DeleteMessageDays)); | |||
| await SendAsync("PUT", $"guilds/{guildId}/bans/{userId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -701,8 +701,8 @@ namespace Discord.API | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotEqual(integrationId, 0, nameof(integrationId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.ExpireBehavior, 0, nameof(args.ExpireBehavior)); | |||
| Preconditions.AtLeast(args.ExpireGracePeriod, 0, nameof(args.ExpireGracePeriod)); | |||
| Preconditions.AtLeast(args._expireBehavior, 0, nameof(args.ExpireBehavior)); | |||
| Preconditions.AtLeast(args._expireGracePeriod, 0, nameof(args.ExpireGracePeriod)); | |||
| return await SendAsync<Integration>("PATCH", $"guilds/{guildId}/integrations/{integrationId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -749,8 +749,8 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.MaxAge, 0, nameof(args.MaxAge)); | |||
| Preconditions.AtLeast(args.MaxUses, 0, nameof(args.MaxUses)); | |||
| Preconditions.AtLeast(args._maxAge, 0, nameof(args.MaxAge)); | |||
| Preconditions.AtLeast(args._maxUses, 0, nameof(args.MaxUses)); | |||
| return await SendAsync<InviteMetadata>("POST", $"channels/{channelId}/invites", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -783,14 +783,14 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); | |||
| Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); | |||
| Preconditions.GreaterThan(args._limit, 0, nameof(args.Limit)); | |||
| Preconditions.GreaterThan(args._afterUserId, 0, nameof(args.AfterUserId)); | |||
| int limit = args.Limit.GetValueOrDefault(int.MaxValue); | |||
| ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); | |||
| int limit = args._limit.GetValueOrDefault(int.MaxValue); | |||
| ulong afterUserId = args._afterUserId.GetValueOrDefault(0); | |||
| List<GuildMember[]> result; | |||
| if (args.Limit.IsSpecified) | |||
| if (args._limit.IsSpecified) | |||
| result = new List<GuildMember[]>((limit + DiscordRestConfig.MaxUsersPerBatch - 1) / DiscordRestConfig.MaxUsersPerBatch); | |||
| else | |||
| result = new List<GuildMember[]>(); | |||
| @@ -861,9 +861,9 @@ namespace Discord.API | |||
| Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||
| Preconditions.NotEqual(roleId, 0, nameof(roleId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.AtLeast(args.Color, 0, nameof(args.Color)); | |||
| Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); | |||
| Preconditions.AtLeast(args.Position, 0, nameof(args.Position)); | |||
| Preconditions.AtLeast(args._color, 0, nameof(args.Color)); | |||
| Preconditions.NotNullOrEmpty(args._name, nameof(args.Name)); | |||
| Preconditions.AtLeast(args._position, 0, nameof(args.Position)); | |||
| return await SendAsync<Role>("PATCH", $"guilds/{guildId}/roles/{roleId}", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -903,7 +903,7 @@ namespace Discord.API | |||
| Preconditions.AtLeast(args.Limit, 0, nameof(args.Limit)); | |||
| int limit = args.Limit; | |||
| ulong? relativeId = args.RelativeMessageId.IsSpecified ? args.RelativeMessageId.Value : (ulong?)null; | |||
| ulong? relativeId = args._relativeMessageId.IsSpecified ? args._relativeMessageId.Value : (ulong?)null; | |||
| string relativeDir; | |||
| switch (args.RelativeDirection) | |||
| @@ -1010,8 +1010,8 @@ namespace Discord.API | |||
| { | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||
| if (args.Content.Length > DiscordRestConfig.MaxMessageSize) | |||
| Preconditions.NotNullOrEmpty(args._content, nameof(args.Content)); | |||
| if (args._content.Length > DiscordRestConfig.MaxMessageSize) | |||
| throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordRestConfig.MaxMessageSize}.", nameof(args.Content)); | |||
| if (guildId != 0) | |||
| @@ -1034,13 +1034,13 @@ namespace Discord.API | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| if (args.Content.GetValueOrDefault(null) == null) | |||
| args.Content = ""; | |||
| else if (args.Content.IsSpecified) | |||
| if (args._content.GetValueOrDefault(null) == null) | |||
| args._content = ""; | |||
| else if (args._content.IsSpecified) | |||
| { | |||
| if (args.Content.Value == null) | |||
| args.Content = ""; | |||
| if (args.Content.Value?.Length > DiscordRestConfig.MaxMessageSize) | |||
| if (args._content.Value == null) | |||
| args._content = ""; | |||
| if (args._content.Value?.Length > DiscordRestConfig.MaxMessageSize) | |||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordRestConfig.MaxMessageSize}.", nameof(args.Content)); | |||
| } | |||
| @@ -1084,8 +1084,8 @@ namespace Discord.API | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| var messageIds = args.MessageIds?.ToArray(); | |||
| Preconditions.NotNull(args.MessageIds, nameof(args.MessageIds)); | |||
| var messageIds = args._messages; | |||
| Preconditions.NotNull(args._messages, nameof(args.MessageIds)); | |||
| Preconditions.AtMost(messageIds.Length, 100, nameof(messageIds.Length)); | |||
| switch (messageIds.Length) | |||
| @@ -1118,10 +1118,10 @@ namespace Discord.API | |||
| Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
| Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| if (args.Content.IsSpecified) | |||
| if (args._content.IsSpecified) | |||
| { | |||
| Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); | |||
| if (args.Content.Value.Length > DiscordRestConfig.MaxMessageSize) | |||
| Preconditions.NotNullOrEmpty(args._content, nameof(args.Content)); | |||
| if (args._content.Value.Length > DiscordRestConfig.MaxMessageSize) | |||
| throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordRestConfig.MaxMessageSize}.", nameof(args.Content)); | |||
| } | |||
| @@ -1195,7 +1195,7 @@ namespace Discord.API | |||
| public async Task<User> ModifySelfAsync(ModifyCurrentUserParams args, RequestOptions options = null) | |||
| { | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.NotNullOrEmpty(args.Username, nameof(args.Username)); | |||
| Preconditions.NotNullOrEmpty(args._username, nameof(args.Username)); | |||
| return await SendAsync<User>("PATCH", "users/@me", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -1209,7 +1209,7 @@ namespace Discord.API | |||
| public async Task<Channel> CreateDMChannelAsync(CreateDMChannelParams args, RequestOptions options = null) | |||
| { | |||
| Preconditions.NotNull(args, nameof(args)); | |||
| Preconditions.GreaterThan(args.RecipientId, 0, nameof(args.Recipient)); | |||
| Preconditions.GreaterThan(args._recipientId, 0, nameof(args.Recipient)); | |||
| return await SendAsync<Channel>("POST", $"users/@me/channels", args, options: options).ConfigureAwait(false); | |||
| } | |||
| @@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class IdentifyParams | |||
| { | |||
| [JsonProperty("token")] | |||
| @@ -4,6 +4,7 @@ using System.Linq; | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class RequestMembersParams | |||
| { | |||
| [JsonProperty("query")] | |||
| @@ -12,8 +13,8 @@ namespace Discord.API.Gateway | |||
| public int Limit { get; set; } | |||
| [JsonProperty("guild_id")] | |||
| public IEnumerable<ulong> GuildIds { get; set; } | |||
| [JsonIgnore] | |||
| public IEnumerable<IGuild> Guilds { set { GuildIds = value.Select(x => x.Id); } } | |||
| private ulong[] _guildIds; | |||
| public IEnumerable<ulong> GuildIds { set { _guildIds = value.ToArray(); } } | |||
| public IEnumerable<IGuild> Guilds { set { _guildIds = value.Select(x => x.Id).ToArray(); } } | |||
| } | |||
| } | |||
| @@ -2,6 +2,7 @@ | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ResumeParams | |||
| { | |||
| [JsonProperty("token")] | |||
| @@ -2,6 +2,7 @@ | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class StatusUpdateParams | |||
| { | |||
| [JsonProperty("idle_since"), Int53] | |||
| @@ -2,6 +2,7 @@ | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class UpdateStatusParams | |||
| { | |||
| [JsonProperty("idle_since")] | |||
| @@ -2,6 +2,7 @@ | |||
| namespace Discord.API.Gateway | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class VoiceStateUpdateParams | |||
| { | |||
| [JsonProperty("self_mute")] | |||
| @@ -10,12 +11,11 @@ namespace Discord.API.Gateway | |||
| public bool SelfDeaf { get; set; } | |||
| [JsonProperty("guild_id")] | |||
| public ulong GuildId { get; set; } | |||
| [JsonIgnore] | |||
| public IGuild Guild { set { GuildId = value.Id; } } | |||
| public ulong? GuildId { get; set; } | |||
| public IGuild Guild { set { GuildId = value?.Id; } } | |||
| [JsonProperty("channel_id")] | |||
| public ulong? ChannelId { get; set; } | |||
| [JsonIgnore] | |||
| public IChannel Channel { set { ChannelId = value?.Id; } } | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Threading.Tasks; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class ApplicationInfo | |||
| { | |||
| } | |||
| } | |||
| @@ -2,15 +2,23 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateChannelInviteParams | |||
| { | |||
| [JsonProperty("max_age")] | |||
| public Optional<int> MaxAge { get; set; } | |||
| internal Optional<int> _maxAge { get; set; } | |||
| public int MaxAge { set { _maxAge = value; } } | |||
| [JsonProperty("max_uses")] | |||
| public Optional<int> MaxUses { get; set; } | |||
| internal Optional<int> _maxUses { get; set; } | |||
| public int MaxUses { set { _maxUses = value; } } | |||
| [JsonProperty("temporary")] | |||
| public Optional<bool> Temporary { get; set; } | |||
| internal Optional<bool> _temporary { get; set; } | |||
| public bool Temporary { set { _temporary = value; } } | |||
| [JsonProperty("xkcdpass")] | |||
| public Optional<bool> XkcdPass { get; set; } | |||
| internal Optional<bool> _xkcdPass { get; set; } | |||
| public bool XkcdPass { set { _xkcdPass = value; } } | |||
| } | |||
| } | |||
| @@ -2,11 +2,12 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateDMChannelParams | |||
| { | |||
| [JsonProperty("recipient_id")] | |||
| public ulong RecipientId { get; set; } | |||
| [JsonIgnore] | |||
| public IUser Recipient { set { RecipientId = value.Id; } } | |||
| internal ulong _recipientId; | |||
| public ulong RecipientId { set { _recipientId = value; } } | |||
| public IUser Recipient { set { _recipientId = value.Id; } } | |||
| } | |||
| } | |||
| @@ -2,9 +2,11 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateGuildBanParams | |||
| { | |||
| [JsonProperty("delete-message-days")] | |||
| public Optional<int> PruneDays { get; set; } | |||
| internal Optional<int> _deleteMessageDays; | |||
| public int DeleteMessageDays { set { _deleteMessageDays = value; } } | |||
| } | |||
| } | |||
| @@ -2,14 +2,19 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateGuildChannelParams | |||
| { | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| internal string _name; | |||
| public string Name { set { _name = value; } } | |||
| [JsonProperty("type")] | |||
| public ChannelType Type { get; set; } | |||
| internal ChannelType _type; | |||
| public ChannelType Type { set { _type = value; } } | |||
| [JsonProperty("bitrate")] | |||
| public Optional<int> Bitrate { get; set; } | |||
| internal Optional<int> _bitrate; | |||
| public int Bitrate { set { _bitrate = value; } } | |||
| } | |||
| } | |||
| @@ -2,11 +2,13 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateGuildIntegrationParams | |||
| { | |||
| [JsonProperty("id")] | |||
| public ulong Id { get; set; } | |||
| public ulong Id { internal get; set; } | |||
| [JsonProperty("type")] | |||
| public string Type { get; set; } | |||
| public string Type { internal get; set; } | |||
| } | |||
| } | |||
| @@ -3,20 +3,17 @@ using System.IO; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateGuildParams | |||
| { | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| public string Name { internal get; set; } | |||
| [JsonProperty("region")] | |||
| public string Region { get; set; } | |||
| public string Region { internal get; set; } | |||
| [JsonProperty("icon")] | |||
| private Optional<Image> _icon { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<Stream> Icon | |||
| { | |||
| get { return _icon.IsSpecified ? _icon.Value.Stream : null; } | |||
| set { _icon = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| internal Optional<Image?> _icon; | |||
| public Stream Icon { set { _icon = value != null ? new Image(value) : (Image?)null; } } | |||
| } | |||
| } | |||
| @@ -2,14 +2,19 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class CreateMessageParams | |||
| { | |||
| [JsonProperty("content")] | |||
| public string Content { get; set; } = ""; | |||
| internal string _content; | |||
| public string Content { set { _content = value; } } | |||
| [JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)] | |||
| public Optional<string> Nonce { get; set; } | |||
| [JsonProperty("tts", DefaultValueHandling = DefaultValueHandling.Ignore)] | |||
| public Optional<bool> IsTTS { get; set; } | |||
| [JsonProperty("nonce")] | |||
| internal Optional<string> _nonce; | |||
| public string Nonce { set { _nonce = value; } } | |||
| [JsonProperty("tts")] | |||
| internal Optional<bool> _tts; | |||
| public bool IsTTS { set { _tts = value; } } | |||
| } | |||
| } | |||
| @@ -4,11 +4,12 @@ using System.Linq; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class DeleteMessagesParams | |||
| { | |||
| [JsonProperty("messages")] | |||
| public IEnumerable<ulong> MessageIds { get; set; } | |||
| [JsonIgnore] | |||
| public IEnumerable<IMessage> Messages { set { MessageIds = value.Select(x => x.Id); } } | |||
| internal ulong[] _messages; | |||
| public IEnumerable<ulong> MessageIds { set { _messages = value.ToArray(); } } | |||
| public IEnumerable<IMessage> Messages { set { _messages = value.Select(x => x.Id).ToArray(); } } | |||
| } | |||
| } | |||
| @@ -2,10 +2,12 @@ | |||
| { | |||
| public class GetChannelMessagesParams | |||
| { | |||
| public int Limit { get; set; } = DiscordRestConfig.MaxMessagesPerBatch; | |||
| public Direction RelativeDirection { get; set; } = Direction.Before; | |||
| public int Limit { internal get; set; } = DiscordRestConfig.MaxMessagesPerBatch; | |||
| public Optional<ulong> RelativeMessageId { get; set; } | |||
| public Optional<IMessage> RelativeMessage { set { RelativeMessageId = value.IsSpecified ? value.Value.Id : Optional.Create<ulong>(); } } | |||
| public Direction RelativeDirection { internal get; set; } = Direction.Before; | |||
| internal Optional<ulong> _relativeMessageId; | |||
| public ulong RelativeMessageId { set { _relativeMessageId = value; } } | |||
| public IMessage RelativeMessage { set { _relativeMessageId = value.Id; } } | |||
| } | |||
| } | |||
| @@ -2,7 +2,10 @@ | |||
| { | |||
| public class GetGuildMembersParams | |||
| { | |||
| public Optional<int> Limit { get; set; } | |||
| public Optional<ulong> AfterUserId { get; set; } | |||
| internal Optional<int> _limit; | |||
| public int Limit { set { _limit = value; } } | |||
| internal Optional<ulong> _afterUserId; | |||
| public ulong AfterUserId { set { _afterUserId = value; } } | |||
| } | |||
| } | |||
| @@ -2,9 +2,10 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class GuildPruneParams | |||
| { | |||
| [JsonProperty("days")] | |||
| public int Days = 30; | |||
| public int Days { internal get; set; } | |||
| } | |||
| } | |||
| @@ -2,11 +2,13 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyChannelPermissionsParams | |||
| { | |||
| [JsonProperty("allow")] | |||
| public Optional<ulong> Allow { get; set; } | |||
| public ulong Allow { internal get; set; } | |||
| [JsonProperty("deny")] | |||
| public Optional<ulong> Deny { get; set; } | |||
| public ulong Deny { internal get; set; } | |||
| } | |||
| } | |||
| @@ -2,9 +2,10 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyCurrentUserNickParams | |||
| { | |||
| [JsonProperty("nick")] | |||
| public string Nickname { get; set; } | |||
| public string Nickname { internal get; set; } | |||
| } | |||
| } | |||
| @@ -3,24 +3,15 @@ using System.IO; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyCurrentUserParams | |||
| { | |||
| [JsonProperty("username")] | |||
| public Optional<string> Username { get; set; } | |||
| internal Optional<string> _username; | |||
| public string Username { set { _username = value; } } | |||
| [JsonProperty("avatar")] | |||
| private Optional<Image> _avatar { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<Stream> Avatar | |||
| { | |||
| get { return _avatar.IsSpecified ? _avatar.Value.Stream : null; } | |||
| set { _avatar = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| [JsonIgnore] | |||
| internal Optional<string> AvatarHash | |||
| { | |||
| get { return _avatar.IsSpecified ? _avatar.Value.Hash : null; } | |||
| set { _avatar = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| internal Optional<Image> _avatar; | |||
| public Stream Avatar { set { _avatar = new Image(value); } } | |||
| } | |||
| } | |||
| @@ -2,11 +2,15 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildChannelParams | |||
| { | |||
| [JsonProperty("name")] | |||
| public Optional<string> Name { get; set; } | |||
| internal Optional<string> _name; | |||
| public string Name { set { _name = value; } } | |||
| [JsonProperty("position")] | |||
| public Optional<int> Position { get; set; } | |||
| internal Optional<int> _position; | |||
| public int Position { set { _position = value; } } | |||
| } | |||
| } | |||
| @@ -2,11 +2,13 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildChannelsParams | |||
| { | |||
| [JsonProperty("id")] | |||
| public ulong Id { get; set; } | |||
| public ulong Id { internal get; set; } | |||
| [JsonProperty("position")] | |||
| public Optional<int> Position { get; set; } | |||
| public int Position { internal get; set; } | |||
| } | |||
| } | |||
| @@ -2,14 +2,16 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildEmbedParams | |||
| { | |||
| [JsonProperty("enabled")] | |||
| public Optional<bool> Enabled { get; set; } | |||
| internal Optional<bool> _enabled; | |||
| public bool Enabled { set { _enabled = value; } } | |||
| [JsonProperty("channel")] | |||
| public Optional<ulong> ChannelId { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<IVoiceChannel> Channel { set { ChannelId = value.IsSpecified ? value.Value.Id : Optional.Create<ulong>(); } } | |||
| internal Optional<ulong?> _channelId; | |||
| public ulong? ChannelId { set { _channelId = value; } } | |||
| public IVoiceChannel Channel { set { _channelId = value != null ? value.Id : (ulong?)null; } } | |||
| } | |||
| } | |||
| @@ -2,13 +2,19 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildIntegrationParams | |||
| { | |||
| [JsonProperty("expire_behavior")] | |||
| public Optional<int> ExpireBehavior { get; set; } | |||
| internal Optional<int> _expireBehavior; | |||
| public int ExpireBehavior { set { _expireBehavior = value; } } | |||
| [JsonProperty("expire_grace_period")] | |||
| public Optional<int> ExpireGracePeriod { get; set; } | |||
| internal Optional<int> _expireGracePeriod; | |||
| public int ExpireGracePeriod { set { _expireGracePeriod = value; } } | |||
| [JsonProperty("enable_emoticons")] | |||
| public Optional<bool> EnableEmoticons { get; set; } | |||
| internal Optional<bool> _enableEmoticons; | |||
| public bool EnableEmoticons { set { _enableEmoticons = value; } } | |||
| } | |||
| } | |||
| @@ -4,23 +4,29 @@ using System.Linq; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildMemberParams | |||
| { | |||
| [JsonProperty("mute")] | |||
| public Optional<bool> Mute { get; set; } | |||
| internal Optional<bool> _mute; | |||
| public bool Mute { set { _mute = value; } } | |||
| [JsonProperty("deaf")] | |||
| public Optional<bool> Deaf { get; set; } | |||
| internal Optional<bool> _deaf; | |||
| public bool Deaf { set { _deaf = value; } } | |||
| [JsonProperty("nick")] | |||
| public Optional<string> Nickname { get; set; } | |||
| internal Optional<string> _nickname; | |||
| public string Nickname { set { _nickname = value; } } | |||
| [JsonProperty("roles")] | |||
| public Optional<IEnumerable<ulong>> RoleIds { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<IEnumerable<IRole>> Roles { set { RoleIds = value.IsSpecified ? Optional.Create(value.Value.Select(x => x.Id)) : Optional.Create<IEnumerable<ulong>>(); } } | |||
| internal Optional<ulong[]> _roleIds; | |||
| public IEnumerable<ulong> RoleIds { set { _roleIds = value.ToArray(); } } | |||
| public IEnumerable<IRole> Roles { set { _roleIds = value.Select(x => x.Id).ToArray(); } } | |||
| [JsonProperty("channel_id")] | |||
| public Optional<ulong> VoiceChannelId { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<IVoiceChannel> VoiceChannel { set { VoiceChannelId = value.IsSpecified ? value.Value.Id : Optional.Create<ulong>(); } } | |||
| internal Optional<ulong> _channelId; | |||
| public ulong VoiceChannelId { set { _channelId = value; } } | |||
| public IVoiceChannel VoiceChannel { set { _channelId = value.Id; } } | |||
| } | |||
| } | |||
| @@ -3,60 +3,49 @@ using System.IO; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildParams | |||
| { | |||
| [JsonProperty("username")] | |||
| public Optional<string> Username { get; set; } | |||
| internal Optional<string> _username; | |||
| public string Username { set { _username = value; } } | |||
| [JsonProperty("name")] | |||
| public Optional<string> Name { get; set; } | |||
| internal Optional<string> _name; | |||
| public string Name { set { _name = value; } } | |||
| [JsonProperty("region")] | |||
| public Optional<IVoiceRegion> Region { get; set; } | |||
| internal Optional<IVoiceRegion> _region; | |||
| public IVoiceRegion Region { set { _region = Optional.Create(value); } } | |||
| [JsonProperty("verification_level")] | |||
| public Optional<VerificationLevel> VerificationLevel { get; set; } | |||
| internal Optional<VerificationLevel> _verificationLevel; | |||
| public VerificationLevel VerificationLevel { set { _verificationLevel = value; } } | |||
| [JsonProperty("default_message_notifications")] | |||
| public Optional<DefaultMessageNotifications> DefaultMessageNotifications { get; set; } | |||
| internal Optional<DefaultMessageNotifications> _defaultMessageNotifications; | |||
| public DefaultMessageNotifications DefaultMessageNotifications { set { _defaultMessageNotifications = value; } } | |||
| [JsonProperty("afk_timeout")] | |||
| public Optional<int> AFKTimeout { get; set; } | |||
| internal Optional<int> _afkTimeout; | |||
| public int AFKTimeout { set { _afkTimeout = value; } } | |||
| [JsonProperty("icon")] | |||
| private Optional<Image> _icon { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<Stream> Icon | |||
| { | |||
| get { return _icon.IsSpecified ? _icon.Value.Stream : null; } | |||
| set { _icon = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| [JsonIgnore] | |||
| internal Optional<string> IconHash | |||
| { | |||
| get { return _icon.IsSpecified ? _icon.Value.Hash : null; } | |||
| set { _icon = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| internal Optional<Image?> _icon; | |||
| public Stream Icon { set { _icon = value != null ? new Image(value) : (Image?)null; } } | |||
| [JsonProperty("splash")] | |||
| private Optional<Image> _splash { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<Stream> Splash | |||
| { | |||
| get { return _splash.IsSpecified ? _splash.Value.Stream : null; } | |||
| set { _splash = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| [JsonIgnore] | |||
| internal Optional<string> SplashHash | |||
| { | |||
| get { return _splash.IsSpecified ? _splash.Value.Hash : null; } | |||
| set { _splash = value.IsSpecified ? new Image(value.Value) : Optional.Create<Image>(); } | |||
| } | |||
| internal Optional<Image?> _splash; | |||
| public Stream Splash { set { _splash = value != null ? new Image(value) : (Image?)null; } } | |||
| [JsonProperty("afk_channel_id")] | |||
| public Optional<ulong?> AFKChannelId { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<IVoiceChannel> AFKChannel { set { OwnerId = value.IsSpecified ? value.Value.Id : Optional.Create<ulong>(); } } | |||
| internal Optional<ulong?> _afkChannelId; | |||
| public ulong? AFKChannelId { set { _afkChannelId = value; } } | |||
| public IVoiceChannel AFKChannel { set { _afkChannelId = value?.Id; } } | |||
| [JsonProperty("owner_id")] | |||
| public Optional<ulong> OwnerId { get; set; } | |||
| [JsonIgnore] | |||
| public Optional<IGuildUser> Owner { set { OwnerId = value.IsSpecified ? value.Value.Id : Optional.Create<ulong>(); } } | |||
| internal Optional<ulong> _ownerId; | |||
| public ulong OwnerId { set { _ownerId = value; } } | |||
| public IGuildUser Owner { set { _ownerId = value.Id; } } | |||
| } | |||
| } | |||
| @@ -2,17 +2,27 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildRoleParams | |||
| { | |||
| [JsonProperty("name")] | |||
| public Optional<string> Name { get; set; } | |||
| internal Optional<string> _name; | |||
| public string Name { set { _name = value; } } | |||
| [JsonProperty("permissions")] | |||
| public Optional<ulong> Permissions { get; set; } | |||
| internal Optional<ulong> _permissions; | |||
| public ulong Permissions { set { _permissions = value; } } | |||
| [JsonProperty("position")] | |||
| public Optional<int> Position { get; set; } | |||
| internal Optional<int> _position; | |||
| public int Position { set { _position = value; } } | |||
| [JsonProperty("color")] | |||
| public Optional<uint> Color { get; set; } | |||
| internal Optional<uint> _color; | |||
| public uint Color { set { _color = value; } } | |||
| [JsonProperty("hoist")] | |||
| public Optional<bool> Hoist { get; set; } | |||
| internal Optional<bool> _hoist; | |||
| public bool Hoist { set { _hoist = value; } } | |||
| } | |||
| } | |||
| @@ -2,9 +2,10 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyGuildRolesParams : ModifyGuildRoleParams | |||
| { | |||
| [JsonProperty("id")] | |||
| public ulong Id { get; set; } | |||
| public ulong Id { internal get; set; } | |||
| } | |||
| } | |||
| @@ -2,9 +2,11 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyMessageParams | |||
| { | |||
| [JsonProperty("content")] | |||
| public Optional<string> Content { get; set; } = ""; | |||
| internal Optional<string> _content; | |||
| public string Content { set { _content = value; } } | |||
| } | |||
| } | |||
| @@ -2,7 +2,10 @@ | |||
| { | |||
| public class ModifyPresenceParams | |||
| { | |||
| public Optional<UserStatus> Status { get; set; } | |||
| public Optional<Discord.Game> Game { get; set; } | |||
| internal Optional<UserStatus> _status; | |||
| public UserStatus Status { set { _status = value; } } | |||
| internal Optional<Discord.Game> _game; | |||
| public Discord.Game Game { set { _game = value; } } | |||
| } | |||
| } | |||
| @@ -2,9 +2,11 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyTextChannelParams : ModifyGuildChannelParams | |||
| { | |||
| [JsonProperty("topic")] | |||
| public Optional<string> Topic { get; set; } | |||
| internal Optional<string> _topic; | |||
| public string Topic { set { _topic = value; } } | |||
| } | |||
| } | |||
| @@ -2,11 +2,15 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||
| public class ModifyVoiceChannelParams : ModifyGuildChannelParams | |||
| { | |||
| [JsonProperty("bitrate")] | |||
| public Optional<int> Bitrate { get; set; } | |||
| internal Optional<int> _bitrate; | |||
| public int Bitrate { set { _bitrate = value; } } | |||
| [JsonProperty("user_limit")] | |||
| public Optional<int> UserLimit { get; set; } | |||
| internal Optional<int> _userLimit; | |||
| public int UserLimit { set { _userLimit = value; } } | |||
| } | |||
| } | |||
| @@ -6,28 +6,35 @@ namespace Discord.API.Rest | |||
| { | |||
| public class UploadFileParams | |||
| { | |||
| public Stream File { get; set; } | |||
| public string Filename { get; set; } = "unknown.dat"; | |||
| public Stream File { internal get; set; } | |||
| public Optional<string> Content { get; set; } | |||
| public Optional<string> Nonce { get; set; } | |||
| public Optional<bool> IsTTS { get; set; } | |||
| internal Optional<string> _filename; | |||
| public string Filename { set { _filename = value; } } | |||
| internal Optional<string> _content; | |||
| public string Content { set { _content = value; } } | |||
| internal Optional<string> _nonce; | |||
| public string Nonce { set { _nonce = value; } } | |||
| internal Optional<bool> _isTTS; | |||
| public bool IsTTS { set { _isTTS = value; } } | |||
| public UploadFileParams(Stream file) | |||
| { | |||
| File = file; | |||
| } | |||
| public IReadOnlyDictionary<string, object> ToDictionary() | |||
| internal IReadOnlyDictionary<string, object> ToDictionary() | |||
| { | |||
| var d = new Dictionary<string, object>(); | |||
| d["file"] = new MultipartFile(File, Filename); | |||
| if (Content.IsSpecified) | |||
| d["content"] = Content.Value; | |||
| if (IsTTS.IsSpecified) | |||
| d["tts"] = IsTTS.Value.ToString(); | |||
| if (Nonce.IsSpecified) | |||
| d["nonce"] = Nonce.Value; | |||
| d["file"] = new MultipartFile(File, _filename.GetValueOrDefault("unknown.dat")); | |||
| if (_content.IsSpecified) | |||
| d["content"] = _content.Value; | |||
| if (_isTTS.IsSpecified) | |||
| d["tts"] = _isTTS.Value.ToString(); | |||
| if (_nonce.IsSpecified) | |||
| d["nonce"] = _nonce.Value; | |||
| return d; | |||
| } | |||
| } | |||
| @@ -56,8 +56,8 @@ namespace Discord | |||
| var args = new ModifyGuildChannelParams(); | |||
| func(args); | |||
| if (!args.Name.IsSpecified) | |||
| args.Name = Name; | |||
| if (!args._name.IsSpecified) | |||
| args._name = Name; | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| @@ -37,8 +37,8 @@ namespace Discord | |||
| var args = new ModifyTextChannelParams(); | |||
| func(args); | |||
| if (!args.Name.IsSpecified) | |||
| args.Name = Name; | |||
| if (!args._name.IsSpecified) | |||
| args._name = Name; | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| @@ -34,8 +34,8 @@ namespace Discord | |||
| var args = new ModifyVoiceChannelParams(); | |||
| func(args); | |||
| if (!args.Name.IsSpecified) | |||
| args.Name = Name; | |||
| if (!args._name.IsSpecified) | |||
| args._name = Name; | |||
| var model = await Discord.ApiClient.ModifyGuildChannelAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| @@ -122,10 +122,10 @@ namespace Discord | |||
| var args = new ModifyGuildParams(); | |||
| func(args); | |||
| if (args.Splash.IsSpecified && _splashId != null) | |||
| args.SplashHash = _splashId; | |||
| if (args.Icon.IsSpecified && _iconId != null) | |||
| args.IconHash = _iconId; | |||
| if (args._splash.IsSpecified && _splashId != null) | |||
| args._splash = new API.Image(_splashId); | |||
| if (args._icon.IsSpecified && _iconId != null) | |||
| args._icon = new API.Image(_iconId); | |||
| var model = await Discord.ApiClient.ModifyGuildAsync(Id, args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| @@ -165,7 +165,7 @@ namespace Discord | |||
| public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); | |||
| public async Task AddBanAsync(ulong userId, int pruneDays = 0) | |||
| { | |||
| var args = new CreateGuildBanParams() { PruneDays = pruneDays }; | |||
| var args = new CreateGuildBanParams() { DeleteMessageDays = pruneDays }; | |||
| await Discord.ApiClient.CreateGuildBanAsync(Id, userId, args).ConfigureAwait(false); | |||
| } | |||
| public Task RemoveBanAsync(IUser user) => RemoveBanAsync(user.Id); | |||
| @@ -51,6 +51,7 @@ namespace Discord | |||
| var args = new ModifyGuildRoleParams(); | |||
| func(args); | |||
| var response = await Discord.ApiClient.ModifyGuildRoleAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| Update(response, UpdateSource.Rest); | |||
| } | |||
| public async Task DeleteAsync() | |||
| @@ -77,6 +77,15 @@ namespace Discord | |||
| if (model.Nick.IsSpecified) | |||
| Nickname = model.Nick.Value; | |||
| } | |||
| private void Update(ModifyGuildMemberParams args, UpdateSource source) | |||
| { | |||
| if (source == UpdateSource.Rest && IsAttached) return; | |||
| if (args._roleIds.IsSpecified) | |||
| Roles = args._roleIds.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray(); | |||
| if (args._nickname.IsSpecified) | |||
| Nickname = args._nickname.Value ?? ""; | |||
| } | |||
| private void UpdateRoles(ulong[] roleIds) | |||
| { | |||
| var roles = ImmutableArray.CreateBuilder<Role>(roleIds.Length + 1); | |||
| @@ -106,20 +115,17 @@ namespace Discord | |||
| func(args); | |||
| bool isCurrentUser = (await Discord.GetCurrentUserAsync().ConfigureAwait(false)).Id == Id; | |||
| if (isCurrentUser && args.Nickname.IsSpecified) | |||
| if (isCurrentUser && args._nickname.IsSpecified) | |||
| { | |||
| var nickArgs = new ModifyCurrentUserNickParams { Nickname = args.Nickname.Value ?? "" }; | |||
| var nickArgs = new ModifyCurrentUserNickParams { Nickname = args._nickname.Value ?? "" }; | |||
| await Discord.ApiClient.ModifyMyNickAsync(Guild.Id, nickArgs).ConfigureAwait(false); | |||
| args.Nickname = new Optional<string>(); //Remove | |||
| args._nickname = Optional.Create<string>(); //Remove | |||
| } | |||
| if (!isCurrentUser || args.Deaf.IsSpecified || args.Mute.IsSpecified || args.RoleIds.IsSpecified) | |||
| if (!isCurrentUser || args._deaf.IsSpecified || args._mute.IsSpecified || args._roleIds.IsSpecified) | |||
| { | |||
| await Discord.ApiClient.ModifyGuildMemberAsync(Guild.Id, Id, args).ConfigureAwait(false); | |||
| if (args.Nickname.IsSpecified) | |||
| Nickname = args.Nickname.Value ?? ""; | |||
| if (args.RoleIds.IsSpecified) | |||
| Roles = args.RoleIds.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray(); | |||
| Update(args, UpdateSource.Rest); | |||
| } | |||
| } | |||
| public async Task KickAsync() | |||
| @@ -53,10 +53,10 @@ namespace Discord | |||
| var args = new ModifyCurrentUserParams(); | |||
| func(args); | |||
| if (!args.Username.IsSpecified) | |||
| args.Username = Username; | |||
| if (args.Avatar.IsSpecified && _avatarId != null) | |||
| args.AvatarHash = _avatarId; | |||
| if (!args._username.IsSpecified) | |||
| args._username = Username; | |||
| if (!args._avatar.IsSpecified && _avatarId != null) | |||
| args._avatar = new API.Image(_avatarId); | |||
| var model = await Discord.ApiClient.ModifySelfAsync(args).ConfigureAwait(false); | |||
| Update(model, UpdateSource.Rest); | |||
| @@ -68,8 +68,8 @@ namespace Discord | |||
| var args = new ModifyPresenceParams(); | |||
| func(args); | |||
| var game = args.Game.GetValueOrDefault(_game); | |||
| var status = args.Status.GetValueOrDefault(_status); | |||
| var game = args._game.GetValueOrDefault(_game); | |||
| var status = args._status.GetValueOrDefault(_status); | |||
| long idleSince = _idleSince; | |||
| if (status == UserStatus.Idle && _status != UserStatus.Idle) | |||
| @@ -48,17 +48,18 @@ namespace Discord | |||
| return cachedMessages.Skip(cachedMessages.Count - limit).ToImmutableArray(); | |||
| else | |||
| { | |||
| Optional<ulong> relativeId; | |||
| if (cachedMessages.Count == 0) | |||
| relativeId = fromId ?? new Optional<ulong>(); | |||
| else | |||
| relativeId = dir == Direction.Before ? cachedMessages[0].Id : cachedMessages[cachedMessages.Count - 1].Id; | |||
| var args = new GetChannelMessagesParams | |||
| { | |||
| Limit = limit - cachedMessages.Count, | |||
| RelativeDirection = dir, | |||
| RelativeMessageId = relativeId | |||
| RelativeDirection = dir | |||
| }; | |||
| if (cachedMessages.Count == 0) | |||
| { | |||
| if (fromId != null) | |||
| args.RelativeMessageId = fromId.Value; | |||
| } | |||
| else | |||
| args.RelativeMessageId = dir == Direction.Before ? cachedMessages[0].Id : cachedMessages[cachedMessages.Count - 1].Id; | |||
| var downloadedMessages = await _discord.ApiClient.GetChannelMessagesAsync(_channel.Id, args).ConfigureAwait(false); | |||
| var guild = (_channel as ISocketGuildChannel)?.Guild; | |||
| @@ -9,11 +9,11 @@ namespace Discord.Extensions | |||
| public static Task AddRolesAsync(this IGuildUser user, params IRole[] roles) | |||
| => AddRolesAsync(user, (IEnumerable<IRole>)roles); | |||
| public static Task AddRolesAsync(this IGuildUser user, IEnumerable<IRole> roles) | |||
| => user.ModifyAsync(x => x.Roles = Optional.Create(user.Roles.Concat(roles))); | |||
| => user.ModifyAsync(x => x.Roles = user.Roles.Concat(roles)); | |||
| public static Task RemoveRolesAsync(this IGuildUser user, params IRole[] roles) | |||
| => RemoveRolesAsync(user, (IEnumerable<IRole>)roles); | |||
| public static Task RemoveRolesAsync(this IGuildUser user, IEnumerable<IRole> roles) | |||
| => user.ModifyAsync(x => x.Roles = Optional.Create(user.Roles.Except(roles))); | |||
| => user.ModifyAsync(x => x.Roles = user.Roles.Except(roles)); | |||
| } | |||
| } | |||