| @@ -2,14 +2,14 @@ | |||
| namespace Discord | |||
| { | |||
| internal static class DateTimeUtils | |||
| { | |||
| public static DateTimeOffset FromSnowflake(ulong value) | |||
| => DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||
| internal static class DateTimeUtils | |||
| { | |||
| public static DateTimeOffset FromSnowflake(ulong value) | |||
| => DateTimeOffset.FromUnixTimeMilliseconds((long)((value >> 22) + 1420070400000UL)); | |||
| public static DateTimeOffset FromTicks(long ticks) | |||
| => new DateTimeOffset(ticks, TimeSpan.Zero); | |||
| public static DateTimeOffset? FromTicks(long? ticks) | |||
| => ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null; | |||
| } | |||
| public static DateTimeOffset FromTicks(long ticks) | |||
| => new DateTimeOffset(ticks, TimeSpan.Zero); | |||
| public static DateTimeOffset? FromTicks(long? ticks) | |||
| => ticks != null ? new DateTimeOffset(ticks.Value, TimeSpan.Zero) : (DateTimeOffset?)null; | |||
| } | |||
| } | |||
| @@ -17,29 +17,29 @@ namespace Discord.Rest | |||
| { | |||
| await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); | |||
| } | |||
| public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, | |||
| public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client, | |||
| Action<ModifyGuildChannelParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyGuildChannelParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| } | |||
| public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, | |||
| public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client, | |||
| Action<ModifyTextChannelParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyTextChannelParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| } | |||
| public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, | |||
| public static async Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, | |||
| Action<ModifyVoiceChannelParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyVoiceChannelParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); | |||
| } | |||
| //Invites | |||
| @@ -54,8 +54,11 @@ namespace Discord.Rest | |||
| var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options); | |||
| Update(model); | |||
| } | |||
| public Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null) | |||
| => ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| public async Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public Task DeleteAsync(RequestOptions options = null) | |||
| => ChannelHelper.DeleteAsync(this, Discord, options); | |||
| @@ -33,9 +33,11 @@ namespace Discord.Rest | |||
| Topic = model.Topic.Value; | |||
| } | |||
| public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null) | |||
| => ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| public async Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null) | |||
| => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); | |||
| @@ -33,8 +33,11 @@ namespace Discord.Rest | |||
| UserLimit = model.UserLimit.Value; | |||
| } | |||
| public Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null) | |||
| => ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| public async Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await ChannelHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | |||
| @@ -6,6 +6,8 @@ using System.Collections.Immutable; | |||
| using System.Diagnostics; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.Guild; | |||
| using EmbedModel = Discord.API.GuildEmbed; | |||
| using System.Linq; | |||
| namespace Discord.Rest | |||
| { | |||
| @@ -90,6 +92,11 @@ namespace Discord.Rest | |||
| Available = true; | |||
| } | |||
| internal void Update(EmbedModel model) | |||
| { | |||
| EmbedChannelId = model.ChannelId; | |||
| IsEmbeddable = model.Enabled; | |||
| } | |||
| //General | |||
| public async Task UpdateAsync(RequestOptions options = null) | |||
| @@ -97,14 +104,31 @@ namespace Discord.Rest | |||
| public Task DeleteAsync(RequestOptions options = null) | |||
| => GuildHelper.DeleteAsync(this, Discord, options); | |||
| public Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null) | |||
| => GuildHelper.ModifyAsync(this, Discord, func, options); | |||
| public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null) | |||
| => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); | |||
| public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null) | |||
| => GuildHelper.ModifyChannelsAsync(this, Discord, args, options); | |||
| public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null) | |||
| => GuildHelper.ModifyRolesAsync(this, Discord, args, options); | |||
| public async Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await GuildHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public async Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public async Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null) | |||
| { | |||
| var arr = args.ToArray(); | |||
| await GuildHelper.ModifyChannelsAsync(this, Discord, arr, options); | |||
| } | |||
| public async Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null) | |||
| { | |||
| var models = await GuildHelper.ModifyRolesAsync(this, Discord, args, options); | |||
| foreach (var model in models) | |||
| { | |||
| var role = GetRole(model.Id); | |||
| if (role != null) | |||
| role.Update(model); | |||
| } | |||
| } | |||
| public Task LeaveAsync(RequestOptions options = null) | |||
| => GuildHelper.LeaveAsync(this, Discord, options); | |||
| @@ -3,19 +3,19 @@ using System; | |||
| using System.Collections.Generic; | |||
| using System.Collections.Immutable; | |||
| using System.Linq; | |||
| using System.Text.RegularExpressions; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.Message; | |||
| namespace Discord.Rest | |||
| { | |||
| internal static class MessageHelper | |||
| { | |||
| public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func, | |||
| public static async Task<Model> ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyMessageParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, args, options); | |||
| return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, args, options); | |||
| } | |||
| public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client, | |||
| RequestOptions options) | |||
| @@ -111,8 +111,11 @@ namespace Discord.Rest | |||
| } | |||
| } | |||
| public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options) | |||
| => MessageHelper.ModifyAsync(this, Discord, func, options); | |||
| public async Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options) | |||
| { | |||
| var model = await MessageHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public Task DeleteAsync(RequestOptions options) | |||
| => MessageHelper.DeleteAsync(this, Discord, options); | |||
| @@ -40,8 +40,11 @@ namespace Discord.Rest | |||
| Permissions = new GuildPermissions(model.Permissions); | |||
| } | |||
| public Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null) | |||
| => RoleHelper.ModifyAsync(this, Discord, func, options); | |||
| public async Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null) | |||
| { | |||
| var model = await RoleHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| public Task DeleteAsync(RequestOptions options = null) | |||
| => RoleHelper.DeleteAsync(this, Discord, options); | |||
| @@ -1,6 +1,7 @@ | |||
| using Discord.API.Rest; | |||
| using System; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.Role; | |||
| namespace Discord.Rest | |||
| { | |||
| @@ -12,12 +13,12 @@ namespace Discord.Rest | |||
| { | |||
| await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); | |||
| } | |||
| public static async Task ModifyAsync(IRole role, BaseDiscordClient client, | |||
| public static async Task<Model> ModifyAsync(IRole role, BaseDiscordClient client, | |||
| Action<ModifyGuildRoleParams> func, RequestOptions options) | |||
| { | |||
| var args = new ModifyGuildRoleParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options); | |||
| return await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options); | |||
| } | |||
| } | |||
| } | |||
| @@ -47,7 +47,8 @@ namespace Discord.Rest | |||
| { | |||
| if (Id != Discord.CurrentUser.Id) | |||
| throw new InvalidOperationException("Unable to modify this object using a different token."); | |||
| await UserHelper.ModifyAsync(this, Discord, func, options); | |||
| var model = await UserHelper.ModifyAsync(this, Discord, func, options); | |||
| Update(model); | |||
| } | |||
| Task ISelfUser.ModifyStatusAsync(Action<ModifyPresenceParams> func, RequestOptions options) { throw new NotSupportedException(); } | |||
| @@ -1,24 +1,26 @@ | |||
| using Discord.API.Rest; | |||
| using System; | |||
| using System.Threading.Tasks; | |||
| using Model = Discord.API.User; | |||
| namespace Discord.Rest | |||
| { | |||
| internal static class UserHelper | |||
| { | |||
| public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func, | |||
| public static async Task<Model> ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyCurrentUserParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifySelfAsync(args, options); | |||
| return await client.ApiClient.ModifySelfAsync(args, options); | |||
| } | |||
| public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func, | |||
| public static async Task<ModifyGuildMemberParams> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func, | |||
| RequestOptions options) | |||
| { | |||
| var args = new ModifyGuildMemberParams(); | |||
| func(args); | |||
| await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options); | |||
| return args; | |||
| } | |||
| public static async Task KickAsync(IGuildUser user, BaseDiscordClient client, | |||