Cleaned up new params

This commit is contained in:
RogueException
2016-12-16 11:11:07 -04:00
parent 3fc043132b
commit 86d9f52438
11 changed files with 106 additions and 28 deletions

View File

@@ -27,16 +27,31 @@ namespace Discord.Rest
AfkChannelId = args.AfkChannelId,
AfkTimeout = args.AfkTimeout,
DefaultMessageNotifications = args.DefaultMessageNotifications,
Icon = args.Icon.IsSpecified ? ImageModel.Create(args.Icon.Value) : Optional.Create<ImageModel?>(),
Name = args.Name,
OwnerId = args.OwnerId,
RegionId = args.RegionId,
Splash = args.Splash.IsSpecified ? ImageModel.Create(args.Splash.Value) : Optional.Create<ImageModel?>(),
Username = args.Username,
VerificationLevel = args.VerificationLevel
};
if (apiArgs.Splash.IsSpecified && guild.SplashId != null)
if (args.AfkChannel.IsSpecified)
apiArgs.AfkChannelId = args.AfkChannel.Value.Id;
else if (args.AfkChannelId.IsSpecified)
apiArgs.AfkChannelId = args.AfkChannelId.Value;
if (args.Owner.IsSpecified)
apiArgs.OwnerId = args.Owner.Value.Id;
else if (args.OwnerId.IsSpecified)
apiArgs.OwnerId = args.OwnerId.Value;
if (args.Region.IsSpecified)
apiArgs.RegionId = args.Region.Value.Id;
else if (args.RegionId.IsSpecified)
apiArgs.RegionId = args.RegionId.Value;
if (!apiArgs.Splash.IsSpecified && guild.SplashId != null)
apiArgs.Splash = new ImageModel(guild.SplashId);
if (apiArgs.Icon.IsSpecified && guild.IconId != null)
if (!apiArgs.Icon.IsSpecified && guild.IconId != null)
apiArgs.Icon = new ImageModel(guild.IconId);
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
@@ -50,9 +65,14 @@ namespace Discord.Rest
func(args);
var apiArgs = new API.Rest.ModifyGuildEmbedParams
{
ChannelId = args.ChannelId,
Enabled = args.Enabled
};
if (args.Channel.IsSpecified)
apiArgs.ChannelId = args.Channel.Value?.Id;
else if (args.ChannelId.IsSpecified)
apiArgs.ChannelId = args.ChannelId.Value;
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
}
public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client,
@@ -74,32 +94,32 @@ namespace Discord.Rest
});
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
}
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false);
}
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
}
//Bans
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray();
}
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId, int pruneDays, RequestOptions options)
{
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays };
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false);
}
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
}
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId, RequestOptions options)
{
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
@@ -114,7 +134,7 @@ namespace Discord.Rest
return RestGuildChannel.Create(client, guild, model);
return null;
}
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false);
@@ -140,7 +160,7 @@ namespace Discord.Rest
}
//Integrations
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id, options).ConfigureAwait(false);
@@ -155,7 +175,7 @@ namespace Discord.Rest
}
//Invites
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);
@@ -191,7 +211,7 @@ namespace Discord.Rest
return RestGuildUser.Create(client, guild, model);
return null;
}
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false);

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Model = Discord.API.GuildMember;
@@ -30,7 +31,7 @@ namespace Discord.Rest
}
}
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
internal RestGuildUser(BaseDiscordClient discord, IGuild guild, ulong id)
@@ -61,21 +62,25 @@ namespace Discord.Rest
roles.Add(roleIds[i]);
_roleIds = roles.ToImmutable();
}
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options).ConfigureAwait(false);
Update(model);
}
public async Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null)
{
{
var args = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
if (args.Deaf.IsSpecified)
IsDeafened = args.Deaf.Value;
if (args.Mute.IsSpecified)
IsMuted = args.Mute.Value;
if (args.RoleIds.IsSpecified)
UpdateRoles(args.RoleIds.Value);
if (args.Nickname.IsSpecified)
Nickname = args.Nickname.Value;
if (args.Roles.IsSpecified)
UpdateRoles(args.Roles.Value.Select(x => x.Id).ToArray());
else if (args.RoleIds.IsSpecified)
UpdateRoles(args.RoleIds.Value.ToArray());
}
public Task KickAsync(RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, options);

View File

@@ -16,9 +16,13 @@ namespace Discord.Rest
func(args);
var apiArgs = new API.Rest.ModifyCurrentUserParams
{
Avatar = args.Avatar.IsSpecified ? ImageModel.Create(args.Avatar.Value) : Optional.Create<ImageModel>(),
Avatar = args.Avatar.IsSpecified ? ImageModel.Create(args.Avatar.Value) : Optional.Create<ImageModel?>(),
Username = args.Username
};
if (!apiArgs.Avatar.IsSpecified && user.AvatarId != null)
apiArgs.Avatar = new ImageModel(user.AvatarId);
return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false);
}
public static async Task<ModifyGuildMemberParams> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func,
@@ -31,9 +35,14 @@ namespace Discord.Rest
ChannelId = args.Channel.IsSpecified ? args.Channel.Value.Id : Optional.Create<ulong>(),
Deaf = args.Deaf,
Mute = args.Mute,
Nickname = args.Nickname,
RoleIds = args.Roles.IsSpecified ? args.Roles.Value.Select(r => r.Id).ToArray() : Optional.Create<ulong[]>(),
Nickname = args.Nickname
};
if (args.Roles.IsSpecified)
apiArgs.RoleIds = args.Roles.Value.Select(x => x.Id).ToArray();
else if (args.RoleIds.IsSpecified)
apiArgs.RoleIds = args.RoleIds.Value.ToArray();
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);
return args;
}